]> git.basschouten.com Git - openhab-addons.git/blob
521849dc412358e71533d2a7274429dd6b98ac76
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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 Location(String presetScene) {
51         this.preset = presetScene;
52     }
53
54     public String getName() {
55         return name;
56     }
57
58     public String getDescription() {
59         return description;
60     }
61
62     public String getType() {
63         return type;
64     }
65
66     public String getPreset() {
67         return preset;
68     }
69
70     public List<String> getLocationAppliances() {
71         return locationAppliances;
72     }
73
74     public Logs getPointLogs() {
75         if (pointLogs == null) {
76             pointLogs = new Logs();
77         }
78         return pointLogs;
79     }
80
81     public ActuatorFunctionalities getActuatorFunctionalities() {
82         if (actuatorFunctionalities == null) {
83             actuatorFunctionalities = new ActuatorFunctionalities();
84         }
85         return actuatorFunctionalities;
86     }
87
88     public Optional<Double> getTemperature() {
89         return this.pointLogs.getTemperature();
90     }
91
92     public Optional<String> getTemperatureUnit() {
93         return this.pointLogs.getTemperatureUnit();
94     }
95
96     public Optional<Double> getSetpointTemperature() {
97         return this.pointLogs.getThermostatTemperature();
98     }
99
100     public Optional<String> getSetpointTemperatureUnit() {
101         return this.pointLogs.getThermostatTemperatureUnit();
102     }
103
104     public Optional<Boolean> getPreHeatState() {
105         return this.actuatorFunctionalities.getPreHeatState();
106     }
107
108     public Optional<Boolean> getCoolingAllowed() {
109         return this.actuatorFunctionalities.getCoolingAllowed();
110     }
111
112     public Optional<String> getRegulationControl() {
113         return this.actuatorFunctionalities.getRegulationControl();
114     }
115
116     public int applianceCount() {
117         if (this.locationAppliances == null) {
118             return 0;
119         } else {
120             return this.locationAppliances.size();
121         }
122     }
123
124     @Override
125     public int compareDateWith(Location compareTo) {
126         if (compareTo == null) {
127             return -1;
128         }
129         ZonedDateTime compareToDate = compareTo.getModifiedDate();
130         ZonedDateTime compareFromDate = this.getModifiedDate();
131         if (compareFromDate == null) {
132             return -1;
133         } else if (compareToDate == null) {
134             return 1;
135         } else {
136             return compareFromDate.compareTo(compareToDate);
137         }
138     }
139
140     @Override
141     public boolean isNewerThan(Location hasModifiedDate) {
142         return compareDateWith(hasModifiedDate) > 0;
143     }
144
145     @Override
146     public boolean isOlderThan(Location hasModifiedDate) {
147         return compareDateWith(hasModifiedDate) < 0;
148     }
149 }