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.evohome.internal.handler;
15 import org.openhab.binding.evohome.internal.EvohomeBindingConstants;
16 import org.openhab.binding.evohome.internal.api.models.v2.response.ZoneStatus;
17 import org.openhab.core.library.types.DecimalType;
18 import org.openhab.core.library.types.StringType;
19 import org.openhab.core.thing.ChannelUID;
20 import org.openhab.core.thing.Thing;
21 import org.openhab.core.thing.ThingStatus;
22 import org.openhab.core.thing.ThingStatusDetail;
23 import org.openhab.core.types.Command;
24 import org.openhab.core.types.RefreshType;
27 * The {@link EvohomeHeatingZoneHandler} is responsible for handling commands, which are
28 * sent to one of the channels.
30 * @author Jasper van Zuijlen - Initial contribution
31 * @author Neil Renaud - Working implementation
32 * @author Jasper van Zuijlen - Refactor + Permanent Zone temperature setting
34 public class EvohomeHeatingZoneHandler extends BaseEvohomeHandler {
36 private static final int CANCEL_SET_POINT_OVERRIDE = 0;
37 private ThingStatus tcsStatus;
38 private ZoneStatus zoneStatus;
40 public EvohomeHeatingZoneHandler(Thing thing) {
45 public void initialize() {
49 public void update(ThingStatus tcsStatus, ZoneStatus zoneStatus) {
50 this.tcsStatus = tcsStatus;
51 this.zoneStatus = zoneStatus;
53 // Make the zone offline when the related display is offline
54 // If the related display is not a thing, ignore this
55 if (tcsStatus != null && tcsStatus.equals(ThingStatus.OFFLINE)) {
56 updateEvohomeThingStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
57 "Display Controller offline");
58 } else if (zoneStatus == null) {
59 updateEvohomeThingStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
60 "Status not found, check the zone id");
61 } else if (!handleActiveFaults(zoneStatus)) {
62 updateEvohomeThingStatus(ThingStatus.ONLINE);
64 updateState(EvohomeBindingConstants.ZONE_TEMPERATURE_CHANNEL,
65 new DecimalType(zoneStatus.getTemperature().getTemperature()));
66 updateState(EvohomeBindingConstants.ZONE_SET_POINT_STATUS_CHANNEL,
67 new StringType(zoneStatus.getHeatSetpoint().getSetpointMode()));
68 updateState(EvohomeBindingConstants.ZONE_SET_POINT_CHANNEL,
69 new DecimalType(zoneStatus.getHeatSetpoint().getTargetTemperature()));
74 public void handleCommand(ChannelUID channelUID, Command command) {
75 if (command == RefreshType.REFRESH) {
76 update(tcsStatus, zoneStatus);
78 EvohomeAccountBridgeHandler bridge = getEvohomeBridge();
80 String channelId = channelUID.getId();
81 if (EvohomeBindingConstants.ZONE_SET_POINT_CHANNEL.equals(channelId)
82 && command instanceof DecimalType) {
83 double newTemp = ((DecimalType) command).doubleValue();
84 if (newTemp == CANCEL_SET_POINT_OVERRIDE) {
85 bridge.cancelSetPointOverride(getEvohomeThingConfig().id);
86 } else if (newTemp < 5) {
89 if (newTemp >= 5 && newTemp <= 35) {
90 bridge.setPermanentSetPoint(getEvohomeThingConfig().id, newTemp);
97 private boolean handleActiveFaults(ZoneStatus zoneStatus) {
98 if (zoneStatus.hasActiveFaults()) {
99 updateEvohomeThingStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
100 zoneStatus.getActiveFault(0).getFaultType());