Home Assistant Unofficial Reference 2024.12.1
events.py
Go to the documentation of this file.
1 """Library from Pub/sub messages, events and device triggers."""
2 
3 from google_nest_sdm.camera_traits import (
4  CameraMotionTrait,
5  CameraPersonTrait,
6  CameraSoundTrait,
7 )
8 from google_nest_sdm.doorbell_traits import DoorbellChimeTrait
9 from google_nest_sdm.event import (
10  CameraMotionEvent,
11  CameraPersonEvent,
12  CameraSoundEvent,
13  DoorbellChimeEvent,
14 )
15 
16 NEST_EVENT = "nest_event"
17 # The nest_event namespace will fire events that are triggered from messages
18 # received via the Pub/Sub subscriber.
19 #
20 # An example event payload:
21 #
22 # {
23 # "event_type": "nest_event"
24 # "data": {
25 # "device_id": "my-device-id",
26 # "type": "camera_motion",
27 # "timestamp": "2021-10-24T19:42:43.304000+00:00",
28 # "nest_event_id": "KcO1HIR9sPKQ2bqby_vTcCcEov...",
29 # "zones": ["Zone 1"],
30 # },
31 # ...
32 # }
33 #
34 # The nest_event_id corresponds to the event id in the SDM API used to retrieve
35 # snapshots.
36 #
37 # The following event types are fired:
38 EVENT_DOORBELL_CHIME = "doorbell_chime"
39 EVENT_CAMERA_MOTION = "camera_motion"
40 EVENT_CAMERA_PERSON = "camera_person"
41 EVENT_CAMERA_SOUND = "camera_sound"
42 
43 # Mapping of supported device traits to home assistant event types. Devices
44 # that support these traits will generate Pub/Sub event messages in
45 # the EVENT_NAME_MAP
46 DEVICE_TRAIT_TRIGGER_MAP = {
47  DoorbellChimeTrait.NAME.value: EVENT_DOORBELL_CHIME,
48  CameraMotionTrait.NAME.value: EVENT_CAMERA_MOTION,
49  CameraPersonTrait.NAME.value: EVENT_CAMERA_PERSON,
50  CameraSoundTrait.NAME.value: EVENT_CAMERA_SOUND,
51 }
52 
53 
54 # Mapping of incoming SDM Pub/Sub event message types to the home assistant
55 # event type to fire.
56 EVENT_NAME_MAP = {
57  DoorbellChimeEvent.NAME.value: EVENT_DOORBELL_CHIME,
58  CameraMotionEvent.NAME.value: EVENT_CAMERA_MOTION,
59  CameraPersonEvent.NAME.value: EVENT_CAMERA_PERSON,
60  CameraSoundEvent.NAME.value: EVENT_CAMERA_SOUND,
61 }
62 
63 # Names for event types shown in the media source
64 MEDIA_SOURCE_EVENT_TITLE_MAP = {
65  DoorbellChimeEvent.NAME.value: "Doorbell",
66  CameraMotionEvent.NAME.value: "Motion",
67  CameraPersonEvent.NAME.value: "Person",
68  CameraSoundEvent.NAME.value: "Sound",
69 }