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