From 0ce7f44294ef3b43a67992ebac1d1b982648ff03 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Tue, 24 Oct 2023 23:25:14 +0200 Subject: [PATCH] Use real devices in water_heater device action tests (#102730) --- .../water_heater/test_device_action.py | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/tests/components/water_heater/test_device_action.py b/tests/components/water_heater/test_device_action.py index a8ca41905d6..8254fb77a77 100644 --- a/tests/components/water_heater/test_device_action.py +++ b/tests/components/water_heater/test_device_action.py @@ -102,9 +102,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 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, @@ -118,7 +130,7 @@ async def test_action(hass: HomeAssistant, entity_registry: er.EntityRegistry) - }, "action": { "domain": DOMAIN, - "device_id": "abcdefgh", + "device_id": device_entry.id, "entity_id": entry.id, "type": "turn_off", }, @@ -130,7 +142,7 @@ async def test_action(hass: HomeAssistant, entity_registry: er.EntityRegistry) - }, "action": { "domain": DOMAIN, - "device_id": "abcdefgh", + "device_id": device_entry.id, "entity_id": entry.id, "type": "turn_on", }, @@ -157,10 +169,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 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, @@ -174,7 +196,7 @@ async def test_action_legacy( }, "action": { "domain": DOMAIN, - "device_id": "abcdefgh", + "device_id": device_entry.id, "entity_id": entry.entity_id, "type": "turn_off", },