2 * Copyright (c) 2010-2022 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.ArrayList;
17 import java.util.List;
18 import java.util.Optional;
20 import com.thoughtworks.xstream.annotations.XStreamAlias;
21 import com.thoughtworks.xstream.annotations.XStreamImplicit;
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}.
30 * @author B. van Wetten - Initial contribution
31 * @author Leo Siepel - finish initial contribution
33 @XStreamAlias("location")
34 public class Location extends PlugwiseBaseModel implements PlugwiseComparableDate<Location> {
37 private String description;
39 private String preset;
41 @XStreamImplicit(itemFieldName = "appliance")
42 private List<String> locationAppliances = new ArrayList<String>();
44 @XStreamImplicit(itemFieldName = "point_log", keyFieldName = "type")
45 private Logs pointLogs;
47 @XStreamImplicit(itemFieldName = "actuator_functionality", keyFieldName = "type")
48 private ActuatorFunctionalities actuatorFunctionalities;
50 public Location(String presetScene) {
51 this.preset = presetScene;
54 public String getName() {
58 public String getDescription() {
62 public String getType() {
66 public String getPreset() {
70 public List<String> getLocationAppliances() {
71 return locationAppliances;
74 public Logs getPointLogs() {
75 if (pointLogs == null) {
76 pointLogs = new Logs();
81 public ActuatorFunctionalities getActuatorFunctionalities() {
82 if (actuatorFunctionalities == null) {
83 actuatorFunctionalities = new ActuatorFunctionalities();
85 return actuatorFunctionalities;
88 public Optional<Double> getTemperature() {
89 return this.pointLogs.getTemperature();
92 public Optional<String> getTemperatureUnit() {
93 return this.pointLogs.getTemperatureUnit();
96 public Optional<Double> getSetpointTemperature() {
97 return this.pointLogs.getThermostatTemperature();
100 public Optional<String> getSetpointTemperatureUnit() {
101 return this.pointLogs.getThermostatTemperatureUnit();
104 public Optional<Boolean> getPreHeatState() {
105 return this.actuatorFunctionalities.getPreHeatState();
108 public Optional<Boolean> getCoolingAllowed() {
109 return this.actuatorFunctionalities.getCoolingAllowed();
112 public Optional<String> getRegulationControl() {
113 return this.actuatorFunctionalities.getRegulationControl();
116 public int applianceCount() {
117 if (this.locationAppliances == null) {
120 return this.locationAppliances.size();
125 public int compareDateWith(Location compareTo) {
126 if (compareTo == null) {
129 ZonedDateTime compareToDate = compareTo.getModifiedDate();
130 ZonedDateTime compareFromDate = this.getModifiedDate();
131 if (compareFromDate == null) {
133 } else if (compareToDate == null) {
136 return compareFromDate.compareTo(compareToDate);
141 public boolean isNewerThan(Location hasModifiedDate) {
142 return compareDateWith(hasModifiedDate) > 0;
146 public boolean isOlderThan(Location hasModifiedDate) {
147 return compareDateWith(hasModifiedDate) < 0;