]> git.basschouten.com Git - openhab-addons.git/blob
782d04c06879c5cae8ec2dfc7c6e727d5b171fa7
[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.netatmo.internal.config;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.netatmo.internal.api.NetatmoException;
18
19 /**
20  * The {@link ApiHandlerConfiguration} is responsible for holding configuration
21  * information needed to access Netatmo API and general binding behavior setup
22  *
23  * @author GaĆ«l L'hopital - Initial contribution
24  */
25 @NonNullByDefault
26 public class ApiHandlerConfiguration {
27     public class Credentials {
28         public final String clientId, clientSecret, username, password;
29
30         private Credentials(@Nullable String clientId, @Nullable String clientSecret, @Nullable String username,
31                 @Nullable String password) throws NetatmoException {
32             this.clientSecret = checkMandatory(clientSecret, "@text/conf-error-no-client-secret");
33             this.username = checkMandatory(username, "@text/conf-error-no-username");
34             this.password = checkMandatory(password, "@text/conf-error-no-password");
35             this.clientId = checkMandatory(clientId, "@text/conf-error-no-client-id");
36         }
37
38         private String checkMandatory(@Nullable String value, String error) throws NetatmoException {
39             if (value == null || value.isBlank()) {
40                 throw new NetatmoException(error);
41             }
42             return value;
43         }
44
45         @Override
46         public String toString() {
47             return "Credentials [clientId=" + clientId + ", username=" + username
48                     + ", password=******, clientSecret=******]";
49         }
50     }
51
52     private @Nullable String clientId;
53     private @Nullable String clientSecret;
54     private @Nullable String username;
55     private @Nullable String password;
56     public @Nullable String webHookUrl;
57     public int reconnectInterval = 300;
58
59     public Credentials getCredentials() throws NetatmoException {
60         return new Credentials(clientId, clientSecret, username, password);
61     }
62 }