mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 16:17:20 +00:00
Use real devices in sensor device trigger tests (#102695)
This commit is contained in:
parent
952f40a181
commit
82cc62416e
@ -418,13 +418,22 @@ async def test_get_trigger_capabilities_none(
|
|||||||
|
|
||||||
async def test_if_fires_not_on_above_below(
|
async def test_if_fires_not_on_above_below(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
entity_registry: er.EntityRegistry,
|
entity_registry: er.EntityRegistry,
|
||||||
calls,
|
calls,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
enable_custom_integrations: None,
|
enable_custom_integrations: None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test for value triggers firing."""
|
"""Test for value 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
|
||||||
|
)
|
||||||
|
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
@ -435,7 +444,7 @@ async def test_if_fires_not_on_above_below(
|
|||||||
"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": "battery_level",
|
"type": "battery_level",
|
||||||
},
|
},
|
||||||
@ -449,12 +458,21 @@ async def test_if_fires_not_on_above_below(
|
|||||||
|
|
||||||
async def test_if_fires_on_state_above(
|
async def test_if_fires_on_state_above(
|
||||||
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 value triggers firing."""
|
"""Test for value 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(entry.entity_id, STATE_UNKNOWN, {"device_class": "battery"})
|
hass.states.async_set(entry.entity_id, STATE_UNKNOWN, {"device_class": "battery"})
|
||||||
|
|
||||||
@ -467,7 +485,7 @@ async def test_if_fires_on_state_above(
|
|||||||
"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": "battery_level",
|
"type": "battery_level",
|
||||||
"above": 10,
|
"above": 10,
|
||||||
@ -508,12 +526,21 @@ async def test_if_fires_on_state_above(
|
|||||||
|
|
||||||
async def test_if_fires_on_state_below(
|
async def test_if_fires_on_state_below(
|
||||||
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 value triggers firing."""
|
"""Test for value 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(entry.entity_id, STATE_UNKNOWN, {"device_class": "battery"})
|
hass.states.async_set(entry.entity_id, STATE_UNKNOWN, {"device_class": "battery"})
|
||||||
|
|
||||||
@ -526,7 +553,7 @@ async def test_if_fires_on_state_below(
|
|||||||
"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": "battery_level",
|
"type": "battery_level",
|
||||||
"below": 10,
|
"below": 10,
|
||||||
@ -567,12 +594,21 @@ async def test_if_fires_on_state_below(
|
|||||||
|
|
||||||
async def test_if_fires_on_state_between(
|
async def test_if_fires_on_state_between(
|
||||||
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 value triggers firing."""
|
"""Test for value 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(entry.entity_id, STATE_UNKNOWN, {"device_class": "battery"})
|
hass.states.async_set(entry.entity_id, STATE_UNKNOWN, {"device_class": "battery"})
|
||||||
|
|
||||||
@ -585,7 +621,7 @@ async def test_if_fires_on_state_between(
|
|||||||
"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": "battery_level",
|
"type": "battery_level",
|
||||||
"above": 10,
|
"above": 10,
|
||||||
@ -638,12 +674,21 @@ async def test_if_fires_on_state_between(
|
|||||||
|
|
||||||
async def test_if_fires_on_state_legacy(
|
async def test_if_fires_on_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 value triggers firing."""
|
"""Test for value 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(entry.entity_id, STATE_UNKNOWN, {"device_class": "battery"})
|
hass.states.async_set(entry.entity_id, STATE_UNKNOWN, {"device_class": "battery"})
|
||||||
|
|
||||||
@ -656,7 +701,7 @@ async def test_if_fires_on_state_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": "battery_level",
|
"type": "battery_level",
|
||||||
"above": 10,
|
"above": 10,
|
||||||
@ -697,12 +742,21 @@ async def test_if_fires_on_state_legacy(
|
|||||||
|
|
||||||
async def test_if_fires_on_state_change_with_for(
|
async def test_if_fires_on_state_change_with_for(
|
||||||
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 triggers firing with delay."""
|
"""Test for triggers firing with delay."""
|
||||||
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"})
|
hass.states.async_set(entry.entity_id, STATE_UNKNOWN, {"device_class": "battery"})
|
||||||
|
|
||||||
@ -715,7 +769,7 @@ async def test_if_fires_on_state_change_with_for(
|
|||||||
"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": "battery_level",
|
"type": "battery_level",
|
||||||
"above": 10,
|
"above": 10,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user