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.BROADCAST_GROUP_SWITCH_RESPONSE;
17 import java.util.regex.Matcher;
18 import java.util.regex.Pattern;
20 import org.openhab.binding.plugwise.internal.protocol.field.MACAddress;
23 * A sleeping end device (SED: Scan, Sense, Switch) sends this message to switch groups on/off when the configured
24 * switching conditions have been met.
26 * @author Wouter Born - Initial contribution
28 public class BroadcastGroupSwitchResponseMessage extends Message {
30 private static final Pattern PAYLOAD_PATTERN = Pattern.compile("(\\w{16})(\\w{2})(\\w{2})");
33 private boolean powerState;
35 public BroadcastGroupSwitchResponseMessage(int sequenceNumber, String payload) {
36 super(BROADCAST_GROUP_SWITCH_RESPONSE, sequenceNumber, payload);
39 public int getPortMask() {
43 public boolean getPowerState() {
48 protected void parsePayload() {
49 Matcher matcher = PAYLOAD_PATTERN.matcher(payload);
50 if (matcher.matches()) {
51 macAddress = new MACAddress(matcher.group(1));
52 portMask = Integer.parseInt(matcher.group(2));
53 powerState = ("01".equals(matcher.group(3)));
55 throw new PlugwisePayloadMismatchException(BROADCAST_GROUP_SWITCH_RESPONSE, PAYLOAD_PATTERN, payload);