From b38692f3a72264fbc04bffd1deaa3f00f8f8e6bf Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Wed, 25 Oct 2023 09:42:00 +0200 Subject: [PATCH] Use real devices in lock device condition tests (#102757) --- .../components/lock/test_device_condition.py | 42 ++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/tests/components/lock/test_device_condition.py b/tests/components/lock/test_device_condition.py index 43513930f2e..59dcbcb4629 100644 --- a/tests/components/lock/test_device_condition.py +++ b/tests/components/lock/test_device_condition.py @@ -129,10 +129,21 @@ async def test_get_conditions_hidden_auxiliary( async def test_if_state( - hass: HomeAssistant, entity_registry: er.EntityRegistry, calls + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, + calls, ) -> None: """Test for turn_on and turn_off conditions.""" - entry = entity_registry.async_get_or_create(DOMAIN, "test", "5678") + 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_or_create( + DOMAIN, "test", "5678", device_id=device_entry.id + ) hass.states.async_set(entry.entity_id, STATE_LOCKED) @@ -147,7 +158,7 @@ async def test_if_state( { "condition": "device", "domain": DOMAIN, - "device_id": "", + "device_id": device_entry.id, "entity_id": entry.id, "type": "is_locked", } @@ -165,7 +176,7 @@ async def test_if_state( { "condition": "device", "domain": DOMAIN, - "device_id": "", + "device_id": device_entry.id, "entity_id": entry.id, "type": "is_unlocked", } @@ -183,7 +194,7 @@ async def test_if_state( { "condition": "device", "domain": DOMAIN, - "device_id": "", + "device_id": device_entry.id, "entity_id": entry.id, "type": "is_unlocking", } @@ -201,7 +212,7 @@ async def test_if_state( { "condition": "device", "domain": DOMAIN, - "device_id": "", + "device_id": device_entry.id, "entity_id": entry.id, "type": "is_locking", } @@ -219,7 +230,7 @@ async def test_if_state( { "condition": "device", "domain": DOMAIN, - "device_id": "", + "device_id": device_entry.id, "entity_id": entry.id, "type": "is_jammed", } @@ -267,10 +278,21 @@ async def test_if_state( async def test_if_state_legacy( - hass: HomeAssistant, entity_registry: er.EntityRegistry, calls + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, + calls, ) -> None: """Test for turn_on and turn_off conditions.""" - entry = entity_registry.async_get_or_create(DOMAIN, "test", "5678") + 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_or_create( + DOMAIN, "test", "5678", device_id=device_entry.id + ) hass.states.async_set(entry.entity_id, STATE_LOCKED) @@ -285,7 +307,7 @@ async def test_if_state_legacy( { "condition": "device", "domain": DOMAIN, - "device_id": "", + "device_id": device_entry.id, "entity_id": entry.entity_id, "type": "is_locked", }