]> git.basschouten.com Git - openhab-addons.git/blob
8303be37046b4a7995dab805053cff43eea69ec4
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.ArrayList;
17 import java.util.List;
18 import java.util.Optional;
19
20 import com.thoughtworks.xstream.annotations.XStreamAlias;
21 import com.thoughtworks.xstream.annotations.XStreamImplicit;
22
23 /**
24  * The {@link Location} class is an object model class that
25  * mirrors the XML structure provided by the Plugwise Home Automation
26  * controller for a Plugwise zone/location.
27  * It implements the {@link PlugwiseComparableDate} interface and
28  * extends the abstract class {@link PlugwiseBaseModel}.
29  * 
30  * @author B. van Wetten - Initial contribution
31  * @author Leo Siepel - finish initial contribution
32  */
33 @XStreamAlias("location")
34 public class Location extends PlugwiseBaseModel implements PlugwiseComparableDate<Location> {
35
36     private String name;
37     private String description;
38     private String type;
39     private String preset;
40
41     @XStreamImplicit(itemFieldName = "appliance")
42     private List<String> locationAppliances = new ArrayList<String>();
43
44     @XStreamImplicit(itemFieldName = "point_log", keyFieldName = "type")
45     private Logs pointLogs;
46
47     @XStreamImplicit(itemFieldName = "actuator_functionality", keyFieldName = "type")
48     private ActuatorFunctionalities actuatorFunctionalities;
49
50     public String getName() {
51         return name;
52     }
53
54     public String getDescription() {
55         return description;
56     }
57
58     public String getType() {
59         return type;
60     }
61
62     public String getPreset() {
63         return preset;
64     }
65
66     public List<String> getLocationAppliances() {
67         return locationAppliances;
68     }
69
70     public Logs getPointLogs() {
71         if (pointLogs == null) {
72             pointLogs = new Logs();
73         }
74         return pointLogs;
75     }
76
77     public ActuatorFunctionalities getActuatorFunctionalities() {
78         if (actuatorFunctionalities == null) {
79             actuatorFunctionalities = new ActuatorFunctionalities();
80         }
81         return actuatorFunctionalities;
82     }
83
84     public Optional<Double> getTemperature() {
85         return this.pointLogs.getTemperature();
86     }
87
88     public Optional<String> getTemperatureUnit() {
89         return this.pointLogs.getTemperatureUnit();
90     }
91
92     public Optional<Double> getSetpointTemperature() {
93         return this.pointLogs.getThermostatTemperature();
94     }
95
96     public Optional<String> getSetpointTemperatureUnit() {
97         return this.pointLogs.getThermostatTemperatureUnit();
98     }
99
100     public Optional<Boolean> getPreHeatState() {
101         return this.actuatorFunctionalities.getPreHeatState();
102     }
103
104     public Optional<Boolean> getCoolingAllowed() {
105         return this.actuatorFunctionalities.getCoolingAllowed();
106     }
107
108     public String getRegulationControl() {
109         if (this.actuatorFunctionalities != null) {
110             return this.actuatorFunctionalities.getRegulationControl();
111         }
112         return null;
113     }
114
115     public void setPreset(String preset) {
116         this.preset = preset;
117     }
118
119     public int applianceCount() {
120         if (this.locationAppliances == null) {
121             return 0;
122         } else {
123             return this.locationAppliances.size();
124         }
125     }
126
127     @Override
128     public int compareDateWith(Location compareTo) {
129         if (compareTo == null) {
130             return -1;
131         }
132         ZonedDateTime compareToDate = compareTo.getModifiedDate();
133         ZonedDateTime compareFromDate = this.getModifiedDate();
134         if (compareFromDate == null) {
135             return -1;
136         } else if (compareToDate == null) {
137             return 1;
138         } else {
139             return compareFromDate.compareTo(compareToDate);
140         }
141     }
142
143     @Override
144     public boolean isNewerThan(Location hasModifiedDate) {
145         return compareDateWith(hasModifiedDate) > 0;
146     }
147
148     @Override
149     public boolean isOlderThan(Location hasModifiedDate) {
150         return compareDateWith(hasModifiedDate) < 0;
151     }
152 }