2 * Copyright (c) 2010-2022 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.SLEEP_SET_REQUEST;
17 import java.time.Duration;
19 import org.openhab.binding.plugwise.internal.protocol.field.MACAddress;
22 * Sets when sleeping end devices (Scan, Sense, Switch) sleep and wake-up .
24 * @author Wouter Born - Initial contribution
26 public class SleepSetRequestMessage extends Message {
28 private static final Duration DEFAULT_SLEEP_DURATION = Duration.ofSeconds(5);
30 private Duration wakeupDuration;
31 private Duration sleepDuration;
32 private Duration wakeupInterval;
35 public SleepSetRequestMessage(MACAddress macAddress, Duration wakeupDuration, Duration sleepDuration,
36 Duration wakeupInterval) {
37 super(SLEEP_SET_REQUEST, macAddress);
38 this.wakeupDuration = wakeupDuration;
39 this.sleepDuration = sleepDuration;
40 this.wakeupInterval = wakeupInterval;
43 public SleepSetRequestMessage(MACAddress macAddress, Duration wakeupDuration, Duration wakeupInterval) {
44 this(macAddress, wakeupDuration, DEFAULT_SLEEP_DURATION, wakeupInterval);
48 protected String payloadToHexString() {
49 String wakeupDurationHex = String.format("%02X", wakeupDuration.getSeconds());
50 String sleepDurationHex = String.format("%04X", sleepDuration.getSeconds());
51 String wakeupIntervalHex = String.format("%04X", wakeupInterval.toMinutes());
52 String unknownHex = String.format("%06X", unknown);
53 return wakeupDurationHex + sleepDurationHex + wakeupIntervalHex + unknownHex;