Ensure homekit options flow remembers excluded entities during edit (#64401)

This commit is contained in:
J. Nick Koston 2022-01-18 19:17:43 -10:00 committed by GitHub
parent efcae8bece
commit 36e2617796
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 7 deletions

View file

@ -456,13 +456,16 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
domains=self.hk_options[CONF_DOMAINS],
)
data_schema = {}
# Strip out entities that no longer exist to prevent error in the UI
valid_entities = [
entity_id for entity_id in entities if entity_id in all_supported_entities
]
if self.hk_options[CONF_HOMEKIT_MODE] == HOMEKIT_MODE_ACCESSORY:
# In accessory mode we can only have one
default_value = valid_entities[0] if valid_entities else None
default_value = next(
iter(
entity_id
for entity_id in entities
if entity_id in all_supported_entities
),
None,
)
entity_schema = vol.In
entities_schema_required = vol.Required
else:
@ -476,12 +479,16 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
vol.Required(CONF_INCLUDE_EXCLUDE_MODE, default=include_exclude_mode)
] = vol.In(INCLUDE_EXCLUDE_MODES)
entity_schema = cv.multi_select
default_value = valid_entities
# Strip out entities that no longer exist to prevent error in the UI
default_value = [
entity_id
for entity_id in entities
if entity_id in all_supported_entities
]
data_schema[
entities_schema_required(CONF_ENTITIES, default=default_value)
] = entity_schema(all_supported_entities)
return self.async_show_form(
step_id="include_exclude", data_schema=vol.Schema(data_schema)
)