]> git.basschouten.com Git - openhab-addons.git/blob
db336058778906767f2a056fab2cf7ed48eaf369
[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 https://developers.google.com/nest/device-access/api/events
31  */
32 public class SDMEvent {
33
34     /**
35      * An object that details information about the relation update.
36      */
37     public static class SDMRelationUpdate {
38         public SDMRelationUpdateType type;
39
40         /**
41          * The resource that the object now has a relation with.
42          */
43         public SDMResourceName subject;
44
45         /**
46          * The resource that triggered the event.
47          */
48         public SDMResourceName object;
49     }
50
51     public enum SDMRelationUpdateType {
52         CREATED,
53         DELETED,
54         UPDATED
55     }
56
57     /**
58      * An object that details information about the resource update.
59      */
60     public static class SDMResourceUpdate {
61         public SDMResourceName name;
62         public SDMTraits traits;
63         public SDMResourceUpdateEvents events;
64     }
65
66     public static class SDMDeviceEvent {
67         public String eventId;
68         public String eventSessionId;
69     }
70
71     public static class SDMResourceUpdateEvents extends SDMTraits {
72         @SerializedName("sdm.devices.events.CameraMotion.Motion")
73         public SDMDeviceEvent cameraMotionEvent;
74
75         @SerializedName("sdm.devices.events.CameraPerson.Person")
76         public SDMDeviceEvent cameraPersonEvent;
77
78         @SerializedName("sdm.devices.events.CameraSound.Sound")
79         public SDMDeviceEvent cameraSoundEvent;
80
81         @SerializedName("sdm.devices.events.DoorbellChime.Chime")
82         public SDMDeviceEvent doorbellChimeEvent;
83
84         public <T> Stream<SDMDeviceEvent> eventStream() {
85             return Stream.of(cameraMotionEvent, cameraPersonEvent, cameraSoundEvent, doorbellChimeEvent)
86                     .filter(Objects::nonNull);
87         }
88
89         public List<SDMDeviceEvent> eventList() {
90             return eventStream().collect(Collectors.toList());
91         }
92
93         public Set<SDMDeviceEvent> eventSet() {
94             return eventStream().collect(Collectors.toSet());
95         }
96     }
97
98     /**
99      * The unique identifier for the event.
100      */
101     public String eventId;
102
103     /**
104      * An object that details information about the relation update.
105      */
106     public SDMRelationUpdate relationUpdate;
107
108     /**
109      * An object that indicates resources that might have similar updates to this event.
110      * The resource of the event itself (from the resourceUpdate object) will always be present in this object.
111      */
112     public List<SDMResourceName> resourceGroup;
113
114     /**
115      * An object that details information about the resource update.
116      */
117     public SDMResourceUpdate resourceUpdate;
118
119     /**
120      * The time when the event occurred.
121      */
122     public ZonedDateTime timestamp;
123
124     /**
125      * A unique, obfuscated identifier that represents the user.
126      */
127     public String userId;
128 }