Publish nest event ids in camera related events (#58299)

This commit is contained in:
Allen Porter 2021-10-26 08:14:12 -07:00 committed by GitHub
parent 11d8bcf0e2
commit f1b082a369
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 6 deletions

View File

@ -122,13 +122,14 @@ class SignalUpdateCallback:
device_entry = device_registry.async_get_device({(DOMAIN, device_id)})
if not device_entry:
return
for event in events:
if not (event_type := EVENT_NAME_MAP.get(event)):
for api_event_type, image_event in events.items():
if not (event_type := EVENT_NAME_MAP.get(api_event_type)):
continue
message = {
"device_id": device_entry.id,
"type": event_type,
"timestamp": event_message.timestamp,
"nest_event_id": image_event.event_id,
}
self._hass.bus.async_fire(NEST_EVENT, message)

View File

@ -17,12 +17,22 @@ NEST_EVENT = "nest_event"
# The nest_event namespace will fire events that are triggered from messages
# received via the Pub/Sub subscriber.
#
# An example event data payload:
# An example event payload:
#
# {
# "device_id": "enterprises/some/device/identifier"
# "event_type": "camera_motion"
# "event_type": "nest_event"
# "data": {
# "device_id": "my-device-id",
# "type": "camera_motion",
# "timestamp": "2021-10-24T19:42:43.304000+00:00",
# "nest_event_id": "KcO1HIR9sPKQ2bqby_vTcCcEov..."
# },
# ...
# }
#
# The nest_event_id corresponds to the event id in the SDM API used to retrieve
# snapshots.
#
# The following event types are fired:
EVENT_DOORBELL_CHIME = "doorbell_chime"
EVENT_CAMERA_MOTION = "camera_motion"

View File

@ -1,4 +1,4 @@
"""Test for Nest binary sensor platform for the Smart Device Management API.
"""Test for Nest events for the Smart Device Management API.
These tests fake out the subscriber/devicemanager, and are not using a real
pubsub subscriber.
@ -117,6 +117,7 @@ async def test_doorbell_chime_event(hass):
"device_id": entry.device_id,
"type": "doorbell_chime",
"timestamp": event_time,
"nest_event_id": EVENT_ID,
}
@ -144,6 +145,7 @@ async def test_camera_motion_event(hass):
"device_id": entry.device_id,
"type": "camera_motion",
"timestamp": event_time,
"nest_event_id": EVENT_ID,
}
@ -171,6 +173,7 @@ async def test_camera_sound_event(hass):
"device_id": entry.device_id,
"type": "camera_sound",
"timestamp": event_time,
"nest_event_id": EVENT_ID,
}
@ -198,6 +201,7 @@ async def test_camera_person_event(hass):
"device_id": entry.device_id,
"type": "camera_person",
"timestamp": event_time,
"nest_event_id": EVENT_ID,
}
@ -234,11 +238,13 @@ async def test_camera_multiple_event(hass):
"device_id": entry.device_id,
"type": "camera_motion",
"timestamp": event_time,
"nest_event_id": EVENT_ID,
}
assert events[1].data == {
"device_id": entry.device_id,
"type": "camera_person",
"timestamp": event_time,
"nest_event_id": EVENT_ID,
}