diff --git a/custom_components/adaptive_lighting/config_flow.py b/custom_components/adaptive_lighting/config_flow.py index fe4867ff..6a340cf9 100644 --- a/custom_components/adaptive_lighting/config_flow.py +++ b/custom_components/adaptive_lighting/config_flow.py @@ -44,6 +44,7 @@ from .const import ( DEFAULT_SUNSET_OFFSET, DEFAULT_TRANSITION, DOMAIN, + FAKE_NONE, ) _LOGGER = logging.getLogger(__name__) @@ -94,8 +95,8 @@ class OptionsFlowHandler(config_entries.OptionsFlow): disable_brightness_adjust = options.get( CONF_DISABLE_BRIGHTNESS_ADJUST, DEFAULT_DISABLE_BRIGHTNESS_ADJUST ) - disable_entity = options.get(CONF_DISABLE_ENTITY, "none") - disable_state = options.get(CONF_DISABLE_STATE, "none") + disable_entity = options.get(CONF_DISABLE_ENTITY, FAKE_NONE) + disable_state = options.get(CONF_DISABLE_STATE, FAKE_NONE) initial_transition = options.get( CONF_INITIAL_TRANSITION, DEFAULT_INITIAL_TRANSITION ) @@ -107,12 +108,12 @@ class OptionsFlowHandler(config_entries.OptionsFlow): only_once = options.get(CONF_ONLY_ONCE, DEFAULT_ONLY_ONCE) sleep_brightness = options.get(CONF_SLEEP_BRIGHTNESS, DEFAULT_SLEEP_BRIGHTNESS) sleep_color_temp = options.get(CONF_SLEEP_COLOR_TEMP, DEFAULT_SLEEP_COLOR_TEMP) - sleep_entity = options.get(CONF_SLEEP_ENTITY, "none") - sleep_state = options.get(CONF_SLEEP_STATE, "none") + sleep_entity = options.get(CONF_SLEEP_ENTITY, FAKE_NONE) + sleep_state = options.get(CONF_SLEEP_STATE, FAKE_NONE) sunrise_offset = options.get(CONF_SUNRISE_OFFSET, DEFAULT_SUNRISE_OFFSET) - sunrise_time = options.get(CONF_SUNRISE_TIME, "none") + sunrise_time = options.get(CONF_SUNRISE_TIME, FAKE_NONE) sunset_offset = options.get(CONF_SUNSET_OFFSET, DEFAULT_SUNSET_OFFSET) - sunset_time = options.get(CONF_SUNSET_TIME, "none") + sunset_time = options.get(CONF_SUNSET_TIME, FAKE_NONE) transition = options.get(CONF_TRANSITION, DEFAULT_TRANSITION) all_lights = self.hass.states.async_entity_ids("light") diff --git a/custom_components/adaptive_lighting/const.py b/custom_components/adaptive_lighting/const.py index 1943de1f..cc6aecd9 100644 --- a/custom_components/adaptive_lighting/const.py +++ b/custom_components/adaptive_lighting/const.py @@ -30,3 +30,4 @@ CONF_SUNSET_TIME = "sunset_time" CONF_TRANSITION, DEFAULT_TRANSITION = "transition", 60 UNDO_UPDATE_LISTENER = "undo_update_listener" +FAKE_NONE = "none" diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index f5258661..ea6b0081 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -83,6 +83,7 @@ from .const import ( DEFAULT_SUNSET_OFFSET, DEFAULT_TRANSITION, DOMAIN, + FAKE_NONE, ICON, SUN_EVENT_MIDNIGHT, SUN_EVENT_NOON, @@ -170,9 +171,9 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): ("_sleep_state", vol.All(cv.ensure_list_csv, [cv.string])), ]: attr = getattr(self, name) - if attr is not None and attr != "none": + if attr is not None and attr != FAKE_NONE: setattr(self, name, validate(attr)) - elif attr == "none": + elif attr == FAKE_NONE: # FIX: Can't use `None` in OptionsFlow. For reasons I do # not understand, I cannot save an option that is empty. setattr(self, name, None)