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.SENSE_REPORT_REQUEST;
17 import java.util.regex.Matcher;
18 import java.util.regex.Pattern;
20 import org.openhab.binding.plugwise.internal.protocol.field.Humidity;
21 import org.openhab.binding.plugwise.internal.protocol.field.MACAddress;
22 import org.openhab.binding.plugwise.internal.protocol.field.Temperature;
25 * A Sense periodically sends this message for updating the current temperature and humidity.
27 * @author Wouter Born - Initial contribution
29 public class SenseReportRequestMessage extends Message {
31 private static final Pattern PAYLOAD_PATTERN = Pattern.compile("(\\w{16})(\\w{4})(\\w{4})");
33 private Humidity humidity;
34 private Temperature temperature;
36 public SenseReportRequestMessage(int sequenceNumber, String payload) {
37 super(SENSE_REPORT_REQUEST, sequenceNumber, payload);
40 public Humidity getHumidity() {
44 public Temperature getTemperature() {
49 protected void parsePayload() {
50 Matcher matcher = PAYLOAD_PATTERN.matcher(payload);
51 if (matcher.matches()) {
52 macAddress = new MACAddress(matcher.group(1));
53 humidity = new Humidity(matcher.group(2));
54 temperature = new Temperature(matcher.group(3));
56 throw new PlugwisePayloadMismatchException(SENSE_REPORT_REQUEST, PAYLOAD_PATTERN, payload);