]> git.basschouten.com Git - openhab-addons.git/blob
873bc30f537b476ec123ab4db10dc7a7495b7bfc
[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.SCAN_PARAMETERS_SET_REQUEST;
16
17 import java.time.Duration;
18
19 import org.openhab.binding.plugwise.internal.protocol.field.MACAddress;
20 import org.openhab.binding.plugwise.internal.protocol.field.Sensitivity;
21
22 /**
23  * Sets the Scan motion detection parameters. These parameters control when the Scan sends on/off commands.
24  *
25  * @author Wouter Born - Initial contribution
26  */
27 public class ScanParametersSetRequestMessage extends Message {
28
29     private Sensitivity sensitivity;
30     private boolean daylightOverride;
31     private Duration switchOffDelay;
32
33     public ScanParametersSetRequestMessage(MACAddress macAddress, Sensitivity sensitivity, boolean daylightOverride,
34             Duration switchOffDelay) {
35         super(SCAN_PARAMETERS_SET_REQUEST, macAddress);
36         this.sensitivity = sensitivity;
37         this.daylightOverride = daylightOverride;
38         this.switchOffDelay = switchOffDelay;
39     }
40
41     @Override
42     protected String payloadToHexString() {
43         String sensitivityHex = String.format("%02X", sensitivity.toInt());
44         String daylightOverrideHex = (daylightOverride ? "01" : "00");
45         String switchOffDelayHex = String.format("%02X", switchOffDelay.toMinutes());
46         return sensitivityHex + daylightOverrideHex + switchOffDelayHex;
47     }
48 }