]> git.basschouten.com Git - openhab-addons.git/blob
cc147e318246da4dd1c8949dbd167652e11bc411
[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.plugwise.internal.protocol;
14
15 import static org.openhab.binding.plugwise.internal.protocol.field.MessageType.NODE_AVAILABLE;
16
17 import java.util.regex.Matcher;
18 import java.util.regex.Pattern;
19
20 import org.openhab.binding.plugwise.internal.protocol.field.MACAddress;
21
22 /**
23  * Node available messages are broadcasted by nodes that are not yet part of a network. They are currently unused
24  * because typically the network is configured using the Plugwise Source software, and never changed after.
25  *
26  * @author Wouter Born, Karel Goderis - Initial contribution
27  */
28 public class NodeAvailableMessage extends Message {
29
30     private static final Pattern PAYLOAD_PATTERN = Pattern.compile("(\\w{16})");
31
32     public NodeAvailableMessage(int sequenceNumber, String payload) {
33         super(NODE_AVAILABLE, sequenceNumber, payload);
34     }
35
36     @Override
37     protected void parsePayload() {
38         Matcher matcher = PAYLOAD_PATTERN.matcher(payload);
39         if (matcher.matches()) {
40             macAddress = new MACAddress(matcher.group(1));
41         } else {
42             throw new PlugwisePayloadMismatchException(NODE_AVAILABLE, PAYLOAD_PATTERN, payload);
43         }
44     }
45 }