Use real devices in switch device condition tests (#102714)

This commit is contained in:
Erik Montnemery 2023-10-24 23:37:48 +02:00 committed by GitHub
parent b5a6e6b9d5
commit e761d5715b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -179,12 +179,21 @@ async def test_get_condition_capabilities_legacy(
async def test_if_state( async def test_if_state(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry, entity_registry: er.EntityRegistry,
calls, calls,
enable_custom_integrations: None, enable_custom_integrations: None,
) -> None: ) -> None:
"""Test for turn_on and turn_off conditions.""" """Test for turn_on and turn_off 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
)
hass.states.async_set(entry.entity_id, STATE_ON) hass.states.async_set(entry.entity_id, STATE_ON)
@ -199,7 +208,7 @@ async def test_if_state(
{ {
"condition": "device", "condition": "device",
"domain": DOMAIN, "domain": DOMAIN,
"device_id": "", "device_id": device_entry.id,
"entity_id": entry.id, "entity_id": entry.id,
"type": "is_on", "type": "is_on",
} }
@ -218,7 +227,7 @@ async def test_if_state(
{ {
"condition": "device", "condition": "device",
"domain": DOMAIN, "domain": DOMAIN,
"device_id": "", "device_id": device_entry.id,
"entity_id": entry.id, "entity_id": entry.id,
"type": "is_off", "type": "is_off",
} }
@ -253,12 +262,21 @@ async def test_if_state(
async def test_if_state_legacy( async def test_if_state_legacy(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry, entity_registry: er.EntityRegistry,
calls, calls,
enable_custom_integrations: None, enable_custom_integrations: None,
) -> None: ) -> None:
"""Test for turn_on and turn_off conditions.""" """Test for turn_on and turn_off 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
)
hass.states.async_set(entry.entity_id, STATE_ON) hass.states.async_set(entry.entity_id, STATE_ON)
@ -273,7 +291,7 @@ async def test_if_state_legacy(
{ {
"condition": "device", "condition": "device",
"domain": DOMAIN, "domain": DOMAIN,
"device_id": "", "device_id": device_entry.id,
"entity_id": entry.entity_id, "entity_id": entry.entity_id,
"type": "is_on", "type": "is_on",
} }
@ -300,6 +318,7 @@ async def test_if_state_legacy(
async def test_if_fires_on_for_condition( async def test_if_fires_on_for_condition(
hass: HomeAssistant, hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry, entity_registry: er.EntityRegistry,
calls, calls,
enable_custom_integrations: None, enable_custom_integrations: None,
@ -309,7 +328,15 @@ async def test_if_fires_on_for_condition(
point2 = point1 + timedelta(seconds=10) point2 = point1 + timedelta(seconds=10)
point3 = point2 + timedelta(seconds=10) point3 = point2 + timedelta(seconds=10)
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, STATE_ON) hass.states.async_set(entry.entity_id, STATE_ON)
@ -324,7 +351,7 @@ async def test_if_fires_on_for_condition(
"condition": { "condition": {
"condition": "device", "condition": "device",
"domain": DOMAIN, "domain": DOMAIN,
"device_id": "", "device_id": device_entry.id,
"entity_id": entry.id, "entity_id": entry.id,
"type": "is_off", "type": "is_off",
"for": {"seconds": 5}, "for": {"seconds": 5},