2 * Copyright (c) 2010-2024 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.openwebnet.internal.handler;
15 import static org.openhab.binding.openwebnet.internal.OpenWebNetBindingConstants.*;
18 import java.util.concurrent.ScheduledFuture;
19 import java.util.concurrent.TimeUnit;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.binding.openwebnet.internal.OpenWebNetBindingConstants;
24 import org.openhab.core.library.types.DecimalType;
25 import org.openhab.core.library.types.OnOffType;
26 import org.openhab.core.library.types.QuantityType;
27 import org.openhab.core.library.types.StringType;
28 import org.openhab.core.library.unit.SIUnits;
29 import org.openhab.core.thing.ChannelUID;
30 import org.openhab.core.thing.Thing;
31 import org.openhab.core.thing.ThingStatus;
32 import org.openhab.core.thing.ThingStatusDetail;
33 import org.openhab.core.thing.ThingTypeUID;
34 import org.openhab.core.types.Command;
35 import org.openhab.core.types.UnDefType;
36 import org.openwebnet4j.communication.OWNException;
37 import org.openwebnet4j.communication.Response;
38 import org.openwebnet4j.message.BaseOpenMessage;
39 import org.openwebnet4j.message.FrameException;
40 import org.openwebnet4j.message.MalformedFrameException;
41 import org.openwebnet4j.message.Thermoregulation;
42 import org.openwebnet4j.message.Thermoregulation.DimThermo;
43 import org.openwebnet4j.message.Thermoregulation.Function;
44 import org.openwebnet4j.message.Thermoregulation.OperationMode;
45 import org.openwebnet4j.message.Thermoregulation.WhatThermo;
46 import org.openwebnet4j.message.Thermoregulation.WhatThermoType;
47 import org.openwebnet4j.message.Where;
48 import org.openwebnet4j.message.WhereThermo;
49 import org.openwebnet4j.message.Who;
50 import org.slf4j.Logger;
51 import org.slf4j.LoggerFactory;
54 * The {@link OpenWebNetThermoregulationHandler} is responsible for handling
55 * commands/messages for Thermoregulation Things. It extends the abstract
56 * {@link OpenWebNetThingHandler}.
58 * @author Massimo Valla - Initial contribution. Added support for 4-zones CU.
59 * Rafactoring and fixed CU state channels updates. Completed support
60 * for HOLIDAY/VACATION modes and refactored mode handling.
61 * @author Gilberto Cocchi - Initial contribution.
62 * @author Andrea Conte - Added support for 99-zone CU and CU state channels.
65 public class OpenWebNetThermoregulationHandler extends OpenWebNetThingHandler {
67 private final Logger logger = LoggerFactory.getLogger(OpenWebNetThermoregulationHandler.class);
69 public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = OpenWebNetBindingConstants.THERMOREGULATION_SUPPORTED_THING_TYPES;
71 private double currentSetPointTemp = 20.0d;
73 private Thermoregulation.@Nullable Function currentFunction = null;
74 private Thermoregulation.@Nullable OperationMode currentMode = null;
75 private int currentWeeklyPrgNum = 1;
76 private int currentScenarioPrgNum = 1;
77 private int currentVacationDays = 1;
79 private boolean isStandAlone = true; // true if zone is not associated to a CU
80 private boolean isCentralUnit = false;
82 private boolean cuAtLeastOneProbeOff = false;
83 private boolean cuAtLeastOneProbeProtection = false;
84 private boolean cuAtLeastOneProbeManual = false;
85 private String cuBatteryStatus = CU_BATTERY_OK;
86 private boolean cuFailureDiscovered = false;
88 private @Nullable ScheduledFuture<?> cuStateChannelsUpdateSchedule;
90 public static final int CU_STATE_CHANNELS_UPDATE_DELAY = 1500; // msec
92 private static final String CU_REMOTE_CONTROL_ENABLED = "ENABLED";
93 private static final String CU_REMOTE_CONTROL_DISABLED = "DISABLED";
94 private static final String CU_BATTERY_OK = "OK";
95 private static final String CU_BATTERY_KO = "KO";
96 private static final String MODE_WEEKLY = "WEEKLY";
98 public OpenWebNetThermoregulationHandler(Thing thing) {
103 public void initialize() {
105 ThingTypeUID thingType = thing.getThingTypeUID();
106 isCentralUnit = OpenWebNetBindingConstants.THING_TYPE_BUS_THERMO_CU.equals(thingType);
107 if (!isCentralUnit) {
108 if (!((WhereThermo) deviceWhere).isProbe()) {
109 Object standAloneConfig = getConfig().get(OpenWebNetBindingConstants.CONFIG_PROPERTY_STANDALONE);
110 if (standAloneConfig != null) {
111 isStandAlone = Boolean.parseBoolean(standAloneConfig.toString());
113 logger.debug("@@@@ THERMO ZONE INITIALIZE isStandAlone={}", isStandAlone);
116 // central unit must have WHERE=#0 or WHERE=0 or WHERE=#0#n
117 String w = deviceWhere.value();
118 if (w == null || !("0".equals(w) || "#0".equals(w) || w.startsWith("#0#"))) {
119 logger.warn("initialize() Invalid WHERE={} for Central Unit.", deviceWhere.value());
120 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
121 "@text/offline.conf-error-where");
128 protected void handleChannelCommand(ChannelUID channel, Command command) {
129 switch (channel.getId()) {
130 case CHANNEL_TEMP_SETPOINT:
131 handleSetpoint(command);
133 case CHANNEL_FUNCTION:
134 handleFunction(command);
139 case CHANNEL_FAN_SPEED:
140 handleSetFanSpeed(command);
142 case CHANNEL_CU_WEEKLY_PROGRAM_NUMBER:
143 case CHANNEL_CU_SCENARIO_PROGRAM_NUMBER:
144 handleSetProgramNumber(channel, command);
146 case CHANNEL_CU_VACATION_DAYS:
147 handleVacationDays(channel, command);
150 logger.warn("handleChannelCommand() Unsupported ChannelUID {}", channel.getId());
156 protected void requestChannelState(ChannelUID channel) {
157 super.requestChannelState(channel);
158 refreshDevice(false);
162 protected Where buildBusWhere(String wStr) throws IllegalArgumentException {
163 return new WhereThermo(wStr);
167 protected String ownIdPrefix() {
168 return Who.THERMOREGULATION.value().toString();
171 private void handleSetFanSpeed(Command command) {
172 if (command instanceof StringType) {
173 Where w = deviceWhere;
175 logger.warn("handleSetFanSpeed() Where is null for thing {}", getThing().getUID());
179 Thermoregulation.FanCoilSpeed speed = Thermoregulation.FanCoilSpeed.valueOf(command.toString());
180 send(Thermoregulation.requestWriteFanCoilSpeed(w.value(), speed));
181 } catch (OWNException e) {
182 logger.warn("handleSetFanSpeed() {}", e.getMessage());
183 } catch (IllegalArgumentException e) {
184 logger.warn("handleSetFanSpeed() Unsupported command {} for thing {}", command, getThing().getUID());
188 logger.warn("handleSetFanSpeed() Unsupported command {} for thing {}", command, getThing().getUID());
192 private void handleSetProgramNumber(ChannelUID channel, Command command) {
193 if (command instanceof DecimalType) {
194 if (!isCentralUnit) {
195 logger.warn("handleSetProgramNumber() This command can be sent only for a Central Unit.");
198 Where w = deviceWhere;
200 logger.warn("handleSetProgramNumber() Where is null for thing {}", getThing().getUID());
204 int programNumber = ((DecimalType) command).intValue();
205 boolean updateOpMode = false;
207 if (CHANNEL_CU_WEEKLY_PROGRAM_NUMBER.equals(channel.getId())) {
208 if (programNumber < 1 || programNumber > 3) {
209 logger.warn("handleSetProgramNumber() Invalid program number {} for thing {}", command,
210 getThing().getUID());
213 updateOpMode = (currentMode == Thermoregulation.OperationMode.WEEKLY);
214 currentWeeklyPrgNum = programNumber;
215 logger.debug("handleSetProgramNumber() currentWeeklyPrgNum changed to: {}", programNumber);
217 if (programNumber < 1 || programNumber > 16) {
218 logger.warn("handleSetProgramNumber() Invalid program number {} for thing {}", command,
219 getThing().getUID());
222 updateOpMode = (currentMode == Thermoregulation.OperationMode.SCENARIO);
223 currentScenarioPrgNum = programNumber;
224 logger.debug("handleSetProgramNumber() currentScenarioPrgNum changed to: {}", programNumber);
227 // force OperationMode update if we are already in SCENARIO or WEEKLY mode
230 send(Thermoregulation.requestWriteWeeklyScenarioMode(getWhere(w.value()), currentMode,
231 currentFunction, programNumber));
232 } catch (OWNException e) {
233 logger.warn("handleSetProgramNumber() {}", e.getMessage());
235 } else { // just update channel
236 updateState(channel, new DecimalType(programNumber));
239 logger.warn("handleSetProgramNumber() Unsupported command {} for thing {}", command, getThing().getUID());
243 private void handleVacationDays(ChannelUID channel, Command command) {
244 if (command instanceof DecimalType) {
245 Where w = deviceWhere;
247 logger.warn("handleVacationDays() Where is null for thing {}", getThing().getUID());
250 if (!isCentralUnit) {
251 logger.warn("handleVacationDays() This command can be sent only for a Central Unit.");
254 int vacationDays = ((DecimalType) command).intValue();
256 if (vacationDays < 1 || vacationDays > 255) {
257 logger.warn("handleVacationDays() vacation days must be between 1 and 255");
261 currentVacationDays = vacationDays;
262 logger.debug("handleVacationDays() currentVacationDays changed to: {}", currentVacationDays);
264 // force OperationMode update if we are already in VACATION mode
265 if (currentMode == Thermoregulation.OperationMode.VACATION) {
267 send(Thermoregulation.requestWriteVacationMode(getWhere(w.value()), currentFunction,
268 currentVacationDays, currentWeeklyPrgNum));
269 } catch (OWNException e) {
270 logger.warn("handleVacationDays() {}", e.getMessage());
271 } catch (IllegalArgumentException e) {
272 logger.warn("handleVacationDays() Unsupported command {} for thing {}", command,
273 getThing().getUID());
275 } else { // just update channel
276 updateState(channel, new DecimalType(currentVacationDays));
279 logger.warn("handleVacationDays() Unsupported command {} for thing {}", command, getThing().getUID());
283 private void handleSetpoint(Command command) {
284 if (command instanceof QuantityType || command instanceof DecimalType) {
285 Where w = deviceWhere;
287 logger.warn("handleSetpoint() Where is null for thing {}", getThing().getUID());
291 if (command instanceof QuantityType) {
292 QuantityType<?> tempCelsius = ((QuantityType<?>) command).toUnit(SIUnits.CELSIUS);
293 if (tempCelsius != null) {
294 newTemp = tempCelsius.doubleValue();
297 newTemp = ((DecimalType) command).doubleValue();
299 if (newTemp >= 5.0 && newTemp <= 40.0) {
302 res = send(Thermoregulation.requestWriteSetpointTemperature(getWhere(w.value()), newTemp,
304 // For zones no setPoint temperature confirmation message is returned from gw,
305 // so we update channel with current requested temp on successful response.
306 if (!isCentralUnit && res != null && res.isSuccess()) {
307 updateState(CHANNEL_TEMP_SETPOINT, getAsQuantityTypeOrNull(newTemp, SIUnits.CELSIUS));
308 currentSetPointTemp = newTemp;
310 } catch (MalformedFrameException | OWNException e) {
311 logger.warn("handleSetpoint() {}", e.getMessage());
314 logger.info("handleSetpoint() Setpoint temperature must be between 5°C and 40°C for thing {}",
315 getThing().getUID());
318 logger.warn("handleSetpoint() Unsupported command {} for thing {}", command, getThing().getUID());
322 private void handleMode(Command command) {
323 if (command instanceof StringType) {
324 Where w = deviceWhere;
326 logger.warn("handleMode() Where is null for thing {}", getThing().getUID());
330 String whStr = getWhere(w.value());
331 String cmdStr = command.toString().toUpperCase();
332 OperationMode newMode;
334 newMode = OperationMode.valueOf(cmdStr);
335 } catch (IllegalArgumentException e) {
336 logger.warn("handleMode() Unsupported command {} for thing {}", command, getThing().getUID());
339 Thermoregulation tMsg = null;
340 if (isCentralUnit) { // CU accepted modes: MANUAL, OFF, PROTECTION, WEEKLY, SCENARIO, HOLIDAY,
346 tMsg = Thermoregulation.requestWriteMode(whStr, newMode, currentFunction, currentSetPointTemp);
350 int programNumber = (MODE_WEEKLY.equals(cmdStr) ? currentWeeklyPrgNum : currentScenarioPrgNum);
351 tMsg = Thermoregulation.requestWriteWeeklyScenarioMode(whStr, newMode, currentFunction,
355 tMsg = Thermoregulation.requestWriteHolidayMode(whStr, currentFunction, currentWeeklyPrgNum);
358 tMsg = Thermoregulation.requestWriteVacationMode(whStr, currentFunction, currentVacationDays,
359 currentWeeklyPrgNum);
362 logger.warn("handleMode() Unsupported command {} for CU thing {}", command,
363 getThing().getUID());
365 } else {// Zone accepted modes: MANUAL, OFF, PROTECTION, AUTO
368 tMsg = Thermoregulation.requestWriteMode(whStr, newMode, currentFunction, currentSetPointTemp);
373 tMsg = Thermoregulation.requestWriteMode(whStr, newMode, Function.GENERIC, currentSetPointTemp);
376 logger.warn("handleMode() Unsupported command {} for ZONE thing {}", command,
377 getThing().getUID());
384 } catch (OWNException e) {
385 logger.warn("handleMode() {}", e.getMessage());
388 logger.warn("handleMode() Unsupported command {} for thing {}", command, getThing().getUID());
393 private String getWhere(String where) {
395 if (where.charAt(0) == '#') {
397 } else { // to support old configurations for CU with where="0"
401 return isStandAlone ? where : "#" + where;
405 private void handleFunction(Command command) {
406 if (command instanceof StringType) {
407 Where w = deviceWhere;
409 logger.warn("handleFunction() Where is null for thing {}", getThing().getUID());
413 Thermoregulation.Function function = Thermoregulation.Function.valueOf(command.toString());
414 send(Thermoregulation.requestWriteFunction(w.value(), function));
415 } catch (OWNException e) {
416 logger.warn("handleFunction() {}", e.getMessage());
417 } catch (IllegalArgumentException e) {
418 logger.warn("handleFunction() Unsupported command {} for thing {}", command, getThing().getUID());
422 logger.warn("handleFunction() Unsupported command {} for thing {}", command, getThing().getUID());
427 protected void handleMessage(BaseOpenMessage msg) {
428 super.handleMessage(msg);
429 logger.debug("@@@@ Thermo.handleMessage(): {}", msg.toStringVerbose());
430 Thermoregulation tmsg = (Thermoregulation) msg;
432 WhatThermo tWhat = (WhatThermo) msg.getWhat();
434 logger.debug("handleMessage() Ignoring unsupported WHAT {}. Frame={}", tWhat, msg);
437 if (tWhat.value() > 40) {
438 // it's a CU mode event, CU state events will follow shortly, so let's reset
442 switch (tWhat.getType()) {
443 case AT_LEAST_ONE_PROBE_ANTIFREEZE:
444 cuAtLeastOneProbeProtection = true;
446 case AT_LEAST_ONE_PROBE_MANUAL:
447 cuAtLeastOneProbeManual = true;
449 case AT_LEAST_ONE_PROBE_OFF:
450 cuAtLeastOneProbeOff = true;
453 cuBatteryStatus = CU_BATTERY_KO;
455 case FAILURE_DISCOVERED:
456 cuFailureDiscovered = true;
458 case RELEASE_SENSOR_LOCAL_ADJUST:
459 logger.debug("handleMessage(): Ignoring unsupported WHAT {}. Frame={}", tWhat, msg);
461 case REMOTE_CONTROL_DISABLED:
462 updateCURemoteControlStatus(CU_REMOTE_CONTROL_DISABLED);
464 case REMOTE_CONTROL_ENABLED:
465 updateCURemoteControlStatus(CU_REMOTE_CONTROL_ENABLED);
468 // check and update values of other channels (mode, function, temp)
469 updateModeAndFunction(tmsg);
470 updateSetpoint(tmsg);
476 if (tmsg.isCommand()) {
477 updateModeAndFunction(tmsg);
479 DimThermo dim = (DimThermo) tmsg.getDim();
482 updateSetpoint(tmsg);
484 case COMPLETE_PROBE_STATUS:
485 updateTargetTemperature(tmsg);
487 case PROBE_TEMPERATURE:
489 updateTemperature(tmsg);
491 case ACTUATOR_STATUS:
492 updateActuatorStatus(tmsg);
495 updateFanCoilSpeed(tmsg);
498 updateLocalOffset(tmsg);
501 updateValveStatus(tmsg);
504 logger.debug("handleMessage() Ignoring unsupported DIM {} for thing {}. Frame={}", tmsg.getDim(),
505 getThing().getUID(), tmsg);
511 private void updateModeAndFunction(Thermoregulation tmsg) {
512 if (tmsg.getWhat() == null) {
513 logger.warn("updateModeAndFunction() Could not parse What {} (WHAT is null)", tmsg.getFrameValue());
516 Thermoregulation.WhatThermo what = tmsg.new WhatThermo(tmsg.getWhat().value());
518 if (what.getFunction() == null) {
519 logger.warn("updateModeAndFunction() Could not parse Function from: {}", tmsg.getFrameValue());
522 // update Function if it's not GENERIC
523 Thermoregulation.Function function = what.getFunction();
524 if (function != Function.GENERIC) {
525 if (currentFunction != function) {
526 updateState(CHANNEL_FUNCTION, new StringType(function.toString()));
527 currentFunction = function;
530 if (what.getType() == WhatThermoType.HEATING || what.getType() == WhatThermoType.CONDITIONING
531 || what.getType() == WhatThermoType.GENERIC) {
532 // *4*1*z## and *4*0*z## do not tell us which mode is the zone now, so let's
538 Thermoregulation.OperationMode operationMode = null;
540 operationMode = what.getMode();
542 if (operationMode != null) {
543 // set ProgramNumber/vacationDays channels when necessary
544 switch (operationMode) {
546 updateVacationDays(tmsg);
550 updateProgramNumber(tmsg);
555 if (!isCentralUnit && !(operationMode == OperationMode.AUTO || operationMode == OperationMode.OFF
556 || operationMode == OperationMode.PROTECTION || operationMode == OperationMode.MANUAL)) {
557 logger.warn("updateModeAndFunction() Unsupported mode for zone {} from message: {}",
558 getThing().getUID(), tmsg.getFrameValue());
561 if (currentMode != operationMode) {
562 updateState(CHANNEL_MODE, new StringType(operationMode.name()));
563 currentMode = operationMode;
567 logger.warn("updateModeAndFunction() Unrecognized mode from message: {}", tmsg.getFrameValue());
571 private void updateVacationDays(Thermoregulation tmsg) {
573 Integer vDays = ((WhatThermo) tmsg.getWhat()).vacationDays();
575 logger.debug("{} - updateVacationDays() set VACATION DAYS to: {}", getThing().getUID(), vDays);
576 updateState(CHANNEL_CU_VACATION_DAYS, new DecimalType(vDays));
577 currentVacationDays = vDays;
581 private void updateProgramNumber(Thermoregulation tmsg) {
583 WhatThermo wt = (WhatThermo) tmsg.getWhat();
587 Integer prNum = wt.programNumber();
589 if (wt.getMode() == OperationMode.SCENARIO) {
590 logger.debug("{} - updateProgramNumber() set SCENARIO program to: {}", getThing().getUID(), prNum);
591 updateState(CHANNEL_CU_SCENARIO_PROGRAM_NUMBER, new DecimalType(prNum));
592 currentScenarioPrgNum = prNum;
593 } else if (wt.getMode() == OperationMode.WEEKLY) {
594 logger.debug("{} - updateProgramNumber() set WEEKLY program to: {}", getThing().getUID(), prNum);
595 updateState(CHANNEL_CU_WEEKLY_PROGRAM_NUMBER, new DecimalType(prNum));
596 currentWeeklyPrgNum = prNum;
601 private void updateTemperature(Thermoregulation tmsg) {
603 double temp = Thermoregulation.parseTemperature(tmsg);
604 updateState(CHANNEL_TEMPERATURE, getAsQuantityTypeOrNull(temp, SIUnits.CELSIUS));
605 } catch (FrameException e) {
606 logger.warn("updateTemperature() FrameException on frame {}: {}", tmsg, e.getMessage());
607 updateState(CHANNEL_TEMPERATURE, UnDefType.UNDEF);
611 private void updateTargetTemperature(Thermoregulation tmsg) {
613 double temp = Thermoregulation.parseTemperature(tmsg);
614 updateState(CHANNEL_TEMP_TARGET, getAsQuantityTypeOrNull(temp, SIUnits.CELSIUS));
615 } catch (FrameException e) {
616 logger.warn("updateTargetTemperature() FrameException on frame {}: {}", tmsg, e.getMessage());
617 updateState(CHANNEL_TEMP_TARGET, UnDefType.UNDEF);
621 private void updateSetpoint(Thermoregulation tmsg) {
625 WhatThermo tw = (WhatThermo) tmsg.getWhat();
627 logger.warn("updateSetpoint() Could not parse what from {} (what is null)", tmsg.getFrameValue());
630 String[] parameters = tmsg.getWhatParams();
631 if (parameters.length > 0 && tw.getType() == WhatThermoType.MANUAL) {
632 // manual setpoint frame should be like *4*110#TTTT*#0##
633 newTemp = Thermoregulation.decodeTemperature(parameters[0]);
634 logger.debug("updateSetpoint() parsed temperature from {}: {} ---> {}", tmsg.toStringVerbose(),
635 parameters[0], newTemp);
638 newTemp = Thermoregulation.parseTemperature(tmsg);
641 updateState(CHANNEL_TEMP_SETPOINT, getAsQuantityTypeOrNull(newTemp, SIUnits.CELSIUS));
642 currentSetPointTemp = newTemp;
644 } catch (NumberFormatException e) {
645 logger.warn("updateSetpoint() NumberFormatException on frame {}: {}", tmsg, e.getMessage());
646 updateState(CHANNEL_TEMP_SETPOINT, UnDefType.UNDEF);
647 } catch (FrameException e) {
648 logger.warn("updateSetpoint() FrameException on frame {}: {}", tmsg, e.getMessage());
649 updateState(CHANNEL_TEMP_SETPOINT, UnDefType.UNDEF);
653 private void updateFanCoilSpeed(Thermoregulation tmsg) {
655 Thermoregulation.FanCoilSpeed speed = Thermoregulation.parseFanCoilSpeed(tmsg);
656 updateState(CHANNEL_FAN_SPEED, new StringType(speed.toString()));
657 } catch (NumberFormatException e) {
658 logger.warn("updateFanCoilSpeed() NumberFormatException on frame {}: {}", tmsg, e.getMessage());
659 updateState(CHANNEL_FAN_SPEED, UnDefType.UNDEF);
660 } catch (FrameException e) {
661 logger.warn("updateFanCoilSpeed() FrameException on frame {}: {}", tmsg, e.getMessage());
662 updateState(CHANNEL_FAN_SPEED, UnDefType.UNDEF);
666 private void updateValveStatus(Thermoregulation tmsg) {
668 Thermoregulation.ValveOrActuatorStatus cv = Thermoregulation.parseValveStatus(tmsg,
669 Thermoregulation.WhatThermoType.CONDITIONING);
670 updateState(CHANNEL_CONDITIONING_VALVES, new StringType(cv.toString()));
671 updateHeatingCooling(false, cv);
673 Thermoregulation.ValveOrActuatorStatus hv = Thermoregulation.parseValveStatus(tmsg,
674 Thermoregulation.WhatThermoType.HEATING);
675 updateState(CHANNEL_HEATING_VALVES, new StringType(hv.toString()));
676 updateHeatingCooling(true, hv);
678 } catch (FrameException e) {
679 logger.warn("updateValveStatus() FrameException on frame {}: {}", tmsg, e.getMessage());
680 updateState(CHANNEL_CONDITIONING_VALVES, UnDefType.UNDEF);
681 updateState(CHANNEL_HEATING_VALVES, UnDefType.UNDEF);
685 private void updateHeatingCooling(boolean heating, Thermoregulation.ValveOrActuatorStatus v) {
686 boolean state = false;
708 updateState(CHANNEL_HEATING, OnOffType.from(state));
710 updateState(CHANNEL_COOLING, OnOffType.from(state));
714 private void updateActuatorStatus(Thermoregulation tmsg) {
716 Thermoregulation.ValveOrActuatorStatus hv = Thermoregulation.parseActuatorStatus(tmsg);
717 updateState(CHANNEL_ACTUATORS, new StringType(hv.toString()));
718 } catch (FrameException e) {
719 logger.warn("updateActuatorStatus() FrameException on frame {}: {}", tmsg, e.getMessage());
720 updateState(CHANNEL_ACTUATORS, UnDefType.UNDEF);
724 private void updateLocalOffset(Thermoregulation tmsg) {
726 Thermoregulation.LocalOffset offset = Thermoregulation.parseLocalOffset(tmsg);
727 updateState(CHANNEL_LOCAL_OFFSET, new StringType(offset.toString()));
728 logger.debug("updateLocalOffset() {}: {}", tmsg, offset.toString());
730 } catch (FrameException e) {
731 logger.warn("updateLocalOffset() FrameException on frame {}: {}", tmsg, e.getMessage());
732 updateState(CHANNEL_LOCAL_OFFSET, UnDefType.UNDEF);
736 private void updateCURemoteControlStatus(String status) {
737 updateState(CHANNEL_CU_REMOTE_CONTROL, new StringType(status));
738 logger.debug("updateCURemoteControlStatus(): {}", status);
741 private void resetCUState() {
742 logger.debug("########### resetting CU state");
743 cuAtLeastOneProbeOff = false;
744 cuAtLeastOneProbeProtection = false;
745 cuAtLeastOneProbeManual = false;
746 cuBatteryStatus = CU_BATTERY_OK;
747 cuFailureDiscovered = false;
749 cuStateChannelsUpdateSchedule = scheduler.schedule(() -> {
750 updateCUStateChannels();
751 }, CU_STATE_CHANNELS_UPDATE_DELAY, TimeUnit.MILLISECONDS);
754 private void updateCUStateChannels() {
755 updateState(CHANNEL_CU_AT_LEAST_ONE_PROBE_OFF, OnOffType.from(cuAtLeastOneProbeOff));
756 updateState(CHANNEL_CU_AT_LEAST_ONE_PROBE_PROTECTION, OnOffType.from(cuAtLeastOneProbeProtection));
757 updateState(CHANNEL_CU_AT_LEAST_ONE_PROBE_MANUAL, OnOffType.from(cuAtLeastOneProbeManual));
758 updateState(CHANNEL_CU_BATTERY_STATUS, new StringType(cuBatteryStatus));
759 updateState(CHANNEL_CU_FAILURE_DISCOVERED, OnOffType.from(cuFailureDiscovered));
762 private Boolean channelExists(String channelID) {
763 return thing.getChannel(channelID) != null;
767 protected void refreshDevice(boolean refreshAll) {
768 logger.debug("--- refreshDevice() : refreshing SINGLE... ({})", thing.getUID());
770 Where w = deviceWhere;
772 logger.warn("refreshDevice() Where is null for thing {}", getThing().getUID());
776 String whereStr = w.value();
780 send(Thermoregulation.requestStatus(getWhere(whereStr)));
781 } catch (OWNException e) {
782 logger.warn("refreshDevice() central unit returned OWNException {}", e.getMessage());
788 send(Thermoregulation.requestTemperature(whereStr));
790 if (!((WhereThermo) w).isProbe()) {
791 // for bus_thermo_zone request also other single channels updates
792 send(Thermoregulation.requestSetPointTemperature(whereStr));
793 send(Thermoregulation.requestMode(whereStr));
795 // refresh ONLY subscribed channels
796 if (channelExists(CHANNEL_FAN_SPEED)) {
797 send(Thermoregulation.requestFanCoilSpeed(whereStr));
799 if (channelExists(CHANNEL_CONDITIONING_VALVES) || channelExists(CHANNEL_HEATING_VALVES)) {
800 send(Thermoregulation.requestValvesStatus(whereStr));
802 if (channelExists(CHANNEL_ACTUATORS)) {
803 send(Thermoregulation.requestActuatorsStatus(whereStr));
805 if (channelExists(CHANNEL_LOCAL_OFFSET)) {
806 send(Thermoregulation.requestLocalOffset(whereStr));
809 } catch (OWNException e) {
810 logger.warn("refreshDevice() where='{}' returned OWNException {}", whereStr, e.getMessage());
815 public void dispose() {
816 ScheduledFuture<?> s = cuStateChannelsUpdateSchedule;
819 logger.debug("dispose() - scheduler stopped.");