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.max.internal.device;
15 import java.math.BigDecimal;
16 import java.math.RoundingMode;
17 import java.util.Calendar;
18 import java.util.Date;
21 * MAX! Heating thermostat & Heating thermostat+ .
23 * @author Andreas Heil (info@aheil.de) - Initial contribution
24 * @author Marcel Verpaalen - OH2 update
26 public class HeatingThermostat extends Device {
27 private ThermostatModeType mode;
29 /** Valve position in % */
30 private int valvePosition;
32 /** Temperature setpoint in degrees celcius */
33 private double temperatureSetpoint;
35 /** Actual Temperature in degrees celcius */
36 private double temperatureActual;
38 /** Date setpoint until the temperature setpoint is valid */
39 private Date dateSetpoint;
41 /** Device type for this thermostat **/
42 private DeviceType deviceType = DeviceType.HeatingThermostat;
44 /** Date/Time the actual temperature was last updated */
45 private Date actualTempLastUpdated;
47 public HeatingThermostat(DeviceConfiguration c) {
52 public DeviceType getType() {
57 * Sets the DeviceType for this thermostat.
59 * @param DeviceType as provided by the C message
61 void setType(DeviceType type) {
62 this.deviceType = type;
66 * Returns the current mode of the thermostat.
68 public String getModeString() {
69 return this.mode.toString();
73 * Returns the current mode of the thermostat.
75 public ThermostatModeType getMode() {
79 public void setMode(ThermostatModeType mode) {
80 if (this.mode != mode) {
87 * Sets the valve position for this thermostat.
89 * @param valvePosition the valve position as provided by the L message
91 public void setValvePosition(int valvePosition) {
92 if (this.valvePosition != valvePosition) {
95 this.valvePosition = valvePosition;
99 * Returns the current valve position of this thermostat in percent.
102 * the valve position as <code>DecimalType</code>
104 public int getValvePosition() {
105 return this.valvePosition;
108 public void setDateSetpoint(Date date) {
109 this.dateSetpoint = date;
112 public Date getDateSetpoint() {
117 * Sets the actual temperature for this thermostat.
119 * @param value the actual temperature raw value as provided by the L message
121 public void setTemperatureActual(double value) {
122 if (this.temperatureActual != value) {
124 this.actualTempLastUpdated = Calendar.getInstance().getTime();
126 this.temperatureActual = value;
130 * Returns the measured temperature of this thermostat.
131 * 0�C is displayed if no actual is measured. Temperature is only updated after valve position changes
134 * the actual temperature as <code>QuantityType</code>
136 public double getTemperatureActual() {
137 return BigDecimal.valueOf(this.temperatureActual).setScale(1, RoundingMode.HALF_UP).doubleValue();
141 * Sets the setpoint temperature for this thermostat.
143 * @param value the setpoint temperature raw value as provided by the L message
145 public void setTemperatureSetpoint(int value) {
146 if (Math.abs(this.temperatureSetpoint - (value / 2.0)) > 0.1) {
149 this.temperatureSetpoint = value / 2.0;
153 * Returns the setpoint temperature of this thermostat.
154 * 4.5�C is displayed as OFF, 30.5�C is displayed as On at the thermostat display.
157 * the setpoint temperature as <code>QuantityType</code>
159 public double getTemperatureSetpoint() {
160 return this.temperatureSetpoint;
164 * @return the Date the actual Temperature was last Updated
166 public Date getActualTempLastUpdated() {
167 return actualTempLastUpdated;
171 * @param actualTempLastUpdated the Date the actual Temperature was last Updated
173 public void setActualTempLastUpdated(Date actualTempLastUpdated) {
174 this.actualTempLastUpdated = actualTempLastUpdated;