]> git.basschouten.com Git - openhab-addons.git/blob
351c91fe31d1ef29024ae1f70bbcdb1986c0593a
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.omnilink.internal.handler.units.dimmable;
14
15 import static org.openhab.binding.omnilink.internal.OmnilinkBindingConstants.CHANNEL_UPB_STATUS;
16
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;
28
29 import com.digitaldan.jomnilinkII.MessageTypes.CommandMessage;
30
31 /**
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.
35  *
36  * @author Craig Hamilton - Initial contribution
37  * @author Ethan Dye - openHAB3 rewrite
38  */
39 @NonNullByDefault
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;
44
45     public UpbUnitHandler(Thing thing) {
46         super(thing);
47     }
48
49     @Override
50     public void handleCommand(ChannelUID channelUID, Command command) {
51         logger.debug("handleCommand called for channel: {}, command: {}", channelUID, command);
52
53         if (command instanceof RefreshType) {
54             updateState(CHANNEL_UPB_STATUS, UnDefType.UNDEF);
55             return;
56         }
57
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);
63                 } else {
64                     logger.debug("Invalid command: {}, must be StringType", command);
65                 }
66                 break;
67             default:
68                 logger.debug("Unknown channel for UPB Unit thing: {}", channelUID);
69                 super.handleCommand(channelUID, command);
70         }
71     }
72 }