diff --git a/tests/components/button/test_device_trigger.py b/tests/components/button/test_device_trigger.py index 32f10044206..e231fc3ae19 100644 --- a/tests/components/button/test_device_trigger.py +++ b/tests/components/button/test_device_trigger.py @@ -105,10 +105,21 @@ async def test_get_triggers_hidden_auxiliary( async def test_if_fires_on_state_change( - 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 triggers firing.""" - 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, "unknown") @@ -121,7 +132,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": "pressed", }, @@ -154,10 +165,21 @@ async def test_if_fires_on_state_change( async def test_if_fires_on_state_change_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 triggers firing.""" - 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, "unknown") @@ -170,7 +192,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": "pressed", },