Use real devices in select device trigger tests (#102694)

This commit is contained in:
Erik Montnemery 2023-10-25 06:13:00 +02:00 committed by GitHub
parent b870933dc7
commit 626123acc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -113,10 +113,21 @@ async def test_get_triggers_hidden_auxiliary(
async def test_if_fires_on_state_change( 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: ) -> None:
"""Test for turn_on and turn_off triggers firing.""" """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( hass.states.async_set(
entry.entity_id, "option1", {"options": ["option1", "option2", "option3"]} entry.entity_id, "option1", {"options": ["option1", "option2", "option3"]}
@ -131,7 +142,7 @@ async def test_if_fires_on_state_change(
"trigger": { "trigger": {
"platform": "device", "platform": "device",
"domain": DOMAIN, "domain": DOMAIN,
"device_id": "", "device_id": device_entry.id,
"entity_id": entry.id, "entity_id": entry.id,
"type": "current_option_changed", "type": "current_option_changed",
"to": "option2", "to": "option2",
@ -152,7 +163,7 @@ async def test_if_fires_on_state_change(
"trigger": { "trigger": {
"platform": "device", "platform": "device",
"domain": DOMAIN, "domain": DOMAIN,
"device_id": "", "device_id": device_entry.id,
"entity_id": entry.id, "entity_id": entry.id,
"type": "current_option_changed", "type": "current_option_changed",
"from": "option2", "from": "option2",
@ -173,7 +184,7 @@ async def test_if_fires_on_state_change(
"trigger": { "trigger": {
"platform": "device", "platform": "device",
"domain": DOMAIN, "domain": DOMAIN,
"device_id": "", "device_id": device_entry.id,
"entity_id": entry.id, "entity_id": entry.id,
"type": "current_option_changed", "type": "current_option_changed",
"from": "option3", "from": "option3",
@ -224,10 +235,21 @@ async def test_if_fires_on_state_change(
async def test_if_fires_on_state_change_legacy( 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: ) -> None:
"""Test for turn_on and turn_off triggers firing.""" """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( hass.states.async_set(
entry.entity_id, "option1", {"options": ["option1", "option2", "option3"]} entry.entity_id, "option1", {"options": ["option1", "option2", "option3"]}
@ -242,7 +264,7 @@ async def test_if_fires_on_state_change_legacy(
"trigger": { "trigger": {
"platform": "device", "platform": "device",
"domain": DOMAIN, "domain": DOMAIN,
"device_id": "", "device_id": device_entry.id,
"entity_id": entry.entity_id, "entity_id": entry.entity_id,
"type": "current_option_changed", "type": "current_option_changed",
"to": "option2", "to": "option2",