]> git.basschouten.com Git - openhab-addons.git/blob
0941c8a9c691d5f44fde2a6cdf930427206e75ea
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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 email;
28     private @Nullable String password;
29     private @Nullable String apiKey;
30
31     private transient Integer connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
32
33     public GardenaConfig() {
34     }
35
36     public GardenaConfig(String email, String password) {
37         this.email = email;
38         this.password = password;
39     }
40
41     /**
42      * Returns the email to connect to Gardena smart system.
43      */
44     public @Nullable String getEmail() {
45         return email;
46     }
47
48     /**
49      * Sets the email to connect to Gardena smart system.
50      */
51     public void setEmail(String email) {
52         this.email = email;
53     }
54
55     /**
56      * Returns the password to connect to Gardena smart system.
57      */
58     public @Nullable String getPassword() {
59         return password;
60     }
61
62     /**
63      * Sets the password to connect to Gardena smart system.
64      */
65     public void setPassword(String password) {
66         this.password = password;
67     }
68
69     /**
70      * Returns the connection timeout to Gardena smart system.
71      */
72     public Integer getConnectionTimeout() {
73         return connectionTimeout;
74     }
75
76     /**
77      * Sets the connection timeout to Gardena smart system.
78      */
79     public void setConnectionTimeout(Integer connectionTimeout) {
80         this.connectionTimeout = connectionTimeout;
81     }
82
83     /**
84      * Returns the api key.
85      */
86     public @Nullable String getApiKey() {
87         return apiKey;
88     }
89
90     /**
91      * Sets the api key.
92      */
93     public void setApiKey(String apiKey) {
94         this.apiKey = apiKey;
95     }
96
97     /**
98      * Validate the config if email, password and apiKey is specified.
99      */
100     public boolean isValid() {
101         final String email = this.email;
102         final String password = this.password;
103         final String apiKey = this.apiKey;
104         return email != null && !email.isBlank() && password != null && !password.isBlank() && apiKey != null
105                 && !apiKey.isBlank();
106     }
107
108     @Override
109     public String toString() {
110         StringBuilder sb = new StringBuilder(GardenaConfig.class.getSimpleName()).append("[");
111         sb.append("email: ").append(email).append(", ");
112         sb.append("connectionTimeout: ").append(connectionTimeout).append(", ");
113         sb.append("apiKey: ").append(apiKey);
114         return sb.append("]").toString();
115     }
116 }