From 03f33792b705c340b3cc48d5551b1859f8e8eecc Mon Sep 17 00:00:00 2001 From: maniac103 Date: Tue, 5 Nov 2024 14:20:00 +0100 Subject: [PATCH] [ecovacs] Fix expired token handling for XML-over-MQTT models (#17333) At least the Deebot 900 sends an unusual error response in case of expired token. Fixes #15961 Signed-off-by: Danny Baumann Signed-off-by: Ciprian Pascu --- .../AbstractPortalIotCommandResponse.java | 19 +++++++++++++------ .../portal/PortalIotCommandJsonResponse.java | 4 ++-- .../portal/PortalIotCommandXmlResponse.java | 4 ++-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/dto/response/portal/AbstractPortalIotCommandResponse.java b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/dto/response/portal/AbstractPortalIotCommandResponse.java index 102018aba70f1..a3890d0d8c457 100644 --- a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/dto/response/portal/AbstractPortalIotCommandResponse.java +++ b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/dto/response/portal/AbstractPortalIotCommandResponse.java @@ -24,14 +24,12 @@ public class AbstractPortalIotCommandResponse { @SerializedName("errno") private final int errorCode; @SerializedName("error") - private final String errorMessage; + private final Object errorObject; // might be a string or a JSON object - // unused field: 'id' (string) - - public AbstractPortalIotCommandResponse(String result, int errorCode, String errorMessage) { + public AbstractPortalIotCommandResponse(String result, int errorCode, Object errorObject) { this.result = result; this.errorCode = errorCode; - this.errorMessage = errorMessage; + this.errorObject = errorObject; } public boolean wasSuccessful() { @@ -39,13 +37,22 @@ public boolean wasSuccessful() { } public boolean failedDueToAuthProblem() { - return "fail".equals(result) && errorMessage != null && errorMessage.toLowerCase().contains("auth error"); + if (!"fail".equals(result)) { + return false; + } + if (errorCode == 3) { + // Error 3 is 'OAuth error' + return true; + } + String errorMessage = errorObject != null ? errorObject.toString().toLowerCase() : ""; + return errorMessage.contains("auth error") || errorMessage.contains("token error"); } public String getErrorMessage() { if (wasSuccessful()) { return null; } + String errorMessage = errorObject != null ? errorObject.toString() : null; return "result=" + result + ", errno=" + errorCode + ", error=" + errorMessage; } } diff --git a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/dto/response/portal/PortalIotCommandJsonResponse.java b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/dto/response/portal/PortalIotCommandJsonResponse.java index 8659b3af9e7ae..2b74c05e84d40 100644 --- a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/dto/response/portal/PortalIotCommandJsonResponse.java +++ b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/dto/response/portal/PortalIotCommandJsonResponse.java @@ -27,8 +27,8 @@ public class PortalIotCommandJsonResponse extends AbstractPortalIotCommandRespon @SerializedName("resp") public final JsonElement response; - public PortalIotCommandJsonResponse(String result, JsonElement response, int errorCode, String errorMessage) { - super(result, errorCode, errorMessage); + public PortalIotCommandJsonResponse(String result, JsonElement response, int errorCode, Object errorObject) { + super(result, errorCode, errorObject); this.response = response; } diff --git a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/dto/response/portal/PortalIotCommandXmlResponse.java b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/dto/response/portal/PortalIotCommandXmlResponse.java index 70d9312ab1f93..6f35ab06f4ea4 100644 --- a/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/dto/response/portal/PortalIotCommandXmlResponse.java +++ b/bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/api/impl/dto/response/portal/PortalIotCommandXmlResponse.java @@ -21,8 +21,8 @@ public class PortalIotCommandXmlResponse extends AbstractPortalIotCommandRespons @SerializedName("resp") private final String responseXml; - public PortalIotCommandXmlResponse(String result, String responseXml, int errorCode, String errorMessage) { - super(result, errorCode, errorMessage); + public PortalIotCommandXmlResponse(String result, String responseXml, int errorCode, Object errorObject) { + super(result, errorCode, errorObject); this.responseXml = responseXml; }