[lgthinq][fix] review fixes

Signed-off-by: Nemer Daud <nemer@smartsw.com.br>
This commit is contained in:
Nemer Daud 2024-11-06 12:18:44 -03:00
parent 600d83eb91
commit 1b57051411
2 changed files with 20 additions and 38 deletions

View File

@ -143,9 +143,8 @@ public class LGThinqGateway implements Serializable {
public String toString() { public String toString() {
return "LGThinqGateway{" + "empBaseUri='" + empBaseUri + '\'' + ", loginBaseUri='" + loginBaseUri + '\'' return "LGThinqGateway{" + "empBaseUri='" + empBaseUri + '\'' + ", loginBaseUri='" + loginBaseUri + '\''
+ ", apiRootV1='" + apiRootV1 + '\'' + ", apiRootV2='" + apiRootV2 + '\'' + ", authBase='" + authBase + ", apiRootV1='" + apiRootV1 + '\'' + ", apiRootV2='" + apiRootV2 + '\'' + ", authBase='" + authBase
+ '\'' + ", language='" + language + '\'' + ", country='" + country + '\'' + ", username='" + '\'' + ", language='" + language + '\'' + ", country='" + country + '\'' + ", username='" + username
+ (!username.isEmpty() ? "******" : "<blank>") + '\'' + ", password='" + '\'' + ", password='" + (!password.isEmpty() ? "******" : "<blank>") + '\''
+ (!password.isEmpty() ? "******" : "<blank>") + '\'' + ", alternativeEmpServer='" + ", alternativeEmpServer='" + alternativeEmpServer + '\'' + ", accountVersion=" + accountVersion + '}';
+ alternativeEmpServer + '\'' + ", accountVersion=" + accountVersion + '}';
} }
} }

View File

