2 * Copyright (c) 2010-2021 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.omnilink.internal.handler;
15 import static org.openhab.binding.omnilink.internal.OmnilinkBindingConstants.*;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.core.library.types.DecimalType;
19 import org.openhab.core.library.types.StringType;
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.types.Command;
25 import org.openhab.core.types.RefreshType;
26 import org.openhab.core.types.UnDefType;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 * The {@link ConsoleHandler} defines some methods that are used to
32 * interface with an OmniLink Console. This by extension also defines the
33 * Console thing that openHAB will be able to pick up and interface with.
35 * @author Craig Hamilton - Initial contribution
36 * @author Ethan Dye - openHAB3 rewrite
39 public class ConsoleHandler extends AbstractOmnilinkHandler {
40 private final Logger logger = LoggerFactory.getLogger(ConsoleHandler.class);
41 private final int thingID = getThingNumber();
43 public ConsoleHandler(Thing thing) {
48 public void initialize() {
49 if (getOmnilinkBridgeHandler() != null) {
50 updateStatus(ThingStatus.ONLINE);
53 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.COMMUNICATION_ERROR,
54 "Received null bridge while initializing Console!");
59 public void handleCommand(ChannelUID channelUID, Command command) {
60 logger.debug("handleCommand called for channel: {}, command: {}", channelUID, command);
62 if (command instanceof RefreshType) {
67 switch (channelUID.getId()) {
68 case CHANNEL_CONSOLE_ENABLE_DISABLE_BEEPER:
69 if (command instanceof StringType) {
70 sendOmnilinkCommand(OmniLinkCmd.CMD_CONSOLE_ENABLE_DISABLE_BEEPER.getNumber(),
71 ((StringType) command).equals(StringType.valueOf("OFF")) ? 0 : 1, thingID);
73 logger.debug("Invalid command: {}, must be StringType", command);
76 case CHANNEL_CONSOLE_BEEP:
77 if (command instanceof DecimalType) {
78 sendOmnilinkCommand(OmniLinkCmd.CMD_CONSOLE_BEEP.getNumber(), ((DecimalType) command).intValue(),
81 logger.debug("Invalid command: {}, must be DecimalType", command);
85 logger.warn("Unknown channel for Console thing: {}", channelUID);
90 public void updateChannels() {
91 updateState(CHANNEL_CONSOLE_ENABLE_DISABLE_BEEPER, UnDefType.UNDEF);
92 updateState(CHANNEL_CONSOLE_BEEP, UnDefType.UNDEF);