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