Ensure selected entity is pre-selected in homekit options flow (#63628)
* Ensure selected entity is pre-selected in homekit options flow - We recently adjusted the flow to exclude entities that had been deleted from breaking the UI validation. We need to include single entities in the set of all supported entities since accessory mode has no domain filter * tweak * Additional fixes * small tweak to speed up building the set * merged fixed version for test branch
This commit is contained in:
parent
0b67d7fb28
commit
9dd09f66e2
2 changed files with 65 additions and 13 deletions
|
@ -447,15 +447,25 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
|
|||
return await self.async_step_advanced()
|
||||
|
||||
entity_filter = self.hk_options.get(CONF_FILTER, {})
|
||||
entities = entity_filter.get(CONF_INCLUDE_ENTITIES, [])
|
||||
|
||||
all_supported_entities = _async_get_matching_entities(
|
||||
self.hass,
|
||||
domains=self.hk_options[CONF_DOMAINS],
|
||||
)
|
||||
|
||||
data_schema = {}
|
||||
entity_schema = vol.In
|
||||
entities = entity_filter.get(CONF_INCLUDE_ENTITIES, [])
|
||||
if self.hk_options[CONF_HOMEKIT_MODE] != HOMEKIT_MODE_ACCESSORY:
|
||||
# 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
|
||||
entity_schema = vol.In
|
||||
entities_schema_required = vol.Required
|
||||
else:
|
||||
# Bridge mode
|
||||
entities_schema_required = vol.Optional
|
||||
include_exclude_mode = MODE_INCLUDE
|
||||
if not entities:
|
||||
include_exclude_mode = MODE_EXCLUDE
|
||||
|
@ -464,13 +474,10 @@ 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
|
||||
valid_entities = [
|
||||
entity_id for entity_id in entities if entity_id in all_supported_entities
|
||||
]
|
||||
data_schema[
|
||||
vol.Optional(CONF_ENTITIES, default=valid_entities)
|
||||
entities_schema_required(CONF_ENTITIES, default=default_value)
|
||||
] = entity_schema(all_supported_entities)
|
||||
|
||||
return self.async_show_form(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue