mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Use real devices in nest device trigger tests (#102692)
This commit is contained in:
parent
e4a1efb680
commit
6e72499f96
@ -230,53 +230,164 @@ async def test_no_triggers(
|
|||||||
assert triggers == []
|
assert triggers == []
|
||||||
|
|
||||||
|
|
||||||
async def test_fires_on_camera_motion(hass: HomeAssistant, calls) -> None:
|
async def test_fires_on_camera_motion(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
create_device: CreateDevice,
|
||||||
|
setup_platform: PlatformSetup,
|
||||||
|
calls,
|
||||||
|
) -> None:
|
||||||
"""Test camera_motion triggers firing."""
|
"""Test camera_motion triggers firing."""
|
||||||
assert await setup_automation(hass, DEVICE_ID, "camera_motion")
|
create_device.create(
|
||||||
|
raw_data=make_camera(
|
||||||
|
device_id=DEVICE_ID,
|
||||||
|
traits={
|
||||||
|
"sdm.devices.traits.CameraMotion": {},
|
||||||
|
"sdm.devices.traits.CameraPerson": {},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
await setup_platform()
|
||||||
|
|
||||||
message = {"device_id": DEVICE_ID, "type": "camera_motion", "timestamp": utcnow()}
|
device_registry = dr.async_get(hass)
|
||||||
|
device_entry = device_registry.async_get_device(identifiers={("nest", DEVICE_ID)})
|
||||||
|
|
||||||
|
assert await setup_automation(hass, device_entry.id, "camera_motion")
|
||||||
|
|
||||||
|
message = {
|
||||||
|
"device_id": device_entry.id,
|
||||||
|
"type": "camera_motion",
|
||||||
|
"timestamp": utcnow(),
|
||||||
|
}
|
||||||
hass.bus.async_fire(NEST_EVENT, message)
|
hass.bus.async_fire(NEST_EVENT, message)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
assert calls[0].data == DATA_MESSAGE
|
assert calls[0].data == DATA_MESSAGE
|
||||||
|
|
||||||
|
|
||||||
async def test_fires_on_camera_person(hass: HomeAssistant, calls) -> None:
|
async def test_fires_on_camera_person(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
create_device: CreateDevice,
|
||||||
|
setup_platform: PlatformSetup,
|
||||||
|
calls,
|
||||||
|
) -> None:
|
||||||
"""Test camera_person triggers firing."""
|
"""Test camera_person triggers firing."""
|
||||||
assert await setup_automation(hass, DEVICE_ID, "camera_person")
|
create_device.create(
|
||||||
|
raw_data=make_camera(
|
||||||
|
device_id=DEVICE_ID,
|
||||||
|
traits={
|
||||||
|
"sdm.devices.traits.CameraMotion": {},
|
||||||
|
"sdm.devices.traits.CameraPerson": {},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
await setup_platform()
|
||||||
|
|
||||||
message = {"device_id": DEVICE_ID, "type": "camera_person", "timestamp": utcnow()}
|
device_registry = dr.async_get(hass)
|
||||||
|
device_entry = device_registry.async_get_device(identifiers={("nest", DEVICE_ID)})
|
||||||
|
|
||||||
|
assert await setup_automation(hass, device_entry.id, "camera_person")
|
||||||
|
|
||||||
|
message = {
|
||||||
|
"device_id": device_entry.id,
|
||||||
|
"type": "camera_person",
|
||||||
|
"timestamp": utcnow(),
|
||||||
|
}
|
||||||
hass.bus.async_fire(NEST_EVENT, message)
|
hass.bus.async_fire(NEST_EVENT, message)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
assert calls[0].data == DATA_MESSAGE
|
assert calls[0].data == DATA_MESSAGE
|
||||||
|
|
||||||
|
|
||||||
async def test_fires_on_camera_sound(hass: HomeAssistant, calls) -> None:
|
async def test_fires_on_camera_sound(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
create_device: CreateDevice,
|
||||||
|
setup_platform: PlatformSetup,
|
||||||
|
calls,
|
||||||
|
) -> None:
|
||||||
"""Test camera_person triggers firing."""
|
"""Test camera_person triggers firing."""
|
||||||
assert await setup_automation(hass, DEVICE_ID, "camera_sound")
|
create_device.create(
|
||||||
|
raw_data=make_camera(
|
||||||
|
device_id=DEVICE_ID,
|
||||||
|
traits={
|
||||||
|
"sdm.devices.traits.CameraMotion": {},
|
||||||
|
"sdm.devices.traits.CameraPerson": {},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
await setup_platform()
|
||||||
|
|
||||||
message = {"device_id": DEVICE_ID, "type": "camera_sound", "timestamp": utcnow()}
|
device_registry = dr.async_get(hass)
|
||||||
|
device_entry = device_registry.async_get_device(identifiers={("nest", DEVICE_ID)})
|
||||||
|
|
||||||
|
assert await setup_automation(hass, device_entry.id, "camera_sound")
|
||||||
|
|
||||||
|
message = {
|
||||||
|
"device_id": device_entry.id,
|
||||||
|
"type": "camera_sound",
|
||||||
|
"timestamp": utcnow(),
|
||||||
|
}
|
||||||
hass.bus.async_fire(NEST_EVENT, message)
|
hass.bus.async_fire(NEST_EVENT, message)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
assert calls[0].data == DATA_MESSAGE
|
assert calls[0].data == DATA_MESSAGE
|
||||||
|
|
||||||
|
|
||||||
async def test_fires_on_doorbell_chime(hass: HomeAssistant, calls) -> None:
|
async def test_fires_on_doorbell_chime(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
create_device: CreateDevice,
|
||||||
|
setup_platform: PlatformSetup,
|
||||||
|
calls,
|
||||||
|
) -> None:
|
||||||
"""Test doorbell_chime triggers firing."""
|
"""Test doorbell_chime triggers firing."""
|
||||||
assert await setup_automation(hass, DEVICE_ID, "doorbell_chime")
|
create_device.create(
|
||||||
|
raw_data=make_camera(
|
||||||
|
device_id=DEVICE_ID,
|
||||||
|
traits={
|
||||||
|
"sdm.devices.traits.CameraMotion": {},
|
||||||
|
"sdm.devices.traits.CameraPerson": {},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
await setup_platform()
|
||||||
|
|
||||||
message = {"device_id": DEVICE_ID, "type": "doorbell_chime", "timestamp": utcnow()}
|
device_registry = dr.async_get(hass)
|
||||||
|
device_entry = device_registry.async_get_device(identifiers={("nest", DEVICE_ID)})
|
||||||
|
|
||||||
|
assert await setup_automation(hass, device_entry.id, "doorbell_chime")
|
||||||
|
|
||||||
|
message = {
|
||||||
|
"device_id": device_entry.id,
|
||||||
|
"type": "doorbell_chime",
|
||||||
|
"timestamp": utcnow(),
|
||||||
|
}
|
||||||
hass.bus.async_fire(NEST_EVENT, message)
|
hass.bus.async_fire(NEST_EVENT, message)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
assert calls[0].data == DATA_MESSAGE
|
assert calls[0].data == DATA_MESSAGE
|
||||||
|
|
||||||
|
|
||||||
async def test_trigger_for_wrong_device_id(hass: HomeAssistant, calls) -> None:
|
async def test_trigger_for_wrong_device_id(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
create_device: CreateDevice,
|
||||||
|
setup_platform: PlatformSetup,
|
||||||
|
calls,
|
||||||
|
) -> None:
|
||||||
"""Test for turn_on and turn_off triggers firing."""
|
"""Test for turn_on and turn_off triggers firing."""
|
||||||
assert await setup_automation(hass, DEVICE_ID, "camera_motion")
|
create_device.create(
|
||||||
|
raw_data=make_camera(
|
||||||
|
device_id=DEVICE_ID,
|
||||||
|
traits={
|
||||||
|
"sdm.devices.traits.CameraMotion": {},
|
||||||
|
"sdm.devices.traits.CameraPerson": {},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
await setup_platform()
|
||||||
|
|
||||||
|
device_registry = dr.async_get(hass)
|
||||||
|
device_entry = device_registry.async_get_device(identifiers={("nest", DEVICE_ID)})
|
||||||
|
|
||||||
|
assert await setup_automation(hass, device_entry.id, "camera_motion")
|
||||||
|
|
||||||
message = {
|
message = {
|
||||||
"device_id": "wrong-device-id",
|
"device_id": "wrong-device-id",
|
||||||
@ -288,12 +399,31 @@ async def test_trigger_for_wrong_device_id(hass: HomeAssistant, calls) -> None:
|
|||||||
assert len(calls) == 0
|
assert len(calls) == 0
|
||||||
|
|
||||||
|
|
||||||
async def test_trigger_for_wrong_event_type(hass: HomeAssistant, calls) -> None:
|
async def test_trigger_for_wrong_event_type(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
create_device: CreateDevice,
|
||||||
|
setup_platform: PlatformSetup,
|
||||||
|
calls,
|
||||||
|
) -> None:
|
||||||
"""Test for turn_on and turn_off triggers firing."""
|
"""Test for turn_on and turn_off triggers firing."""
|
||||||
assert await setup_automation(hass, DEVICE_ID, "camera_motion")
|
create_device.create(
|
||||||
|
raw_data=make_camera(
|
||||||
|
device_id=DEVICE_ID,
|
||||||
|
traits={
|
||||||
|
"sdm.devices.traits.CameraMotion": {},
|
||||||
|
"sdm.devices.traits.CameraPerson": {},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
await setup_platform()
|
||||||
|
|
||||||
|
device_registry = dr.async_get(hass)
|
||||||
|
device_entry = device_registry.async_get_device(identifiers={("nest", DEVICE_ID)})
|
||||||
|
|
||||||
|
assert await setup_automation(hass, device_entry.id, "camera_motion")
|
||||||
|
|
||||||
message = {
|
message = {
|
||||||
"device_id": DEVICE_ID,
|
"device_id": device_entry.id,
|
||||||
"type": "wrong-event-type",
|
"type": "wrong-event-type",
|
||||||
"timestamp": utcnow(),
|
"timestamp": utcnow(),
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user