]> git.basschouten.com Git - openhab-addons.git/blob
b8a3d2360b49c75c8f89ce2ec03a435606f0ec84
[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.plugwiseha.internal.api.model.dto;
14
15 import java.time.ZonedDateTime;
16 import java.util.Optional;
17
18 import com.thoughtworks.xstream.annotations.XStreamAlias;
19 import com.thoughtworks.xstream.annotations.XStreamImplicit;
20
21 /**
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}.
27  * 
28  * @author B. van Wetten - Initial contribution
29  * @author Leo Siepel - finish initial contribution
30  */
31 @XStreamAlias("appliance")
32 public class Appliance extends PlugwiseBaseModel implements PlugwiseComparableDate<Appliance> {
33
34     private String name;
35     private String description;
36     private String type;
37     private String location;
38
39     @XStreamAlias("module")
40     private Module module;
41
42     @XStreamAlias("zig_bee_node")
43     private ZigBeeNode zigbeeNode;
44
45     @XStreamImplicit(itemFieldName = "point_log", keyFieldName = "type")
46     private Logs pointLogs;
47
48     @XStreamImplicit(itemFieldName = "actuator_functionality", keyFieldName = "type")
49     private ActuatorFunctionalities actuatorFunctionalities;
50
51     public String getName() {
52         return name;
53     }
54
55     public String getDescription() {
56         return description;
57     }
58
59     public String getType() {
60         return type;
61     }
62
63     public String getLocation() {
64         return location;
65     }
66
67     public ZigBeeNode getZigbeeNode() {
68         if (zigbeeNode == null) {
69             zigbeeNode = new ZigBeeNode();
70         }
71         return zigbeeNode;
72     }
73
74     public Module getModule() {
75         if (module == null) {
76             module = new Module();
77         }
78         return module;
79     }
80
81     public Logs getPointLogs() {
82         if (pointLogs == null) {
83             pointLogs = new Logs();
84         }
85         return pointLogs;
86     }
87
88     public ActuatorFunctionalities getActuatorFunctionalities() {
89         if (actuatorFunctionalities == null) {
90             actuatorFunctionalities = new ActuatorFunctionalities();
91         }
92         return actuatorFunctionalities;
93     }
94
95     public Optional<Double> getTemperature() {
96         return this.pointLogs.getTemperature();
97     }
98
99     public Optional<String> getTemperatureUnit() {
100         return this.pointLogs.getTemperatureUnit();
101     }
102
103     public Optional<Double> getSetpointTemperature() {
104         return this.pointLogs.getThermostatTemperature();
105     }
106
107     public Optional<String> getSetpointTemperatureUnit() {
108         return this.pointLogs.getThermostatTemperatureUnit();
109     }
110
111     public Optional<Double> getOffsetTemperature() {
112         return this.pointLogs.getOffsetTemperature();
113     }
114
115     public Optional<String> getOffsetTemperatureUnit() {
116         return this.pointLogs.getOffsetTemperatureUnit();
117     }
118
119     public Optional<Boolean> getRelayState() {
120         return this.pointLogs.getRelayState();
121     }
122
123     public Optional<Boolean> getRelayLockState() {
124         return this.actuatorFunctionalities.getRelayLockState();
125     }
126
127     public Optional<Double> getBatteryLevel() {
128         return this.pointLogs.getBatteryLevel();
129     }
130
131     public Optional<Double> getPowerUsage() {
132         return this.pointLogs.getPowerUsage();
133     }
134
135     public Optional<Double> getValvePosition() {
136         return this.pointLogs.getValvePosition();
137     }
138
139     public Optional<Double> getWaterPressure() {
140         return this.pointLogs.getWaterPressure();
141     }
142
143     public Optional<Boolean> getCHState() {
144         return this.pointLogs.getCHState();
145     }
146
147     public Optional<Boolean> getCoolingState() {
148         return this.pointLogs.getCoolingState();
149     }
150
151     public Optional<Double> getIntendedBoilerTemp() {
152         return this.pointLogs.getIntendedBoilerTemp();
153     }
154
155     public Optional<String> getIntendedBoilerTempUnit() {
156         return this.pointLogs.getIntendedBoilerTempUnit();
157     }
158
159     public Optional<Double> getReturnWaterTemp() {
160         return this.pointLogs.getReturnWaterTemp();
161     }
162
163     public Optional<String> getReturnWaterTempUnit() {
164         return this.pointLogs.getReturnWaterTempUnit();
165     }
166
167     public Optional<Boolean> getFlameState() {
168         return this.pointLogs.getFlameState();
169     }
170
171     public Optional<Boolean> getIntendedHeatingState() {
172         return this.pointLogs.getIntendedHeatingState();
173     }
174
175     public Optional<Double> getModulationLevel() {
176         return this.pointLogs.getModulationLevel();
177     }
178
179     public Optional<Double> getOTAppFaultCode() {
180         return this.pointLogs.getOTAppFaultCode();
181     }
182
183     public Optional<Double> getDHWTemp() {
184         return this.pointLogs.getDHWTemp();
185     }
186
187     public Optional<String> getDHWTempUnit() {
188         return this.pointLogs.getDHWTempUnit();
189     }
190
191     public Optional<Double> getOTOEMFaultcode() {
192         return this.pointLogs.getOTOEMFaultcode();
193     }
194
195     public Optional<Double> getBoilerTemp() {
196         return this.pointLogs.getBoilerTemp();
197     }
198
199     public Optional<String> getBoilerTempUnit() {
200         return this.pointLogs.getBoilerTempUnit();
201     }
202
203     public Optional<Double> getDHTSetpoint() {
204         return this.pointLogs.getDHTSetpoint();
205     }
206
207     public Optional<String> getDHTSetpointUnit() {
208         return this.pointLogs.getDHTSetpointUnit();
209     }
210
211     public Optional<Double> getMaxBoilerTemp() {
212         return this.pointLogs.getMaxBoilerTemp();
213     }
214
215     public Optional<String> getMaxBoilerTempUnit() {
216         return this.pointLogs.getMaxBoilerTempUnit();
217     }
218
219     public Optional<Boolean> getDHWComfortMode() {
220         return this.pointLogs.getDHWComfortMode();
221     }
222
223     public Optional<Boolean> getDHWState() {
224         return this.pointLogs.getDHWState();
225     }
226
227     public boolean isZigbeeDevice() {
228         return (this.zigbeeNode instanceof ZigBeeNode);
229     }
230
231     public boolean isBatteryOperated() {
232         if (this.zigbeeNode instanceof ZigBeeNode) {
233             return "battery".equals(this.zigbeeNode.getPowerSource()) && this.getBatteryLevel().isPresent();
234         } else {
235             return false;
236         }
237     }
238
239     @Override
240     public int compareDateWith(Appliance compareTo) {
241         if (compareTo == null) {
242             return -1;
243         }
244         ZonedDateTime compareToDate = compareTo.getModifiedDate();
245         ZonedDateTime compareFromDate = this.getModifiedDate();
246         if (compareFromDate == null) {
247             return -1;
248         } else if (compareToDate == null) {
249             return 1;
250         } else {
251             return compareFromDate.compareTo(compareToDate);
252         }
253     }
254
255     @Override
256     public boolean isNewerThan(Appliance hasModifiedDate) {
257         return compareDateWith(hasModifiedDate) > 0;
258     }
259
260     @Override
261     public boolean isOlderThan(Appliance hasModifiedDate) {
262         return compareDateWith(hasModifiedDate) < 0;
263     }
264 }