From f56343f4470161370d6139e1c3518e05d249cd4f Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Tue, 24 Oct 2023 23:43:50 +0200 Subject: [PATCH] Use real devices in lock device action tests (#102723) --- tests/components/lock/test_device_action.py | 38 ++++++++++++++++----- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/tests/components/lock/test_device_action.py b/tests/components/lock/test_device_action.py index f87fa4cc178..1e451920baf 100644 --- a/tests/components/lock/test_device_action.py +++ b/tests/components/lock/test_device_action.py @@ -136,9 +136,21 @@ async def test_get_actions_hidden_auxiliary( assert actions == unordered(expected_actions) -async def test_action(hass: HomeAssistant, entity_registry: er.EntityRegistry) -> None: +async def test_action( + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, +) -> None: """Test for lock actions.""" - 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 + ) assert await async_setup_component( hass, @@ -149,7 +161,7 @@ async def test_action(hass: HomeAssistant, entity_registry: er.EntityRegistry) - "trigger": {"platform": "event", "event_type": "test_event_lock"}, "action": { "domain": DOMAIN, - "device_id": "abcdefgh", + "device_id": device_entry.id, "entity_id": entry.id, "type": "lock", }, @@ -158,7 +170,7 @@ async def test_action(hass: HomeAssistant, entity_registry: er.EntityRegistry) - "trigger": {"platform": "event", "event_type": "test_event_unlock"}, "action": { "domain": DOMAIN, - "device_id": "abcdefgh", + "device_id": device_entry.id, "entity_id": entry.id, "type": "unlock", }, @@ -167,7 +179,7 @@ async def test_action(hass: HomeAssistant, entity_registry: er.EntityRegistry) - "trigger": {"platform": "event", "event_type": "test_event_open"}, "action": { "domain": DOMAIN, - "device_id": "abcdefgh", + "device_id": device_entry.id, "entity_id": entry.id, "type": "open", }, @@ -211,10 +223,20 @@ async def test_action(hass: HomeAssistant, entity_registry: er.EntityRegistry) - async def test_action_legacy( - hass: HomeAssistant, entity_registry: er.EntityRegistry + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, ) -> None: """Test for lock actions.""" - 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 + ) assert await async_setup_component( hass, @@ -225,7 +247,7 @@ async def test_action_legacy( "trigger": {"platform": "event", "event_type": "test_event_lock"}, "action": { "domain": DOMAIN, - "device_id": "abcdefgh", + "device_id": device_entry.id, "entity_id": entry.id, "type": "lock", },