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.SwitchConfig;
18 import org.openhab.binding.lutron.internal.radiora.protocol.LocalZoneChangeFeedback;
19 import org.openhab.binding.lutron.internal.radiora.protocol.RadioRAFeedback;
20 import org.openhab.binding.lutron.internal.radiora.protocol.SetSwitchLevelCommand;
21 import org.openhab.binding.lutron.internal.radiora.protocol.ZoneMapFeedback;
22 import org.openhab.core.library.types.OnOffType;
23 import org.openhab.core.thing.ChannelUID;
24 import org.openhab.core.thing.Thing;
25 import org.openhab.core.types.Command;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
30 * Handler for RadioRA switches
32 * @author Jeff Lauterbach - Initial Contribution
36 public class SwitchHandler extends LutronHandler {
38 private final Logger logger = LoggerFactory.getLogger(SwitchHandler.class);
39 private @NonNullByDefault({}) SwitchConfig config;
41 public SwitchHandler(Thing thing) {
46 public void initialize() {
47 config = getConfigAs(SwitchConfig.class);
52 public void handleCommand(ChannelUID channelUID, Command command) {
53 RS232Handler bridgeHandler = getRS232Handler();
54 if (LutronBindingConstants.CHANNEL_SWITCH.equals(channelUID.getId())) {
55 if (command instanceof OnOffType) {
56 SetSwitchLevelCommand cmd = new SetSwitchLevelCommand(config.getZoneNumber(), (OnOffType) command,
59 if (bridgeHandler != null) {
60 bridgeHandler.sendCommand(cmd);
67 public void handleFeedback(RadioRAFeedback feedback) {
68 if (feedback instanceof LocalZoneChangeFeedback) {
69 handleLocalZoneChangeFeedback((LocalZoneChangeFeedback) feedback);
70 } else if (feedback instanceof ZoneMapFeedback) {
71 handleZoneMapFeedback((ZoneMapFeedback) feedback);
75 private void handleZoneMapFeedback(ZoneMapFeedback feedback) {
76 if (!systemsMatch(feedback.getSystem(), config.system)) {
79 char value = feedback.getZoneValue(config.getZoneNumber());
82 updateState(LutronBindingConstants.CHANNEL_SWITCH, OnOffType.ON);
83 } else if (value == '0') {
84 updateState(LutronBindingConstants.CHANNEL_SWITCH, OnOffType.OFF);
88 private void handleLocalZoneChangeFeedback(LocalZoneChangeFeedback feedback) {
89 if (systemsMatch(feedback.getSystem(), config.system) && feedback.getZoneNumber() == config.getZoneNumber()) {
90 if (LocalZoneChangeFeedback.State.CHG.equals(feedback.getState())) {
91 logger.debug("Not Implemented Yet - CHG state received from Local Zone Change Feedback.");
94 updateState(LutronBindingConstants.CHANNEL_SWITCH, OnOffType.valueOf(feedback.getState().toString()));