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.ANNOUNCE_AWAKE_REQUEST;
17 import java.util.Arrays;
18 import java.util.regex.Matcher;
19 import java.util.regex.Pattern;
21 import org.openhab.binding.plugwise.internal.protocol.field.MACAddress;
24 * A sleeping end device (SED: Scan, Sense, Switch) sends this message to announce that is awake.
26 * @author Wouter Born - Initial contribution
28 public class AnnounceAwakeRequestMessage extends Message {
30 public enum AwakeReason {
32 /** The SED joins the network for maintenance */
35 /** The SED joins a network for the first time */
38 /** The SED joins a network it has already joined, e.g. after reinserting a battery */
41 /** When a SED switches a device group or when reporting values such as temperature/humidity */
44 /** A human pressed the button on a SED to wake it up */
47 public static AwakeReason forValue(int value) {
48 return Arrays.stream(values()).filter(awakeReason -> awakeReason.id == value).findFirst().get();
58 private static final Pattern PAYLOAD_PATTERN = Pattern.compile("(\\w{16})(\\w{2})");
60 private AwakeReason awakeReason;
62 public AnnounceAwakeRequestMessage(int sequenceNumber, String payload) {
63 super(ANNOUNCE_AWAKE_REQUEST, sequenceNumber, payload);
66 public AwakeReason getAwakeReason() {
71 protected void parsePayload() {
72 Matcher matcher = PAYLOAD_PATTERN.matcher(payload);
73 if (matcher.matches()) {
74 macAddress = new MACAddress(matcher.group(1));
75 awakeReason = AwakeReason.forValue(Integer.parseInt(matcher.group(2)));
77 throw new PlugwisePayloadMismatchException(ANNOUNCE_AWAKE_REQUEST, PAYLOAD_PATTERN, payload);