2 * Copyright (c) 2010-2021 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.openhab.binding.lutron.internal.LutronBindingConstants;
16 import org.openhab.binding.lutron.internal.radiora.config.SwitchConfig;
17 import org.openhab.binding.lutron.internal.radiora.protocol.LocalZoneChangeFeedback;
18 import org.openhab.binding.lutron.internal.radiora.protocol.RadioRAFeedback;
19 import org.openhab.binding.lutron.internal.radiora.protocol.SetSwitchLevelCommand;
20 import org.openhab.binding.lutron.internal.radiora.protocol.ZoneMapFeedback;
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 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * Handler for RadioRA switches
31 * @author Jeff Lauterbach - Initial Contribution
34 public class SwitchHandler extends LutronHandler {
36 private Logger logger = LoggerFactory.getLogger(SwitchHandler.class);
38 public SwitchHandler(Thing thing) {
43 public void handleCommand(ChannelUID channelUID, Command command) {
44 if (LutronBindingConstants.CHANNEL_SWITCH.equals(channelUID.getId())) {
45 if (command instanceof OnOffType) {
46 SetSwitchLevelCommand cmd = new SetSwitchLevelCommand(getConfigAs(SwitchConfig.class).getZoneNumber(),
49 getRS232Handler().sendCommand(cmd);
55 public void handleFeedback(RadioRAFeedback feedback) {
56 if (feedback instanceof LocalZoneChangeFeedback) {
57 handleLocalZoneChangeFeedback((LocalZoneChangeFeedback) feedback);
58 } else if (feedback instanceof ZoneMapFeedback) {
59 handleZoneMapFeedback((ZoneMapFeedback) feedback);
63 private void handleZoneMapFeedback(ZoneMapFeedback feedback) {
64 char value = feedback.getZoneValue(getConfigAs(SwitchConfig.class).getZoneNumber());
67 updateState(LutronBindingConstants.CHANNEL_SWITCH, OnOffType.ON);
68 } else if (value == '0') {
69 updateState(LutronBindingConstants.CHANNEL_SWITCH, OnOffType.OFF);
73 private void handleLocalZoneChangeFeedback(LocalZoneChangeFeedback feedback) {
74 if (feedback.getZoneNumber() == getConfigAs(SwitchConfig.class).getZoneNumber()) {
75 if (LocalZoneChangeFeedback.State.CHG.equals(feedback.getState())) {
76 logger.debug("Not Implemented Yet - CHG state received from Local Zone Change Feedback.");
79 updateState(LutronBindingConstants.CHANNEL_SWITCH, OnOffType.valueOf(feedback.getState().toString()));