Hello again!
Trying to modify an integration I found that creates animated lighting scenes.
Currently, it only works via the configuration.yaml, and I was thinking that it’d be kind of nice to have it accessible through the actual UI, if it’s not too big of a PITA.
Of course, when I try to convert the schema from the one used for parsing configuration.yaml, I get a number of errors related to trying to use vol.any and some other things.
Here is the original PLATFORM_SCHEMA:
PLATFORM_SCHEMA = vol.Schema({
vol.Required(CONF_PLATFORM): 'animated_scenes',
vol.Optional(CONF_NAME, default="Animated Scene"): cv.string,
vol.Optional(CONF_LIGHTS): cv.entity_ids,
vol.Optional(CONF_IGNORE_OFF, default=True): bool,
vol.Optional(CONF_RESTORE, default=True): bool,
vol.Optional(CONF_COLORS, default=[]): vol.All(
cv.ensure_list, [vol.Any(vol.Schema({
vol.Required(CONF_COLOR_TYPE): CONF_COLOR_RGB,
vol.Required(CONF_COLOR): vol.All([vol.Range(min=0, max=255)]),
vol.Optional(CONF_BRIGHTNESS): vol.Any(vol.Range(min=0, max=255), vol.All([vol.Range(min=0, max=255)])),
vol.Optional(CONF_WEIGHT, default=10): vol.Range(min=0, max=255),
vol.Optional(CONF_ONE_CHANGE_PER_TICK, default=False): bool
}), vol.Schema({
vol.Required(CONF_COLOR_TYPE): CONF_COLOR_XY,
vol.Required(CONF_COLOR): vol.All([vol.Coerce(float), vol.Range(min=0, max=1)]),
vol.Optional(CONF_BRIGHTNESS): vol.Any(vol.Range(min=0, max=255), vol.All([vol.Range(min=0, max=255)])),
vol.Optional(CONF_WEIGHT, default=10): vol.Range(min=0, max=255),
vol.Optional(CONF_ONE_CHANGE_PER_TICK, default=False): bool
}), vol.Schema({
vol.Required(CONF_COLOR_TYPE): CONF_COLOR_HS,
vol.Required(CONF_COLOR): vol.All([vol.Coerce(float), vol.Range(min=0, max=100)]),
vol.Optional(CONF_BRIGHTNESS): vol.Any(vol.Range(min=0, max=255), vol.All([vol.Range(min=0, max=255)])),
vol.Optional(CONF_WEIGHT, default=10): vol.Range(min=0, max=255),
vol.Optional(CONF_ONE_CHANGE_PER_TICK, default=False): bool
}), vol.Schema({
vol.Required(CONF_COLOR_TYPE): CONF_COLOR_TEMP,
vol.Required(CONF_COLOR): vol.All(vol.Coerce(int), vol.Range(min=0, max=250)),
vol.Optional(CONF_BRIGHTNESS): vol.Any(vol.Range(min=0, max=255), vol.All([vol.Range(min=0, max=255)])),
vol.Optional(CONF_WEIGHT, default=10): vol.Range(min=0, max=255),
vol.Optional(CONF_ONE_CHANGE_PER_TICK, default=False): bool
}))]
),
vol.Optional(CONF_TRANSITION, default=1): vol.Any(vol.Range(min=0, max=60), vol.All([vol.Range(min=0, max=60)])),
vol.Optional(CONF_CHANGE_FREQUENCY): vol.Any(vol.Range(min=0, max=60), vol.All([vol.Range(min=0, max=60)])),
vol.Optional(CONF_CHANGE_AMOUNT): vol.Any('all', vol.Range(min=0, max=10), vol.All([vol.Range(min=0, max=10)])),
vol.Optional(CONF_ANIMATE_BRIGHTNESS, default=True): bool,
vol.Optional(CONF_ANIMATE_COLOR, default=True): bool,
vol.Optional(CONF_BRIGHTNESS): vol.Any(vol.Range(min=0, max=255), vol.All([vol.Range(min=0, max=255)]))
})
The first issue it has is with the CONF_COLORS param, which I’m sure is due to the nested values. I created a simple class called ColorObject, which I was hoping to substitute in the definition? But, even if I fix that, I’m still not quite sure how I’d go about presenting a color picker in a list that can be expanded indefinitely.
Similarly, the CONF_LIGHTS values should be populated by filtering all entities by LIGHT type, and then only those that support changing colors.
And then it also appears that the CONF_TRANSITION and CONF_BRIGHTNESS fields can be lists with multiple integer values.
I’m assuming that I will need to break the config flow into several steps - set the “main” params, select target entities, and then set the color objects…but my first hurdle is just creating a schema that can be displayed in a form, for which I’m having trouble even finding basic documentation for.
So, any pointers to lead me in the right direction would be greatly appreciated.