]> git.basschouten.com Git - openhab-addons.git/blob
b320f7c42ad331daa1d35a5621ff02ee9b27970a
[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 EXPMessage} class represents a parsed zone (EXP or REL) message.
21  * Based partly on code from the OH1 alarmdecoder binding by Bernd Pfrommer.
22  *
23  * @author Bob Adair - Initial contribution
24  */
25 @NonNullByDefault
26 public class EXPMessage extends ADMessage {
27
28     // Example: !EXP:07,01,01
29     // Example: !REL:12,01,01
30
31     /** Address number */
32     public final int address;
33
34     /** Channel number */
35     public final int channel;
36
37     /** Message data */
38     public final int data;
39
40     public EXPMessage(String message) throws IllegalArgumentException {
41         super(message);
42
43         String topLevel[] = message.split(":");
44         if (topLevel.length != 2) {
45             throw new IllegalArgumentException("Multiple colons found in EXP message");
46         }
47
48         List<String> parts = splitMsg(topLevel[1]);
49
50         if (parts.size() != 3) {
51             throw new IllegalArgumentException("Invalid number of parts in EXP message");
52         }
53
54         try {
55             address = Integer.parseInt(parts.get(0));
56             channel = Integer.parseInt(parts.get(1));
57             data = Integer.parseInt(parts.get(2));
58         } catch (NumberFormatException e) {
59             throw new IllegalArgumentException("EXP message contains invalid number: " + e.getMessage(), e);
60         }
61
62         if ((data & ~0x1) != 0) {
63             throw new IllegalArgumentException("zone status should only be 0 or 1");
64         }
65     }
66 }