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.math.BigDecimal;
16 import java.time.ZonedDateTime;
17 import java.util.List;
18 import java.util.Objects;
20 import java.util.stream.Collectors;
21 import java.util.stream.Stream;
23 import com.google.gson.annotations.SerializedName;
26 * The common SDM traits that are used in the {@link SDMDevice} and {@link SDMEvent} types.
28 * @author Wouter Born - Initial contribution
30 public class SDMTraits {
33 * This trait belongs to any device that supports generation of images from events.
35 public static class SDMCameraEventImageTrait extends SDMCameraTrait {
39 * This trait belongs to any device that supports taking images.
41 public static class SDMCameraImageTrait extends SDMCameraTrait {
43 * Maximum image resolution that is supported.
45 public SDMResolution maxImageResolution;
49 * This trait belongs to any device that supports live streaming.
51 public static class SDMCameraLiveStreamTrait extends SDMCameraTrait {
53 * Maximum resolution of the video live stream.
55 public SDMResolution maxVideoResolution;
58 * Video codecs supported for the live stream.
60 public List<String> videoCodecs;
63 * Audio codecs supported for the live stream.
65 public List<String> audioCodecs;
68 * Protocols supported for the live stream.
70 public List<String> supportedProtocols;
74 * This trait belongs to any device that supports motion detection events.
76 public static class SDMCameraMotionTrait extends SDMCameraTrait {
80 * This trait belongs to any device that supports person detection events.
82 public static class SDMCameraPersonTrait extends SDMCameraTrait {
86 * This trait belongs to any device that supports sound detection events.
88 public static class SDMCameraSoundTrait extends SDMCameraTrait {
91 public static class SDMCameraTrait extends SDMTrait {
94 public enum SDMConnectivityStatus {
100 * This trait belongs to any device that has connectivity information.
102 public static class SDMConnectivityTrait extends SDMDeviceTrait {
104 * Device connectivity status.
106 public SDMConnectivityStatus status;
110 * This trait belongs to any device for device-related information.
112 public static class SDMDeviceInfoTrait extends SDMDeviceTrait {
114 * Custom name of the device. Corresponds to the Label value for a device in the Nest App.
116 public String customName;
120 * This trait belongs to any device for device-related settings information.
122 public static class SDMDeviceSettingsTrait extends SDMDeviceTrait {
124 * Format of the degrees displayed on a Google Nest Thermostat.
126 public SDMTemperatureScale temperatureScale;
129 public static class SDMDeviceTrait extends SDMTrait {
133 * This trait belongs to any device that supports a doorbell chime and related press events.
135 public static class SDMDoorbellChimeTrait extends SDMDoorbellTrait {
138 public static class SDMDoorbellTrait extends SDMTrait {
141 public enum SDMThermostatEcoMode {
147 * This trait belongs to any device that has the system ability to control the fan.
149 public static class SDMFanTrait extends SDMDeviceTrait {
151 * Current timer mode.
153 public SDMFanTimerMode timerMode;
156 * Timestamp, in RFC 3339 format, at which timer mode will turn to OFF.
158 public ZonedDateTime timerTimeout;
162 * This trait belongs to any device that has a sensor to measure humidity.
164 public static class SDMHumidityTrait extends SDMDeviceTrait {
166 * Percent humidity, measured at the device.
168 public BigDecimal ambientHumidityPercent;
171 public enum SDMHvacStatus {
177 public static class SDMResolution {
179 * Maximum image resolution width.
184 * Maximum image resolution height.
190 * This trait belongs to any room for room-related information.
192 public static class SDMRoomInfoTrait extends SDMStructureTrait {
194 * Custom name of the room. Corresponds to the name in the Google Home App.
196 public String customName;
200 * This trait belongs to any structure for structure-related information.
202 public static class SDMStructureInfoTrait extends SDMStructureTrait {
204 * Custom name of the structure. Corresponds to the name in the Google Home App.
206 public String customName;
209 public static class SDMStructureTrait extends SDMTrait {
212 public enum SDMTemperatureScale {
218 * This trait belongs to any device that has a sensor to measure temperature.
220 public static class SDMTemperatureTrait extends SDMDeviceTrait {
222 * Temperature in degrees Celsius, measured at the device.
224 public BigDecimal ambientTemperatureCelsius;
228 * This trait belongs to device types of THERMOSTAT that support ECO modes.
230 public static class SDMThermostatEcoTrait extends SDMThermostatTrait {
232 * List of supported Eco modes.
234 public List<SDMThermostatEcoMode> availableModes;
237 * The current Eco mode of the thermostat.
239 public SDMThermostatEcoMode mode;
242 * Lowest temperature in Celsius at which the thermostat begins heating in Eco mode.
244 public BigDecimal heatCelsius;
247 * Highest temperature in Celsius at which the thermostat begins cooling in Eco mode.
249 public BigDecimal coolCelsius;
253 * This trait belongs to device types of THERMOSTAT that can report HVAC details.
255 public static class SDMThermostatHvacTrait extends SDMThermostatTrait {
257 * Current HVAC status of the thermostat.
259 public SDMHvacStatus status;
262 public enum SDMThermostatMode {
270 * This trait belongs to device types of THERMOSTAT that support different thermostat modes.
272 public static class SDMThermostatModeTrait extends SDMThermostatTrait {
274 * List of supported thermostat modes.
276 public List<SDMThermostatMode> availableModes;
279 * The current thermostat mode.
281 public SDMThermostatMode mode;
285 * This trait belongs to device types of THERMOSTAT that support setting target temperature and temperature range.
287 public static class SDMThermostatTemperatureSetpointTrait extends SDMThermostatTrait {
289 * Target temperature in Celsius for thermostat HEAT and HEATCOOL modes.
291 public BigDecimal heatCelsius;
294 * Target temperature in Celsius for thermostat COOL and HEATCOOL modes.
296 public BigDecimal coolCelsius;
299 public static class SDMThermostatTrait extends SDMTrait {
302 public enum SDMFanTimerMode {
307 public static class SDMTrait {
310 @SerializedName("sdm.devices.traits.CameraEventImage")
311 public SDMCameraEventImageTrait cameraEventImage;
313 @SerializedName("sdm.devices.traits.CameraImage")
314 public SDMCameraImageTrait cameraImage;
316 @SerializedName("sdm.devices.traits.CameraLiveStream")
317 public SDMCameraLiveStreamTrait cameraLiveStream;
319 @SerializedName("sdm.devices.traits.CameraMotion")
320 public SDMCameraMotionTrait cameraMotion;
322 @SerializedName("sdm.devices.traits.CameraPerson")
323 public SDMCameraPersonTrait cameraPerson;
325 @SerializedName("sdm.devices.traits.CameraSound")
326 public SDMCameraSoundTrait cameraSound;
328 @SerializedName("sdm.devices.traits.Connectivity")
329 public SDMConnectivityTrait connectivity;
331 @SerializedName("sdm.devices.traits.DoorbellChime")
332 public SDMDoorbellChimeTrait doorbellChime;
334 @SerializedName("sdm.devices.traits.Fan")
335 public SDMFanTrait fan;
337 @SerializedName("sdm.devices.traits.Humidity")
338 public SDMHumidityTrait humidity;
340 @SerializedName("sdm.devices.traits.Info")
341 public SDMDeviceInfoTrait deviceInfo;
343 @SerializedName("sdm.devices.traits.Settings")
344 public SDMDeviceSettingsTrait deviceSettings;
346 @SerializedName("sdm.devices.traits.Temperature")
347 public SDMTemperatureTrait temperature;
349 @SerializedName("sdm.devices.traits.ThermostatEco")
350 public SDMThermostatEcoTrait thermostatEco;
352 @SerializedName("sdm.devices.traits.ThermostatHvac")
353 public SDMThermostatHvacTrait thermostatHvac;
355 @SerializedName("sdm.devices.traits.ThermostatMode")
356 public SDMThermostatModeTrait thermostatMode;
358 @SerializedName("sdm.devices.traits.ThermostatTemperatureSetpoint")
359 public SDMThermostatTemperatureSetpointTrait thermostatTemperatureSetpoint;
361 @SerializedName("sdm.structures.traits.Info")
362 public SDMStructureInfoTrait structureInfo;
364 @SerializedName("sdm.structures.traits.RoomInfo")
365 public SDMRoomInfoTrait roomInfo;
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);
374 public List<SDMTrait> traitList() {
375 return traitStream().collect(Collectors.toList());
378 public Set<SDMTrait> traitSet() {
379 return traitStream().collect(Collectors.toSet());
382 public void updateTraits(SDMTraits other) {
383 if (other.cameraEventImage != null) {
384 cameraEventImage = other.cameraEventImage;
386 if (other.cameraImage != null) {
387 cameraImage = other.cameraImage;
389 if (other.cameraLiveStream != null) {
390 cameraLiveStream = other.cameraLiveStream;
392 if (other.cameraMotion != null) {
393 cameraMotion = other.cameraMotion;
395 if (other.cameraPerson != null) {
396 cameraPerson = other.cameraPerson;
398 if (other.cameraSound != null) {
399 cameraSound = other.cameraSound;
401 if (other.connectivity != null) {
402 connectivity = other.connectivity;
404 if (other.doorbellChime != null) {
405 doorbellChime = other.doorbellChime;
407 if (other.fan != null) {
410 if (other.humidity != null) {
411 humidity = other.humidity;
413 if (other.deviceInfo != null) {
414 deviceInfo = other.deviceInfo;
416 if (other.deviceSettings != null) {
417 deviceSettings = other.deviceSettings;
419 if (other.temperature != null) {
420 temperature = other.temperature;
422 if (other.thermostatEco != null) {
423 thermostatEco = other.thermostatEco;
425 if (other.thermostatHvac != null) {
426 thermostatHvac = other.thermostatHvac;
428 if (other.thermostatMode != null) {
429 thermostatMode = other.thermostatMode;
431 if (other.thermostatTemperatureSetpoint != null) {
432 thermostatTemperatureSetpoint = other.thermostatTemperatureSetpoint;
434 if (other.structureInfo != null) {
435 structureInfo = other.structureInfo;
437 if (other.roomInfo != null) {
438 roomInfo = other.roomInfo;