Use real devices in sensor device condition tests (#102713)

pull/102702/head^2
Erik Montnemery 2023-10-24 23:37:36 +02:00 committed by GitHub
parent ff60a8072e
commit b5a6e6b9d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 55 additions and 10 deletions

View File

@ -461,13 +461,22 @@ async def test_get_condition_capabilities_none(
async def test_if_state_not_above_below(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
calls,
caplog: pytest.LogCaptureFixture,
enable_custom_integrations: None,
) -> None:
"""Test for bad value 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,
@ -480,7 +489,7 @@ async def test_if_state_not_above_below(
{
"condition": "device",
"domain": DOMAIN,
"device_id": "",
"device_id": device_entry.id,
"entity_id": entry.id,
"type": "is_battery_level",
}
@ -495,12 +504,21 @@ async def test_if_state_not_above_below(
async def test_if_state_above(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
calls,
enable_custom_integrations: None,
) -> None:
"""Test for value 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_UNKNOWN, {"device_class": "battery"})
@ -515,7 +533,7 @@ async def test_if_state_above(
{
"condition": "device",
"domain": DOMAIN,
"device_id": "",
"device_id": device_entry.id,
"entity_id": entry.id,
"type": "is_battery_level",
"above": 10,
@ -553,12 +571,21 @@ async def test_if_state_above(
async def test_if_state_above_legacy(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
calls,
enable_custom_integrations: None,
) -> None:
"""Test for value 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_UNKNOWN, {"device_class": "battery"})
@ -573,7 +600,7 @@ async def test_if_state_above_legacy(
{
"condition": "device",
"domain": DOMAIN,
"device_id": "",
"device_id": device_entry.id,
"entity_id": entry.entity_id,
"type": "is_battery_level",
"above": 10,
@ -611,12 +638,21 @@ async def test_if_state_above_legacy(
async def test_if_state_below(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
calls,
enable_custom_integrations: None,
) -> None:
"""Test for value 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_UNKNOWN, {"device_class": "battery"})
@ -631,7 +667,7 @@ async def test_if_state_below(
{
"condition": "device",
"domain": DOMAIN,
"device_id": "",
"device_id": device_entry.id,
"entity_id": entry.id,
"type": "is_battery_level",
"below": 10,
@ -669,12 +705,21 @@ async def test_if_state_below(
async def test_if_state_between(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
calls,
enable_custom_integrations: None,
) -> None:
"""Test for value 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_UNKNOWN, {"device_class": "battery"})
@ -689,7 +734,7 @@ async def test_if_state_between(
{
"condition": "device",
"domain": DOMAIN,
"device_id": "",
"device_id": device_entry.id,
"entity_id": entry.id,
"type": "is_battery_level",
"above": 10,