]> git.basschouten.com Git - openhab-addons.git/blob
e0f1045b194c8b54b4df5b313dbf2070ec420ec3
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.lutron.internal.radiora.handler;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.lutron.internal.LutronBindingConstants;
17 import org.openhab.binding.lutron.internal.radiora.config.PhantomButtonConfig;
18 import org.openhab.binding.lutron.internal.radiora.protocol.ButtonPressCommand;
19 import org.openhab.binding.lutron.internal.radiora.protocol.LEDMapFeedback;
20 import org.openhab.binding.lutron.internal.radiora.protocol.RadioRAFeedback;
21 import org.openhab.core.library.types.OnOffType;
22 import org.openhab.core.thing.ChannelUID;
23 import org.openhab.core.thing.Thing;
24 import org.openhab.core.types.Command;
25
26 /**
27  * Handler for RadioRA Phantom buttons
28  *
29  * @author Jeff Lauterbach - Initial Contribution
30  *
31  */
32 @NonNullByDefault
33 public class PhantomButtonHandler extends LutronHandler {
34
35     private @NonNullByDefault({}) PhantomButtonConfig config;
36
37     public PhantomButtonHandler(Thing thing) {
38         super(thing);
39     }
40
41     @Override
42     public void initialize() {
43         config = getConfigAs(PhantomButtonConfig.class);
44         super.initialize();
45     }
46
47     @Override
48     public void handleCommand(ChannelUID channelUID, Command command) {
49         RS232Handler bridgeHandler = getRS232Handler();
50         if (channelUID.getId().equals(LutronBindingConstants.CHANNEL_SWITCH)) {
51             if (command instanceof OnOffType) {
52                 ButtonPressCommand cmd = new ButtonPressCommand(config.getButtonNumber(),
53                         ButtonPressCommand.ButtonState.valueOf(command.toString()), config.system);
54                 if (bridgeHandler != null) {
55                     bridgeHandler.sendCommand(cmd);
56                 }
57             }
58         }
59     }
60
61     @Override
62     public void handleFeedback(RadioRAFeedback feedback) {
63         if (feedback instanceof LEDMapFeedback ledMapFeedback) {
64             handleLEDMapFeedback(ledMapFeedback);
65         }
66     }
67
68     private void handleLEDMapFeedback(LEDMapFeedback feedback) {
69         boolean zoneEnabled = feedback.getZoneValue(getConfigAs(PhantomButtonConfig.class).getButtonNumber()) == '1';
70
71         updateState(LutronBindingConstants.CHANNEL_SWITCH, OnOffType.from(zoneEnabled));
72     }
73 }