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.units.dimmable;
15 import static org.openhab.binding.omnilink.internal.OmnilinkBindingConstants.CHANNEL_UPB_STATUS;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.omnilink.internal.handler.OmniLinkCmd;
20 import org.openhab.binding.omnilink.internal.handler.units.DimmableUnitHandler;
21 import org.openhab.core.library.types.StringType;
22 import org.openhab.core.thing.ChannelUID;
23 import org.openhab.core.thing.Thing;
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 UpbUnitHandler} defines some methods that are used to
32 * interface with an OmniLink UPB Unit. This by extension also defines the
33 * UPB Unit 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 UpbUnitHandler extends DimmableUnitHandler {
40 private final Logger logger = LoggerFactory.getLogger(UpbUnitHandler.class);
41 private final int thingID = getThingNumber();
42 public @Nullable String number;
44 public UpbUnitHandler(Thing thing) {
49 public void handleCommand(ChannelUID channelUID, Command command) {
50 logger.debug("handleCommand called for channel: {}, command: {}", channelUID, command);
52 if (command instanceof RefreshType) {
53 updateState(CHANNEL_UPB_STATUS, UnDefType.UNDEF);
57 switch (channelUID.getId()) {
58 case CHANNEL_UPB_STATUS:
59 if (command instanceof StringType) {
60 sendOmnilinkCommand(OmniLinkCmd.CMD_UNIT_UPB_REQ_STATUS.getNumber(), 0, thingID);
61 updateState(CHANNEL_UPB_STATUS, UnDefType.UNDEF);
63 logger.debug("Invalid command: {}, must be StringType", command);
67 logger.debug("Unknown channel for UPB Unit thing: {}", channelUID);
68 super.handleCommand(channelUID, command);