]> git.basschouten.com Git - openhab-addons.git/blob
21407288d1de9eae462bf19d0b7399364ff56889
[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.SENSE_BOUNDARIES_SET_REQUEST;
16
17 import org.openhab.binding.plugwise.internal.protocol.field.BoundaryAction;
18 import org.openhab.binding.plugwise.internal.protocol.field.BoundaryType;
19 import org.openhab.binding.plugwise.internal.protocol.field.Humidity;
20 import org.openhab.binding.plugwise.internal.protocol.field.MACAddress;
21 import org.openhab.binding.plugwise.internal.protocol.field.Temperature;
22
23 /**
24  * Sets the Sense boundary switching parameters. These parameters control when the Sense sends on/off commands.
25  *
26  * @author Wouter Born - Initial contribution
27  */
28 public class SenseBoundariesSetRequestMessage extends Message {
29
30     private static final String MIN_BOUNDARY_VALUE = "0000";
31     private static final String MAX_BOUNDARY_VALUE = "FFFF";
32
33     private BoundaryType boundaryType;
34     private BoundaryAction boundaryAction;
35     private String lowerBoundaryHex;
36     private String upperBoundaryHex;
37
38     /**
39      * Disables Sense boundary switching.
40      */
41     public SenseBoundariesSetRequestMessage(MACAddress macAddress) {
42         super(SENSE_BOUNDARIES_SET_REQUEST, macAddress);
43         this.boundaryType = BoundaryType.TEMPERATURE;
44         this.boundaryAction = BoundaryAction.OFF_BELOW_ON_ABOVE;
45         this.lowerBoundaryHex = MIN_BOUNDARY_VALUE;
46         this.upperBoundaryHex = MAX_BOUNDARY_VALUE;
47     }
48
49     public SenseBoundariesSetRequestMessage(MACAddress macAddress, Temperature lowerBoundary, Temperature upperBoundary,
50             BoundaryAction boundaryAction) {
51         super(SENSE_BOUNDARIES_SET_REQUEST, macAddress);
52         this.boundaryType = BoundaryType.TEMPERATURE;
53         this.boundaryAction = boundaryAction;
54         this.lowerBoundaryHex = lowerBoundary.toHex();
55         this.upperBoundaryHex = upperBoundary.toHex();
56     }
57
58     public SenseBoundariesSetRequestMessage(MACAddress macAddress, Humidity lowerBoundary, Humidity upperBoundary,
59             BoundaryAction boundaryAction) {
60         super(SENSE_BOUNDARIES_SET_REQUEST, macAddress);
61         this.boundaryType = BoundaryType.HUMIDITY;
62         this.boundaryAction = boundaryAction;
63         this.lowerBoundaryHex = lowerBoundary.toHex();
64         this.upperBoundaryHex = upperBoundary.toHex();
65     }
66
67     @Override
68     protected String payloadToHexString() {
69         String boundaryTypeHex = String.format("%02X", boundaryType.toInt());
70         String lowerBoundaryActionHex = String.format("%02X", boundaryAction.getLowerAction());
71         String upperBoundaryActionHex = String.format("%02X", boundaryAction.getUpperAction());
72         return boundaryTypeHex + upperBoundaryHex + upperBoundaryActionHex + lowerBoundaryHex + lowerBoundaryActionHex;
73     }
74 }