]> git.basschouten.com Git - openhab-addons.git/blob
acde2175ba67fe61155b5d5879d7c5062f342e91
[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.config;
14
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;
17
18 import java.time.Duration;
19 import java.util.Objects;
20
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;
29
30 /**
31  * The {@link PlugwiseScanConfig} class represents the configuration for a Plugwise Sense.
32  *
33  * @author Wouter Born - Initial contribution
34  */
35 @NonNullByDefault
36 public class PlugwiseSenseConfig {
37
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;
50
51     public MACAddress getMACAddress() {
52         return new MACAddress(macAddress);
53     }
54
55     public Duration getMeasurementInterval() {
56         return Duration.ofMinutes(measurementInterval);
57     }
58
59     public BoundaryType getBoundaryType() {
60         return BoundaryType.valueOf(PlugwiseUtils.lowerCamelToUpperUnderscore(boundaryType));
61     }
62
63     public BoundaryAction getBoundaryAction() {
64         return BoundaryAction.valueOf(PlugwiseUtils.lowerCamelToUpperUnderscore(boundaryAction));
65     }
66
67     public Temperature getTemperatureBoundaryMin() {
68         return new Temperature(temperatureBoundaryMin);
69     }
70
71     public Temperature getTemperatureBoundaryMax() {
72         return new Temperature(temperatureBoundaryMax);
73     }
74
75     public Humidity getHumidityBoundaryMin() {
76         return new Humidity(humidityBoundaryMin);
77     }
78
79     public Humidity getHumidityBoundaryMax() {
80         return new Humidity(humidityBoundaryMax);
81     }
82
83     public Duration getWakeupInterval() {
84         return Duration.ofMinutes(wakeupInterval);
85     }
86
87     public Duration getWakeupDuration() {
88         return Duration.ofSeconds(wakeupDuration);
89     }
90
91     public boolean isUpdateConfiguration() {
92         return updateConfiguration;
93     }
94
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;
100     }
101
102     public boolean equalSleepParameters(PlugwiseSenseConfig other) {
103         return this.wakeupInterval == other.wakeupInterval && this.wakeupDuration == other.wakeupDuration;
104     }
105
106     @Override
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 + "]";
114     }
115 }