]> git.basschouten.com Git - openhab-addons.git/blob
0a6644cc45d83b15908a69b3cc8ad6a14d6c1966
[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.max.internal.device;
14
15 import java.math.BigDecimal;
16 import java.math.RoundingMode;
17 import java.util.Calendar;
18 import java.util.Date;
19
20 /**
21  * MAX! Heating thermostat & Heating thermostat+ .
22  *
23  * @author Andreas Heil (info@aheil.de) - Initial contribution
24  * @author Marcel Verpaalen - OH2 update
25  */
26 public class HeatingThermostat extends Device {
27     private ThermostatModeType mode;
28
29     /** Valve position in % */
30     private int valvePosition;
31
32     /** Temperature setpoint in degrees celcius */
33     private double temperatureSetpoint;
34
35     /** Actual Temperature in degrees celcius */
36     private double temperatureActual;
37
38     /** Date setpoint until the temperature setpoint is valid */
39     private Date dateSetpoint;
40
41     /** Device type for this thermostat **/
42     private DeviceType deviceType = DeviceType.HeatingThermostat;
43
44     /** Date/Time the actual temperature was last updated */
45     private Date actualTempLastUpdated;
46
47     public HeatingThermostat(DeviceConfiguration c) {
48         super(c);
49     }
50
51     @Override
52     public DeviceType getType() {
53         return deviceType;
54     }
55
56     /**
57      * Sets the DeviceType for this thermostat.
58      *
59      * @param DeviceType as provided by the C message
60      */
61     void setType(DeviceType type) {
62         this.deviceType = type;
63     }
64
65     /**
66      * Returns the current mode of the thermostat.
67      */
68     public String getModeString() {
69         return this.mode.toString();
70     }
71
72     /**
73      * Returns the current mode of the thermostat.
74      */
75     public ThermostatModeType getMode() {
76         return this.mode;
77     }
78
79     public void setMode(ThermostatModeType mode) {
80         if (this.mode != mode) {
81             setUpdated(true);
82         }
83         this.mode = mode;
84     }
85
86     /**
87      * Sets the valve position for this thermostat.
88      *
89      * @param valvePosition the valve position as provided by the L message
90      */
91     public void setValvePosition(int valvePosition) {
92         if (this.valvePosition != valvePosition) {
93             setUpdated(true);
94         }
95         this.valvePosition = valvePosition;
96     }
97
98     /**
99      * Returns the current valve position of this thermostat in percent.
100      *
101      * @return
102      *         the valve position as <code>DecimalType</code>
103      */
104     public int getValvePosition() {
105         return this.valvePosition;
106     }
107
108     public void setDateSetpoint(Date date) {
109         this.dateSetpoint = date;
110     }
111
112     public Date getDateSetpoint() {
113         return dateSetpoint;
114     }
115
116     /**
117      * Sets the actual temperature for this thermostat.
118      *
119      * @param value the actual temperature raw value as provided by the L message
120      */
121     public void setTemperatureActual(double value) {
122         if (this.temperatureActual != value) {
123             setUpdated(true);
124             this.actualTempLastUpdated = Calendar.getInstance().getTime();
125         }
126         this.temperatureActual = value;
127     }
128
129     /**
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
132      *
133      * @return
134      *         the actual temperature as <code>QuantityType</code>
135      */
136     public double getTemperatureActual() {
137         return BigDecimal.valueOf(this.temperatureActual).setScale(1, RoundingMode.HALF_UP).doubleValue();
138     }
139
140     /**
141      * Sets the setpoint temperature for this thermostat.
142      *
143      * @param value the setpoint temperature raw value as provided by the L message
144      */
145     public void setTemperatureSetpoint(int value) {
146         if (Math.abs(this.temperatureSetpoint - (value / 2.0)) > 0.1) {
147             setUpdated(true);
148         }
149         this.temperatureSetpoint = value / 2.0;
150     }
151
152     /**
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.
155      *
156      * @return
157      *         the setpoint temperature as <code>QuantityType</code>
158      */
159     public double getTemperatureSetpoint() {
160         return this.temperatureSetpoint;
161     }
162
163     /**
164      * @return the Date the actual Temperature was last Updated
165      */
166     public Date getActualTempLastUpdated() {
167         return actualTempLastUpdated;
168     }
169
170     /**
171      * @param actualTempLastUpdated the Date the actual Temperature was last Updated
172      */
173     public void setActualTempLastUpdated(Date actualTempLastUpdated) {
174         this.actualTempLastUpdated = actualTempLastUpdated;
175     }
176 }