2 * Copyright (c) 2010-2022 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.units.DimmableUnitHandler;
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.types.Command;
24 import org.openhab.core.types.RefreshType;
25 import org.openhab.core.types.UnDefType;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 import com.digitaldan.jomnilinkII.MessageTypes.CommandMessage;
32 * The {@link UpbUnitHandler} defines some methods that are used to
33 * interface with an OmniLink UPB Unit. This by extension also defines the
34 * UPB Unit thing that openHAB will be able to pick up and interface with.
36 * @author Craig Hamilton - Initial contribution
37 * @author Ethan Dye - openHAB3 rewrite
40 public class UpbUnitHandler extends DimmableUnitHandler {
41 private final Logger logger = LoggerFactory.getLogger(UpbUnitHandler.class);
42 private final int thingID = getThingNumber();
43 public @Nullable String number;
45 public UpbUnitHandler(Thing thing) {
50 public void handleCommand(ChannelUID channelUID, Command command) {
51 logger.debug("handleCommand called for channel: {}, command: {}", channelUID, command);
53 if (command instanceof RefreshType) {
54 updateState(CHANNEL_UPB_STATUS, UnDefType.UNDEF);
58 switch (channelUID.getId()) {
59 case CHANNEL_UPB_STATUS:
60 if (command instanceof StringType) {
61 sendOmnilinkCommand(CommandMessage.CMD_UNIT_UPB_REQ_STATUS, 0, thingID);
62 updateState(CHANNEL_UPB_STATUS, UnDefType.UNDEF);
64 logger.debug("Invalid command: {}, must be StringType", command);
68 logger.debug("Unknown channel for UPB Unit thing: {}", channelUID);
69 super.handleCommand(channelUID, command);