]> git.basschouten.com Git - openhab-addons.git/blob
dc479924d36bccb42f7d05e7d9eaa29dd556b17e
[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.math.BigDecimal;
16 import java.time.ZonedDateTime;
17 import java.util.List;
18 import java.util.Objects;
19 import java.util.Set;
20 import java.util.stream.Collectors;
21 import java.util.stream.Stream;
22
23 import com.google.gson.annotations.SerializedName;
24
25 /**
26  * The common SDM traits that are used in the {@link SDMDevice} and {@link SDMEvent} types.
27  *
28  * @author Wouter Born - Initial contribution
29  */
30 public class SDMTraits {
31
32     /**
33      * This trait belongs to any device that supports generation of images from events.
34      */
35     public static class SDMCameraEventImageTrait extends SDMCameraTrait {
36     }
37
38     /**
39      * This trait belongs to any device that supports taking images.
40      */
41     public static class SDMCameraImageTrait extends SDMCameraTrait {
42         /**
43          * Maximum image resolution that is supported.
44          */
45         public SDMResolution maxImageResolution;
46     }
47
48     /**
49      * This trait belongs to any device that supports live streaming.
50      */
51     public static class SDMCameraLiveStreamTrait extends SDMCameraTrait {
52         /**
53          * Maximum resolution of the video live stream.
54          */
55         public SDMResolution maxVideoResolution;
56
57         /**
58          * Video codecs supported for the live stream.
59          */
60         public List<String> videoCodecs;
61
62         /**
63          * Audio codecs supported for the live stream.
64          */
65         public List<String> audioCodecs;
66
67         /**
68          * Protocols supported for the live stream.
69          */
70         public List<String> supportedProtocols;
71     }
72
73     /**
74      * This trait belongs to any device that supports motion detection events.
75      */
76     public static class SDMCameraMotionTrait extends SDMCameraTrait {
77     }
78
79     /**
80      * This trait belongs to any device that supports person detection events.
81      */
82     public static class SDMCameraPersonTrait extends SDMCameraTrait {
83     }
84
85     /**
86      * This trait belongs to any device that supports sound detection events.
87      */
88     public static class SDMCameraSoundTrait extends SDMCameraTrait {
89     }
90
91     public static class SDMCameraTrait extends SDMTrait {
92     }
93
94     public enum SDMConnectivityStatus {
95         OFFLINE,
96         ONLINE
97     }
98
99     /**
100      * This trait belongs to any device that has connectivity information.
101      */
102     public static class SDMConnectivityTrait extends SDMDeviceTrait {
103         /**
104          * Device connectivity status.
105          */
106         public SDMConnectivityStatus status;
107     }
108
109     /**
110      * This trait belongs to any device for device-related information.
111      */
112     public static class SDMDeviceInfoTrait extends SDMDeviceTrait {
113         /**
114          * Custom name of the device. Corresponds to the Label value for a device in the Nest App.
115          */
116         public String customName;
117     }
118
119     /**
120      * This trait belongs to any device for device-related settings information.
121      */
122     public static class SDMDeviceSettingsTrait extends SDMDeviceTrait {
123         /**
124          * Format of the degrees displayed on a Google Nest Thermostat.
125          */
126         public SDMTemperatureScale temperatureScale;
127     }
128
129     public static class SDMDeviceTrait extends SDMTrait {
130     }
131
132     /**
133      * This trait belongs to any device that supports a doorbell chime and related press events.
134      */
135     public static class SDMDoorbellChimeTrait extends SDMDoorbellTrait {
136     }
137
138     public static class SDMDoorbellTrait extends SDMTrait {
139     }
140
141     public enum SDMThermostatEcoMode {
142         MANUAL_ECO,
143         OFF
144     }
145
146     /**
147      * This trait belongs to any device that has the system ability to control the fan.
148      */
149     public static class SDMFanTrait extends SDMDeviceTrait {
150         /**
151          * Current timer mode.
152          */
153         public SDMFanTimerMode timerMode;
154
155         /**
156          * Timestamp, in RFC 3339 format, at which timer mode will turn to OFF.
157          */
158         public ZonedDateTime timerTimeout;
159     }
160
161     /**
162      * This trait belongs to any device that has a sensor to measure humidity.
163      */
164     public static class SDMHumidityTrait extends SDMDeviceTrait {
165         /**
166          * Percent humidity, measured at the device.
167          */
168         public BigDecimal ambientHumidityPercent;
169     }
170
171     public enum SDMHvacStatus {
172         OFF,
173         HEATING,
174         COOLING
175     }
176
177     public static class SDMResolution {
178         /**
179          * Maximum image resolution width.
180          */
181         public int width;
182
183         /**
184          * Maximum image resolution height.
185          */
186         public int height;
187     }
188
189     /**
190      * This trait belongs to any room for room-related information.
191      */
192     public static class SDMRoomInfoTrait extends SDMStructureTrait {
193         /**
194          * Custom name of the room. Corresponds to the name in the Google Home App.
195          */
196         public String customName;
197     }
198
199     /**
200      * This trait belongs to any structure for structure-related information.
201      */
202     public static class SDMStructureInfoTrait extends SDMStructureTrait {
203         /**
204          * Custom name of the structure. Corresponds to the name in the Google Home App.
205          */
206         public String customName;
207     }
208
209     public static class SDMStructureTrait extends SDMTrait {
210     }
211
212     public enum SDMTemperatureScale {
213         CELSIUS,
214         FAHRENHEIT;
215     }
216
217     /**
218      * This trait belongs to any device that has a sensor to measure temperature.
219      */
220     public static class SDMTemperatureTrait extends SDMDeviceTrait {
221         /**
222          * Temperature in degrees Celsius, measured at the device.
223          */
224         public BigDecimal ambientTemperatureCelsius;
225     }
226
227     /**
228      * This trait belongs to device types of THERMOSTAT that support ECO modes.
229      */
230     public static class SDMThermostatEcoTrait extends SDMThermostatTrait {
231         /**
232          * List of supported Eco modes.
233          */
234         public List<SDMThermostatEcoMode> availableModes;
235
236         /**
237          * The current Eco mode of the thermostat.
238          */
239         public SDMThermostatEcoMode mode;
240
241         /**
242          * Lowest temperature in Celsius at which the thermostat begins heating in Eco mode.
243          */
244         public BigDecimal heatCelsius;
245
246         /**
247          * Highest temperature in Celsius at which the thermostat begins cooling in Eco mode.
248          */
249         public BigDecimal coolCelsius;
250     }
251
252     /**
253      * This trait belongs to device types of THERMOSTAT that can report HVAC details.
254      */
255     public static class SDMThermostatHvacTrait extends SDMThermostatTrait {
256         /**
257          * Current HVAC status of the thermostat.
258          */
259         public SDMHvacStatus status;
260     }
261
262     public enum SDMThermostatMode {
263         HEAT,
264         COOL,
265         HEATCOOL,
266         OFF
267     }
268
269     /**
270      * This trait belongs to device types of THERMOSTAT that support different thermostat modes.
271      */
272     public static class SDMThermostatModeTrait extends SDMThermostatTrait {
273         /**
274          * List of supported thermostat modes.
275          */
276         public List<SDMThermostatMode> availableModes;
277
278         /**
279          * The current thermostat mode.
280          */
281         public SDMThermostatMode mode;
282     }
283
284     /**
285      * This trait belongs to device types of THERMOSTAT that support setting target temperature and temperature range.
286      */
287     public static class SDMThermostatTemperatureSetpointTrait extends SDMThermostatTrait {
288         /**
289          * Target temperature in Celsius for thermostat HEAT and HEATCOOL modes.
290          */
291         public BigDecimal heatCelsius;
292
293         /**
294          * Target temperature in Celsius for thermostat COOL and HEATCOOL modes.
295          */
296         public BigDecimal coolCelsius;
297     }
298
299     public static class SDMThermostatTrait extends SDMTrait {
300     }
301
302     public enum SDMFanTimerMode {
303         ON,
304         OFF
305     }
306
307     public static class SDMTrait {
308     }
309
310     @SerializedName("sdm.devices.traits.CameraEventImage")
311     public SDMCameraEventImageTrait cameraEventImage;
312
313     @SerializedName("sdm.devices.traits.CameraImage")
314     public SDMCameraImageTrait cameraImage;
315
316     @SerializedName("sdm.devices.traits.CameraLiveStream")
317     public SDMCameraLiveStreamTrait cameraLiveStream;
318
319     @SerializedName("sdm.devices.traits.CameraMotion")
320     public SDMCameraMotionTrait cameraMotion;
321
322     @SerializedName("sdm.devices.traits.CameraPerson")
323     public SDMCameraPersonTrait cameraPerson;
324
325     @SerializedName("sdm.devices.traits.CameraSound")
326     public SDMCameraSoundTrait cameraSound;
327
328     @SerializedName("sdm.devices.traits.Connectivity")
329     public SDMConnectivityTrait connectivity;
330
331     @SerializedName("sdm.devices.traits.DoorbellChime")
332     public SDMDoorbellChimeTrait doorbellChime;
333
334     @SerializedName("sdm.devices.traits.Fan")
335     public SDMFanTrait fan;
336
337     @SerializedName("sdm.devices.traits.Humidity")
338     public SDMHumidityTrait humidity;
339
340     @SerializedName("sdm.devices.traits.Info")
341     public SDMDeviceInfoTrait deviceInfo;
342
343     @SerializedName("sdm.devices.traits.Settings")
344     public SDMDeviceSettingsTrait deviceSettings;
345
346     @SerializedName("sdm.devices.traits.Temperature")
347     public SDMTemperatureTrait temperature;
348
349     @SerializedName("sdm.devices.traits.ThermostatEco")
350     public SDMThermostatEcoTrait thermostatEco;
351
352     @SerializedName("sdm.devices.traits.ThermostatHvac")
353     public SDMThermostatHvacTrait thermostatHvac;
354
355     @SerializedName("sdm.devices.traits.ThermostatMode")
356     public SDMThermostatModeTrait thermostatMode;
357
358     @SerializedName("sdm.devices.traits.ThermostatTemperatureSetpoint")
359     public SDMThermostatTemperatureSetpointTrait thermostatTemperatureSetpoint;
360
361     @SerializedName("sdm.structures.traits.Info")
362     public SDMStructureInfoTrait structureInfo;
363
364     @SerializedName("sdm.structures.traits.RoomInfo")
365     public SDMRoomInfoTrait roomInfo;
366
367     public <T> Stream<SDMTrait> traitStream() {
368         return Stream.of(cameraEventImage, cameraImage, cameraLiveStream, cameraMotion, cameraPerson, cameraSound,
369                 connectivity, doorbellChime, fan, humidity, deviceInfo, deviceSettings, temperature, thermostatEco,
370                 thermostatHvac, thermostatMode, thermostatTemperatureSetpoint, structureInfo, roomInfo)
371                 .filter(Objects::nonNull);
372     }
373
374     public List<SDMTrait> traitList() {
375         return traitStream().collect(Collectors.toList());
376     }
377
378     public Set<SDMTrait> traitSet() {
379         return traitStream().collect(Collectors.toSet());
380     }
381
382     public void updateTraits(SDMTraits other) {
383         if (other.cameraEventImage != null) {
384             cameraEventImage = other.cameraEventImage;
385         }
386         if (other.cameraImage != null) {
387             cameraImage = other.cameraImage;
388         }
389         if (other.cameraLiveStream != null) {
390             cameraLiveStream = other.cameraLiveStream;
391         }
392         if (other.cameraMotion != null) {
393             cameraMotion = other.cameraMotion;
394         }
395         if (other.cameraPerson != null) {
396             cameraPerson = other.cameraPerson;
397         }
398         if (other.cameraSound != null) {
399             cameraSound = other.cameraSound;
400         }
401         if (other.connectivity != null) {
402             connectivity = other.connectivity;
403         }
404         if (other.doorbellChime != null) {
405             doorbellChime = other.doorbellChime;
406         }
407         if (other.fan != null) {
408             fan = other.fan;
409         }
410         if (other.humidity != null) {
411             humidity = other.humidity;
412         }
413         if (other.deviceInfo != null) {
414             deviceInfo = other.deviceInfo;
415         }
416         if (other.deviceSettings != null) {
417             deviceSettings = other.deviceSettings;
418         }
419         if (other.temperature != null) {
420             temperature = other.temperature;
421         }
422         if (other.thermostatEco != null) {
423             thermostatEco = other.thermostatEco;
424         }
425         if (other.thermostatHvac != null) {
426             thermostatHvac = other.thermostatHvac;
427         }
428         if (other.thermostatMode != null) {
429             thermostatMode = other.thermostatMode;
430         }
431         if (other.thermostatTemperatureSetpoint != null) {
432             thermostatTemperatureSetpoint = other.thermostatTemperatureSetpoint;
433         }
434         if (other.structureInfo != null) {
435             structureInfo = other.structureInfo;
436         }
437         if (other.roomInfo != null) {
438             roomInfo = other.roomInfo;
439         }
440     }
441 }