Skip to content

Commit ab7081d

Browse files
authored
Include non-primary entities targeted directly by label (home-assistant#149309)
1 parent 4762c64 commit ab7081d

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

homeassistant/helpers/target.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,7 @@ def async_extract_referenced_entity_ids(
182182
selected.missing_labels.add(label_id)
183183

184184
for entity_entry in entities.get_entries_for_label(label_id):
185-
if (
186-
entity_entry.entity_category is None
187-
and entity_entry.hidden_by is None
188-
):
185+
if entity_entry.hidden_by is None:
189186
selected.indirectly_referenced.add(entity_entry.entity_id)
190187

191188
for device_entry in dev_reg.devices.get_devices_for_label(label_id):

tests/helpers/test_service.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,13 @@ def label_mock(hass: HomeAssistant) -> None:
361361
labels={"my-label"},
362362
entity_category=EntityCategory.CONFIG,
363363
)
364+
diag_entity_with_my_label = RegistryEntryWithDefaults(
365+
entity_id="light.diag_with_my_label",
366+
unique_id="diag_with_my_label",
367+
platform="test",
368+
labels={"my-label"},
369+
entity_category=EntityCategory.DIAGNOSTIC,
370+
)
364371
entity_with_label1_from_device = RegistryEntryWithDefaults(
365372
entity_id="light.with_label1_from_device",
366373
unique_id="with_label1_from_device",
@@ -398,6 +405,7 @@ def label_mock(hass: HomeAssistant) -> None:
398405
hass,
399406
{
400407
config_entity_with_my_label.entity_id: config_entity_with_my_label,
408+
diag_entity_with_my_label.entity_id: diag_entity_with_my_label,
401409
entity_with_label1_and_label2_from_device.entity_id: entity_with_label1_and_label2_from_device,
402410
entity_with_label1_from_device.entity_id: entity_with_label1_from_device,
403411
entity_with_label1_from_device_and_different_area.entity_id: entity_with_label1_from_device_and_different_area,
@@ -781,6 +789,8 @@ async def test_extract_entity_ids_from_labels(hass: HomeAssistant) -> None:
781789

782790
assert {
783791
"light.with_my_label",
792+
"light.config_with_my_label",
793+
"light.diag_with_my_label",
784794
} == await service.async_extract_entity_ids(hass, call)
785795

786796
call = ServiceCall(hass, "light", "turn_on", {"label_id": "label1"})

tests/helpers/test_target.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,13 @@ def registries_mock(hass: HomeAssistant) -> None:
245245
labels={"my-label"},
246246
entity_category=EntityCategory.CONFIG,
247247
)
248+
diag_entity_with_my_label = RegistryEntryWithDefaults(
249+
entity_id="light.diag_with_my_label",
250+
unique_id="diag_with_my_label",
251+
platform="test",
252+
labels={"my-label"},
253+
entity_category=EntityCategory.DIAGNOSTIC,
254+
)
248255
entity_with_label1_from_device = RegistryEntryWithDefaults(
249256
entity_id="light.with_label1_from_device",
250257
unique_id="with_label1_from_device",
@@ -289,6 +296,7 @@ def registries_mock(hass: HomeAssistant) -> None:
289296
entity_in_area_a.entity_id: entity_in_area_a,
290297
entity_in_area_b.entity_id: entity_in_area_b,
291298
config_entity_with_my_label.entity_id: config_entity_with_my_label,
299+
diag_entity_with_my_label.entity_id: diag_entity_with_my_label,
292300
entity_with_label1_and_label2_from_device.entity_id: entity_with_label1_and_label2_from_device,
293301
entity_with_label1_from_device.entity_id: entity_with_label1_from_device,
294302
entity_with_label1_from_device_and_different_area.entity_id: entity_with_label1_from_device_and_different_area,
@@ -407,7 +415,11 @@ def registries_mock(hass: HomeAssistant) -> None:
407415
{ATTR_LABEL_ID: "my-label"},
408416
False,
409417
target.SelectedEntities(
410-
indirectly_referenced={"light.with_my_label"},
418+
indirectly_referenced={
419+
"light.with_my_label",
420+
"light.config_with_my_label",
421+
"light.diag_with_my_label",
422+
},
411423
missing_labels={"my-label"},
412424
),
413425
),

0 commit comments

Comments
 (0)