diff --git a/homeassistant/components/nest/__init__.py b/homeassistant/components/nest/__init__.py index 87682c7043e..fce475e1788 100644 --- a/homeassistant/components/nest/__init__.py +++ b/homeassistant/components/nest/__init__.py @@ -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) diff --git a/homeassistant/components/nest/events.py b/homeassistant/components/nest/events.py index abfe688c71c..6802a98cc40 100644 --- a/homeassistant/components/nest/events.py +++ b/homeassistant/components/nest/events.py @@ -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" diff --git a/tests/components/nest/test_events.py b/tests/components/nest/test_events.py index df459a35f71..6e9dd7dd40d 100644 --- a/tests/components/nest/test_events.py +++ b/tests/components/nest/test_events.py @@ -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, }