]> git.basschouten.com Git - openhab-addons.git/blob
3857b9e82e8cf5486b02cdc14fe26b28802a3658
[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.protocol;
14
15 import java.util.List;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18
19 /**
20  * The {@link LRRMessage} class represents a parsed LRR message.
21  * Based partly on code from the OH1 alarmdecoder binding by Bernd Pfrommer and Lucky Mallari.
22  *
23  * @author Bob Adair - Initial contribution
24  */
25 @NonNullByDefault
26 public class LRRMessage extends ADMessage {
27
28     // Example: !LRR:012,1,CID_1441,ff
29     // or: !LRR:000,1,ARM_AWAY
30
31     /** Event data contains user number or zone number for the event */
32     public final String eventData;
33
34     /** Partition event applies to. 0 means all partitions. */
35     public final int partition;
36
37     /** CID message for event as defined in SIA DC-05-1999.09 standard */
38     public final String cidMessage;
39
40     /** Report code */
41     public final String reportCode;
42
43     public LRRMessage(String message) throws IllegalArgumentException {
44         super(message);
45
46         String topLevel[] = message.split(":");
47         if (topLevel.length != 2) {
48             throw new IllegalArgumentException("multiple colons in LRR message");
49         }
50
51         List<String> parts = splitMsg(topLevel[1]);
52
53         // Apparently the 4th part of the LRR message may not be included depending on version
54         if (parts.size() < 3 || parts.size() > 4) {
55             throw new IllegalArgumentException("Invalid number of parts in LRR message");
56         }
57
58         eventData = parts.get(0);
59         cidMessage = parts.get(2);
60         reportCode = parts.size() == 4 ? parts.get(3) : "";
61
62         try {
63             partition = Integer.parseInt(parts.get(1));
64         } catch (NumberFormatException e) {
65             throw new IllegalArgumentException("LRR msg contains invalid number: " + e.getMessage(), e);
66         }
67     }
68 }