2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.gardena.internal.config;
15 import org.apache.commons.lang.StringUtils;
16 import org.apache.commons.lang.builder.ToStringBuilder;
17 import org.apache.commons.lang.builder.ToStringStyle;
19 import com.google.gson.annotations.SerializedName;
22 * The main Gardena config class.
24 * @author Gerhard Riegler - Initial contribution
26 public class GardenaConfig {
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;
32 @SerializedName("username")
34 private String password;
36 private transient Integer sessionTimeout = DEFAULT_SESSION_TIMEOUT;
37 private transient Integer connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
38 private transient Integer refresh = DEFAULT_REFRESH;
40 public GardenaConfig() {
43 public GardenaConfig(String email, String password) {
45 this.password = password;
49 * Returns the email to connect to Gardena Smart Home.
51 public String getEmail() {
56 * Sets the email to connect to Gardena Smart Home.
58 public void setEmail(String email) {
63 * Returns the password to connect to Gardena Smart Home.
65 public String getPassword() {
70 * Sets the password to connect to Gardena Smart Home.
72 public void setPassword(String password) {
73 this.password = password;
77 * Returns the session timeout to Gardena Smart Home.
79 public int getSessionTimeout() {
80 return sessionTimeout;
84 * Sets the session timeout to Gardena Smart Home.
86 public void setSessionTimeout(int sessionTimeout) {
87 this.sessionTimeout = sessionTimeout;
91 * Returns the connection timeout to Gardena Smart Home.
93 public Integer getConnectionTimeout() {
94 return connectionTimeout;
98 * Sets the connection timeout to Gardena Smart Home.
100 public void setConnectionTimeout(Integer connectionTimeout) {
101 this.connectionTimeout = connectionTimeout;
105 * Returns the refresh interval to fetch new data from Gardena Smart Home.
107 public Integer getRefresh() {
112 * Returns the refresh interval to fetch new data from Gardena Smart Home.
114 public void setRefresh(Integer refresh) {
115 this.refresh = refresh;
119 * Validate the config, if at least email and password is specified.
121 public boolean isValid() {
122 return StringUtils.isNotBlank(email) && StringUtils.isNotBlank(password);
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();