From 47c3aef7a2ee461bcc6d8521dee93140a96245ac Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 7 Apr 2022 01:46:41 -1000 Subject: [PATCH] Fix registered entities without a category not being exclude-able in the HomeKit UI (#69543) --- .../components/homekit/config_flow.py | 2 +- tests/components/homekit/test_config_flow.py | 24 +++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/homekit/config_flow.py b/homeassistant/components/homekit/config_flow.py index 79193cd3dac..b7a00bc3ade 100644 --- a/homeassistant/components/homekit/config_flow.py +++ b/homeassistant/components/homekit/config_flow.py @@ -652,7 +652,7 @@ def _exclude_by_entity_registry( (entry := ent_reg.async_get(entity_id)) and ( entry.hidden_by is not None - or (not include_entity_category or entry.entity_category is not None) + or (not include_entity_category and entry.entity_category is not None) ) ) diff --git a/tests/components/homekit/test_config_flow.py b/tests/components/homekit/test_config_flow.py index fc3ef3e2710..42ce6779528 100644 --- a/tests/components/homekit/test_config_flow.py +++ b/tests/components/homekit/test_config_flow.py @@ -1347,6 +1347,16 @@ async def test_options_flow_exclude_mode_skips_category_entities( entity_category=EntityCategory.CONFIG, ) hass.states.async_set(sonos_config_switch.entity_id, "off") + + sonos_notconfig_switch: RegistryEntry = entity_reg.async_get_or_create( + "switch", + "sonos", + "notconfig", + device_id="1234", + entity_category=None, + ) + hass.states.async_set(sonos_notconfig_switch.entity_id, "off") + await hass.async_block_till_done() result = await hass.config_entries.options.async_init( @@ -1391,14 +1401,24 @@ async def test_options_flow_exclude_mode_skips_category_entities( result4 = await hass.config_entries.options.async_configure( result2["flow_id"], - user_input={"entities": ["media_player.tv", "switch.other"]}, + user_input={ + "entities": [ + "media_player.tv", + "switch.other", + sonos_notconfig_switch.entity_id, + ] + }, ) assert result4["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert config_entry.options == { "mode": "bridge", "filter": { "exclude_domains": [], - "exclude_entities": ["media_player.tv", "switch.other"], + "exclude_entities": [ + "media_player.tv", + "switch.other", + sonos_notconfig_switch.entity_id, + ], "include_domains": ["media_player", "switch"], "include_entities": [], },