2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.nest.internal.sdm.dto;
15 import java.time.ZonedDateTime;
16 import java.util.List;
17 import java.util.Objects;
19 import java.util.stream.Collectors;
20 import java.util.stream.Stream;
22 import com.google.gson.annotations.SerializedName;
25 * The {@link SDMEvent} is used for mapping the SDM event data received from the SDM API in messages pulled from a
28 * @author Wouter Born - Initial contribution
30 * @see https://developers.google.com/nest/device-access/api/events
32 public class SDMEvent {
35 * An object that details information about the relation update.
37 public static class SDMRelationUpdate {
38 public SDMRelationUpdateType type;
41 * The resource that the object now has a relation with.
43 public SDMResourceName subject;
46 * The resource that triggered the event.
48 public SDMResourceName object;
51 public enum SDMRelationUpdateType {
58 * An object that details information about the resource update.
60 public static class SDMResourceUpdate {
61 public SDMResourceName name;
62 public SDMTraits traits;
63 public SDMResourceUpdateEvents events;
66 public static class SDMDeviceEvent {
67 public String eventId;
68 public String eventSessionId;
71 public static class SDMResourceUpdateEvents extends SDMTraits {
72 @SerializedName("sdm.devices.events.CameraMotion.Motion")
73 public SDMDeviceEvent cameraMotionEvent;
75 @SerializedName("sdm.devices.events.CameraPerson.Person")
76 public SDMDeviceEvent cameraPersonEvent;
78 @SerializedName("sdm.devices.events.CameraSound.Sound")
79 public SDMDeviceEvent cameraSoundEvent;
81 @SerializedName("sdm.devices.events.DoorbellChime.Chime")
82 public SDMDeviceEvent doorbellChimeEvent;
84 public <T> Stream<SDMDeviceEvent> eventStream() {
85 return Stream.of(cameraMotionEvent, cameraPersonEvent, cameraSoundEvent, doorbellChimeEvent)
86 .filter(Objects::nonNull);
89 public List<SDMDeviceEvent> eventList() {
90 return eventStream().collect(Collectors.toList());
93 public Set<SDMDeviceEvent> eventSet() {
94 return eventStream().collect(Collectors.toSet());
99 * The unique identifier for the event.
101 public String eventId;
104 * An object that details information about the relation update.
106 public SDMRelationUpdate relationUpdate;
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.
112 public List<SDMResourceName> resourceGroup;
115 * An object that details information about the resource update.
117 public SDMResourceUpdate resourceUpdate;
120 * The time when the event occurred.
122 public ZonedDateTime timestamp;
125 * A unique, obfuscated identifier that represents the user.
127 public String userId;