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.config;
15 import static org.openhab.binding.plugwise.internal.protocol.field.BoundaryAction.OFF_BELOW_ON_ABOVE;
16 import static org.openhab.binding.plugwise.internal.protocol.field.BoundaryType.NONE;
18 import java.time.Duration;
19 import java.util.Objects;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.openhab.binding.plugwise.internal.PlugwiseUtils;
23 import org.openhab.binding.plugwise.internal.protocol.field.BoundaryAction;
24 import org.openhab.binding.plugwise.internal.protocol.field.BoundaryType;
25 import org.openhab.binding.plugwise.internal.protocol.field.Humidity;
26 import org.openhab.binding.plugwise.internal.protocol.field.MACAddress;
27 import org.openhab.binding.plugwise.internal.protocol.field.Temperature;
28 import org.openhab.core.util.StringUtils;
31 * The {@link PlugwiseScanConfig} class represents the configuration for a Plugwise Sense.
33 * @author Wouter Born - Initial contribution
36 public class PlugwiseSenseConfig {
38 private String macAddress = "";
39 private int measurementInterval = 15; // minutes
40 private String boundaryType = Objects.requireNonNull(StringUtils.capitalizeByUnderscore(NONE.name()));
41 private String boundaryAction = Objects
42 .requireNonNull(StringUtils.capitalizeByUnderscore(OFF_BELOW_ON_ABOVE.name()));
43 private int temperatureBoundaryMin = 15; // degrees Celsius
44 private int temperatureBoundaryMax = 25; // degrees Celsius
45 private int humidityBoundaryMin = 45; // relative humidity (RH)
46 private int humidityBoundaryMax = 65; // relative humidity (RH)
47 private int wakeupInterval = 1440; // minutes (1 day)
48 private int wakeupDuration = 10; // seconds
49 private boolean updateConfiguration = true;
51 public MACAddress getMACAddress() {
52 return new MACAddress(macAddress);
55 public Duration getMeasurementInterval() {
56 return Duration.ofMinutes(measurementInterval);
59 public BoundaryType getBoundaryType() {
60 return BoundaryType.valueOf(PlugwiseUtils.lowerCamelToUpperUnderscore(boundaryType));
63 public BoundaryAction getBoundaryAction() {
64 return BoundaryAction.valueOf(PlugwiseUtils.lowerCamelToUpperUnderscore(boundaryAction));
67 public Temperature getTemperatureBoundaryMin() {
68 return new Temperature(temperatureBoundaryMin);
71 public Temperature getTemperatureBoundaryMax() {
72 return new Temperature(temperatureBoundaryMax);
75 public Humidity getHumidityBoundaryMin() {
76 return new Humidity(humidityBoundaryMin);
79 public Humidity getHumidityBoundaryMax() {
80 return new Humidity(humidityBoundaryMax);
83 public Duration getWakeupInterval() {
84 return Duration.ofMinutes(wakeupInterval);
87 public Duration getWakeupDuration() {
88 return Duration.ofSeconds(wakeupDuration);
91 public boolean isUpdateConfiguration() {
92 return updateConfiguration;
95 public boolean equalBoundaryParameters(PlugwiseSenseConfig other) {
96 return boundaryType.equals(other.boundaryType) && boundaryAction.equals(other.boundaryAction)
97 && temperatureBoundaryMin == other.temperatureBoundaryMin
98 && temperatureBoundaryMax == other.temperatureBoundaryMax
99 && humidityBoundaryMin == other.humidityBoundaryMin && humidityBoundaryMax == other.humidityBoundaryMax;
102 public boolean equalSleepParameters(PlugwiseSenseConfig other) {
103 return this.wakeupInterval == other.wakeupInterval && this.wakeupDuration == other.wakeupDuration;
107 public String toString() {
108 return "PlugwiseSenseConfig [macAddress=" + macAddress + ", measurementInterval=" + measurementInterval
109 + ", boundaryType=" + boundaryType + ", boundaryAction=" + boundaryAction + ", temperatureBoundaryMin="
110 + temperatureBoundaryMin + ", temperatureBoundaryMax=" + temperatureBoundaryMax
111 + ", humidityBoundaryMin=" + humidityBoundaryMin + ", humidityBoundaryMax=" + humidityBoundaryMax
112 + ", wakeupInterval=" + wakeupInterval + ", wakeupDuration=" + wakeupDuration + ", updateConfiguration="
113 + updateConfiguration + "]";