Use real devices in nest device trigger tests (#102692)

pull/102787/head
Erik Montnemery 2023-10-25 15:13:38 +02:00 committed by GitHub
parent e4a1efb680
commit 6e72499f96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 147 additions and 17 deletions

View File

@ -230,53 +230,164 @@ async def test_no_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."""
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)
await hass.async_block_till_done()
assert len(calls) == 1
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."""
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)
await hass.async_block_till_done()
assert len(calls) == 1
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."""
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)
await hass.async_block_till_done()
assert len(calls) == 1
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."""
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)
await hass.async_block_till_done()
assert len(calls) == 1
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."""
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 = {
"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
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."""
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 = {
"device_id": DEVICE_ID,
"device_id": device_entry.id,
"type": "wrong-event-type",
"timestamp": utcnow(),
}