From d8baa38751c4b152b0791316038069c02b28fd8c Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Tue, 24 Oct 2023 22:42:44 +0200 Subject: [PATCH] Use real devices in update device trigger tests (#102697) --- .../components/update/test_device_trigger.py | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/tests/components/update/test_device_trigger.py b/tests/components/update/test_device_trigger.py index b2d06a642a8..16749167c41 100644 --- a/tests/components/update/test_device_trigger.py +++ b/tests/components/update/test_device_trigger.py @@ -176,6 +176,7 @@ async def test_get_trigger_capabilities_legacy( async def test_if_fires_on_state_change( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, entity_registry: er.EntityRegistry, calls: list[ServiceCall], enable_custom_integrations: None, @@ -187,7 +188,14 @@ async def test_if_fires_on_state_change( assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}}) await hass.async_block_till_done() + config_entry = MockConfigEntry(domain="test", data={}) + config_entry.add_to_hass(hass) + device_entry = device_registry.async_get_or_create( + config_entry_id=config_entry.entry_id, + connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, + ) entry = entity_registry.async_get("update.update_available") + entity_registry.async_update_entity(entry.entity_id, device_id=device_entry.id) assert await async_setup_component( hass, @@ -198,7 +206,7 @@ async def test_if_fires_on_state_change( "trigger": { "platform": "device", "domain": DOMAIN, - "device_id": "", + "device_id": device_entry.id, "entity_id": entry.id, "type": "turned_on", }, @@ -222,7 +230,7 @@ async def test_if_fires_on_state_change( "trigger": { "platform": "device", "domain": DOMAIN, - "device_id": "", + "device_id": device_entry.id, "entity_id": "update.update_available", "type": "turned_off", }, @@ -270,6 +278,7 @@ async def test_if_fires_on_state_change( async def test_if_fires_on_state_change_legacy( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, entity_registry: er.EntityRegistry, calls: list[ServiceCall], enable_custom_integrations: None, @@ -281,7 +290,14 @@ async def test_if_fires_on_state_change_legacy( assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}}) await hass.async_block_till_done() + config_entry = MockConfigEntry(domain="test", data={}) + config_entry.add_to_hass(hass) + device_entry = device_registry.async_get_or_create( + config_entry_id=config_entry.entry_id, + connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, + ) entry = entity_registry.async_get("update.update_available") + entity_registry.async_update_entity(entry.entity_id, device_id=device_entry.id) assert await async_setup_component( hass, @@ -292,7 +308,7 @@ async def test_if_fires_on_state_change_legacy( "trigger": { "platform": "device", "domain": DOMAIN, - "device_id": "", + "device_id": device_entry.id, "entity_id": entry.entity_id, "type": "turned_off", }, @@ -332,6 +348,7 @@ async def test_if_fires_on_state_change_legacy( async def test_if_fires_on_state_change_with_for( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, entity_registry: er.EntityRegistry, calls: list[ServiceCall], enable_custom_integrations: None, @@ -343,7 +360,14 @@ async def test_if_fires_on_state_change_with_for( assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}}) await hass.async_block_till_done() + config_entry = MockConfigEntry(domain="test", data={}) + config_entry.add_to_hass(hass) + device_entry = device_registry.async_get_or_create( + config_entry_id=config_entry.entry_id, + connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")}, + ) entry = entity_registry.async_get("update.update_available") + entity_registry.async_update_entity(entry.entity_id, device_id=device_entry.id) assert await async_setup_component( hass, @@ -354,7 +378,7 @@ async def test_if_fires_on_state_change_with_for( "trigger": { "platform": "device", "domain": DOMAIN, - "device_id": "", + "device_id": device_entry.id, "entity_id": entry.id, "type": "turned_off", "for": {"seconds": 5},