]> git.basschouten.com Git - openhab-addons.git/commitdiff
[automower] Adapt login due to Husqvarna API change (#13263)
authorBoris Krivonog <boris.krivonog@inova.si>
Mon, 15 Aug 2022 19:02:00 +0000 (21:02 +0200)
committerGitHub <noreply@github.com>
Mon, 15 Aug 2022 19:02:00 +0000 (21:02 +0200)
* The Automower Connect API Authentication does not work anymore as they moved to a new authentication method. (AppKey and AppSecret) - adopted. Fixes issue #12980.

Signed-off-by: Boris Krivonog <boris.krivonog@inova.si>
bundles/org.openhab.binding.automower/README.md
bundles/org.openhab.binding.automower/src/main/java/org/openhab/binding/automower/internal/bridge/AutomowerBridge.java
bundles/org.openhab.binding.automower/src/main/java/org/openhab/binding/automower/internal/bridge/AutomowerBridgeConfiguration.java
bundles/org.openhab.binding.automower/src/main/java/org/openhab/binding/automower/internal/bridge/AutomowerBridgeHandler.java
bundles/org.openhab.binding.automower/src/main/resources/OH-INF/i18n/automower.properties
bundles/org.openhab.binding.automower/src/main/resources/OH-INF/i18n/automower_de.properties
bundles/org.openhab.binding.automower/src/main/resources/OH-INF/i18n/automower_fr.properties
bundles/org.openhab.binding.automower/src/main/resources/OH-INF/i18n/automower_hu.properties
bundles/org.openhab.binding.automower/src/main/resources/OH-INF/thing/thing-types.xml

index 076bfeafb017df6a322cbb84d489ecdeddff4fbe..e39532316a4fb9dbb3d9cf9c1c3920d42d755842 100644 (file)
@@ -21,8 +21,7 @@ Once the bridge is created and configured, OpenHab will automatically discover a
 `bridge:`
 
 - appKey (mandatory): The Application Key is required to communicate with the Automower Connect API. It can be obtained by registering an Application on [the Husqvarna Website](https://developer.husqvarnagroup.cloud/). This application also needs to be connected to the ["Authentication API" and the "Automower Connect API"](https://developer.husqvarnagroup.cloud/docs/getting-started)
-- userName (mandatory): The user name for which the application key has been issued
-- password (mandatory): The password for the given user
+- appSecret (mandatory): The Application Secret is required to communicate with the Automower Connect API. It can be obtained by registering an Application on [the Husqvarna Website](https://developer.husqvarnagroup.cloud/).
 - pollingInterval (optional): How often the bridge state should be queried in seconds. Default is 1h (3600s)
 
 Keep in mind that the status of the bridge should not be queried too often.
index d97ba84d61ac2f75f90b982715cb6c042bbc6e7f..4d086129f6927897788dba97f5551bb9e0064580 100644 (file)
@@ -40,17 +40,13 @@ import org.openhab.core.auth.client.oauth2.OAuthResponseException;
 public class AutomowerBridge {
     private final OAuthClientService authService;
     private final String appKey;
-    private final String userName;
-    private final String password;
 
     private final AutomowerConnectApi automowerApi;
 
-    public AutomowerBridge(OAuthClientService authService, String appKey, String userName, String password,
-            HttpClient httpClient, ScheduledExecutorService scheduler) {
+    public AutomowerBridge(OAuthClientService authService, String appKey, HttpClient httpClient,
+            ScheduledExecutorService scheduler) {
         this.authService = authService;
         this.appKey = appKey;
-        this.userName = userName;
-        this.password = password;
 
         this.automowerApi = new AutomowerConnectApi(httpClient);
     }
@@ -59,7 +55,7 @@ public class AutomowerBridge {
         try {
             AccessTokenResponse result = authService.getAccessTokenResponse();
             if (result == null) {
-                result = authService.getAccessTokenByResourceOwnerPasswordCredentials(userName, password, null);
+                result = authService.getAccessTokenByClientCredentials(null);
             }
             return result;
         } catch (OAuthException | IOException | OAuthResponseException e) {
index 286821ef3e7634be08123ad4edc9e02e9cd254ad..4508500f7b91a469e304fd902429ed5836ae1e07 100644 (file)
@@ -23,8 +23,7 @@ import org.eclipse.jdt.annotation.Nullable;
 @NonNullByDefault
 public final class AutomowerBridgeConfiguration {
     private @Nullable String appKey;
-    private @Nullable String userName;
-    private @Nullable String password;
+    private @Nullable String appSecret;
 
     private @Nullable Integer pollingInterval;
 
@@ -47,19 +46,11 @@ public final class AutomowerBridgeConfiguration {
         this.appKey = appKey;
     }
 
-    public @Nullable String getUserName() {
-        return userName;
+    public @Nullable String getAppSecret() {
+        return appSecret;
     }
 
-    public void setUserName(String userName) {
-        this.userName = userName;
-    }
-
-    public @Nullable String getPassword() {
-        return password;
-    }
-
-    public void setPassword(String password) {
-        this.password = password;
+    public void setAppSecret(String appSecret) {
+        this.appSecret = appSecret;
     }
 }
index 32136bbcc28db0d2048d517ef2c950ce47d9a0b0..cbfac9d155f9d6e0c4f1682110250843ff6eb1b2 100644 (file)
@@ -93,26 +93,22 @@ public class AutomowerBridgeHandler extends BaseBridgeHandler {
         AutomowerBridgeConfiguration bridgeConfiguration = getConfigAs(AutomowerBridgeConfiguration.class);
 
         final String appKey = bridgeConfiguration.getAppKey();
-        final String userName = bridgeConfiguration.getUserName();
-        final String password = bridgeConfiguration.getPassword();
+        final String appSecret = bridgeConfiguration.getAppSecret();
         final Integer pollingIntervalS = bridgeConfiguration.getPollingInterval();
 
         if (appKey == null || appKey.isEmpty()) {
             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "@text/conf-error-no-app-key");
-        } else if (userName == null || userName.isEmpty()) {
-            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "@text/conf-error-no-username");
-        } else if (password == null || password.isEmpty()) {
-            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "@text/conf-error-no-password");
+        } else if (appSecret == null || appSecret.isEmpty()) {
+            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "@text/conf-error-no-app-secret");
         } else if (pollingIntervalS != null && pollingIntervalS < 1) {
             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
                     "@text/conf-error-invalid-polling-interval");
         } else {
             oAuthService = oAuthFactory.createOAuthClientService(thing.getUID().getAsString(), HUSQVARNA_API_TOKEN_URL,
-                    null, appKey, null, null, null);
+                    null, appKey, appSecret, null, null);
 
             if (bridge == null) {
-                AutomowerBridge currentBridge = new AutomowerBridge(oAuthService, appKey, userName, password,
-                        httpClient, scheduler);
+                AutomowerBridge currentBridge = new AutomowerBridge(oAuthService, appKey, httpClient, scheduler);
                 bridge = currentBridge;
                 startAutomowerBridgePolling(currentBridge, pollingIntervalS);
             }
index 7e27e84346582138a637409a3c9fa74fa2d068c2..a531cb864f8370cfc37fa0bddc4db6ec26807a2e 100644 (file)
@@ -18,12 +18,11 @@ thing-type.config.automower.automower.mowerId.description = The Id of an automow
 thing-type.config.automower.automower.pollingInterval.label = Polling Interval
 thing-type.config.automower.automower.pollingInterval.description = How often the current automower state should be polled in seconds
 thing-type.config.automower.bridge.appKey.label = Application Key
-thing-type.config.automower.bridge.appKey.description = The Application Key is required to communication with the Automower Connect Api at https://developer.husqvarnagroup.cloud/. It can be obtained by registering an Application on the Husqvarna Website. This application also needs to be connected to the "Authentication API" and the "Automower Connect API"
-thing-type.config.automower.bridge.password.description = The password for the given user
+thing-type.config.automower.bridge.appKey.description = The Application Key is required to communicate with the Automower Connect API at https://developer.husqvarnagroup.cloud/. It can be obtained by registering an Application on the Husqvarna Website. This application also needs to be connected to the "Authentication API" and the "Automower Connect API"
+thing-type.config.automower.bridge.appSecret.label = Application Secret
+thing-type.config.automower.bridge.appSecret.description = The Application Secret is required to communicate with the Automower Connect API at https://developer.husqvarnagroup.cloud/. It can be obtained by registering an Application on the Husqvarna Website.
 thing-type.config.automower.bridge.pollingInterval.label = Polling Interval
 thing-type.config.automower.bridge.pollingInterval.description = How often the available automowers should be queried in seconds
-thing-type.config.automower.bridge.userName.label = User Name
-thing-type.config.automower.bridge.userName.description = The user name for which the application key has been issued
 
 # channel types
 
@@ -118,8 +117,7 @@ comm-error-query-mower-failed = Unable to query the automower status
 comm-error-send-mower-command-failed = Unable to send automower command
 comm-error-mower-not-connected-to-cloud = Automower not connected to the cloud
 conf-error-no-app-key = Cannot connect to Automower bridge as no app key is available in the configuration
-conf-error-no-username = Cannot connect to Automower bridge as no username is available in the configuration
-conf-error-no-password = Cannot connect to Automower bridge as no password is available in the configuration
+conf-error-no-app-secret = Cannot connect to Automower bridge as no app secret is available in the configuration
 conf-error-invalid-polling-interval = Invalid polling interval specified. The polling interval has to be >= 1
 conf-error-no-mower-id = No Automower ID specified. Unable to communicate with the mower without an ID
 conf-error-no-bridge = No valid bridge for the automower is available
index 7e18184a388dedd82d34d0435d08b9fcc15bd39b..ec9f63f912217690425f8689d20eb354d8298d86 100644 (file)
@@ -7,12 +7,6 @@ thing-type.automower.bridge.description = Erlaubt die Kommunikation mit der Husq
 thing-type.config.automower.bridge.appKey.label = Application Key
 thing-type.config.automower.bridge.appKey.description = Der Application Key wird für die Kommunication mit der Automower Connect API benötigt. Um diesen zu erhalten muss eine Anwendung auf der Husqvarna Website registriert werden. Diese Anwendung muss mit der "Authentication API" und der "Automower Connect API" verknüpft werden.
 
-thing-type.config.automower.bridge.userName.label = Benutzername
-thing-type.config.automower.bridge.userName.description = Der Benutzername für den der Application Key ausgestellt wurde.
-
-thing-type.config.automower.bridge.password.label = Passwort
-thing-type.config.automower.bridge.password.description = Das Passwort für den angegebenen Benutzer.
-
 thing-type.config.automower.bridge.pollingInterval.label = Polling Intervall
 thing-type.config.automower.bridge.pollingInterval.description = Das Intervall in dem die Verbindung mit dem Automower Connect API überprüft werden soll. Der Standardwert ist 3600s (1h)
 
index b9ea7422834a18081145b5af50f974c803bf7785..9966d52121ee0199d75e9364c0cc61e194a03f34 100644 (file)
@@ -31,8 +31,6 @@ channel-type.automower.calendar-tasks.label = Les informations du planning au fo
 channel-type.automower.calendar-tasks.description = Les informations du planning au format JSON
 
 conf-error-no-app-key = Impossible de se connecter à la passerelle Automower car aucune clé d'application n'est définie dans la configuration
-conf-error-no-username = Impossible de se connecter à la passerelle Automower car il n'y a aucun nom d'utilisateur défini dans la configuration
-conf-error-no-password = Impossible de se connecter à la passerelle Automower car il n'y a aucun mot de passe défini dans la configuration
 conf-error-invalid-polling-interval = Définition invalide de l'intervalle d'interrogation. Il doit être >\= 1
 
 conf-error-no-mower-id = Aucun identifiant de robot tondeuse spécifié. Impossible de communiquer avec la tondeuse sans ID
index 3b693c07d94d1abb7aa9be353b8bbbad89871919..372c14b61d408de564c8bbf8327c01546c93953e 100644 (file)
@@ -31,8 +31,6 @@ channel-type.automower.calendar-tasks.label = A tervező információi JSON form
 channel-type.automower.calendar-tasks.description = A tervező információi JSON formátumban
 
 conf-error-no-app-key = Nem tudok a robotfűnyíró hídhoz kapcsolódni, mivel nincs alkalmazás kulcs megadva a beállításokban
-conf-error-no-username = Nem tudok a robotfűnyíró hídhoz kapcsolódni, mivel nincs felhasználó megadva a beállításokban
-conf-error-no-password = Nem tudok a robotfűnyíró hídhoz kapcsolódni, mivel nincs jelszó megadva a beállításokban
 conf-error-invalid-polling-interval = Érvénytelen lekérdezési időköz lett megadva. A lekérdezési időköz >\= 1 kell legyen
 
 conf-error-no-mower-id = Nincs megadva robotfűnyíró azonosító. Nem tudok a fűnyíróval kommunikálni azonosító nélkül
index 5edae121a4fba1c25aa0c9e2eb000d4c486948c3..b039eeea8edfb0d0e11bac457fdfd2f37d23a8a3 100644 (file)
                <config-description>
                        <parameter name="appKey" type="text" required="true">
                                <label>Application Key</label>
-                               <description>The Application Key is required to communication with the Automower Connect Api at
+                               <description>The Application Key is required to communicate with the Automower Connect API at
                                        https://developer.husqvarnagroup.cloud/. It can be obtained by
                                        registering an Application on the Husqvarna Website.
                                        This application also needs to be connected to the
                                        "Authentication API" and the "Automower Connect API"</description>
                        </parameter>
-                       <parameter name="userName" type="text" required="true">
-                               <label>User Name</label>
-                               <description>The user name for which the application key has been issued</description>
-                       </parameter>
-                       <parameter name="password" type="text" required="true">
-                               <context>password</context>
-                               <description>The password for the given user</description>
+                       <parameter name="appSecret" type="text" required="true">
+                               <label>Application Secret</label>
+                               <description>The Application Secret is required to communicate with the Automower Connect API at
+                                       https://developer.husqvarnagroup.cloud/. It can be obtained by
+                                       registering an Application on the Husqvarna Website.</description>
                        </parameter>
                        <parameter name="pollingInterval" type="integer" required="false" unit="s">
                                <label>Polling Interval</label>