@ -12,24 +12,7 @@
*/ */
package org.openhab.binding.lgthinq.lgservices.api; package org.openhab.binding.lgthinq.lgservices.api;
import static org.openhab.binding.lgthinq.lgservices.LGServicesConstants.LG_API_API_KEY_V2; import static org.openhab.binding.lgthinq.lgservices.LGServicesConstants.*;
import static org.openhab.binding.lgthinq.lgservices.LGServicesConstants.LG_API_APPLICATION_KEY;
import static org.openhab.binding.lgthinq.lgservices.LGServicesConstants.LG_API_APP_LEVEL;
import static org.openhab.binding.lgthinq.lgservices.LGServicesConstants.LG_API_APP_OS;
import static org.openhab.binding.lgthinq.lgservices.LGServicesConstants.LG_API_APP_TYPE;
import static org.openhab.binding.lgthinq.lgservices.LGServicesConstants.LG_API_APP_VER;
import static org.openhab.binding.lgthinq.lgservices.LGServicesConstants.LG_API_CLIENT_ID;
import static org.openhab.binding.lgthinq.lgservices.LGServicesConstants.LG_API_DATE_FORMAT;
import static org.openhab.binding.lgthinq.lgservices.LGServicesConstants.LG_API_MESSAGE_ID;
import static org.openhab.binding.lgthinq.lgservices.LGServicesConstants.LG_API_OAUTH_CLIENT_KEY;
import static org.openhab.binding.lgthinq.lgservices.LGServicesConstants.LG_API_OAUTH_SEARCH_KEY_PATH;
import static org.openhab.binding.lgthinq.lgservices.LGServicesConstants.LG_API_OAUTH_SECRET_KEY;
import static org.openhab.binding.lgthinq.lgservices.LGServicesConstants.LG_API_PRE_LOGIN_PATH;
import static org.openhab.binding.lgthinq.lgservices.LGServicesConstants.LG_API_SVC_CODE;
import static org.openhab.binding.lgthinq.lgservices.LGServicesConstants.LG_API_SVC_PHASE;
import static org.openhab.binding.lgthinq.lgservices.LGServicesConstants.LG_API_V2_AUTH_PATH;
import static org.openhab.binding.lgthinq.lgservices.LGServicesConstants.LG_API_V2_SESSION_LOGIN_PATH;
import static org.openhab.binding.lgthinq.lgservices.LGServicesConstants.LG_API_V2_USER_INFO;
import java.io.IOException; import java.io.IOException;
import java.net.URLEncoder; import java.net.URLEncoder;
@ -90,17 +73,17 @@ public class LGThinqOauthEmpAuthenticator {
private Map<String, String> getGatewayRestHeader(String language, String country) { private Map<String, String> getGatewayRestHeader(String language, String country) {
return Map.ofEntries(new AbstractMap.SimpleEntry<String, String>("Accept", "application/json"), return Map.ofEntries(new AbstractMap.SimpleEntry<String, String>("Accept", "application/json"),
new AbstractMap.SimpleEntry<String, String>("x-api-key", LG_API_API_KEY_V2), new AbstractMap.SimpleEntry<>("x-api-key", LG_API_API_KEY_V2),
new AbstractMap.SimpleEntry<String, String>("x-country-code", country), new AbstractMap.SimpleEntry<>("x-country-code", country),
new AbstractMap.SimpleEntry<String, String>("x-client-id", LG_API_CLIENT_ID), new AbstractMap.SimpleEntry<>("x-client-id", LG_API_CLIENT_ID),
new AbstractMap.SimpleEntry<String, String>("x-language-code", language), new AbstractMap.SimpleEntry<>("x-language-code", language),
new AbstractMap.SimpleEntry<String, String>("x-message-id", LG_API_MESSAGE_ID), new AbstractMap.SimpleEntry<>("x-message-id", LG_API_MESSAGE_ID),
new AbstractMap.SimpleEntry<String, String>("x-service-code", LG_API_SVC_CODE), new AbstractMap.SimpleEntry<>("x-service-code", LG_API_SVC_CODE),
new AbstractMap.SimpleEntry<String, String>("x-service-phase", LG_API_SVC_PHASE), new AbstractMap.SimpleEntry<>("x-service-phase", LG_API_SVC_PHASE),
new AbstractMap.SimpleEntry<String, String>("x-thinq-app-level", LG_API_APP_LEVEL), new AbstractMap.SimpleEntry<>("x-thinq-app-level", LG_API_APP_LEVEL),
new AbstractMap.SimpleEntry<String, String>("x-thinq-app-os", LG_API_APP_OS), new AbstractMap.SimpleEntry<>("x-thinq-app-os", LG_API_APP_OS),
new AbstractMap.SimpleEntry<String, String>("x-thinq-app-type", LG_API_APP_TYPE), new AbstractMap.SimpleEntry<>("x-thinq-app-type", LG_API_APP_TYPE),
new AbstractMap.SimpleEntry<String, String>("x-thinq-app-ver", LG_API_APP_VER)); new AbstractMap.SimpleEntry<>("x-thinq-app-ver", LG_API_APP_VER));
} }
private Map<String, String> getLoginHeader(LGThinqGateway gw) { private Map<String, String> getLoginHeader(LGThinqGateway gw) {
@ -123,7 +106,7 @@ public class LGThinqOauthEmpAuthenticator {
return headers; return headers;
} }
public LGThinqGateway discoverGatewayConfiguration(String gwUrl, String language, String country, LGThinqGateway discoverGatewayConfiguration(String gwUrl, String language, String country,
String alternativeEmpServer) throws IOException { String alternativeEmpServer) throws IOException {
Map<String, String> header = getGatewayRestHeader(language, country); Map<String, String> header = getGatewayRestHeader(language, country);
RestResult result; RestResult result;
@ -145,7 +128,7 @@ public class LGThinqOauthEmpAuthenticator {
} }
} }
public PreLoginResult preLoginUser(LGThinqGateway gw, String username, String password) throws IOException { PreLoginResult preLoginUser(LGThinqGateway gw, String username, String password) throws IOException {
String encPwd = RestUtils.getPreLoginEncPwd(password); String encPwd = RestUtils.getPreLoginEncPwd(password);
Map<String, String> headers = getLoginHeader(gw); Map<String, String> headers = getLoginHeader(gw);
// 1) Doing preLogin -> getting the password key // 1) Doing preLogin -> getting the password key
@ -174,7 +157,7 @@ public class LGThinqOauthEmpAuthenticator {
"Unexpected login json result. Node 'signature' not found")); "Unexpected login json result. Node 'signature' not found"));
} }
public LoginAccountResult loginUser(LGThinqGateway gw, PreLoginResult preLoginResult) throws IOException { LoginAccountResult loginUser(LGThinqGateway gw, PreLoginResult preLoginResult) throws IOException {
// 2 - Login with username and hashed password // 2 - Login with username and hashed password
Map<String, String> headers = getLoginHeader(gw); Map<String, String> headers = getLoginHeader(gw);
headers.put("X-Signature", preLoginResult.signature()); headers.put("X-Signature", preLoginResult.signature());
@ -267,7 +250,7 @@ public class LGThinqOauthEmpAuthenticator {
return oauthEmpHeaders; return oauthEmpHeaders;
} }
public UserInfo getUserInfo(TokenResult token) throws IOException { UserInfo getUserInfo(TokenResult token) throws IOException {
UriBuilder builder = UriBuilder.fromUri(token.getOauthBackendUrl()).path(LG_API_V2_USER_INFO); UriBuilder builder = UriBuilder.fromUri(token.getOauthBackendUrl()).path(LG_API_V2_USER_INFO);
String oauthUrl = builder.build().toURL().toString(); String oauthUrl = builder.build().toURL().toString();
String timestamp = getCurrentTimestamp(); String timestamp = getCurrentTimestamp();
@ -307,7 +290,7 @@ public class LGThinqOauthEmpAuthenticator {
Objects.requireNonNullElse(accountInfo.get("displayUserID"), "")); Objects.requireNonNullElse(accountInfo.get("displayUserID"), ""));
} }
public TokenResult doRefreshToken(TokenResult currentToken) throws IOException, RefreshTokenException { TokenResult doRefreshToken(TokenResult currentToken) throws IOException, RefreshTokenException {
UriBuilder builder = UriBuilder.fromUri(currentToken.getOauthBackendUrl()).path(LG_API_V2_AUTH_PATH); UriBuilder builder = UriBuilder.fromUri(currentToken.getOauthBackendUrl()).path(LG_API_V2_AUTH_PATH);
String oauthUrl = builder.build().toURL().toString(); String oauthUrl = builder.build().toURL().toString();
String timestamp = getCurrentTimestamp(); String timestamp = getCurrentTimestamp();