]> git.basschouten.com Git - openhab-addons.git/blob
9ee36a1a4d75ea989ba69ecc82bec5d0f678b917
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.plugwise.internal.protocol;
14
15 import static org.openhab.binding.plugwise.internal.protocol.field.MessageType.SLEEP_SET_REQUEST;
16
17 import java.time.Duration;
18
19 import org.openhab.binding.plugwise.internal.protocol.field.MACAddress;
20
21 /**
22  * Sets when sleeping end devices (Scan, Sense, Switch) sleep and wake-up .
23  *
24  * @author Wouter Born - Initial contribution
25  */
26 public class SleepSetRequestMessage extends Message {
27
28     private static final Duration DEFAULT_SLEEP_DURATION = Duration.ofSeconds(5);
29
30     private Duration wakeupDuration;
31     private Duration sleepDuration;
32     private Duration wakeupInterval;
33     private int unknown;
34
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;
41     }
42
43     public SleepSetRequestMessage(MACAddress macAddress, Duration wakeupDuration, Duration wakeupInterval) {
44         this(macAddress, wakeupDuration, DEFAULT_SLEEP_DURATION, wakeupInterval);
45     }
46
47     @Override
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;
54     }
55 }