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.bticinosmarther.internal.api.dto;
15 import static org.openhab.binding.bticinosmarther.internal.SmartherBindingConstants.*;
17 import java.time.ZonedDateTime;
18 import java.time.format.DateTimeParseException;
19 import java.util.Collections;
20 import java.util.List;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.binding.bticinosmarther.internal.api.dto.Enums.LoadState;
24 import org.openhab.binding.bticinosmarther.internal.api.dto.Enums.MeasureUnit;
25 import org.openhab.binding.bticinosmarther.internal.api.exception.SmartherIllegalPropertyValueException;
26 import org.openhab.binding.bticinosmarther.internal.util.DateUtil;
28 import com.google.gson.annotations.SerializedName;
31 * The {@code Chronothermostat} class defines the dto for Smarther API chronothermostat object.
33 * @author Fabio Possieri - Initial contribution
35 public class Chronothermostat {
37 private static final String TIME_FOREVER = "Forever";
39 private String function;
41 @SerializedName("setPoint")
42 private Measure setPointTemperature;
43 private List<Program> programs;
44 @SerializedName("temperatureFormat")
45 private String temperatureFormat;
46 @SerializedName("loadState")
47 private String loadState;
48 @SerializedName("activationTime")
49 private String activationTime;
51 private Sensor thermometer;
52 private Sensor hygrometer;
53 private boolean online;
54 private Sender sender;
57 * Returns the operational function of this chronothermostat module.
59 * @return a string containing the module operational function
61 public String getFunction() {
66 * Returns the operational mode of this chronothermostat module.
68 * @return a string containing the module operational mode
70 public String getMode() {
75 * Returns the operational setpoint temperature of this chronothermostat module.
77 * @return a {@link Measure} object representing the module operational setpoint temperature
79 public Measure getSetPointTemperature() {
80 return setPointTemperature;
84 * Returns the list of programs registered on this chronothermostat module.
86 * @return the list of registered programs, or an empty list in case of no programs available
88 public List<Program> getPrograms() {
89 return (programs != null) ? programs : Collections.emptyList();
93 * Returns the operational temperature format of this chronothermostat module.
95 * @return a string containing the module operational temperature format
97 public String getTemperatureFormat() {
98 return temperatureFormat;
102 * Returns the operational temperature format of this chronothermostat module.
104 * @return a {@link MeasureUnit} object representing the module operational temperature format
106 * @throws {@link SmartherIllegalPropertyValueException}
107 * if the measure internal raw unit cannot be mapped to any valid measure unit
109 public MeasureUnit getTemperatureFormatUnit() throws SmartherIllegalPropertyValueException {
110 return MeasureUnit.fromValue(temperatureFormat);
114 * Returns the operational load state of this chronothermostat module.
116 * @return a string containing the module operational load state
118 public String getLoadState() {
123 * Tells whether the load state of this chronothermostat module is "active" (i.e. module is turned on).
125 * @return {@code true} if the load state is active, {@code false} otherwise
127 * @throws {@link SmartherIllegalPropertyValueException}
128 * if the load state internal raw value cannot be mapped to any valid load state enum value
130 public boolean isActive() throws SmartherIllegalPropertyValueException {
131 return LoadState.fromValue(loadState).isActive();
135 * Returns the operational activation time of this chronothermostat module.
137 * @return a string containing the module operational activation time
139 public String getActivationTime() {
140 return activationTime;
144 * Returns a label for the operational activation time of this chronothermostat module.
146 * @return a string containing the module operational activation time label, or {@code null} if the activation time
147 * cannot be parsed to a valid date/time
149 public @Nullable String getActivationTimeLabel() {
150 String timeLabel = TIME_FOREVER;
151 if (activationTime != null) {
153 final ZonedDateTime dateActivationTime = DateUtil.parseZonedTime(activationTime, DTF_DATETIME_EXT);
154 final ZonedDateTime dateTomorrow = DateUtil.getZonedStartOfDay(1, dateActivationTime.getZone());
156 if (dateActivationTime.isBefore(dateTomorrow)) {
157 timeLabel = DateUtil.format(dateActivationTime, DTF_TODAY);
158 } else if (dateActivationTime.isBefore(dateTomorrow.plusDays(1))) {
159 timeLabel = DateUtil.format(dateActivationTime, DTF_TOMORROW);
161 timeLabel = DateUtil.format(dateActivationTime, DTF_DAY_HHMM);
163 } catch (DateTimeParseException e) {
171 * Returns the current time (clock) of this chronothermostat module.
173 * @return a string containing the module current time
175 public String getTime() {
180 * Returns the thermometer sensor of this chronothermostat module.
182 * @return the thermometer sensor of this module
184 public Sensor getThermometer() {
189 * Returns the hygrometer sensor of this chronothermostat module.
191 * @return the hygrometer sensor of this module
193 public Sensor getHygrometer() {
198 * Tells whether this module is online.
200 * @return {@code true} if the module is online, {@code false} otherwise
202 public boolean isOnline() {
207 * Returns the sender associated with this chronothermostat module.
209 * @return a {@link Sender} object representing the sender associated with this module, or {@code null} in case of
210 * no sender information available
212 public @Nullable Sender getSender() {
217 * Returns the operational program of this chronothermostat module.
219 * @return a {@link Program} object representing the module operational program, or {@code null} in case of no
220 * program currently set for this module
222 public @Nullable Program getProgram() {
223 return (programs != null && !programs.isEmpty()) ? programs.get(0) : null;
227 public String toString() {
228 return String.format(
229 "function=%s, mode=%s, setPointTemperature=[%s], programs=%s, temperatureFormat=%s, loadState=%s, time=%s, activationTime=%s, thermometer=[%s], hygrometer=[%s], online=%s, sender=[%s]",
230 function, mode, setPointTemperature, programs, temperatureFormat, loadState, time, activationTime,
231 thermometer, hygrometer, online, sender);