]> git.basschouten.com Git - openhab-addons.git/blob
d6fde718a9d5cb8e065d2e6602a23a454da739cd
[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.config.PlugwiseRelayConfig.PowerStateChanging.COMMAND_SWITCHING;
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.core.util.StringUtils;
24
25 /**
26  * The {@link PlugwiseRelayConfig} class represents the configuration for a Plugwise relay device (Circle, Circle+,
27  * Stealth).
28  *
29  * @author Wouter Born - Initial contribution
30  */
31 @NonNullByDefault
32 public class PlugwiseRelayConfig {
33
34     public enum PowerStateChanging {
35         COMMAND_SWITCHING,
36         ALWAYS_ON,
37         ALWAYS_OFF
38     }
39
40     private String macAddress = "";
41     private String powerStateChanging = Objects
42             .requireNonNull(StringUtils.capitalizeByUnderscore(COMMAND_SWITCHING.name()));
43     private boolean suppliesPower = false;
44     private int measurementInterval = 60; // minutes
45     private boolean temporarilyNotInNetwork = false;
46     private boolean updateConfiguration = true;
47
48     public MACAddress getMACAddress() {
49         return new MACAddress(macAddress);
50     }
51
52     public PowerStateChanging getPowerStateChanging() {
53         return PowerStateChanging.valueOf(PlugwiseUtils.lowerCamelToUpperUnderscore(powerStateChanging));
54     }
55
56     public boolean isSuppliesPower() {
57         return suppliesPower;
58     }
59
60     public Duration getMeasurementInterval() {
61         return Duration.ofMinutes(measurementInterval);
62     }
63
64     public boolean isTemporarilyNotInNetwork() {
65         return temporarilyNotInNetwork;
66     }
67
68     public boolean isUpdateConfiguration() {
69         return updateConfiguration;
70     }
71
72     @Override
73     public String toString() {
74         return "PlugwiseRelayConfig [macAddress=" + macAddress + ", powerStateChanging=" + powerStateChanging
75                 + ", suppliesPower=" + suppliesPower + ", measurementInterval=" + measurementInterval
76                 + ", temporarilyNotInNetwork=" + temporarilyNotInNetwork + ", updateConfiguration="
77                 + updateConfiguration + "]";
78     }
79 }