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.GatewayStatus;
17 import org.openhab.binding.evohome.internal.api.models.v2.response.TemperatureControlSystemStatus;
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 * Handler for a temperature control system. Gets and sets global system mode.
29 * @author Jasper van Zuijlen - Initial contribution
32 public class EvohomeTemperatureControlSystemHandler extends BaseEvohomeHandler {
33 private GatewayStatus gatewayStatus;
34 private TemperatureControlSystemStatus tcsStatus;
36 public EvohomeTemperatureControlSystemHandler(Thing thing) {
41 public void initialize() {
45 public void update(GatewayStatus gatewayStatus, TemperatureControlSystemStatus tcsStatus) {
46 this.gatewayStatus = gatewayStatus;
47 this.tcsStatus = tcsStatus;
49 if (tcsStatus == null || gatewayStatus == null) {
50 updateEvohomeThingStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
51 "Status not found, check the display id");
52 } else if (!handleActiveFaults(gatewayStatus)) {
53 updateEvohomeThingStatus(ThingStatus.ONLINE);
54 updateState(EvohomeBindingConstants.DISPLAY_SYSTEM_MODE_CHANNEL,
55 new StringType(tcsStatus.getMode().getMode()));
60 public void handleCommand(ChannelUID channelUID, Command command) {
61 if (command == RefreshType.REFRESH) {
62 update(gatewayStatus, tcsStatus);
63 } else if (channelUID.getId().equals(EvohomeBindingConstants.DISPLAY_SYSTEM_MODE_CHANNEL)) {
64 EvohomeAccountBridgeHandler bridge = getEvohomeBridge();
66 bridge.setTcsMode(getEvohomeThingConfig().id, command.toString());
71 private boolean handleActiveFaults(GatewayStatus gatewayStatus) {
72 if (gatewayStatus.hasActiveFaults()) {
73 updateEvohomeThingStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
74 gatewayStatus.getActiveFault(0).getFaultType());