Teach zwave_js device trigger about entity registry ids (#96303)

This commit is contained in:
Erik Montnemery 2023-07-22 17:29:24 +02:00 committed by GitHub
parent 77f2eb0ac9
commit a8d77cc5ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 83 additions and 4 deletions

View File

@ -142,7 +142,7 @@ SCENE_ACTIVATION_VALUE_NOTIFICATION_SCHEMA = (
# State based trigger schemas
BASE_STATE_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend(
{
vol.Required(CONF_ENTITY_ID): cv.entity_id,
vol.Required(CONF_ENTITY_ID): cv.entity_id_or_uuid,
}
)
@ -272,7 +272,7 @@ async def async_get_triggers(
and not entity.disabled
):
triggers.append(
{**base_trigger, CONF_TYPE: NODE_STATUS, CONF_ENTITY_ID: entity_id}
{**base_trigger, CONF_TYPE: NODE_STATUS, CONF_ENTITY_ID: entity.id}
)
# Handle notification event triggers

View File

@ -345,7 +345,7 @@ async def test_get_node_status_triggers(
entity_id = async_get_node_status_sensor_entity_id(
hass, device.id, ent_reg, dev_reg
)
ent_reg.async_update_entity(entity_id, **{"disabled_by": None})
entity = ent_reg.async_update_entity(entity_id, **{"disabled_by": None})
await hass.config_entries.async_reload(integration.entry_id)
await hass.async_block_till_done()
@ -354,7 +354,7 @@ async def test_get_node_status_triggers(
"domain": DOMAIN,
"type": "state.node_status",
"device_id": device.id,
"entity_id": entity_id,
"entity_id": entity.id,
"metadata": {"secondary": True},
}
triggers = await async_get_device_automations(
@ -377,6 +377,85 @@ async def test_if_node_status_change_fires(
entity_id = async_get_node_status_sensor_entity_id(
hass, device.id, ent_reg, dev_reg
)
entity = ent_reg.async_update_entity(entity_id, **{"disabled_by": None})
await hass.config_entries.async_reload(integration.entry_id)
await hass.async_block_till_done()
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: [
# from
{
"trigger": {
"platform": "device",
"domain": DOMAIN,
"device_id": device.id,
"entity_id": entity.id,
"type": "state.node_status",
"from": "alive",
},
"action": {
"service": "test.automation",
"data_template": {
"some": (
"state.node_status - "
"{{ trigger.platform}} - "
"{{ trigger.from_state.state }}"
)
},
},
},
# no from or to
{
"trigger": {
"platform": "device",
"domain": DOMAIN,
"device_id": device.id,
"entity_id": entity.id,
"type": "state.node_status",
},
"action": {
"service": "test.automation",
"data_template": {
"some": (
"state.node_status2 - "
"{{ trigger.platform}} - "
"{{ trigger.from_state.state }}"
)
},
},
},
]
},
)
# Test status change
event = Event(
"dead", data={"source": "node", "event": "dead", "nodeId": node.node_id}
)
node.receive_event(event)
await hass.async_block_till_done()
assert len(calls) == 2
assert calls[0].data["some"] == "state.node_status - device - alive"
assert calls[1].data["some"] == "state.node_status2 - device - alive"
async def test_if_node_status_change_fires_legacy(
hass: HomeAssistant, client, lock_schlage_be469, integration, calls
) -> None:
"""Test for node_status trigger firing."""
node: Node = lock_schlage_be469
dev_reg = async_get_dev_reg(hass)
device = dev_reg.async_get_device(
{get_device_id(client.driver, lock_schlage_be469)}
)
assert device
ent_reg = async_get_ent_reg(hass)
entity_id = async_get_node_status_sensor_entity_id(
hass, device.id, ent_reg, dev_reg
)
ent_reg.async_update_entity(entity_id, **{"disabled_by": None})
await hass.config_entries.async_reload(integration.entry_id)
await hass.async_block_till_done()