mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Add turned on or off device trigger to toggle entity (#61089)
* Add turned on or off device trigger to toggle entity * Renamed changed_states trigger to toggled * Adjust tests * Fix homekit triggers test * Add tests * Adjust tests after rebase Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
@@ -51,6 +51,13 @@ async def test_get_triggers(hass, device_reg, entity_reg):
|
||||
)
|
||||
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
|
||||
expected_triggers = [
|
||||
{
|
||||
"platform": "device",
|
||||
"domain": DOMAIN,
|
||||
"type": "toggled",
|
||||
"device_id": device_entry.id,
|
||||
"entity_id": f"{DOMAIN}.test_5678",
|
||||
},
|
||||
{
|
||||
"platform": "device",
|
||||
"domain": DOMAIN,
|
||||
@@ -159,6 +166,30 @@ async def test_if_fires_on_state_change(hass, calls, enable_custom_integrations)
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"trigger": {
|
||||
"platform": "device",
|
||||
"domain": DOMAIN,
|
||||
"device_id": "",
|
||||
"entity_id": ent1.entity_id,
|
||||
"type": "toggled",
|
||||
},
|
||||
"action": {
|
||||
"service": "test.automation",
|
||||
"data_template": {
|
||||
"some": "turn_on_or_off {{ trigger.%s }}"
|
||||
% "}} - {{ trigger.".join(
|
||||
(
|
||||
"platform",
|
||||
"entity_id",
|
||||
"from_state.state",
|
||||
"to_state.state",
|
||||
"for",
|
||||
)
|
||||
)
|
||||
},
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
)
|
||||
@@ -168,17 +199,19 @@ async def test_if_fires_on_state_change(hass, calls, enable_custom_integrations)
|
||||
|
||||
hass.states.async_set(ent1.entity_id, STATE_OFF)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
assert calls[0].data["some"] == "turn_off device - {} - on - off - None".format(
|
||||
ent1.entity_id
|
||||
)
|
||||
assert len(calls) == 2
|
||||
assert {calls[0].data["some"], calls[1].data["some"]} == {
|
||||
f"turn_off device - {ent1.entity_id} - on - off - None",
|
||||
f"turn_on_or_off device - {ent1.entity_id} - on - off - None",
|
||||
}
|
||||
|
||||
hass.states.async_set(ent1.entity_id, STATE_ON)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 2
|
||||
assert calls[1].data["some"] == "turn_on device - {} - off - on - None".format(
|
||||
ent1.entity_id
|
||||
)
|
||||
assert len(calls) == 4
|
||||
assert {calls[2].data["some"], calls[3].data["some"]} == {
|
||||
f"turn_on device - {ent1.entity_id} - off - on - None",
|
||||
f"turn_on_or_off device - {ent1.entity_id} - off - on - None",
|
||||
}
|
||||
|
||||
|
||||
async def test_if_fires_on_state_change_with_for(
|
||||
|
||||
Reference in New Issue
Block a user