small fixes

This commit is contained in:
Bas Nijholt 2020-09-16 11:06:15 +02:00
commit 909584abbf
2 changed files with 19 additions and 11 deletions

View file

@ -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)

View file

@ -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)