From b870933dc755f6c2d0f80852d61400eeba00a25e Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Wed, 25 Oct 2023 06:11:55 +0200 Subject: [PATCH] Use real devices in remote device action tests (#102725) --- tests/components/remote/test_device_action.py | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/tests/components/remote/test_device_action.py b/tests/components/remote/test_device_action.py index 97ff2fd58a0..76e6075a18f 100644 --- a/tests/components/remote/test_device_action.py +++ b/tests/components/remote/test_device_action.py @@ -110,12 +110,21 @@ async def test_get_actions_hidden_auxiliary( async def test_action( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, entity_registry: er.EntityRegistry, calls, enable_custom_integrations: None, ) -> None: """Test for turn_on and turn_off 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, @@ -126,7 +135,7 @@ async def test_action( "trigger": {"platform": "event", "event_type": "test_off"}, "action": { "domain": DOMAIN, - "device_id": "", + "device_id": device_entry.id, "entity_id": entry.id, "type": "turn_off", }, @@ -135,7 +144,7 @@ async def test_action( "trigger": {"platform": "event", "event_type": "test_on"}, "action": { "domain": DOMAIN, - "device_id": "", + "device_id": device_entry.id, "entity_id": entry.id, "type": "turn_on", }, @@ -144,7 +153,7 @@ async def test_action( "trigger": {"platform": "event", "event_type": "test_toggle"}, "action": { "domain": DOMAIN, - "device_id": "", + "device_id": device_entry.id, "entity_id": entry.id, "type": "toggle", }, @@ -176,12 +185,21 @@ async def test_action( async def test_action_legacy( hass: HomeAssistant, + device_registry: dr.DeviceRegistry, entity_registry: er.EntityRegistry, calls, enable_custom_integrations: None, ) -> None: """Test for turn_on and turn_off 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, @@ -192,7 +210,7 @@ async def test_action_legacy( "trigger": {"platform": "event", "event_type": "test_off"}, "action": { "domain": DOMAIN, - "device_id": "", + "device_id": device_entry.id, "entity_id": entry.entity_id, "type": "turn_off", },