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.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;
30 import com.digitaldan.jomnilinkII.MessageTypes.CommandMessage;
33 * The {@link ConsoleHandler} defines some methods that are used to
34 * interface with an OmniLink Console. This by extension also defines the
35 * Console thing that openHAB will be able to pick up and interface with.
37 * @author Craig Hamilton - Initial contribution
38 * @author Ethan Dye - openHAB3 rewrite
41 public class ConsoleHandler extends AbstractOmnilinkHandler {
42 private final Logger logger = LoggerFactory.getLogger(ConsoleHandler.class);
43 private final int thingID = getThingNumber();
45 public ConsoleHandler(Thing thing) {
50 public void initialize() {
51 if (getOmnilinkBridgeHandler() != null) {
52 updateStatus(ThingStatus.ONLINE);
55 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.COMMUNICATION_ERROR,
56 "Received null bridge while initializing Console!");
61 public void handleCommand(ChannelUID channelUID, Command command) {
62 logger.debug("handleCommand called for channel: {}, command: {}", channelUID, command);
64 if (command instanceof RefreshType) {
69 switch (channelUID.getId()) {
70 case CHANNEL_CONSOLE_ENABLE_DISABLE_BEEPER:
71 if (command instanceof StringType stringCommand) {
72 sendOmnilinkCommand(CommandMessage.CMD_CONSOLE_ENABLE_DISABLE_BEEPER,
73 stringCommand.equals(StringType.valueOf("OFF")) ? 0 : 1, thingID);
75 logger.debug("Invalid command: {}, must be StringType", command);
78 case CHANNEL_CONSOLE_BEEP:
79 if (command instanceof DecimalType decimalCommand) {
80 sendOmnilinkCommand(CommandMessage.CMD_CONSOLE_BEEP, decimalCommand.intValue(), thingID);
82 logger.debug("Invalid command: {}, must be DecimalType", command);
86 logger.warn("Unknown channel for Console thing: {}", channelUID);
91 public void updateChannels() {
92 updateState(CHANNEL_CONSOLE_ENABLE_DISABLE_BEEPER, UnDefType.UNDEF);
93 updateState(CHANNEL_CONSOLE_BEEP, UnDefType.UNDEF);