]> git.basschouten.com Git - openhab-addons.git/commitdiff
[tapocontrol] fixed cloud connection error (#16822)
authorChristian Wild <40909464+wildcs@users.noreply.github.com>
Fri, 31 May 2024 04:48:00 +0000 (06:48 +0200)
committerGitHub <noreply@github.com>
Fri, 31 May 2024 04:48:00 +0000 (06:48 +0200)
Signed-off-by: Christian Wild <christian@wildclan.de>
bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/api/TapoCloudConnector.java
bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/api/protocol/aes/SecurePassthrough.java
bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/api/protocol/klap/KlapProtocol.java
bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/api/protocol/passthrough/PassthroughProtocol.java
bundles/org.openhab.binding.tapocontrol/src/main/java/org/openhab/binding/tapocontrol/internal/dto/TapoRequest.java

index 1dcbb2ee215f65ba68ab11704c95e732cc6d0039..23351b2ca1e432221523e972aad02d2a323b29c8 100644 (file)
@@ -19,7 +19,6 @@ import static org.openhab.binding.tapocontrol.internal.helpers.utils.JsonUtils.*
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jetty.client.HttpClient;
-import org.eclipse.jetty.client.api.Request;
 import org.openhab.binding.tapocontrol.internal.api.protocol.passthrough.PassthroughProtocol;
 import org.openhab.binding.tapocontrol.internal.devices.bridge.TapoBridgeHandler;
 import org.openhab.binding.tapocontrol.internal.devices.bridge.dto.TapoCloudLoginData;
@@ -185,13 +184,4 @@ public class TapoCloudConnector implements TapoConnectorInterface {
         }
         return url;
     }
-
-    /**
-     * Set http-headers
-     */
-    public Request setHeaders(Request httpRequest) {
-        httpRequest.header("content-type", CONTENT_TYPE_JSON);
-        httpRequest.header("Accept", CONTENT_TYPE_JSON);
-        return httpRequest;
-    }
 }
index 2d3f65ba577c7b3df1d8cb6303a931e81032f27d..4bb3f6689e25bd8dba6003def6147dfb7c1aee53 100644 (file)
@@ -112,7 +112,7 @@ public class SecurePassthrough implements TapoProtocolInterface {
             logger.trace("({}) encrypted request: '{}' with cookie '{}'", uid, tapoRequest, session.getCookie());
         }
 
-        Request httpRequest = httpDelegator.getHttpClient().newRequest(url).method(HttpMethod.POST.toString());
+        Request httpRequest = httpDelegator.getHttpClient().newRequest(url).method(HttpMethod.POST);
 
         /* set header */
         httpRequest = setHeaders(httpRequest);
