Skip to content

Commit

Permalink
[iaqualink] Fixes critical login issue due to changed auth URLs. Move…
Browse files Browse the repository at this point in the history
…s 'model' package to 'dto' to fix checkstyle warnings. (openhab#10853)

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Luca Calcaterra <calcaterra.luca@gmail.com>
  • Loading branch information
digitaldan authored and lucacalcaterra committed Jul 26, 2021
1 parent 2c1ed40 commit a635ce0
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
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;

Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -113,8 +114,8 @@ public AccountInfo login(@Nullable String username, @Nullable String password, @
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());
}
Expand All @@ -139,7 +140,7 @@ public AccountInfo login(@Nullable String username, @Nullable String password, @
*/
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
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;
Expand Down

0 comments on commit a635ce0

Please sign in to comment.