]> git.basschouten.com Git - openhab-addons.git/blob
2f0ad87289342e8df230e56697b3801db8c60bc5
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.MODULE_JOINED_NETWORK_REQUEST;
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  * Module joined network request. Sent when a SED (re)joins the network. E.g. when you reinsert the battery of a Scan.
24  *
25  * @author Wouter Born - Initial contribution
26  */
27 public class ModuleJoinedNetworkRequestMessage extends Message {
28
29     private static final Pattern PAYLOAD_PATTERN = Pattern.compile("(\\w{16})");
30
31     public ModuleJoinedNetworkRequestMessage(int sequenceNumber, String payload) {
32         super(MODULE_JOINED_NETWORK_REQUEST, sequenceNumber, payload);
33     }
34
35     @Override
36     protected void parsePayload() {
37         Matcher matcher = PAYLOAD_PATTERN.matcher(payload);
38         if (matcher.matches()) {
39             macAddress = new MACAddress(matcher.group(1));
40         } else {
41             throw new PlugwisePayloadMismatchException(MODULE_JOINED_NETWORK_REQUEST, PAYLOAD_PATTERN, payload);
42         }
43     }
44 }