@@ -141,7 +141,7 @@ public class SecurePassthrough implements TapoProtocolInterface {
         TapoRequest encryptedRequest = session.encryptRequest(tapoRequest);
         logger.trace("({}) sending encrypted request to '{}' with cookie '{}'", uid, url, session.getCookie());
 
-        Request httpRequest = httpDelegator.getHttpClient().newRequest(url).method(HttpMethod.POST.toString());
+        Request httpRequest = httpDelegator.getHttpClient().newRequest(url).method(HttpMethod.POST);
 
         /* set header */
         httpRequest = setHeaders(httpRequest);
@@ -192,7 +192,7 @@ public class SecurePassthrough implements TapoProtocolInterface {
      */
     @Override
     public void responseReceived(ContentResponse response, String command) throws TapoErrorHandler {
-        logger.trace("({}) recived response: {}", uid, response.getContentAsString());
+        logger.trace("({}) received response: {}", uid, response.getContentAsString());
         TapoResponse tapoResponse = getTapoResponse(response);
         httpDelegator.handleResponse(tapoResponse, command);
         httpDelegator.responsePasstrough(response.getContentAsString(), command);
@@ -266,7 +266,6 @@ public class SecurePassthrough implements TapoProtocolInterface {
      * Set HTTP-Headers
      */
     protected Request setHeaders(Request httpRequest) {
-        httpRequest.header("content-type", CONTENT_TYPE_JSON);
         httpRequest.header("Accept", CONTENT_TYPE_JSON);
         if (session.isHandshakeComplete()) {
             httpRequest.header(HTTP_AUTH_TYPE_COOKIE, session.getCookie());
index 4e3c59b7204d42e78472b0a0324f1ca0fa085604..650fc038851974befb231196aaa4304526b7c06b 100644 (file)
@@ -94,7 +94,7 @@ public class KlapProtocol implements org.openhab.binding.tapocontrol.internal.ap
         String command = tapoRequest.method();
         logger.trace("({}) sending unencrypted request: '{}' to '{}' ", uid, tapoRequest, url);
 
-        Request httpRequest = httpDelegator.getHttpClient().newRequest(url).method(HttpMethod.POST.toString());
+        Request httpRequest = httpDelegator.getHttpClient().newRequest(url).method(HttpMethod.POST);
 
         /* set header */
         httpRequest = setHeaders(httpRequest);
@@ -126,7 +126,7 @@ public class KlapProtocol implements org.openhab.binding.tapocontrol.internal.ap
         Integer ivSequence = session.getIvSequence();
         logger.trace("({}) encrypted request is '{}' with sequence '{}'", uid, encrypteString, ivSequence);
 
-        Request httpRequest = httpDelegator.getHttpClient().newRequest(url).method(HttpMethod.POST.toString());
+        Request httpRequest = httpDelegator.getHttpClient().newRequest(url).method(HttpMethod.POST);
 
         /* set header and params */
         httpRequest = setHeaders(httpRequest);
@@ -263,7 +263,6 @@ public class KlapProtocol implements org.openhab.binding.tapocontrol.internal.ap
      */
     protected Request setHeaders(Request httpRequest) {
         if (!session.isHandshakeComplete()) {
-            httpRequest.header("content-type", CONTENT_TYPE_JSON);
             httpRequest.header("Accept", CONTENT_TYPE_JSON);
         }
         if (!session.getCookie().isBlank()) {
index 77b05f881e66fedffd2241422b554093f67f061a..205e348640a8b6c7b05d1f516a4906f3a0e25be6 100644 (file)
@@ -95,7 +95,7 @@ public class PassthroughProtocol implements TapoProtocolInterface {
         logger.trace("({}) sending encrypted request to '{}' ", uid, url);
         logger.trace("({}) unencrypted request: '{}'", uid, tapoRequest);
 
-        Request httpRequest = httpDelegator.getHttpClient().newRequest(url).method(HttpMethod.POST.toString());
+        Request httpRequest = httpDelegator.getHttpClient().newRequest(url).method(HttpMethod.POST);
 
         /* set header */
         httpRequest = setHeaders(httpRequest);
@@ -131,7 +131,7 @@ public class PassthroughProtocol implements TapoProtocolInterface {
         logger.trace("({}) sendAsncRequest to '{}'", uid, url);
         logger.trace("({}) command/payload: '{}''{}'", uid, command, tapoRequest.params());
 
-        Request httpRequest = httpDelegator.getHttpClient().newRequest(url).method(HttpMethod.POST.toString());
+        Request httpRequest = httpDelegator.getHttpClient().newRequest(url).method(HttpMethod.POST);
 
         /* set header */
         httpRequest = setHeaders(httpRequest);
@@ -180,7 +180,7 @@ public class PassthroughProtocol implements TapoProtocolInterface {
      */
     @Override
     public void responseReceived(ContentResponse response, String command) throws TapoErrorHandler {
-        logger.trace("({}) recived response: {}", uid, response.getContentAsString());
+        logger.trace("({}) received response: {}", uid, response.getContentAsString());
         TapoResponse tapoResponse = getTapoResponse(response);
         if (!tapoResponse.hasError()) {
             switch (command) {
@@ -222,8 +222,9 @@ public class PassthroughProtocol implements TapoProtocolInterface {
         if (response.getStatus() == 200) {
             return getTapoResponse(response.getContentAsString());
         } else {
-            logger.debug("({}) invalid response received", uid);
-            throw new TapoErrorHandler(ERR_BINDING_HTTP_RESPONSE, "invalid response receicved");
+            String reason = response.getStatus() + " " + response.getReason();
+            logger.debug("({}) invalid response received - {}", uid, reason);
+            throw new TapoErrorHandler(ERR_BINDING_HTTP_RESPONSE, reason);
         }
     }
 
@@ -250,7 +251,6 @@ public class PassthroughProtocol implements TapoProtocolInterface {
      * Set HTTP-Headers
      */
     public Request setHeaders(Request httpRequest) {
-        httpRequest.header("content-type", CONTENT_TYPE_JSON);
         httpRequest.header("Accept", CONTENT_TYPE_JSON);
         return httpRequest;
     }
index 5751067283eab912066c2b26e71ae0c95fc00914..48d1bd71abf316dfac79459b8432f1d6cb7fc3ca 100644 (file)
 package org.openhab.binding.tapocontrol.internal.dto;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
 
 import com.google.gson.GsonBuilder;
 import com.google.gson.annotations.Expose;
 
-import io.reactivex.annotations.Nullable;
-
 /**
  * Holds data sent to device
  *
@@ -31,7 +30,7 @@ public record TapoRequest(@Expose String method, @Expose @Nullable Object params
     /**
      * Create request with command (method) and data (params) sent to device
      */
-    public TapoRequest(String method, Object params) {
+    public TapoRequest(String method, @Nullable Object params) {
         this(method, params, System.currentTimeMillis());
     }
 
@@ -39,7 +38,7 @@ public record TapoRequest(@Expose String method, @Expose @Nullable Object params
      * Create request with command (method) sent to device
      */
     public TapoRequest(String method) {
-        this(method, "", System.currentTimeMillis());
+        this(method, null, System.currentTimeMillis());
     }
 
     /***********************************************