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.dominoswiss.internal;
15 import static org.openhab.binding.dominoswiss.internal.DominoswissBindingConstants.*;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.core.thing.Bridge;
20 import org.openhab.core.thing.ChannelUID;
21 import org.openhab.core.thing.Thing;
22 import org.openhab.core.thing.ThingStatus;
23 import org.openhab.core.thing.ThingStatusDetail;
24 import org.openhab.core.thing.binding.BaseThingHandler;
25 import org.openhab.core.types.Command;
26 import org.openhab.core.types.RefreshType;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 * The {@link BlindHandler} is responsible for handling commands, which are
32 * sent to one of the channels.The class defines common constants, which are
33 * used across the whole binding
35 * @author Frieso Aeschbacher - Initial contribution
38 public class BlindHandler extends BaseThingHandler {
40 private Logger logger = LoggerFactory.getLogger(BlindHandler.class);
42 private @Nullable EGateHandler dominoswissHandler;
44 private String id = "";
46 public BlindHandler(Thing thing) {
51 public void handleCommand(ChannelUID channelUID, Command command) {
52 logger.debug("Blind got command: {} and ChannelUID: {} ", command.toFullString(),
53 channelUID.getIdWithoutGroup());
54 Bridge bridge = getBridge();
55 EGateHandler localDominoswissHandler = dominoswissHandler;
57 localDominoswissHandler = (EGateHandler) bridge.getHandler();
59 if (localDominoswissHandler == null) {
60 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_UNINITIALIZED, "EGate not available");
61 logger.debug("Blind thing {} has no server configured, ignoring command: {}", getThing().getUID(), command);
65 // Some of the code below is not designed to handle REFRESH
66 if (command == RefreshType.REFRESH) {
69 switch (channelUID.getIdWithoutGroup()) {
71 if (command instanceof Number) {
72 localDominoswissHandler.pulseUp(id);
75 case CHANNEL_PULSEDOWN:
76 if (command instanceof Number) {
77 localDominoswissHandler.pulseDown(id);
80 case CHANNEL_CONTINOUSUP:
81 if (command instanceof Number) {
82 localDominoswissHandler.continuousUp(id);
85 case CHANNEL_CONTINOUSDOWN:
86 if (command instanceof Number) {
87 localDominoswissHandler.continuousDown(id);
91 if (command instanceof Number) {
92 localDominoswissHandler.stop(id);
96 if (command instanceof Number) {
97 localDominoswissHandler.continuousUp(id);
101 if (command instanceof Number) {
102 localDominoswissHandler.continuousDown(id);
106 if (command.toFullString() == DOWN) {
107 localDominoswissHandler.continuousDown(id);
108 } else if (command.toFullString() == UP) {
109 localDominoswissHandler.continuousUp(id);
110 } else if (command.toFullString() == CHANNEL_STOP) {
111 localDominoswissHandler.stop(id);
113 logger.debug("Blind got command but nothing executed: {} and ChannelUID: {}",
114 command.toFullString(), channelUID.getIdWithoutGroup());
118 if (command instanceof Number) {
120 localDominoswissHandler.tiltDown(id);
121 } catch (InterruptedException e) {
122 logger.debug("EGate tiltDown error: {} ", e.toString());
128 if (command instanceof Number) {
130 localDominoswissHandler.tiltUp(id);
131 } catch (InterruptedException e) {
132 logger.debug("EGate tiltUP error: {} ", e.toString());
138 if (command.toFullString() == UP) {
139 localDominoswissHandler.pulseUp(id);
140 } else if (command.toFullString() == DOWN) {
141 localDominoswissHandler.pulseDown(id);
142 } else if (command.toFullString() == CHANNEL_STOP) {
143 localDominoswissHandler.stop(id);
145 logger.debug("Blind got command but nothing executed: {} and ChannelUID: {}",
146 command.toFullString(), channelUID.getIdWithoutGroup());
155 public void initialize() {
156 this.id = getConfig().as(BlindConfig.class).id;
157 Bridge bridge = getBridge();
158 if (bridge != null) {
159 dominoswissHandler = (EGateHandler) bridge.getHandler();
160 EGateHandler localDominoswissHandler = dominoswissHandler;
161 if (localDominoswissHandler != null) {
162 localDominoswissHandler.registerBlind(this.id, getThing().getUID());
164 ThingStatus bridgeStatus = bridge.getStatus();
165 if (bridgeStatus == ThingStatus.ONLINE && getThing().getStatus() != ThingStatus.ONLINE) {
166 updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE);
167 localDominoswissHandler = (EGateHandler) bridge.getHandler();
168 } else if (bridgeStatus == ThingStatus.OFFLINE) {
169 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
171 } catch (Exception e) {
172 logger.debug("Could not update ThingStatus ", e);
173 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE, e.toString());
181 * Gets the ID of this Blind
183 public String getID() {