Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -53,22 +53,25 @@ async def extract_entities_from_automation_config(
return entities

# Extract entities from trigger config
if "trigger" in config:
entities.update(
await extract_entities_from_trigger_config(hass, config["trigger"])
)
for key in ("trigger", "triggers"):
if key in config:
entities.update(
await extract_entities_from_trigger_config(hass, config[key])
)

# Extract entities from condition config
if "condition" in config:
entities.update(
await extract_entities_from_condition_config(hass, config["condition"])
)
for key in ("condition", "conditions"):
if key in config:
entities.update(
await extract_entities_from_condition_config(hass, config[key])
)

# Extract entities from action config
if "action" in config:
entities.update(
await extract_entities_from_action_config(hass, config["action"])
)
for key in ("action", "actions"):
if key in config:
entities.update(
await extract_entities_from_action_config(hass, config[key])
)

return entities

Expand Down Expand Up @@ -343,11 +346,10 @@ async def _async_compute_unknown_references(self, entity: Any) -> set[str]:
self.hass, entity.raw_config
)
)
all_entities.difference_update(
extract_event_types_from_trigger_config(
entity.raw_config.get("trigger")
for key in ("trigger", "triggers"):
all_entities.difference_update(
extract_event_types_from_trigger_config(entity.raw_config.get(key))
)
)

# Extract entities from Template objects within the automation entity
all_entities.update(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,54 @@ async def test_automation_full_config(hass: HomeAssistant) -> None:
}


async def test_automation_full_config_with_plural_keys(hass: HomeAssistant) -> None:
"""A modern automation config yields entities from plural sections."""
config = {
"alias": "Test",
"triggers": [{"trigger": "state", "entity_id": "binary_sensor.motion"}],
"conditions": [
{
"condition": "state",
"entity_id": "input_boolean.snooze_uptime_alerts",
"state": "off",
}
],
"actions": [
{"action": "light.turn_on", "target": {"entity_id": "light.kitchen"}},
],
}

assert await extract_entities_from_automation_config(hass, config) == {
"binary_sensor.motion",
"input_boolean.snooze_uptime_alerts",
"light.kitchen",
}


async def test_plural_condition_entity_is_reported_unknown(
hass: HomeAssistant,
) -> None:
"""A missing entity in a plural ``conditions`` section is reported."""
entity = MockAutomationEntity(
raw_config={
"conditions": [
{
"condition": "state",
"entity_id": "input_boolean.snooze_uptime_alerts",
"state": "off",
}
],
},
referenced_entities=set(),
)
repair = SpookRepair(hass)
repair._known_entity_ids = set()

assert await repair._async_compute_unknown_references(entity) == {
"input_boolean.snooze_uptime_alerts"
}


async def test_automation_non_dict_returns_empty(hass: HomeAssistant) -> None:
"""A non-dict argument short-circuits to an empty set."""
assert await extract_entities_from_automation_config(hass, []) == set()
Expand Down
Loading