2 * Copyright (c) 2010-2023 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.lutron.internal.radiora.handler;
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;
27 * Handler for RadioRA Phantom buttons
29 * @author Jeff Lauterbach - Initial Contribution
33 public class PhantomButtonHandler extends LutronHandler {
35 private @NonNullByDefault({}) PhantomButtonConfig config;
37 public PhantomButtonHandler(Thing thing) {
42 public void initialize() {
43 config = getConfigAs(PhantomButtonConfig.class);
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);
62 public void handleFeedback(RadioRAFeedback feedback) {
63 if (feedback instanceof LEDMapFeedback ledMapFeedback) {
64 handleLEDMapFeedback(ledMapFeedback);
68 private void handleLEDMapFeedback(LEDMapFeedback feedback) {
69 boolean zoneEnabled = feedback.getZoneValue(getConfigAs(PhantomButtonConfig.class).getButtonNumber()) == '1';
71 updateState(LutronBindingConstants.CHANNEL_SWITCH, OnOffType.from(zoneEnabled));