]> git.basschouten.com Git - openhab-addons.git/blob
342ac8f4692d37303794faf802deb64ef0f155bb
[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.PlugwiseUtils.*;
16 import static org.openhab.binding.plugwise.internal.protocol.field.BoundaryAction.OFF_BELOW_ON_ABOVE;
17 import static org.openhab.binding.plugwise.internal.protocol.field.BoundaryType.NONE;
18
19 import java.time.Duration;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.openhab.binding.plugwise.internal.protocol.field.BoundaryAction;
23 import org.openhab.binding.plugwise.internal.protocol.field.BoundaryType;
24 import org.openhab.binding.plugwise.internal.protocol.field.Humidity;
25 import org.openhab.binding.plugwise.internal.protocol.field.MACAddress;
26 import org.openhab.binding.plugwise.internal.protocol.field.Temperature;
27
28 /**
29  * The {@link PlugwiseScanConfig} class represents the configuration for a Plugwise Sense.
30  *
31  * @author Wouter Born - Initial contribution
32  */
33 @NonNullByDefault
34 public class PlugwiseSenseConfig {
35
36     private String macAddress = "";
37     private int measurementInterval = 15; // minutes
38     private String boundaryType = upperUnderscoreToLowerCamel(NONE.name());
39     private String boundaryAction = upperUnderscoreToLowerCamel(OFF_BELOW_ON_ABOVE.name());
40     private int temperatureBoundaryMin = 15; // degrees Celsius
41     private int temperatureBoundaryMax = 25; // degrees Celsius
42     private int humidityBoundaryMin = 45; // relative humidity (RH)
43     private int humidityBoundaryMax = 65; // relative humidity (RH)
44     private int wakeupInterval = 1440; // minutes (1 day)
45     private int wakeupDuration = 10; // seconds
46     private boolean updateConfiguration = true;
47
48     public MACAddress getMACAddress() {
49         return new MACAddress(macAddress);
50     }
51
52     public Duration getMeasurementInterval() {
53         return Duration.ofMinutes(measurementInterval);
54     }
55
56     public BoundaryType getBoundaryType() {
57         return BoundaryType.valueOf(lowerCamelToUpperUnderscore(boundaryType));
58     }
59
60     public BoundaryAction getBoundaryAction() {
61         return BoundaryAction.valueOf(lowerCamelToUpperUnderscore(boundaryAction));
62     }
63
64     public Temperature getTemperatureBoundaryMin() {
65         return new Temperature(temperatureBoundaryMin);
66     }
67
68     public Temperature getTemperatureBoundaryMax() {
69         return new Temperature(temperatureBoundaryMax);
70     }
71
72     public Humidity getHumidityBoundaryMin() {
73         return new Humidity(humidityBoundaryMin);
74     }
75
76     public Humidity getHumidityBoundaryMax() {
77         return new Humidity(humidityBoundaryMax);
78     }
79
80     public Duration getWakeupInterval() {
81         return Duration.ofMinutes(wakeupInterval);
82     }
83
84     public Duration getWakeupDuration() {
85         return Duration.ofSeconds(wakeupDuration);
86     }
87
88     public boolean isUpdateConfiguration() {
89         return updateConfiguration;
90     }
91
92     public boolean equalBoundaryParameters(PlugwiseSenseConfig other) {
93         return boundaryType.equals(other.boundaryType) && boundaryAction.equals(other.boundaryAction)
94                 && temperatureBoundaryMin == other.temperatureBoundaryMin
95                 && temperatureBoundaryMax == other.temperatureBoundaryMax
96                 && humidityBoundaryMin == other.humidityBoundaryMin && humidityBoundaryMax == other.humidityBoundaryMax;
97     }
98
99     public boolean equalSleepParameters(PlugwiseSenseConfig other) {
100         return this.wakeupInterval == other.wakeupInterval && this.wakeupDuration == other.wakeupDuration;
101     }
102
103     @Override
104     public String toString() {
105         return "PlugwiseSenseConfig [macAddress=" + macAddress + ", measurementInterval=" + measurementInterval
106                 + ", boundaryType=" + boundaryType + ", boundaryAction=" + boundaryAction + ", temperatureBoundaryMin="
107                 + temperatureBoundaryMin + ", temperatureBoundaryMax=" + temperatureBoundaryMax
108                 + ", humidityBoundaryMin=" + humidityBoundaryMin + ", humidityBoundaryMax=" + humidityBoundaryMax
109                 + ", wakeupInterval=" + wakeupInterval + ", wakeupDuration=" + wakeupDuration + ", updateConfiguration="
110                 + updateConfiguration + "]";
111     }
112 }