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.alarmdecoder.internal.handler;
15 import static org.openhab.binding.alarmdecoder.internal.AlarmDecoderBindingConstants.*;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.alarmdecoder.internal.config.RFZoneConfig;
19 import org.openhab.binding.alarmdecoder.internal.protocol.ADMessage;
20 import org.openhab.binding.alarmdecoder.internal.protocol.RFXMessage;
21 import org.openhab.core.library.types.OnOffType;
22 import org.openhab.core.library.types.OpenClosedType;
23 import org.openhab.core.thing.ChannelUID;
24 import org.openhab.core.thing.Thing;
25 import org.openhab.core.thing.ThingStatus;
26 import org.openhab.core.thing.ThingStatusDetail;
27 import org.openhab.core.types.Command;
28 import org.openhab.core.types.UnDefType;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 * The {@link RFZoneHandler} is responsible for handling wired zones (i.e. RFX messages).
35 * @author Bob Adair - Initial contribution
36 * @author Bill Forsyth - Initial contribution
39 public class RFZoneHandler extends ADThingHandler {
41 private final Logger logger = LoggerFactory.getLogger(RFZoneHandler.class);
43 private RFZoneConfig config = new RFZoneConfig();
45 public RFZoneHandler(Thing thing) {
50 public void initialize() {
51 config = getConfigAs(RFZoneConfig.class);
53 if (config.serial < 0) {
54 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Invalid serial setting");
57 logger.debug("RF Zone handler initializing for serial {}", config.serial);
61 logger.trace("RF Zone handler finished initializing");
65 * Set contact channel states to "UNDEF" at init time. The real states will be set either when the first message
66 * arrives for the zone, or they will be set to "CLOSED" the first time the panel goes into the "READY" state.
69 public void initChannelState() {
70 UnDefType state = UnDefType.UNDEF;
71 updateState(CHANNEL_RF_LOWBAT, state);
72 updateState(CHANNEL_RF_SUPERVISION, state);
73 updateState(CHANNEL_RF_LOOP1, state);
74 updateState(CHANNEL_RF_LOOP2, state);
75 updateState(CHANNEL_RF_LOOP3, state);
76 updateState(CHANNEL_RF_LOOP4, state);
77 firstUpdateReceived.set(false);
81 public void notifyPanelReady() {
82 logger.trace("RF Zone handler for {} received panel ready notification.", config.serial);
83 if (firstUpdateReceived.compareAndSet(false, true)) {
84 updateState(CHANNEL_RF_LOOP1, OpenClosedType.CLOSED);
85 updateState(CHANNEL_RF_LOOP2, OpenClosedType.CLOSED);
86 updateState(CHANNEL_RF_LOOP3, OpenClosedType.CLOSED);
87 updateState(CHANNEL_RF_LOOP4, OpenClosedType.CLOSED);
92 public void handleCommand(ChannelUID channelUID, Command command) {
93 // Does not accept any commands
97 public void handleUpdate(ADMessage msg) {
98 if (!(msg instanceof RFXMessage)) {
101 RFXMessage rfxMsg = (RFXMessage) msg;
103 if (config.serial == rfxMsg.serial) {
104 logger.trace("RF Zone handler for serial {} received update: {}", config.serial, rfxMsg.data);
105 firstUpdateReceived.set(true);
107 updateState(CHANNEL_RF_LOWBAT, (rfxMsg.data & RFXMessage.BIT_LOWBAT) == 0 ? OnOffType.OFF : OnOffType.ON);
108 updateState(CHANNEL_RF_SUPERVISION,
109 (rfxMsg.data & RFXMessage.BIT_SUPER) == 0 ? OnOffType.OFF : OnOffType.ON);
111 updateState(CHANNEL_RF_LOOP1,
112 (rfxMsg.data & RFXMessage.BIT_LOOP1) == 0 ? OpenClosedType.CLOSED : OpenClosedType.OPEN);
113 updateState(CHANNEL_RF_LOOP2,
114 (rfxMsg.data & RFXMessage.BIT_LOOP2) == 0 ? OpenClosedType.CLOSED : OpenClosedType.OPEN);
115 updateState(CHANNEL_RF_LOOP3,
116 (rfxMsg.data & RFXMessage.BIT_LOOP3) == 0 ? OpenClosedType.CLOSED : OpenClosedType.OPEN);
117 updateState(CHANNEL_RF_LOOP4,
118 (rfxMsg.data & RFXMessage.BIT_LOOP4) == 0 ? OpenClosedType.CLOSED : OpenClosedType.OPEN);