]> git.basschouten.com Git - openhab-addons.git/blob
1b8fbc05fc80d8ba8b81bb8419aedae7c7f94377
[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.gardena.internal.config;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17
18 /**
19  * The main Gardena config class.
20  *
21  * @author Gerhard Riegler - Initial contribution
22  */
23 @NonNullByDefault
24 public class GardenaConfig {
25     private static final Integer DEFAULT_CONNECTION_TIMEOUT = 10;
26
27     private @Nullable String apiSecret;
28     private @Nullable String apiKey;
29
30     private transient Integer connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
31
32     public GardenaConfig() {
33     }
34
35     public GardenaConfig(String apiKey, String apiSecret) {
36         this.apiKey = apiKey;
37         this.apiSecret = apiSecret;
38     }
39
40     /**
41      * Returns the apiSecret to connect to Gardena smart system.
42      */
43     public @Nullable String getApiSecret() {
44         return apiSecret;
45     }
46
47     /**
48      * Sets the apiSecret to connect to Gardena smart system.
49      */
50     public void setApiSecret(String apiSecret) {
51         this.apiSecret = apiSecret;
52     }
53
54     /**
55      * Returns the connection timeout to Gardena smart system.
56      */
57     public Integer getConnectionTimeout() {
58         return connectionTimeout;
59     }
60
61     /**
62      * Sets the connection timeout to Gardena smart system.
63      */
64     public void setConnectionTimeout(Integer connectionTimeout) {
65         this.connectionTimeout = connectionTimeout;
66     }
67
68     /**
69      * Returns the api key.
70      */
71     public @Nullable String getApiKey() {
72         return apiKey;
73     }
74
75     /**
76      * Sets the api key.
77      */
78     public void setApiKey(String apiKey) {
79         this.apiKey = apiKey;
80     }
81
82     /**
83      * Validate the config if email, password and apiKey is specified.
84      */
85     public boolean isValid() {
86         final String apiSecret = this.apiSecret;
87         final String apiKey = this.apiKey;
88         return apiSecret != null && !apiSecret.isBlank() && apiKey != null && !apiKey.isBlank();
89     }
90
91     @Override
92     public String toString() {
93         StringBuilder sb = new StringBuilder(GardenaConfig.class.getSimpleName()).append("[");
94         sb.append("connectionTimeout: ").append(connectionTimeout).append(", ");
95         sb.append("apiKey: ").append(apiKey);
96         return sb.append("]").toString();
97     }
98 }