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.plugwise.internal.protocol;
15 import static org.openhab.binding.plugwise.internal.protocol.field.MessageType.DEVICE_ROLE_CALL_RESPONSE;
17 import java.util.regex.Matcher;
18 import java.util.regex.Pattern;
20 import org.openhab.binding.plugwise.internal.protocol.field.MACAddress;
24 * The Circle+ sends this message as response to a {@link RoleCallRequestMessage}. It contains the MAC address for the
25 * the node identified by the node ID in the request message. When no node is known with given ID, the MAC
26 * address will be empty.
29 * The MAC address can belong to a relay device (Circle, Stealth) as well as a sleeping end device (SED: Scan, Sense,
30 * Switch). An {@link InformationRequestMessage} can be used to determine the actual device type (when it is online).
33 * The Circle+ MAC address can not be retrieved from the node list. The Circle+ MAC address can be retrieved with a
34 * {@link NetworkStatusRequestMessage}.
37 * @author Wouter Born, Karel Goderis - Initial contribution
39 public class RoleCallResponseMessage extends Message {
41 private static final Pattern PAYLOAD_PATTERN = Pattern.compile("(\\w{16})(\\w{16})(\\w{2})");
42 private static final String EMPTY_MAC_ADDRESS = "FFFFFFFFFFFFFFFF";
45 private MACAddress nodeMAC;
47 public RoleCallResponseMessage(int sequenceNumber, String payload) {
48 super(DEVICE_ROLE_CALL_RESPONSE, sequenceNumber, payload);
51 public int getNodeID() {
55 public MACAddress getNodeMAC() {
60 protected void parsePayload() {
61 Matcher matcher = PAYLOAD_PATTERN.matcher(payload);
62 if (matcher.matches()) {
63 macAddress = new MACAddress(matcher.group(1));
64 nodeMAC = matcher.group(2).equals(EMPTY_MAC_ADDRESS) ? null : new MACAddress(matcher.group(2));
65 nodeID = (Integer.parseInt(matcher.group(3), 16));
67 throw new PlugwisePayloadMismatchException(DEVICE_ROLE_CALL_RESPONSE, PAYLOAD_PATTERN, payload);