]> git.basschouten.com Git - openhab-addons.git/blob
d3808cfd5a67e22ad18b660780df0e38c6b34e4f
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.alarmdecoder.internal.handler;
14
15 import static org.openhab.binding.alarmdecoder.internal.AlarmDecoderBindingConstants.*;
16
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;
30
31 /**
32  * The {@link LRRHandler} is responsible for handling long range radio (LRR) messages.
33  *
34  * @author Bob Adair - Initial contribution
35  * @author Bill Forsyth - Initial contribution
36  */
37 @NonNullByDefault
38 public class LRRHandler extends ADThingHandler {
39
40     private final Logger logger = LoggerFactory.getLogger(LRRHandler.class);
41
42     private LRRConfig config = new LRRConfig();
43
44     public LRRHandler(Thing thing) {
45         super(thing);
46     }
47
48     @Override
49     public void initialize() {
50         config = getConfigAs(LRRConfig.class);
51
52         if (config.partition < 0) {
53             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR);
54             return;
55         }
56         logger.debug("LRR handler initializing for partition {}", config.partition);
57
58         initDeviceState();
59
60         logger.trace("LRR handler finished initializing");
61     }
62
63     @Override
64     public void initChannelState() {
65         // Do nothing
66     }
67
68     @Override
69     public void notifyPanelReady() {
70         // Do nothing
71     }
72
73     @Override
74     public void handleCommand(ChannelUID channelUID, Command command) {
75         // All channels are read-only, so ignore all commands.
76     }
77
78     @Override
79     public void handleUpdate(ADMessage msg) {
80         if (!(msg instanceof LRRMessage)) {
81             return;
82         }
83         LRRMessage lrrMsg = (LRRMessage) msg;
84
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));
91         }
92     }
93 }