]> git.basschouten.com Git - openhab-addons.git/blob
2fda1ced90bcbe70347dadd90b9df1ebf737b04c
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.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;
29
30 /**
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.
34  *
35  * @author Craig Hamilton - Initial contribution
36  * @author Ethan Dye - openHAB3 rewrite
37  */
38 @NonNullByDefault
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;
43
44     public UpbUnitHandler(Thing thing) {
45         super(thing);
46     }
47
48     @Override
49     public void handleCommand(ChannelUID channelUID, Command command) {
50         logger.debug("handleCommand called for channel: {}, command: {}", channelUID, command);
51
52         if (command instanceof RefreshType) {
53             updateState(CHANNEL_UPB_STATUS, UnDefType.UNDEF);
54             return;
55         }
56
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);
62                 } else {
63                     logger.debug("Invalid command: {}, must be StringType", command);
64                 }
65                 break;
66             default:
67                 logger.debug("Unknown channel for UPB Unit thing: {}", channelUID);
68                 super.handleCommand(channelUID, command);
69         }
70     }
71 }