[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 <dan@digitaldan.com>
This commit is contained in:
Dan Cunningham 2021-06-12 04:39:17 -07:00 committed by GitHub
parent 2b9a37efa9
commit e0257bb76f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 30 additions and 26 deletions

View File

@ -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);

View File

@ -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

View File

@ -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.

View File

@ -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.

View File

@ -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;

View File

@ -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.

View File

@ -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.

View File

@ -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;
}

View File

@ -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;