fix bug and use vol.In for entity selection

This commit is contained in:
Bas Nijholt 2020-09-26 18:24:44 +02:00
commit ef04036bfe
3 changed files with 20 additions and 6 deletions

View file

@ -7,7 +7,15 @@ from homeassistant import config_entries
from homeassistant.core import callback
import homeassistant.helpers.config_validation as cv
from .const import CONF_LIGHTS, DOMAIN, EXTRA_VALIDATION, NONE_STR, VALIDATION_TUPLES
from .const import (
CONF_DISABLE_ENTITY,
CONF_LIGHTS,
CONF_SLEEP_ENTITY,
DOMAIN,
EXTRA_VALIDATION,
NONE_STR,
VALIDATION_TUPLES,
)
_LOGGER = logging.getLogger(__name__)
@ -80,12 +88,18 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
if not errors:
return self.async_create_entry(title="", data=user_input)
all_lights = cv.multi_select(self.hass.states.async_entity_ids("light"))
all_lights = sorted(self.hass.states.async_entity_ids("light"))
all_entities = sorted(self.hass.states.async_entity_ids())
to_replace = {
CONF_LIGHTS: cv.multi_select(all_lights),
CONF_DISABLE_ENTITY: vol.In([NONE_STR] + all_entities),
CONF_SLEEP_ENTITY: vol.In([NONE_STR] + all_entities),
}
options_schema = {}
for name, default, validation in VALIDATION_TUPLES:
key = vol.Optional(name, default=conf.options.get(name, default))
value = validation if name != CONF_LIGHTS else all_lights
value = to_replace.get(name, validation)
options_schema[key] = value
return self.async_show_form(

View file

@ -51,7 +51,7 @@ def int_between(a, b):
VALIDATION_TUPLES = [
(CONF_LIGHTS, DEFAULT_LIGHTS, cv.entity_ids),
(CONF_DISABLE_BRIGHTNESS_ADJUST, DEFAULT_DISABLE_BRIGHTNESS_ADJUST, bool),
(CONF_DISABLE_ENTITY, NONE_STR, str),
(CONF_DISABLE_ENTITY, NONE_STR, cv.entity_id),
(CONF_DISABLE_STATE, NONE_STR, str),
(CONF_INITIAL_TRANSITION, DEFAULT_INITIAL_TRANSITION, VALID_TRANSITION),
(CONF_INTERVAL, DEFAULT_INTERVAL, cv.positive_int),
@ -62,7 +62,7 @@ VALIDATION_TUPLES = [
(CONF_ONLY_ONCE, DEFAULT_ONLY_ONCE, bool),
(CONF_SLEEP_BRIGHTNESS, DEFAULT_SLEEP_BRIGHTNESS, int_between(1, 100)),
(CONF_SLEEP_COLOR_TEMP, DEFAULT_SLEEP_COLOR_TEMP, int_between(1000, 10000)),
(CONF_SLEEP_ENTITY, NONE_STR, str),
(CONF_SLEEP_ENTITY, NONE_STR, cv.entity_id),
(CONF_SLEEP_STATE, NONE_STR, str),
(CONF_SUNRISE_OFFSET, DEFAULT_SUNRISE_OFFSET, int),
(CONF_SUNRISE_TIME, NONE_STR, str),

View file

@ -422,7 +422,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
and self.hass.states.get(self._disable_entity).state in self._disable_state
)
async def _adjust_light(self, light, transition, colors_only):
async def _adjust_light(self, light, transition, colors_only=False):
service_data = {ATTR_ENTITY_ID: light}
features = self._supported_features(light)