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 <a href="https://developers.google.com/nest/device-access/api/events">
31 * https://developers.google.com/nest/device-access/api/events</a>
33 public class SDMEvent {
36 * An object that details information about the relation update.
38 public static class SDMRelationUpdate {
39 public SDMRelationUpdateType type;
42 * The resource that the object now has a relation with.
44 public SDMResourceName subject;
47 * The resource that triggered the event.
49 public SDMResourceName object;
52 public enum SDMRelationUpdateType {
59 * An object that details information about the resource update.
61 public static class SDMResourceUpdate {
62 public SDMResourceName name;
63 public SDMTraits traits;
64 public SDMResourceUpdateEvents events;
67 public static class SDMDeviceEvent {
68 public String eventId;
69 public String eventSessionId;
72 public static class SDMResourceUpdateEvents extends SDMTraits {
73 @SerializedName("sdm.devices.events.CameraMotion.Motion")
74 public SDMDeviceEvent cameraMotionEvent;
76 @SerializedName("sdm.devices.events.CameraPerson.Person")
77 public SDMDeviceEvent cameraPersonEvent;
79 @SerializedName("sdm.devices.events.CameraSound.Sound")
80 public SDMDeviceEvent cameraSoundEvent;
82 @SerializedName("sdm.devices.events.DoorbellChime.Chime")
83 public SDMDeviceEvent doorbellChimeEvent;
85 public <T> Stream<SDMDeviceEvent> eventStream() {
86 return Stream.of(cameraMotionEvent, cameraPersonEvent, cameraSoundEvent, doorbellChimeEvent)
87 .filter(Objects::nonNull);
90 public List<SDMDeviceEvent> eventList() {
91 return eventStream().collect(Collectors.toList());
94 public Set<SDMDeviceEvent> eventSet() {
95 return eventStream().collect(Collectors.toSet());
100 * The unique identifier for the event.
102 public String eventId;
105 * An object that details information about the relation update.
107 public SDMRelationUpdate relationUpdate;
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.
113 public List<SDMResourceName> resourceGroup;
116 * An object that details information about the resource update.
118 public SDMResourceUpdate resourceUpdate;
121 * The time when the event occurred.
123 public ZonedDateTime timestamp;
126 * A unique, obfuscated identifier that represents the user.
128 public String userId;