From e0257bb76ff5600fec78de869a90dd15acc37810 Mon Sep 17 00:00:00 2001 From: Dan Cunningham Date: Sat, 12 Jun 2021 04:39:17 -0700 Subject: [PATCH] [iaqualink] Fixes critical login issue due to changed auth URLs. Moves 'model' package to 'dto' to fix checkstyle warnings. (#10853) Signed-off-by: Dan Cunningham --- .../internal/api/IAqualinkClient.java | 21 ++++++++++--------- .../api/{model => dto}/AccountInfo.java | 2 +- .../api/{model => dto}/Auxiliary.java | 2 +- .../internal/api/{model => dto}/Device.java | 2 +- .../internal/api/{model => dto}/Home.java | 2 +- .../internal/api/{model => dto}/OneTouch.java | 2 +- .../internal/api/{model => dto}/SignIn.java | 2 +- .../config/IAqualinkConfiguration.java | 13 +++++++----- .../internal/handler/IAqualinkHandler.java | 10 ++++----- 9 files changed, 30 insertions(+), 26 deletions(-) rename bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/{model => dto}/AccountInfo.java (98%) rename bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/{model => dto}/Auxiliary.java (96%) rename bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/{model => dto}/Device.java (98%) rename bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/{model => dto}/Home.java (98%) rename bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/{model => dto}/OneTouch.java (95%) rename bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/{model => dto}/SignIn.java (95%) diff --git a/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/IAqualinkClient.java b/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/IAqualinkClient.java index 53c36c0b031..5f6a4f5f663 100644 --- a/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/IAqualinkClient.java +++ b/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/IAqualinkClient.java @@ -31,12 +31,12 @@ import org.eclipse.jetty.client.util.StringContentProvider; import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.http.HttpStatus; -import org.openhab.binding.iaqualink.internal.api.model.AccountInfo; -import org.openhab.binding.iaqualink.internal.api.model.Auxiliary; -import org.openhab.binding.iaqualink.internal.api.model.Device; -import org.openhab.binding.iaqualink.internal.api.model.Home; -import org.openhab.binding.iaqualink.internal.api.model.OneTouch; -import org.openhab.binding.iaqualink.internal.api.model.SignIn; +import org.openhab.binding.iaqualink.internal.api.dto.AccountInfo; +import org.openhab.binding.iaqualink.internal.api.dto.Auxiliary; +import org.openhab.binding.iaqualink.internal.api.dto.Device; +import org.openhab.binding.iaqualink.internal.api.dto.Home; +import org.openhab.binding.iaqualink.internal.api.dto.OneTouch; +import org.openhab.binding.iaqualink.internal.api.dto.SignIn; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -73,7 +73,8 @@ public class IAqualinkClient { private static final String HEADER_ACCEPT_LANGUAGE = "en-us"; private static final String HEADER_ACCEPT_ENCODING = "br, gzip, deflate"; - private static final String SUPPORT_URL = "https://support.iaqualink.com"; + private static final String AUTH_URL = "https://prod.zodiac-io.com/users/v1/login"; + private static final String DEVICES_URL = "https://r-api.iaqualink.net/devices.json"; private static final String IAQUALINK_BASE_URL = "https://p-api.iaqualink.net/v1/mobile/session.json"; private Gson gson = new GsonBuilder().registerTypeAdapter(Home.class, new HomeDeserializer()) @@ -113,8 +114,8 @@ public class IAqualinkClient { throws IOException, NotAuthorizedException { String signIn = gson.toJson(new SignIn(apiKey, username, password)).toString(); try { - ContentResponse response = httpClient.newRequest(SUPPORT_URL + "/users/sign_in.json") - .method(HttpMethod.POST).content(new StringContentProvider(signIn), "application/json").send(); + ContentResponse response = httpClient.newRequest(AUTH_URL).method(HttpMethod.POST) + .content(new StringContentProvider(signIn), "application/json").send(); if (response.getStatus() == HttpStatus.UNAUTHORIZED_401) { throw new NotAuthorizedException(response.getReason()); } @@ -139,7 +140,7 @@ public class IAqualinkClient { */ public Device[] getDevices(@Nullable String apiKey, @Nullable String token, int id) throws IOException, NotAuthorizedException { - return getAqualinkObject(UriBuilder.fromUri(SUPPORT_URL + "/devices.json"). // + return getAqualinkObject(UriBuilder.fromUri(DEVICES_URL). // queryParam("api_key", apiKey). // queryParam("authentication_token", token). // queryParam("user_id", id).build(), Device[].class); diff --git a/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/model/AccountInfo.java b/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/dto/AccountInfo.java similarity index 98% rename from bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/model/AccountInfo.java rename to bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/dto/AccountInfo.java index 934524200c2..abb627ad4c2 100644 --- a/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/model/AccountInfo.java +++ b/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/dto/AccountInfo.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.iaqualink.internal.api.model; +package org.openhab.binding.iaqualink.internal.api.dto; /** * Account Info Object diff --git a/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/model/Auxiliary.java b/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/dto/Auxiliary.java similarity index 96% rename from bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/model/Auxiliary.java rename to bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/dto/Auxiliary.java index aa29a1dada7..2ac0373a247 100644 --- a/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/model/Auxiliary.java +++ b/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/dto/Auxiliary.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.iaqualink.internal.api.model; +package org.openhab.binding.iaqualink.internal.api.dto; /** * Auxiliary devices. diff --git a/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/model/Device.java b/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/dto/Device.java similarity index 98% rename from bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/model/Device.java rename to bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/dto/Device.java index f253c654692..594c4fde2ad 100644 --- a/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/model/Device.java +++ b/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/dto/Device.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.iaqualink.internal.api.model; +package org.openhab.binding.iaqualink.internal.api.dto; /** * Device refers to a iAqualink Pool Controller. diff --git a/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/model/Home.java b/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/dto/Home.java similarity index 98% rename from bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/model/Home.java rename to bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/dto/Home.java index a66fba246c7..fad89b1151c 100644 --- a/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/model/Home.java +++ b/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/dto/Home.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.iaqualink.internal.api.model; +package org.openhab.binding.iaqualink.internal.api.dto; import java.util.Map; diff --git a/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/model/OneTouch.java b/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/dto/OneTouch.java similarity index 95% rename from bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/model/OneTouch.java rename to bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/dto/OneTouch.java index f28bcbd2bd9..5c9eeb5019a 100644 --- a/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/model/OneTouch.java +++ b/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/dto/OneTouch.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.iaqualink.internal.api.model; +package org.openhab.binding.iaqualink.internal.api.dto; /** * OneTouch Macros. diff --git a/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/model/SignIn.java b/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/dto/SignIn.java similarity index 95% rename from bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/model/SignIn.java rename to bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/dto/SignIn.java index 29b6b75605e..c6ca28591bb 100644 --- a/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/model/SignIn.java +++ b/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/api/dto/SignIn.java @@ -10,7 +10,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.iaqualink.internal.api.model; +package org.openhab.binding.iaqualink.internal.api.dto; /** * Object used to login to service. diff --git a/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/config/IAqualinkConfiguration.java b/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/config/IAqualinkConfiguration.java index b73bab60cbe..16e530c358b 100644 --- a/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/config/IAqualinkConfiguration.java +++ b/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/config/IAqualinkConfiguration.java @@ -12,36 +12,39 @@ */ package org.openhab.binding.iaqualink.internal.config; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * Configuration properties for connecting to a iAqualink Account * * @author Dan Cunningham - Initial contribution * */ +@NonNullByDefault public class IAqualinkConfiguration { /** * user to us when connecting to the account */ - public String userName; + public String userName = ""; /** * password to us when connecting to the account */ - public String password; + public String password = ""; /** * Option serialId of the pool controller to connect to, only useful if you have more then one controller */ - public String serialId; + public String serialId = ""; /** * fixed API key provided by iAqualink clients (Android, IOS) , unknown if this will change in the future. */ - public String apiKey; + public String apiKey = ""; /** * Rate we poll for new data */ - public int refresh; + public int refresh = 30; } diff --git a/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/handler/IAqualinkHandler.java b/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/handler/IAqualinkHandler.java index 1387dcc7c2b..50a4e189bf4 100644 --- a/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/handler/IAqualinkHandler.java +++ b/bundles/org.openhab.binding.iaqualink/src/main/java/org/openhab/binding/iaqualink/internal/handler/IAqualinkHandler.java @@ -38,11 +38,11 @@ import org.eclipse.jetty.client.HttpClient; import org.openhab.binding.iaqualink.internal.IAqualinkBindingConstants; import org.openhab.binding.iaqualink.internal.api.IAqualinkClient; import org.openhab.binding.iaqualink.internal.api.IAqualinkClient.NotAuthorizedException; -import org.openhab.binding.iaqualink.internal.api.model.AccountInfo; -import org.openhab.binding.iaqualink.internal.api.model.Auxiliary; -import org.openhab.binding.iaqualink.internal.api.model.Device; -import org.openhab.binding.iaqualink.internal.api.model.Home; -import org.openhab.binding.iaqualink.internal.api.model.OneTouch; +import org.openhab.binding.iaqualink.internal.api.dto.AccountInfo; +import org.openhab.binding.iaqualink.internal.api.dto.Auxiliary; +import org.openhab.binding.iaqualink.internal.api.dto.Device; +import org.openhab.binding.iaqualink.internal.api.dto.Home; +import org.openhab.binding.iaqualink.internal.api.dto.OneTouch; import org.openhab.binding.iaqualink.internal.config.IAqualinkConfiguration; import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.OnOffType;