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.qbus.internal.protocol;
15 import java.io.IOException;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.qbus.internal.handler.QbusThermostatHandler;
22 * The {@link QbusThermostat} class represents the thermostat Qbus communication object. It contains all
23 * fields representing a Qbus thermostat and has methods to set the thermostat mode and setpoint in Qbus and
24 * receive thermostat updates.
26 * @author Koen Schockaert - Initial Contribution
30 public final class QbusThermostat {
32 private @Nullable QbusCommunication qComm;
35 private double measured = 0.0;
36 private double setpoint = 0.0;
37 private @Nullable Integer mode;
39 private @Nullable QbusThermostatHandler thingHandler;
41 QbusThermostat(Integer id) {
46 * This method should be called if the ThingHandler for the thing corresponding to the termostat is initialized.
47 * It keeps a record of the thing handler in this object so the thing can be updated when
48 * the thermostat receives an update from the Qbus client.
52 public void setThingHandler(QbusThermostatHandler handler) {
53 this.thingHandler = handler;
57 * This method sets a pointer to the qComm THERMOSTAT of class {@link QbusCommunication}.
58 * This is then used to be able to call back the sendCommand method in this class to send a command to the
63 public void setQComm(QbusCommunication qComm) {
68 * Update all values of the Thermostat
70 * @param measured current temperature in 1°C multiples
71 * @param setpoint the setpoint temperature in 1°C multiples
72 * @param mode 0="Manual", 1="Freeze", 2="Economic", 3="Comfort", 4="Night"
74 public void updateState(Double measured, Double setpoint, Integer mode) {
75 this.measured = measured;
76 this.setpoint = setpoint;
79 QbusThermostatHandler handler = this.thingHandler;
80 if (handler != null) {
81 handler.handleStateUpdate(this);
86 * Get measured temperature of the Thermostat.
88 * @return measured temperature in 0.5°C multiples
90 public @Nullable Double getMeasured() {
95 * Get setpoint temperature of the Thermostat.
97 * @return the setpoint temperature in 0.5°C multiples
99 public @Nullable Double getSetpoint() {
100 return this.setpoint;
104 * Get the Thermostat mode.
106 * @return the mode: 0="Manual", 1="Freeze", 2="Economic", 3="Comfort", 4="Night"
108 public @Nullable Integer getMode() {
113 * Sends Thermostat mode to Qbus.
117 * @throws InterruptedException
118 * @throws IOException
120 public void executeMode(int mode, String sn) throws InterruptedException, IOException {
121 QbusMessageCmd qCmd = new QbusMessageCmd(sn, "executeThermostat").withId(this.id).withMode(mode);
122 QbusCommunication comm = this.qComm;
124 comm.sendMessage(qCmd);
129 * Sends Thermostat setpoint to Qbus.
132 * @throws IOException
133 * @throws InterruptedException
135 public void executeSetpoint(double setpoint, String sn) throws InterruptedException, IOException {
136 QbusMessageCmd qCmd = new QbusMessageCmd(sn, "executeThermostat").withId(this.id).withSetPoint(setpoint);
137 QbusCommunication comm = this.qComm;
139 comm.sendMessage(qCmd);