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.protocol;
15 import java.util.List;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
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.
23 * @author Bob Adair - Initial contribution
26 public class EXPMessage extends ADMessage {
28 // Example: !EXP:07,01,01
29 // Example: !REL:12,01,01
32 public final int address;
35 public final int channel;
38 public final int data;
40 public EXPMessage(String message) throws IllegalArgumentException {
43 String[] topLevel = message.split(":");
44 if (topLevel.length != 2) {
45 throw new IllegalArgumentException("Multiple colons found in EXP message");
48 List<String> parts = splitMsg(topLevel[1]);
50 if (parts.size() != 3) {
51 throw new IllegalArgumentException("Invalid number of parts in EXP message");
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);
62 if ((data & ~0x1) != 0) {
63 throw new IllegalArgumentException("zone status should only be 0 or 1");