]> git.basschouten.com Git - openhab-addons.git/blob
205254431aa90524bb0338789d111259edcdb020
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.util.Map;
16 import java.util.Optional;
17
18 /**
19  * The {@link Logs} class is an object model class that
20  * mirrors the XML structure provided by the Plugwise Home Automation
21  * controller for the collection of logs.
22  * It extends the {@link PlugwiseHACollection} class.
23  * 
24  * @author B. van Wetten - Initial contribution
25  */
26 public class Logs extends PlugwiseHACollection<Log> {
27
28     private static final String THERMOSTAT = "thermostat";
29     private static final String TEMPERATURE = "temperature";
30     private static final String TEMPERATURE_OFFSET = "temperature_offset";
31     private static final String BATTERY = "battery";
32     private static final String POWER_USAGE = "electricity_consumed";
33     private static final String RELAY = "relay";
34     private static final String DHWSTATE = "domestic_hot_water_state";
35     private static final String COOLINGSTATE = "cooling_state";
36     private static final String INTENDEDBOILERTEMP = "intended_boiler_temperature";
37     private static final String FLAMESTATE = "flame_state";
38     private static final String INTENDEDHEATINGSTATE = "intended_central_heating_state";
39     private static final String MODULATIONLEVEL = "modulation_level";
40     private static final String OTAPPLICATIONFAULTCODE = "open_therm_application_specific_fault_code";
41     private static final String DHWTEMP = "domestic_hot_water_temperature";
42     private static final String OTOEMFAULTCODE = "open_therm_oem_fault_code";
43     private static final String BOILERTEMP = "boiler_temperature";
44     private static final String DHWSETPOINT = "domestic_hot_water_setpoint";
45     private static final String MAXBOILERTEMP = "maximum_boiler_temperature";
46     private static final String DHWCOMFORTMODE = "domestic_hot_water_comfort_mode";
47     private static final String CHSTATE = "central_heating_state";
48     private static final String VALVE_POSITION = "valve_position";
49     private static final String WATER_PRESSURE = "central_heater_water_pressure";
50
51     public Optional<Boolean> getCoolingState() {
52         return this.getLog(COOLINGSTATE).map(logEntry -> logEntry.getMeasurementAsBoolean()).orElse(Optional.empty());
53     }
54
55     public Optional<Double> getIntendedBoilerTemp() {
56         return this.getLog(INTENDEDBOILERTEMP).map(logEntry -> logEntry.getMeasurementAsDouble())
57                 .orElse(Optional.empty());
58     }
59
60     public Optional<String> getIntendedBoilerTempUnit() {
61         return this.getLog(INTENDEDBOILERTEMP).map(logEntry -> logEntry.getMeasurementUnit()).orElse(Optional.empty());
62     }
63
64     public Optional<Boolean> getFlameState() {
65         return this.getLog(FLAMESTATE).map(logEntry -> logEntry.getMeasurementAsBoolean()).orElse(Optional.empty());
66     }
67
68     public Optional<Boolean> getIntendedHeatingState() {
69         return this.getLog(INTENDEDHEATINGSTATE).map(logEntry -> logEntry.getMeasurementAsBoolean())
70                 .orElse(Optional.empty());
71     }
72
73     public Optional<Double> getModulationLevel() {
74         return this.getLog(MODULATIONLEVEL).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
75     }
76
77     public Optional<Double> getOTAppFaultCode() {
78         return this.getLog(OTAPPLICATIONFAULTCODE).map(logEntry -> logEntry.getMeasurementAsDouble())
79                 .orElse(Optional.empty());
80     }
81
82     public Optional<Double> getDHWTemp() {
83         return this.getLog(DHWTEMP).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
84     }
85
86     public Optional<String> getDHWTempUnit() {
87         return this.getLog(DHWTEMP).map(logEntry -> logEntry.getMeasurementUnit()).orElse(Optional.empty());
88     }
89
90     public Optional<Double> getOTOEMFaultcode() {
91         return this.getLog(OTOEMFAULTCODE).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
92     }
93
94     public Optional<Double> getBoilerTemp() {
95         return this.getLog(BOILERTEMP).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
96     }
97
98     public Optional<String> getBoilerTempUnit() {
99         return this.getLog(BOILERTEMP).map(logEntry -> logEntry.getMeasurementUnit()).orElse(Optional.empty());
100     }
101
102     public Optional<Double> getDHTSetpoint() {
103         return this.getLog(DHWSETPOINT).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
104     }
105
106     public Optional<String> getDHTSetpointUnit() {
107         return this.getLog(DHWSETPOINT).map(logEntry -> logEntry.getMeasurementUnit()).orElse(Optional.empty());
108     }
109
110     public Optional<Double> getMaxBoilerTemp() {
111         return this.getLog(MAXBOILERTEMP).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
112     }
113
114     public Optional<String> getMaxBoilerTempUnit() {
115         return this.getLog(MAXBOILERTEMP).map(logEntry -> logEntry.getMeasurementUnit()).orElse(Optional.empty());
116     }
117
118     public Optional<Boolean> getDHWComfortMode() {
119         return this.getLog(DHWCOMFORTMODE).map(logEntry -> logEntry.getMeasurementAsBoolean()).orElse(Optional.empty());
120     }
121
122     public Optional<Double> getTemperature() {
123         return this.getLog(TEMPERATURE).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
124     }
125
126     public Optional<String> getTemperatureUnit() {
127         return this.getLog(TEMPERATURE).map(logEntry -> logEntry.getMeasurementUnit()).orElse(Optional.empty());
128     }
129
130     public Optional<Double> getThermostatTemperature() {
131         return this.getLog(THERMOSTAT).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
132     }
133
134     public Optional<String> getThermostatTemperatureUnit() {
135         return this.getLog(THERMOSTAT).map(logEntry -> logEntry.getMeasurementUnit()).orElse(Optional.empty());
136     }
137
138     public Optional<Double> getOffsetTemperature() {
139         return this.getLog(TEMPERATURE_OFFSET).map(logEntry -> logEntry.getMeasurementAsDouble())
140                 .orElse(Optional.empty());
141     }
142
143     public Optional<String> getOffsetTemperatureUnit() {
144         return this.getLog(TEMPERATURE_OFFSET).map(logEntry -> logEntry.getMeasurementUnit()).orElse(Optional.empty());
145     }
146
147     public Optional<Boolean> getRelayState() {
148         return this.getLog(RELAY).map(logEntry -> logEntry.getMeasurementAsBoolean()).orElse(Optional.empty());
149     }
150
151     public Optional<Boolean> getDHWState() {
152         return this.getLog(DHWSTATE).map(logEntry -> logEntry.getMeasurementAsBoolean()).orElse(Optional.empty());
153     }
154
155     public Optional<Boolean> getCHState() {
156         return this.getLog(CHSTATE).map(logEntry -> logEntry.getMeasurementAsBoolean()).orElse(Optional.empty());
157     }
158
159     public Optional<Double> getValvePosition() {
160         return this.getLog(VALVE_POSITION).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
161     }
162
163     public Optional<Double> getWaterPressure() {
164         return this.getLog(WATER_PRESSURE).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
165     }
166
167     public Optional<Double> getBatteryLevel() {
168         return this.getLog(BATTERY).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
169     }
170
171     public Optional<Double> getPowerUsage() {
172         return this.getLog(POWER_USAGE).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
173     }
174
175     public Optional<Log> getLog(String logItem) {
176         return Optional.ofNullable(this.get(logItem));
177     }
178
179     @Override
180     public void merge(Map<String, Log> logsToMerge) {
181         if (logsToMerge != null) {
182             for (Log logToMerge : logsToMerge.values()) {
183                 String type = logToMerge.getType();
184                 Log originalLog = this.get(type);
185
186                 if (originalLog == null || originalLog.isOlderThan(logToMerge)) {
187                     this.put(type, logToMerge);
188                 } else {
189                     this.put(type, originalLog);
190                 }
191             }
192         }
193     }
194 }