diff --git a/tests/components/select/test_device_condition.py b/tests/components/select/test_device_condition.py index 18ebd428891..3e0ecd6e547 100644 --- a/tests/components/select/test_device_condition.py +++ b/tests/components/select/test_device_condition.py @@ -115,10 +115,19 @@ async def test_get_conditions_hidden_auxiliary( async def test_if_selected_option( hass: HomeAssistant, calls: list[ServiceCall], + device_registry: dr.DeviceRegistry, entity_registry: er.EntityRegistry, ) -> None: """Test for selected_option 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 + ) assert await async_setup_component( hass, @@ -131,7 +140,7 @@ async def test_if_selected_option( { "condition": "device", "domain": DOMAIN, - "device_id": "", + "device_id": device_entry.id, "entity_id": entry.id, "type": "selected_option", "option": "option1", @@ -150,7 +159,7 @@ async def test_if_selected_option( { "condition": "device", "domain": DOMAIN, - "device_id": "", + "device_id": device_entry.id, "entity_id": entry.id, "type": "selected_option", "option": "option2", @@ -195,10 +204,19 @@ async def test_if_selected_option( async def test_if_selected_option_legacy( hass: HomeAssistant, calls: list[ServiceCall], + device_registry: dr.DeviceRegistry, entity_registry: er.EntityRegistry, ) -> None: """Test for selected_option 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 + ) assert await async_setup_component( hass, @@ -211,7 +229,7 @@ async def test_if_selected_option_legacy( { "condition": "device", "domain": DOMAIN, - "device_id": "", + "device_id": device_entry.id, "entity_id": entry.entity_id, "type": "selected_option", "option": "option1",