Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use real devices in binary_sensor device trigger tests #102678

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 28 additions & 4 deletions tests/components/binary_sensor/test_device_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ async def test_get_trigger_capabilities_legacy(

async def test_if_fires_on_state_change(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
calls,
enable_custom_integrations: None,
Expand All @@ -245,10 +246,17 @@ async def test_if_fires_on_state_change(
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
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_or_create(
DOMAIN,
"test",
platform.ENTITIES["battery"].unique_id,
device_id=device_entry.id,
)

assert await async_setup_component(
Expand All @@ -260,7 +268,7 @@ async def test_if_fires_on_state_change(
"trigger": {
"platform": "device",
"domain": DOMAIN,
"device_id": "",
"device_id": device_entry.id,
"entity_id": entry.id,
"type": "bat_low",
},
Expand All @@ -284,7 +292,7 @@ async def test_if_fires_on_state_change(
"trigger": {
"platform": "device",
"domain": DOMAIN,
"device_id": "",
"device_id": device_entry.id,
"entity_id": entry.id,
"type": "not_bat_low",
},
Expand Down Expand Up @@ -329,6 +337,7 @@ async def test_if_fires_on_state_change(

async def test_if_fires_on_state_change_with_for(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
calls,
enable_custom_integrations: None,
Expand All @@ -340,10 +349,17 @@ async def test_if_fires_on_state_change_with_for(
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
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_or_create(
DOMAIN,
"test",
platform.ENTITIES["battery"].unique_id,
device_id=device_entry.id,
)

assert await async_setup_component(
Expand All @@ -355,7 +371,7 @@ async def test_if_fires_on_state_change_with_for(
"trigger": {
"platform": "device",
"domain": DOMAIN,
"device_id": "",
"device_id": device_entry.id,
"entity_id": entry.id,
"type": "turned_off",
"for": {"seconds": 5},
Expand Down Expand Up @@ -398,6 +414,7 @@ async def test_if_fires_on_state_change_with_for(

async def test_if_fires_on_state_change_legacy(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
calls,
enable_custom_integrations: None,
Expand All @@ -409,10 +426,17 @@ async def test_if_fires_on_state_change_legacy(
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
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_or_create(
DOMAIN,
"test",
platform.ENTITIES["battery"].unique_id,
device_id=device_entry.id,
)

assert await async_setup_component(
Expand All @@ -424,7 +448,7 @@ async def test_if_fires_on_state_change_legacy(
"trigger": {
"platform": "device",
"domain": DOMAIN,
"device_id": "",
"device_id": device_entry.id,
"entity_id": entry.entity_id,
"type": "turned_off",
},
Expand Down