[automower] Adapt login due to Husqvarna API change (#13263)
* 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>
This commit is contained in:
parent
932346a091
commit
0a79b8574c
@ -21,8 +21,7 @@ Once the bridge is created and configured, OpenHab will automatically discover a
|
|||||||
`bridge:`
|
`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)
|
- 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
|
- 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/).
|
||||||
- password (mandatory): The password for the given user
|
|
||||||
- pollingInterval (optional): How often the bridge state should be queried in seconds. Default is 1h (3600s)
|
- 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.
|
Keep in mind that the status of the bridge should not be queried too often.
|
||||||
|
|||||||
@ -40,17 +40,13 @@ import org.openhab.core.auth.client.oauth2.OAuthResponseException;
|
|||||||
public class AutomowerBridge {
|
public class AutomowerBridge {
|
||||||
private final OAuthClientService authService;
|
private final OAuthClientService authService;
|
||||||
private final String appKey;
|
private final String appKey;
|
||||||
private final String userName;
|
|
||||||
private final String password;
|
|
||||||
|
|
||||||
private final AutomowerConnectApi automowerApi;
|
private final AutomowerConnectApi automowerApi;
|
||||||
|
|
||||||
public AutomowerBridge(OAuthClientService authService, String appKey, String userName, String password,
|
public AutomowerBridge(OAuthClientService authService, String appKey, HttpClient httpClient,
|
||||||
HttpClient httpClient, ScheduledExecutorService scheduler) {
|
ScheduledExecutorService scheduler) {
|
||||||
this.authService = authService;
|
this.authService = authService;
|
||||||
this.appKey = appKey;
|
this.appKey = appKey;
|
||||||
this.userName = userName;
|
|
||||||
this.password = password;
|
|
||||||
|
|
||||||
this.automowerApi = new AutomowerConnectApi(httpClient);
|
this.automowerApi = new AutomowerConnectApi(httpClient);
|
||||||
}
|
}
|
||||||
@ -59,7 +55,7 @@ public class AutomowerBridge {
|
|||||||
try {
|
try {
|
||||||
AccessTokenResponse result = authService.getAccessTokenResponse();
|
AccessTokenResponse result = authService.getAccessTokenResponse();
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
result = authService.getAccessTokenByResourceOwnerPasswordCredentials(userName, password, null);
|
result = authService.getAccessTokenByClientCredentials(null);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
} catch (OAuthException | IOException | OAuthResponseException e) {
|
} catch (OAuthException | IOException | OAuthResponseException e) {
|
||||||
|
|||||||
@ -23,8 +23,7 @@ import org.eclipse.jdt.annotation.Nullable;
|
|||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public final class AutomowerBridgeConfiguration {
|
public final class AutomowerBridgeConfiguration {
|
||||||
private @Nullable String appKey;
|
private @Nullable String appKey;
|
||||||
private @Nullable String userName;
|
private @Nullable String appSecret;
|
||||||
private @Nullable String password;
|
|
||||||
|
|
||||||
private @Nullable Integer pollingInterval;
|
private @Nullable Integer pollingInterval;
|
||||||
|
|
||||||
@ -47,19 +46,11 @@ public final class AutomowerBridgeConfiguration {
|
|||||||
this.appKey = appKey;
|
this.appKey = appKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable String getUserName() {
|
public @Nullable String getAppSecret() {
|
||||||
return userName;
|
return appSecret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserName(String userName) {
|
public void setAppSecret(String appSecret) {
|
||||||
this.userName = userName;
|
this.appSecret = appSecret;
|
||||||
}
|
|
||||||
|
|
||||||
public @Nullable String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
|
||||||
this.password = password;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -93,26 +93,22 @@ public class AutomowerBridgeHandler extends BaseBridgeHandler {
|
|||||||
AutomowerBridgeConfiguration bridgeConfiguration = getConfigAs(AutomowerBridgeConfiguration.class);
|
AutomowerBridgeConfiguration bridgeConfiguration = getConfigAs(AutomowerBridgeConfiguration.class);
|
||||||
|
|
||||||
final String appKey = bridgeConfiguration.getAppKey();
|
final String appKey = bridgeConfiguration.getAppKey();
|
||||||
final String userName = bridgeConfiguration.getUserName();
|
final String appSecret = bridgeConfiguration.getAppSecret();
|
||||||
final String password = bridgeConfiguration.getPassword();
|
|
||||||
final Integer pollingIntervalS = bridgeConfiguration.getPollingInterval();
|
final Integer pollingIntervalS = bridgeConfiguration.getPollingInterval();
|
||||||
|
|
||||||
if (appKey == null || appKey.isEmpty()) {
|
if (appKey == null || appKey.isEmpty()) {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "@text/conf-error-no-app-key");
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "@text/conf-error-no-app-key");
|
||||||
} else if (userName == null || userName.isEmpty()) {
|
} else if (appSecret == null || appSecret.isEmpty()) {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "@text/conf-error-no-username");
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "@text/conf-error-no-app-secret");
|
||||||
} else if (password == null || password.isEmpty()) {
|
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "@text/conf-error-no-password");
|
|
||||||
} else if (pollingIntervalS != null && pollingIntervalS < 1) {
|
} else if (pollingIntervalS != null && pollingIntervalS < 1) {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
||||||
"@text/conf-error-invalid-polling-interval");
|
"@text/conf-error-invalid-polling-interval");
|
||||||
} else {
|
} else {
|
||||||
oAuthService = oAuthFactory.createOAuthClientService(thing.getUID().getAsString(), HUSQVARNA_API_TOKEN_URL,
|
oAuthService = oAuthFactory.createOAuthClientService(thing.getUID().getAsString(), HUSQVARNA_API_TOKEN_URL,
|
||||||
null, appKey, null, null, null);
|
null, appKey, appSecret, null, null);
|
||||||
|
|
||||||
if (bridge == null) {
|
if (bridge == null) {
|
||||||
AutomowerBridge currentBridge = new AutomowerBridge(oAuthService, appKey, userName, password,
|
AutomowerBridge currentBridge = new AutomowerBridge(oAuthService, appKey, httpClient, scheduler);
|
||||||
httpClient, scheduler);
|
|
||||||
bridge = currentBridge;
|
bridge = currentBridge;
|
||||||
startAutomowerBridgePolling(currentBridge, pollingIntervalS);
|
startAutomowerBridgePolling(currentBridge, pollingIntervalS);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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.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.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.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.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.password.description = The password for the given user
|
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.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.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
|
# 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-send-mower-command-failed = Unable to send automower command
|
||||||
comm-error-mower-not-connected-to-cloud = Automower not connected to the cloud
|
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-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-app-secret = Cannot connect to Automower bridge as no app secret is available in the configuration
|
||||||
conf-error-no-password = Cannot connect to Automower bridge as no password is available in the configuration
|
|
||||||
conf-error-invalid-polling-interval = Invalid polling interval specified. The polling interval has to be >= 1
|
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-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
|
conf-error-no-bridge = No valid bridge for the automower is available
|
||||||
|
|||||||
@ -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.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.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.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)
|
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)
|
||||||
|
|
||||||
|
|||||||
@ -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
|
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-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-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
|
conf-error-no-mower-id = Aucun identifiant de robot tondeuse spécifié. Impossible de communiquer avec la tondeuse sans ID
|
||||||
|
|||||||
@ -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
|
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-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-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
|
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
|
||||||
|
|||||||
@ -12,19 +12,17 @@
|
|||||||
<config-description>
|
<config-description>
|
||||||
<parameter name="appKey" type="text" required="true">
|
<parameter name="appKey" type="text" required="true">
|
||||||
<label>Application Key</label>
|
<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
|
https://developer.husqvarnagroup.cloud/. It can be obtained by
|
||||||
registering an Application on the Husqvarna Website.
|
registering an Application on the Husqvarna Website.
|
||||||
This application also needs to be connected to the
|
This application also needs to be connected to the
|
||||||
"Authentication API" and the "Automower Connect API"</description>
|
"Authentication API" and the "Automower Connect API"</description>
|
||||||
</parameter>
|
</parameter>
|
||||||
<parameter name="userName" type="text" required="true">
|
<parameter name="appSecret" type="text" required="true">
|
||||||
<label>User Name</label>
|
<label>Application Secret</label>
|
||||||
<description>The user name for which the application key has been issued</description>
|
<description>The Application Secret is required to communicate with the Automower Connect API at
|
||||||
</parameter>
|
https://developer.husqvarnagroup.cloud/. It can be obtained by
|
||||||
<parameter name="password" type="text" required="true">
|
registering an Application on the Husqvarna Website.</description>
|
||||||
<context>password</context>
|
|
||||||
<description>The password for the given user</description>
|
|
||||||
</parameter>
|
</parameter>
|
||||||
<parameter name="pollingInterval" type="integer" required="false" unit="s">
|
<parameter name="pollingInterval" type="integer" required="false" unit="s">
|
||||||
<label>Polling Interval</label>
|
<label>Polling Interval</label>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user