mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Use real devices in binary_sensor device condition tests (#102704)
This commit is contained in:
parent
4d83cffb39
commit
9d3cdc85ca
@ -234,6 +234,7 @@ 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,
|
||||||
@ -245,7 +246,14 @@ async def test_if_state(
|
|||||||
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
|
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
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(platform.ENTITIES["battery"].entity_id)
|
entry = entity_registry.async_get(platform.ENTITIES["battery"].entity_id)
|
||||||
|
entity_registry.async_update_entity(entry.entity_id, device_id=device_entry.id)
|
||||||
|
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
@ -258,7 +266,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_bat_low",
|
"type": "is_bat_low",
|
||||||
}
|
}
|
||||||
@ -277,7 +285,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_not_bat_low",
|
"type": "is_not_bat_low",
|
||||||
}
|
}
|
||||||
@ -312,6 +320,7 @@ 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,
|
||||||
@ -323,7 +332,14 @@ async def test_if_state_legacy(
|
|||||||
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
|
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
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(platform.ENTITIES["battery"].entity_id)
|
entry = entity_registry.async_get(platform.ENTITIES["battery"].entity_id)
|
||||||
|
entity_registry.async_update_entity(entry.entity_id, device_id=device_entry.id)
|
||||||
|
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
@ -336,7 +352,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_bat_low",
|
"type": "is_bat_low",
|
||||||
}
|
}
|
||||||
@ -364,6 +380,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,
|
||||||
@ -379,7 +396,14 @@ async def test_if_fires_on_for_condition(
|
|||||||
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
|
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
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(platform.ENTITIES["battery"].entity_id)
|
entry = entity_registry.async_get(platform.ENTITIES["battery"].entity_id)
|
||||||
|
entity_registry.async_update_entity(entry.entity_id, device_id=device_entry.id)
|
||||||
|
|
||||||
with freeze_time(point1) as time_freeze:
|
with freeze_time(point1) as time_freeze:
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
@ -392,7 +416,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_not_bat_low",
|
"type": "is_not_bat_low",
|
||||||
"for": {"seconds": 5},
|
"for": {"seconds": 5},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user