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.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.evohome.internal.EvohomeBindingConstants;
18 import org.openhab.binding.evohome.internal.api.models.v2.dto.response.GatewayStatus;
19 import org.openhab.binding.evohome.internal.api.models.v2.dto.response.TemperatureControlSystemStatus;
20 import org.openhab.core.library.types.StringType;
21 import org.openhab.core.thing.ChannelUID;
22 import org.openhab.core.thing.Thing;
23 import org.openhab.core.thing.ThingStatus;
24 import org.openhab.core.thing.ThingStatusDetail;
25 import org.openhab.core.types.Command;
26 import org.openhab.core.types.RefreshType;
29 * Handler for a temperature control system. Gets and sets global system mode.
31 * @author Jasper van Zuijlen - Initial contribution
35 public class EvohomeTemperatureControlSystemHandler extends BaseEvohomeHandler {
36 private @Nullable GatewayStatus gatewayStatus;
37 private @Nullable TemperatureControlSystemStatus tcsStatus;
39 public EvohomeTemperatureControlSystemHandler(Thing thing) {
44 public void initialize() {
48 public void update(@Nullable GatewayStatus gatewayStatus, @Nullable TemperatureControlSystemStatus tcsStatus) {
49 this.gatewayStatus = gatewayStatus;
50 this.tcsStatus = tcsStatus;
52 if (tcsStatus == null || gatewayStatus == null) {
53 updateEvohomeThingStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
54 "Status not found, check the display id");
55 } else if (!handleActiveFaults(gatewayStatus)) {
56 updateEvohomeThingStatus(ThingStatus.ONLINE);
57 updateState(EvohomeBindingConstants.DISPLAY_SYSTEM_MODE_CHANNEL,
58 new StringType(tcsStatus.getMode().getMode()));
63 public void handleCommand(ChannelUID channelUID, Command command) {
64 if (command == RefreshType.REFRESH) {
65 update(gatewayStatus, tcsStatus);
66 } else if (channelUID.getId().equals(EvohomeBindingConstants.DISPLAY_SYSTEM_MODE_CHANNEL)) {
67 EvohomeAccountBridgeHandler bridge = getEvohomeBridge();
69 bridge.setTcsMode(getEvohomeThingConfig().id, command.toString());
74 private boolean handleActiveFaults(GatewayStatus gatewayStatus) {
75 if (gatewayStatus.hasActiveFaults()) {
76 updateEvohomeThingStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
77 gatewayStatus.getActiveFault(0).getFaultType());