]> git.basschouten.com Git - openhab-addons.git/blob
76e8d00c6441248f9b22d44d3351b29df3b0c200
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.nest.internal.sdm.dto;
14
15 import java.time.ZonedDateTime;
16 import java.util.List;
17 import java.util.Objects;
18 import java.util.Set;
19 import java.util.stream.Collectors;
20 import java.util.stream.Stream;
21
22 import com.google.gson.annotations.SerializedName;
23
24 /**
25  * The {@link SDMEvent} is used for mapping the SDM event data received from the SDM API in messages pulled from a
26  * Pub/Sub topic.
27  *
28  * @author Wouter Born - Initial contribution
29  *
30  * @see <a href="https://developers.google.com/nest/device-access/api/events">
31  *      https://developers.google.com/nest/device-access/api/events</a>
32  */
33 public class SDMEvent {
34
35     /**
36      * An object that details information about the relation update.
37      */
38     public static class SDMRelationUpdate {
39         public SDMRelationUpdateType type;
40
41         /**
42          * The resource that the object now has a relation with.
43          */
44         public SDMResourceName subject;
45
46         /**
47          * The resource that triggered the event.
48          */
49         public SDMResourceName object;
50     }
51
52     public enum SDMRelationUpdateType {
53         CREATED,
54         DELETED,
55         UPDATED
56     }
57
58     /**
59      * An object that details information about the resource update.
60      */
61     public static class SDMResourceUpdate {
62         public SDMResourceName name;
63         public SDMTraits traits;
64         public SDMResourceUpdateEvents events;
65     }
66
67     public static class SDMDeviceEvent {
68         public String eventId;
69         public String eventSessionId;
70     }
71
72     public static class SDMResourceUpdateEvents extends SDMTraits {
73         @SerializedName("sdm.devices.events.CameraMotion.Motion")
74         public SDMDeviceEvent cameraMotionEvent;
75
76         @SerializedName("sdm.devices.events.CameraPerson.Person")
77         public SDMDeviceEvent cameraPersonEvent;
78
79         @SerializedName("sdm.devices.events.CameraSound.Sound")
80         public SDMDeviceEvent cameraSoundEvent;
81
82         @SerializedName("sdm.devices.events.DoorbellChime.Chime")
83         public SDMDeviceEvent doorbellChimeEvent;
84
85         public <T> Stream<SDMDeviceEvent> eventStream() {
86             return Stream.of(cameraMotionEvent, cameraPersonEvent, cameraSoundEvent, doorbellChimeEvent)
87                     .filter(Objects::nonNull);
88         }
89
90         public List<SDMDeviceEvent> eventList() {
91             return eventStream().collect(Collectors.toList());
92         }
93
94         public Set<SDMDeviceEvent> eventSet() {
95             return eventStream().collect(Collectors.toSet());
96         }
97     }
98
99     /**
100      * The unique identifier for the event.
101      */
102     public String eventId;
103
104     /**
105      * An object that details information about the relation update.
106      */
107     public SDMRelationUpdate relationUpdate;
108
109     /**
110      * An object that indicates resources that might have similar updates to this event.
111      * The resource of the event itself (from the resourceUpdate object) will always be present in this object.
112      */
113     public List<SDMResourceName> resourceGroup;
114
115     /**
116      * An object that details information about the resource update.
117      */
118     public SDMResourceUpdate resourceUpdate;
119
120     /**
121      * The time when the event occurred.
122      */
123     public ZonedDateTime timestamp;
124
125     /**
126      * A unique, obfuscated identifier that represents the user.
127      */
128     public String userId;
129 }