]> git.basschouten.com Git - openhab-addons.git/blob
6a8e3795ebdf8a45abeda34eaf604840f2e49c60
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.apache.commons.lang.StringUtils;
16 import org.apache.commons.lang.builder.ToStringBuilder;
17 import org.apache.commons.lang.builder.ToStringStyle;
18
19 import com.google.gson.annotations.SerializedName;
20
21 /**
22  * The main Gardena config class.
23  *
24  * @author Gerhard Riegler - Initial contribution
25  */
26 public class GardenaConfig {
27
28     private static final Integer DEFAULT_SESSION_TIMEOUT = 30;
29     private static final Integer DEFAULT_CONNECTION_TIMEOUT = 10;
30     private static final Integer DEFAULT_REFRESH = 60;
31
32     @SerializedName("username")
33     private String email;
34     private String password;
35
36     private transient Integer sessionTimeout = DEFAULT_SESSION_TIMEOUT;
37     private transient Integer connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
38     private transient Integer refresh = DEFAULT_REFRESH;
39
40     public GardenaConfig() {
41     }
42
43     public GardenaConfig(String email, String password) {
44         this.email = email;
45         this.password = password;
46     }
47
48     /**
49      * Returns the email to connect to Gardena Smart Home.
50      */
51     public String getEmail() {
52         return email;
53     }
54
55     /**
56      * Sets the email to connect to Gardena Smart Home.
57      */
58     public void setEmail(String email) {
59         this.email = email;
60     }
61
62     /**
63      * Returns the password to connect to Gardena Smart Home.
64      */
65     public String getPassword() {
66         return password;
67     }
68
69     /**
70      * Sets the password to connect to Gardena Smart Home.
71      */
72     public void setPassword(String password) {
73         this.password = password;
74     }
75
76     /**
77      * Returns the session timeout to Gardena Smart Home.
78      */
79     public int getSessionTimeout() {
80         return sessionTimeout;
81     }
82
83     /**
84      * Sets the session timeout to Gardena Smart Home.
85      */
86     public void setSessionTimeout(int sessionTimeout) {
87         this.sessionTimeout = sessionTimeout;
88     }
89
90     /**
91      * Returns the connection timeout to Gardena Smart Home.
92      */
93     public Integer getConnectionTimeout() {
94         return connectionTimeout;
95     }
96
97     /**
98      * Sets the connection timeout to Gardena Smart Home.
99      */
100     public void setConnectionTimeout(Integer connectionTimeout) {
101         this.connectionTimeout = connectionTimeout;
102     }
103
104     /**
105      * Returns the refresh interval to fetch new data from Gardena Smart Home.
106      */
107     public Integer getRefresh() {
108         return refresh;
109     }
110
111     /**
112      * Returns the refresh interval to fetch new data from Gardena Smart Home.
113      */
114     public void setRefresh(Integer refresh) {
115         this.refresh = refresh;
116     }
117
118     /**
119      * Validate the config, if at least email and password is specified.
120      */
121     public boolean isValid() {
122         return StringUtils.isNotBlank(email) && StringUtils.isNotBlank(password);
123     }
124
125     @Override
126     public String toString() {
127         return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("email", email)
128                 .append("password", StringUtils.isBlank(password) ? "" : StringUtils.repeat("*", password.length()))
129                 .append("sessionTimeout", sessionTimeout).append("connectionTimeout", connectionTimeout)
130                 .append("refresh", refresh).toString();
131     }
132 }