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_BOUNDARIES_SET_REQUEST;
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;
24 * Sets the Sense boundary switching parameters. These parameters control when the Sense sends on/off commands.
26 * @author Wouter Born - Initial contribution
28 public class SenseBoundariesSetRequestMessage extends Message {
30 private static final String MIN_BOUNDARY_VALUE = "0000";
31 private static final String MAX_BOUNDARY_VALUE = "FFFF";
33 private BoundaryType boundaryType;
34 private BoundaryAction boundaryAction;
35 private String lowerBoundaryHex;
36 private String upperBoundaryHex;
39 * Disables Sense boundary switching.
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;
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();
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();
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;