]> git.basschouten.com Git - openhab-addons.git/blob
fa06bdc616ea961828f1ebb55684d74d5249c13c
[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.Sensitivity.MEDIUM;
17
18 import java.time.Duration;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.plugwise.internal.protocol.field.MACAddress;
22 import org.openhab.binding.plugwise.internal.protocol.field.Sensitivity;
23
24 /**
25  * The {@link PlugwiseScanConfig} class represents the configuration for a Plugwise Scan.
26  *
27  * @author Wouter Born - Initial contribution
28  */
29 @NonNullByDefault
30 public class PlugwiseScanConfig {
31
32     private String macAddress = "";
33     private String sensitivity = upperUnderscoreToLowerCamel(MEDIUM.name());
34     private int switchOffDelay = 5; // minutes
35     private boolean daylightOverride = false;
36     private int wakeupInterval = 1440; // minutes (1 day)
37     private int wakeupDuration = 10; // seconds
38     private boolean recalibrate = false;
39     private boolean updateConfiguration = true;
40
41     public MACAddress getMACAddress() {
42         return new MACAddress(macAddress);
43     }
44
45     public Sensitivity getSensitivity() {
46         return Sensitivity.valueOf(lowerCamelToUpperUnderscore(sensitivity));
47     }
48
49     public Duration getSwitchOffDelay() {
50         return Duration.ofMinutes(switchOffDelay);
51     }
52
53     public boolean isDaylightOverride() {
54         return daylightOverride;
55     }
56
57     public Duration getWakeupInterval() {
58         return Duration.ofMinutes(wakeupInterval);
59     }
60
61     public Duration getWakeupDuration() {
62         return Duration.ofSeconds(wakeupDuration);
63     }
64
65     public boolean isRecalibrate() {
66         return recalibrate;
67     }
68
69     public boolean isUpdateConfiguration() {
70         return updateConfiguration;
71     }
72
73     public boolean equalScanParameters(PlugwiseScanConfig other) {
74         return this.sensitivity.equals(other.sensitivity) && this.switchOffDelay == other.switchOffDelay
75                 && this.daylightOverride == other.daylightOverride;
76     }
77
78     public boolean equalSleepParameters(PlugwiseScanConfig other) {
79         return this.wakeupInterval == other.wakeupInterval && this.wakeupDuration == other.wakeupDuration;
80     }
81
82     @Override
83     public String toString() {
84         return "PlugwiseScanConfig [macAddress=" + macAddress + ", sensitivity=" + sensitivity + ", switchOffDelay="
85                 + switchOffDelay + ", daylightOverride=" + daylightOverride + ", wakeupInterval=" + wakeupInterval
86                 + ", wakeupDuration=" + wakeupDuration + ", recalibrate=" + recalibrate + ", updateConfiguration="
87                 + updateConfiguration + "]";
88     }
89 }