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.LRRConfig;
19 import org.openhab.binding.alarmdecoder.internal.protocol.ADMessage;
20 import org.openhab.binding.alarmdecoder.internal.protocol.LRRMessage;
21 import org.openhab.core.library.types.DecimalType;
22 import org.openhab.core.library.types.StringType;
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.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 * The {@link LRRHandler} is responsible for handling long range radio (LRR) messages.
34 * @author Bob Adair - Initial contribution
35 * @author Bill Forsyth - Initial contribution
38 public class LRRHandler extends ADThingHandler {
40 private final Logger logger = LoggerFactory.getLogger(LRRHandler.class);
42 private LRRConfig config = new LRRConfig();
44 public LRRHandler(Thing thing) {
49 public void initialize() {
50 config = getConfigAs(LRRConfig.class);
52 if (config.partition < 0) {
53 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR);
56 logger.debug("LRR handler initializing for partition {}", config.partition);
60 logger.trace("LRR handler finished initializing");
64 public void initChannelState() {
69 public void notifyPanelReady() {
74 public void handleCommand(ChannelUID channelUID, Command command) {
75 // All channels are read-only, so ignore all commands.
79 public void handleUpdate(ADMessage msg) {
80 if (!(msg instanceof LRRMessage)) {
83 LRRMessage lrrMsg = (LRRMessage) msg;
85 if (config.partition == lrrMsg.partition || config.partition == 0 || lrrMsg.partition == 0) {
86 logger.trace("LRR handler for partition {} received update: {}", config.partition, msg);
87 updateState(CHANNEL_LRR_PARTITION, new DecimalType(lrrMsg.partition));
88 updateState(CHANNEL_LRR_EVENTDATA, new DecimalType(lrrMsg.eventData));
89 updateState(CHANNEL_LRR_CIDMESSAGE, new StringType(lrrMsg.cidMessage));
90 updateState(CHANNEL_LRR_REPORTCODE, new StringType(lrrMsg.reportCode));