1
mirror of https://github.com/home-assistant/core synced 2024-07-30 21:18:57 +02:00

Exclude hidden entities from targets (#68149)

This commit is contained in:
Erik Montnemery 2022-03-15 16:42:22 +01:00 committed by GitHub
parent 8ea31cea3a
commit 34eb4aa2d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 7 deletions

View File

@ -359,7 +359,7 @@ def async_extract_referenced_entity_ids(
if area_id not in area_reg.areas:
selected.missing_areas.add(area_id)
# Find devices for this area
# Find devices for targeted areas
selected.referenced_devices.update(selector.device_ids)
for device_entry in dev_reg.devices.values():
if device_entry.area_id in selector.area_ids:
@ -369,20 +369,20 @@ def async_extract_referenced_entity_ids(
return selected
for ent_entry in ent_reg.entities.values():
# Do not add config or diagnostic entities referenced by areas or devices
if ent_entry.entity_category is not None:
# Do not add entities which are hidden or which are config or diagnostic entities
if ent_entry.entity_category is not None or ent_entry.hidden_by is not None:
continue
if (
# when area matches the target area
# The entity's area matches a targeted area
ent_entry.area_id in selector.area_ids
# when device matches a referenced devices with no explicitly set area
# The entity's device matches a device referenced by an area and the entity
# has no explicitly set area
or (
not ent_entry.area_id
and ent_entry.device_id in selected.referenced_devices
)
# when device matches target device
# The entity's device matches a targeted device
or ent_entry.device_id in selector.device_ids
):
selected.indirectly_referenced.add(ent_entry.entity_id)

View File

@ -121,6 +121,13 @@ def area_mock(hass):
area_id="own-area",
entity_category="config",
)
hidden_entity_in_own_area = ent_reg.RegistryEntry(
entity_id="light.hidden_in_own_area",
unique_id="hidden-in-own-area-id",
platform="test",
area_id="own-area",
hidden_by=ent_reg.RegistryEntryHider.USER,
)
entity_in_area = ent_reg.RegistryEntry(
entity_id="light.in_area",
unique_id="in-area-id",
@ -134,6 +141,13 @@ def area_mock(hass):
device_id=device_in_area.id,
entity_category="config",
)
hidden_entity_in_area = ent_reg.RegistryEntry(
entity_id="light.hidden_in_area",
unique_id="hidden-in-area-id",
platform="test",
device_id=device_in_area.id,
hidden_by=ent_reg.RegistryEntryHider.USER,
)
entity_in_other_area = ent_reg.RegistryEntry(
entity_id="light.in_other_area",
unique_id="in-area-a-id",
@ -161,6 +175,13 @@ def area_mock(hass):
device_id=device_no_area.id,
entity_category="config",
)
hidden_entity_no_area = ent_reg.RegistryEntry(
entity_id="light.hidden_no_area",
unique_id="hidden-no-area-id",
platform="test",
device_id=device_no_area.id,
hidden_by=ent_reg.RegistryEntryHider.USER,
)
entity_diff_area = ent_reg.RegistryEntry(
entity_id="light.diff_area",
unique_id="diff-area-id",
@ -186,12 +207,15 @@ def area_mock(hass):
{
entity_in_own_area.entity_id: entity_in_own_area,
config_entity_in_own_area.entity_id: config_entity_in_own_area,
hidden_entity_in_own_area.entity_id: hidden_entity_in_own_area,
entity_in_area.entity_id: entity_in_area,
config_entity_in_area.entity_id: config_entity_in_area,
hidden_entity_in_area.entity_id: hidden_entity_in_area,
entity_in_other_area.entity_id: entity_in_other_area,
entity_assigned_to_area.entity_id: entity_assigned_to_area,
entity_no_area.entity_id: entity_no_area,
config_entity_no_area.entity_id: config_entity_no_area,
hidden_entity_no_area.entity_id: hidden_entity_no_area,
entity_diff_area.entity_id: entity_diff_area,
entity_in_area_a.entity_id: entity_in_area_a,
entity_in_area_b.entity_id: entity_in_area_b,