diff --git a/custom_components/adaptive_lighting/config_flow.py b/custom_components/adaptive_lighting/config_flow.py index 05b81498..af59f121 100644 --- a/custom_components/adaptive_lighting/config_flow.py +++ b/custom_components/adaptive_lighting/config_flow.py @@ -51,8 +51,8 @@ class OptionsFlowHandler(config_entries.OptionsFlow): if user_input is not None: return self.async_create_entry(title="", data=user_input) - options_schema = vol.Schema( - _convert_to_options_schema(self.hass, self.config_entry.options) + options_schema = _convert_to_options_schema( + self.hass, self.config_entry.options ) return self.async_show_form(step_id="init", data_schema=options_schema) diff --git a/custom_components/adaptive_lighting/const.py b/custom_components/adaptive_lighting/const.py index 51a97a0d..5345b777 100644 --- a/custom_components/adaptive_lighting/const.py +++ b/custom_components/adaptive_lighting/const.py @@ -79,17 +79,25 @@ def _convert_to_options_schema(hass, options): for key, value in _COMMON_SCHEMA.items(): if key.schema == CONF_LIGHTS: all_lights = hass.states.async_entity_ids("light") - value = cv.multi_select(all_lights) + to_type = cv.multi_select(all_lights) elif value == cv.boolean: - value = bool + to_type = bool elif ( - isinstance(value, vol.All) and value.validators[0].type == int + isinstance(value, vol.All) + and hasattr(value.validators, "type") + and value.validators[0].type == int ) or value == VALID_TRANSITION: - pass + to_type = value elif value == cv.time_period: - value = cv.time_period_dict + to_type = cv.time_period_dict else: - value = str - default = options.get(key.schema, value.default()) - schema[vol.Optional(key.schema, default=default)] = value - return vol.Schema(schema) + to_type = str + + default = ( + key.default() + if not isinstance(key.default, vol.Undefined) + else vol.UNDEFINED + ) + default = options.get(key.schema, default) + schema[vol.Optional(key.schema, default=default)] = to_type + return vol.Schema(schema)