]> git.basschouten.com Git - openhab-addons.git/blob
96d60fdd56b735cc03559ed7b47034531ceeca21
[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.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     private static final String RETURNWATERTEMP = "return_water_temperature";
51
52     public Optional<Boolean> getCoolingState() {
53         return this.getLog(COOLINGSTATE).map(logEntry -> logEntry.getMeasurementAsBoolean()).orElse(Optional.empty());
54     }
55
56     public Optional<Double> getIntendedBoilerTemp() {
57         return this.getLog(INTENDEDBOILERTEMP).map(logEntry -> logEntry.getMeasurementAsDouble())
58                 .orElse(Optional.empty());
59     }
60
61     public Optional<String> getIntendedBoilerTempUnit() {
62         return this.getLog(INTENDEDBOILERTEMP).map(logEntry -> logEntry.getMeasurementUnit()).orElse(Optional.empty());
63     }
64
65     public Optional<Boolean> getFlameState() {
66         return this.getLog(FLAMESTATE).map(logEntry -> logEntry.getMeasurementAsBoolean()).orElse(Optional.empty());
67     }
68
69     public Optional<Boolean> getIntendedHeatingState() {
70         return this.getLog(INTENDEDHEATINGSTATE).map(logEntry -> logEntry.getMeasurementAsBoolean())
71                 .orElse(Optional.empty());
72     }
73
74     public Optional<Double> getModulationLevel() {
75         return this.getLog(MODULATIONLEVEL).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
76     }
77
78     public Optional<Double> getOTAppFaultCode() {
79         return this.getLog(OTAPPLICATIONFAULTCODE).map(logEntry -> logEntry.getMeasurementAsDouble())
80                 .orElse(Optional.empty());
81     }
82
83     public Optional<Double> getDHWTemp() {
84         return this.getLog(DHWTEMP).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
85     }
86
87     public Optional<String> getDHWTempUnit() {
88         return this.getLog(DHWTEMP).map(logEntry -> logEntry.getMeasurementUnit()).orElse(Optional.empty());
89     }
90
91     public Optional<Double> getOTOEMFaultcode() {
92         return this.getLog(OTOEMFAULTCODE).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
93     }
94
95     public Optional<Double> getBoilerTemp() {
96         return this.getLog(BOILERTEMP).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
97     }
98
99     public Optional<String> getBoilerTempUnit() {
100         return this.getLog(BOILERTEMP).map(logEntry -> logEntry.getMeasurementUnit()).orElse(Optional.empty());
101     }
102
103     public Optional<Double> getReturnWaterTemp() {
104         return this.getLog(RETURNWATERTEMP).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
105     }
106
107     public Optional<String> getReturnWaterTempUnit() {
108         return this.getLog(RETURNWATERTEMP).map(logEntry -> logEntry.getMeasurementUnit()).orElse(Optional.empty());
109     }
110
111     public Optional<Double> getDHTSetpoint() {
112         return this.getLog(DHWSETPOINT).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
113     }
114
115     public Optional<String> getDHTSetpointUnit() {
116         return this.getLog(DHWSETPOINT).map(logEntry -> logEntry.getMeasurementUnit()).orElse(Optional.empty());
117     }
118
119     public Optional<Double> getMaxBoilerTemp() {
120         return this.getLog(MAXBOILERTEMP).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
121     }
122
123     public Optional<String> getMaxBoilerTempUnit() {
124         return this.getLog(MAXBOILERTEMP).map(logEntry -> logEntry.getMeasurementUnit()).orElse(Optional.empty());
125     }
126
127     public Optional<Boolean> getDHWComfortMode() {
128         return this.getLog(DHWCOMFORTMODE).map(logEntry -> logEntry.getMeasurementAsBoolean()).orElse(Optional.empty());
129     }
130
131     public Optional<Double> getTemperature() {
132         return this.getLog(TEMPERATURE).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
133     }
134
135     public Optional<String> getTemperatureUnit() {
136         return this.getLog(TEMPERATURE).map(logEntry -> logEntry.getMeasurementUnit()).orElse(Optional.empty());
137     }
138
139     public Optional<Double> getThermostatTemperature() {
140         return this.getLog(THERMOSTAT).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
141     }
142
143     public Optional<String> getThermostatTemperatureUnit() {
144         return this.getLog(THERMOSTAT).map(logEntry -> logEntry.getMeasurementUnit()).orElse(Optional.empty());
145     }
146
147     public Optional<Double> getOffsetTemperature() {
148         return this.getLog(TEMPERATURE_OFFSET).map(logEntry -> logEntry.getMeasurementAsDouble())
149                 .orElse(Optional.empty());
150     }
151
152     public Optional<String> getOffsetTemperatureUnit() {
153         return this.getLog(TEMPERATURE_OFFSET).map(logEntry -> logEntry.getMeasurementUnit()).orElse(Optional.empty());
154     }
155
156     public Optional<Boolean> getRelayState() {
157         return this.getLog(RELAY).map(logEntry -> logEntry.getMeasurementAsBoolean()).orElse(Optional.empty());
158     }
159
160     public Optional<Boolean> getDHWState() {
161         return this.getLog(DHWSTATE).map(logEntry -> logEntry.getMeasurementAsBoolean()).orElse(Optional.empty());
162     }
163
164     public Optional<Boolean> getCHState() {
165         return this.getLog(CHSTATE).map(logEntry -> logEntry.getMeasurementAsBoolean()).orElse(Optional.empty());
166     }
167
168     public Optional<Double> getValvePosition() {
169         return this.getLog(VALVE_POSITION).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
170     }
171
172     public Optional<Double> getWaterPressure() {
173         return this.getLog(WATER_PRESSURE).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
174     }
175
176     public Optional<Double> getBatteryLevel() {
177         return this.getLog(BATTERY).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
178     }
179
180     public Optional<Double> getPowerUsage() {
181         return this.getLog(POWER_USAGE).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
182     }
183
184     public Optional<Log> getLog(String logItem) {
185         return Optional.ofNullable(this.get(logItem));
186     }
187
188     @Override
189     public void merge(Map<String, Log> logsToMerge) {
190         if (logsToMerge != null) {
191             for (Log logToMerge : logsToMerge.values()) {
192                 String type = logToMerge.getType();
193                 Log originalLog = this.get(type);
194
195                 if (originalLog == null || originalLog.isOlderThan(logToMerge)) {
196                     this.put(type, logToMerge);
197                 } else {
198                     this.put(type, originalLog);
199                 }
200             }
201         }
202     }
203 }