2 * Copyright (c) 2010-2023 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;
16 import java.util.Optional;
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.
24 * @author B. van Wetten - Initial contribution
26 public class Logs extends PlugwiseHACollection<Log> {
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";
52 public Optional<Boolean> getCoolingState() {
53 return this.getLog(COOLINGSTATE).map(logEntry -> logEntry.getMeasurementAsBoolean()).orElse(Optional.empty());
56 public Optional<Double> getIntendedBoilerTemp() {
57 return this.getLog(INTENDEDBOILERTEMP).map(logEntry -> logEntry.getMeasurementAsDouble())
58 .orElse(Optional.empty());
61 public Optional<String> getIntendedBoilerTempUnit() {
62 return this.getLog(INTENDEDBOILERTEMP).map(logEntry -> logEntry.getMeasurementUnit()).orElse(Optional.empty());
65 public Optional<Boolean> getFlameState() {
66 return this.getLog(FLAMESTATE).map(logEntry -> logEntry.getMeasurementAsBoolean()).orElse(Optional.empty());
69 public Optional<Boolean> getIntendedHeatingState() {
70 return this.getLog(INTENDEDHEATINGSTATE).map(logEntry -> logEntry.getMeasurementAsBoolean())
71 .orElse(Optional.empty());
74 public Optional<Double> getModulationLevel() {
75 return this.getLog(MODULATIONLEVEL).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
78 public Optional<Double> getOTAppFaultCode() {
79 return this.getLog(OTAPPLICATIONFAULTCODE).map(logEntry -> logEntry.getMeasurementAsDouble())
80 .orElse(Optional.empty());
83 public Optional<Double> getDHWTemp() {
84 return this.getLog(DHWTEMP).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
87 public Optional<String> getDHWTempUnit() {
88 return this.getLog(DHWTEMP).map(logEntry -> logEntry.getMeasurementUnit()).orElse(Optional.empty());
91 public Optional<Double> getOTOEMFaultcode() {
92 return this.getLog(OTOEMFAULTCODE).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
95 public Optional<Double> getBoilerTemp() {
96 return this.getLog(BOILERTEMP).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
99 public Optional<String> getBoilerTempUnit() {
100 return this.getLog(BOILERTEMP).map(logEntry -> logEntry.getMeasurementUnit()).orElse(Optional.empty());
103 public Optional<Double> getReturnWaterTemp() {
104 return this.getLog(RETURNWATERTEMP).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
107 public Optional<String> getReturnWaterTempUnit() {
108 return this.getLog(RETURNWATERTEMP).map(logEntry -> logEntry.getMeasurementUnit()).orElse(Optional.empty());
111 public Optional<Double> getDHTSetpoint() {
112 return this.getLog(DHWSETPOINT).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
115 public Optional<String> getDHTSetpointUnit() {
116 return this.getLog(DHWSETPOINT).map(logEntry -> logEntry.getMeasurementUnit()).orElse(Optional.empty());
119 public Optional<Double> getMaxBoilerTemp() {
120 return this.getLog(MAXBOILERTEMP).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
123 public Optional<String> getMaxBoilerTempUnit() {
124 return this.getLog(MAXBOILERTEMP).map(logEntry -> logEntry.getMeasurementUnit()).orElse(Optional.empty());
127 public Optional<Boolean> getDHWComfortMode() {
128 return this.getLog(DHWCOMFORTMODE).map(logEntry -> logEntry.getMeasurementAsBoolean()).orElse(Optional.empty());
131 public Optional<Double> getTemperature() {
132 return this.getLog(TEMPERATURE).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
135 public Optional<String> getTemperatureUnit() {
136 return this.getLog(TEMPERATURE).map(logEntry -> logEntry.getMeasurementUnit()).orElse(Optional.empty());
139 public Optional<Double> getThermostatTemperature() {
140 return this.getLog(THERMOSTAT).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
143 public Optional<String> getThermostatTemperatureUnit() {
144 return this.getLog(THERMOSTAT).map(logEntry -> logEntry.getMeasurementUnit()).orElse(Optional.empty());
147 public Optional<Double> getOffsetTemperature() {
148 return this.getLog(TEMPERATURE_OFFSET).map(logEntry -> logEntry.getMeasurementAsDouble())
149 .orElse(Optional.empty());
152 public Optional<String> getOffsetTemperatureUnit() {
153 return this.getLog(TEMPERATURE_OFFSET).map(logEntry -> logEntry.getMeasurementUnit()).orElse(Optional.empty());
156 public Optional<Boolean> getRelayState() {
157 return this.getLog(RELAY).map(logEntry -> logEntry.getMeasurementAsBoolean()).orElse(Optional.empty());
160 public Optional<Boolean> getDHWState() {
161 return this.getLog(DHWSTATE).map(logEntry -> logEntry.getMeasurementAsBoolean()).orElse(Optional.empty());
164 public Optional<Boolean> getCHState() {
165 return this.getLog(CHSTATE).map(logEntry -> logEntry.getMeasurementAsBoolean()).orElse(Optional.empty());
168 public Optional<Double> getValvePosition() {
169 return this.getLog(VALVE_POSITION).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
172 public Optional<Double> getWaterPressure() {
173 return this.getLog(WATER_PRESSURE).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
176 public Optional<Double> getBatteryLevel() {
177 return this.getLog(BATTERY).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
180 public Optional<Double> getPowerUsage() {
181 return this.getLog(POWER_USAGE).map(logEntry -> logEntry.getMeasurementAsDouble()).orElse(Optional.empty());
184 public Optional<Log> getLog(String logItem) {
185 return Optional.ofNullable(this.get(logItem));
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);
195 if (originalLog == null || originalLog.isOlderThan(logToMerge)) {
196 this.put(type, logToMerge);
198 this.put(type, originalLog);