Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,19 @@ def _should_skip_service_data_value(
return service is not None and service.startswith("notify.") and key == "target"


def _filter_out_notify_service_references(entities: set[str]) -> set[str]:
"""Drop ``notify.*`` matches found in a ``data`` payload.

A genuine reference to a ``notify`` domain entity is always expressed via
``target.entity_id`` (handled separately by ``_extract_entities_from_target``).
A ``notify.*``-shaped string found as a free-form value inside ``data`` is,
in practice, a legacy notify *service* identifier forwarded by a
third-party integration (e.g. a "send to multiple notifiers" action), not
an entity reference - so it should never be flagged as unknown.
"""
return {entity for entity in entities if not entity.startswith("notify.")}


async def _extract_entities_from_service_data(
hass: HomeAssistant, config: dict[str, Any]
) -> set[str]:
Expand All @@ -257,7 +270,8 @@ async def _extract_entities_from_service_data(
for key, value in data_value.items():
if _should_skip_service_data_value(service, key):
continue
entities.update(await extract_entities_from_value(hass, value))
found = await extract_entities_from_value(hass, value)
entities.update(_filter_out_notify_service_references(found))
return entities


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,45 @@ async def test_notify_service_data_target_is_not_an_entity_reference(
assert await extract_entities_from_action_config(hass, config) == set()


async def test_third_party_service_data_notify_list_is_not_an_entity_reference(
hass: HomeAssistant,
) -> None:
"""Legacy notify service names forwarded by a third-party action are not entities.

Reproduces a real-world false positive: a custom "fan-out notifier" action
(e.g. ``notifier_hub.send``) accepts a list of legacy ``notify.*`` service
names under an arbitrary ``data`` key. These are service identifiers, not
entity references, and must not be flagged as unknown entities even though
the calling service is not itself in the ``notify`` domain.
"""
config = {
"action": "notifier_hub.send",
"data": {
"title": "Hello",
"message": "World",
"notify": ["notify.mobile_app_phone", "notify.old_tablet"],
},
}
assert await extract_entities_from_action_config(hass, config) == set()


async def test_notify_target_entity_id_is_still_detected(hass: HomeAssistant) -> None:
"""A genuine ``target.entity_id`` reference to a notify entity is still found.

Guards against overreaching the ``data``-payload notify filter: entities in
the ``notify`` domain referenced through ``target.entity_id`` (the only
legitimate way to target a notify *entity*, as opposed to a legacy notify
*service*) must still be reported when unknown.
"""
config = {
"action": "some_domain.some_service",
"target": {"entity_id": "notify.mobile_app_phone"},
}
assert await extract_entities_from_action_config(hass, config) == {
"notify.mobile_app_phone"
}


async def test_non_notify_action_data_target_remains_entity_reference(
hass: HomeAssistant,
) -> None:
Expand Down