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.plugwiseha.internal.api.model.dto;
15 import java.time.ZonedDateTime;
16 import java.util.Optional;
18 import com.thoughtworks.xstream.annotations.XStreamAlias;
19 import com.thoughtworks.xstream.annotations.XStreamImplicit;
22 * The {@link Appliance} class is an object model class that
23 * mirrors the XML structure provided by the Plugwise Home Automation
24 * controller for a Plugwise appliance.
25 * It implements the {@link PlugwiseComparableDate} interface and
26 * extends the abstract class {@link PlugwiseBaseModel}.
28 * @author B. van Wetten - Initial contribution
29 * @author Leo Siepel - finish initial contribution
31 @XStreamAlias("appliance")
32 public class Appliance extends PlugwiseBaseModel implements PlugwiseComparableDate<Appliance> {
35 private String description;
37 private String location;
39 @XStreamAlias("module")
40 private Module module;
42 @XStreamAlias("zig_bee_node")
43 private ZigBeeNode zigbeeNode;
45 @XStreamImplicit(itemFieldName = "point_log", keyFieldName = "type")
46 private Logs pointLogs;
48 @XStreamImplicit(itemFieldName = "actuator_functionality", keyFieldName = "type")
49 private ActuatorFunctionalities actuatorFunctionalities;
51 public String getName() {
55 public String getDescription() {
59 public String getType() {
63 public String getLocation() {
67 public ZigBeeNode getZigbeeNode() {
68 if (zigbeeNode == null) {
69 zigbeeNode = new ZigBeeNode();
74 public Module getModule() {
76 module = new Module();
81 public Logs getPointLogs() {
82 if (pointLogs == null) {
83 pointLogs = new Logs();
88 public ActuatorFunctionalities getActuatorFunctionalities() {
89 if (actuatorFunctionalities == null) {
90 actuatorFunctionalities = new ActuatorFunctionalities();
92 return actuatorFunctionalities;
95 public Optional<Double> getTemperature() {
96 return this.pointLogs.getTemperature();
99 public Optional<String> getTemperatureUnit() {
100 return this.pointLogs.getTemperatureUnit();
103 public Optional<Double> getSetpointTemperature() {
104 return this.pointLogs.getThermostatTemperature();
107 public Optional<String> getSetpointTemperatureUnit() {
108 return this.pointLogs.getThermostatTemperatureUnit();
111 public Optional<Double> getOffsetTemperature() {
112 return this.pointLogs.getOffsetTemperature();
115 public Optional<String> getOffsetTemperatureUnit() {
116 return this.pointLogs.getOffsetTemperatureUnit();
119 public Optional<Boolean> getRelayState() {
120 return this.pointLogs.getRelayState();
123 public Optional<Boolean> getRelayLockState() {
124 return this.actuatorFunctionalities.getRelayLockState();
127 public Optional<Double> getBatteryLevel() {
128 return this.pointLogs.getBatteryLevel();
131 public Optional<Double> getPowerUsage() {
132 return this.pointLogs.getPowerUsage();
135 public Optional<Double> getValvePosition() {
136 return this.pointLogs.getValvePosition();
139 public Optional<Double> getWaterPressure() {
140 return this.pointLogs.getWaterPressure();
143 public Optional<Boolean> getCHState() {
144 return this.pointLogs.getCHState();
147 public Optional<Boolean> getCoolingState() {
148 return this.pointLogs.getCoolingState();
151 public Optional<Double> getIntendedBoilerTemp() {
152 return this.pointLogs.getIntendedBoilerTemp();
155 public Optional<String> getIntendedBoilerTempUnit() {
156 return this.pointLogs.getIntendedBoilerTempUnit();
159 public Optional<Double> getReturnWaterTemp() {
160 return this.pointLogs.getReturnWaterTemp();
163 public Optional<String> getReturnWaterTempUnit() {
164 return this.pointLogs.getReturnWaterTempUnit();
167 public Optional<Boolean> getFlameState() {
168 return this.pointLogs.getFlameState();
171 public Optional<Boolean> getIntendedHeatingState() {
172 return this.pointLogs.getIntendedHeatingState();
175 public Optional<Double> getModulationLevel() {
176 return this.pointLogs.getModulationLevel();
179 public Optional<Double> getOTAppFaultCode() {
180 return this.pointLogs.getOTAppFaultCode();
183 public Optional<Double> getDHWTemp() {
184 return this.pointLogs.getDHWTemp();
187 public Optional<String> getDHWTempUnit() {
188 return this.pointLogs.getDHWTempUnit();
191 public Optional<Double> getOTOEMFaultcode() {
192 return this.pointLogs.getOTOEMFaultcode();
195 public Optional<Double> getBoilerTemp() {
196 return this.pointLogs.getBoilerTemp();
199 public Optional<String> getBoilerTempUnit() {
200 return this.pointLogs.getBoilerTempUnit();
203 public Optional<Double> getDHTSetpoint() {
204 return this.pointLogs.getDHTSetpoint();
207 public Optional<String> getDHTSetpointUnit() {
208 return this.pointLogs.getDHTSetpointUnit();
211 public Optional<Double> getMaxBoilerTemp() {
212 return this.pointLogs.getMaxBoilerTemp();
215 public Optional<String> getMaxBoilerTempUnit() {
216 return this.pointLogs.getMaxBoilerTempUnit();
219 public Optional<Boolean> getDHWComfortMode() {
220 return this.pointLogs.getDHWComfortMode();
223 public Optional<Boolean> getDHWState() {
224 return this.pointLogs.getDHWState();
227 public boolean isZigbeeDevice() {
228 return (this.zigbeeNode instanceof ZigBeeNode);
231 public boolean isBatteryOperated() {
232 if (this.zigbeeNode instanceof ZigBeeNode) {
233 return this.zigbeeNode.getPowerSource().equals("battery") && this.getBatteryLevel().isPresent();
240 public int compareDateWith(Appliance compareTo) {
241 if (compareTo == null) {
244 ZonedDateTime compareToDate = compareTo.getModifiedDate();
245 ZonedDateTime compareFromDate = this.getModifiedDate();
246 if (compareFromDate == null) {
248 } else if (compareToDate == null) {
251 return compareFromDate.compareTo(compareToDate);
256 public boolean isNewerThan(Appliance hasModifiedDate) {
257 return compareDateWith(hasModifiedDate) > 0;
261 public boolean isOlderThan(Appliance hasModifiedDate) {
262 return compareDateWith(hasModifiedDate) < 0;