2 * Copyright (c) 2010-2022 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.netatmo.internal.config;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.netatmo.internal.api.NetatmoException;
20 * The {@link ApiHandlerConfiguration} is responsible for holding configuration
21 * information needed to access Netatmo API and general binding behavior setup
23 * @author Gaƫl L'hopital - Initial contribution
26 public class ApiHandlerConfiguration {
27 public class Credentials {
28 public final String clientId, clientSecret, username, password;
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");
38 private String checkMandatory(@Nullable String value, String error) throws NetatmoException {
39 if (value == null || value.isBlank()) {
40 throw new NetatmoException(error);
46 public String toString() {
47 return "Credentials [clientId=" + clientId + ", username=" + username
48 + ", password=******, clientSecret=******]";
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;
59 public Credentials getCredentials() throws NetatmoException {
60 return new Credentials(clientId, clientSecret, username, password);