From 907e33518e2f63ec9d775a4ac3bfc5d42d5ff506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20L=27hopital?= Date: Tue, 24 May 2022 12:59:59 +0200 Subject: [PATCH] [netatmo] Removing feature restriction from binding configuration (#12795) * Removing feature restriction from binding configuration Signed-off-by: clinique --- bundles/org.openhab.binding.netatmo/README.md | 1 - .../internal/api/AuthenticationApi.java | 23 ++++++++----------- .../internal/config/BindingConfiguration.java | 5 ---- .../internal/handler/ApiBridgeHandler.java | 4 ++-- .../main/resources/OH-INF/binding/binding.xml | 13 ----------- .../resources/OH-INF/i18n/netatmo.properties | 6 ----- .../OH-INF/i18n/netatmo_it.properties | 6 ----- 7 files changed, 11 insertions(+), 47 deletions(-) diff --git a/bundles/org.openhab.binding.netatmo/README.md b/bundles/org.openhab.binding.netatmo/README.md index 078da46b6..9e7cb90c6 100644 --- a/bundles/org.openhab.binding.netatmo/README.md +++ b/bundles/org.openhab.binding.netatmo/README.md @@ -30,7 +30,6 @@ The binding has the following configuration options: | Parameter | Type | Description | |--------------|---------------|--------------------------------------------------------------------------------------------| -| features | String | The perimeter of functionalities given to the binding WEATHER, AIR_CARE, ENERGY, SECURITY | | readFriends | Boolean | Enables or disables the discovery of guest weather stations. | diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/AuthenticationApi.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/AuthenticationApi.java index 5aabc4194..926ce4168 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/AuthenticationApi.java +++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/AuthenticationApi.java @@ -43,6 +43,7 @@ import org.slf4j.LoggerFactory; */ @NonNullByDefault public class AuthenticationApi extends RestManager { + private static final String ALL_SCOPES = FeatureArea.toScopeString(FeatureArea.AS_SET); private static final UriBuilder OAUTH_BUILDER = getApiBaseBuilder().path(PATH_OAUTH); private static final UriBuilder AUTH_BUILDER = OAUTH_BUILDER.clone().path(SUB_PATH_AUTHORIZE); private static final URI TOKEN_URI = OAUTH_BUILDER.clone().path(SUB_PATH_TOKEN).build(); @@ -58,12 +59,10 @@ public class AuthenticationApi extends RestManager { this.scheduler = scheduler; } - public String authorize(ApiHandlerConfiguration credentials, Set features, @Nullable String code, - @Nullable String redirectUri) throws NetatmoException { - String clientId = credentials.clientId; - String clientSecret = credentials.clientSecret; - if (!(clientId.isBlank() || clientSecret.isBlank())) { - Map params = new HashMap<>(Map.of(SCOPE, toScopeString(features))); + public String authorize(ApiHandlerConfiguration credentials, @Nullable String code, @Nullable String redirectUri) + throws NetatmoException { + if (!(credentials.clientId.isBlank() || credentials.clientSecret.isBlank())) { + Map params = new HashMap<>(Map.of(SCOPE, ALL_SCOPES)); String refreshToken = credentials.refreshToken; if (!refreshToken.isBlank()) { params.put(REFRESH_TOKEN, refreshToken); @@ -73,7 +72,7 @@ public class AuthenticationApi extends RestManager { } } if (params.size() > 1) { - return requestToken(clientId, clientSecret, params); + return requestToken(credentials.clientId, credentials.clientSecret, params); } } throw new IllegalArgumentException("Inconsistent configuration state, please file a bug report."); @@ -118,12 +117,8 @@ public class AuthenticationApi extends RestManager { return tokenResponse.isPresent(); } - private static String toScopeString(Set features) { - return FeatureArea.toScopeString(features.isEmpty() ? FeatureArea.AS_SET : features); - } - - public static UriBuilder getAuthorizationBuilder(String clientId, Set features) { - return AUTH_BUILDER.clone().queryParam(CLIENT_ID, clientId).queryParam(SCOPE, toScopeString(features)) - .queryParam(STATE, clientId); + public static UriBuilder getAuthorizationBuilder(String clientId) { + return AUTH_BUILDER.clone().queryParam(CLIENT_ID, clientId).queryParam(SCOPE, ALL_SCOPES).queryParam(STATE, + clientId); } } diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/config/BindingConfiguration.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/config/BindingConfiguration.java index b52ec31a9..2ebe703f4 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/config/BindingConfiguration.java +++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/config/BindingConfiguration.java @@ -12,10 +12,7 @@ */ package org.openhab.binding.netatmo.internal.config; -import java.util.Set; - import org.eclipse.jdt.annotation.NonNullByDefault; -import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.FeatureArea; /** * The {@link BindingConfiguration} is responsible for holding configuration of the binding itself. @@ -24,11 +21,9 @@ import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.FeatureAre */ @NonNullByDefault public class BindingConfiguration { - public Set features = Set.of(); public boolean readFriends = false; public void update(BindingConfiguration newConfig) { - this.features = newConfig.features; this.readFriends = newConfig.readFriends; } } diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/ApiBridgeHandler.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/ApiBridgeHandler.java index e4f0e65bf..a332892fa 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/ApiBridgeHandler.java +++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/ApiBridgeHandler.java @@ -125,7 +125,7 @@ public class ApiBridgeHandler extends BaseBridgeHandler { try { logger.debug("Connecting to Netatmo API."); - String refreshToken = connectApi.authorize(configuration, bindingConf.features, code, redirectUri); + String refreshToken = connectApi.authorize(configuration, code, redirectUri); if (configuration.refreshToken.isBlank()) { Configuration thingConfig = editConfiguration(); @@ -273,7 +273,7 @@ public class ApiBridgeHandler extends BaseBridgeHandler { } public UriBuilder formatAuthorizationUrl() { - return AuthenticationApi.getAuthorizationBuilder(getId(), bindingConf.features); + return AuthenticationApi.getAuthorizationBuilder(getId()); } @Override diff --git a/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/binding/binding.xml b/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/binding/binding.xml index 976fa7a65..575b33180 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/binding/binding.xml +++ b/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/binding/binding.xml @@ -9,19 +9,6 @@ - - - Defines the set of capabilities you want to operate on. - - - - - - - true - WEATHER - - For Weather Stations: A friend gave you access to their Netatmo Weather Station. diff --git a/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/i18n/netatmo.properties b/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/i18n/netatmo.properties index cd840b3f8..c24c75c09 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/i18n/netatmo.properties +++ b/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/i18n/netatmo.properties @@ -5,12 +5,6 @@ binding.netatmo.description = The Netatmo binding integrates Weather Station wit # binding config -binding.config.netatmo.features.label = Feature Area -binding.config.netatmo.features.description = Defines the set of capabilities you want to operate on. -binding.config.netatmo.features.option.AIR_CARE = Air Care -binding.config.netatmo.features.option.WEATHER = Weather -binding.config.netatmo.features.option.ENERGY = Energy -binding.config.netatmo.features.option.SECURITY = Security binding.config.netatmo.readFriends.label = Access Guests binding.config.netatmo.readFriends.description = For Weather Stations: A friend gave you access to their Netatmo Weather Station. diff --git a/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/i18n/netatmo_it.properties b/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/i18n/netatmo_it.properties index 42d867d2a..3cdf85459 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/i18n/netatmo_it.properties +++ b/bundles/org.openhab.binding.netatmo/src/main/resources/OH-INF/i18n/netatmo_it.properties @@ -5,12 +5,6 @@ binding.netatmo.description = Il binding Netatmo integra la Stazione Meteo con a # binding config -binding.config.netatmo.features.label = Area Feature -binding.config.netatmo.features.description = Definisce il set di funzionalità su cui si desidera operare. -binding.config.netatmo.features.option.AIR_CARE = Cura Aria -binding.config.netatmo.features.option.WEATHER = Meteo -binding.config.netatmo.features.option.ENERGY = Energia -binding.config.netatmo.features.option.SECURITY = Sicurezza binding.config.netatmo.readFriends.label = Accesso Ospiti binding.config.netatmo.readFriends.description = Per le Stazioni Meteorologiche\: Un amico ti ha dato accesso alla sua Stazione Meteo Netatmo.