]> git.basschouten.com Git - openhab-addons.git/commitdiff
[miio] Fix cleaning record for newer vacuums (#15944)
authorMarcel <marcel@verpaalen.com>
Mon, 27 Nov 2023 23:10:27 +0000 (00:10 +0100)
committerGitHub <noreply@github.com>
Mon, 27 Nov 2023 23:10:27 +0000 (00:10 +0100)
* [miio] Fix cleaning record for newer vacuums

Fixes Roborock Q7Max Historical Cleaning record missing

closing #15490

---------

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/handler/MiIoVacuumHandler.java
bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/robot/HistoryRecordDTO.java

index a36bcf463044148072a49f5256ca5f4fa64c4b8a..df76917b550c82a26b8b9a8cd370c5e06ac594b7 100644 (file)
@@ -539,7 +539,7 @@ public class MiIoVacuumHandler extends MiIoAbstractHandler {
     }
 
     private void updateHistoryRecord(HistoryRecordDTO historyRecordDTO) {
-        JsonObject historyRecord = new JsonObject();
+        JsonObject historyRecord = GSON.toJsonTree(historyRecordDTO).getAsJsonObject();
         if (historyRecordDTO.getStart() != null) {
             historyRecord.addProperty("start", historyRecordDTO.getStart().split("\\+")[0]);
             updateState(CHANNEL_HISTORY_START_TIME, new DateTimeType(historyRecordDTO.getStart().split("\\+")[0]));
@@ -703,6 +703,13 @@ public class MiIoVacuumHandler extends MiIoAbstractHandler {
                 if (response.getResult().isJsonArray() && response.getResult().getAsJsonArray().size() > 0
                         && response.getResult().getAsJsonArray().get(0).isJsonArray()) {
                     updateHistoryRecordLegacy(response.getResult().getAsJsonArray().get(0).getAsJsonArray());
+                } else if (response.getResult().isJsonArray() && response.getResult().getAsJsonArray().size() > 0
+                        && response.getResult().getAsJsonArray().get(0).isJsonObject()) {
+                    final HistoryRecordDTO historyRecordDTO = GSON.fromJson(
+                            response.getResult().getAsJsonArray().get(0).getAsJsonObject(), HistoryRecordDTO.class);
+                    if (historyRecordDTO != null) {
+                        updateHistoryRecord(historyRecordDTO);
+                    }
                 } else if (response.getResult().isJsonObject()) {
                     final HistoryRecordDTO historyRecordDTO = GSON.fromJson(response.getResult().getAsJsonObject(),
                             HistoryRecordDTO.class);
@@ -710,7 +717,7 @@ public class MiIoVacuumHandler extends MiIoAbstractHandler {
                         updateHistoryRecord(historyRecordDTO);
                     }
                 } else {
-                    logger.debug("Could not extract cleaning history record from: {}", response);
+                    logger.debug("Could not extract cleaning history record from: {}", response.getResult());
                 }
                 break;
             case GET_MAP:
@@ -734,11 +741,9 @@ public class MiIoVacuumHandler extends MiIoAbstractHandler {
             case GET_FW_FEATURES:
             case GET_CUSTOMIZED_CLEAN_MODE:
             case GET_MULTI_MAP_LIST:
-
             case SET_COLLECT_DUST:
             case SET_CLEAN_MOP_START:
             case SET_CLEAN_MOP_STOP:
-
                 for (RobotCababilities cmd : FEATURES_CHANNELS) {
                     if (response.getCommand().getCommand().contentEquals(cmd.getCommand())) {
                         updateState(cmd.getChannel(), new StringType(response.getResult().toString()));
index c30b044536b68c8afb5ab9974f4ca37758060b3a..ca21f465de5a00eb3c5f104c496ce12475c82abd 100644 (file)
@@ -27,6 +27,9 @@ public class HistoryRecordDTO {
     @SerializedName("start")
     @Expose
     private String start;
+    @SerializedName("begin")
+    @Expose
+    private String begin;
     @SerializedName("end")
     @Expose
     private String end;
@@ -45,6 +48,9 @@ public class HistoryRecordDTO {
     @SerializedName("finished")
     @Expose
     private Integer finished;
+    @SerializedName("complete")
+    @Expose
+    private Integer complete;
     @SerializedName("start_type")
     @Expose
     private Integer startType;
@@ -57,9 +63,12 @@ public class HistoryRecordDTO {
     @SerializedName("dust_collection_status")
     @Expose
     private Integer dustCollectionStatus;
+    @SerializedName("map_flag")
+    @Expose
+    private Integer mapFlag;
 
     public final String getStart() {
-        return start;
+        return start != null ? start : begin;
     }
 
     public final void setStart(String start) {
@@ -107,7 +116,7 @@ public class HistoryRecordDTO {
     }
 
     public final Integer getFinished() {
-        return finished;
+        return finished != null ? finished : complete;
     }
 
     public final void setFinished(Integer finished) {
@@ -145,4 +154,12 @@ public class HistoryRecordDTO {
     public final void setDustCollectionStatus(Integer dustCollectionStatus) {
         this.dustCollectionStatus = dustCollectionStatus;
     }
+
+    public final Integer getMapFlag() {
+        return mapFlag;
+    }
+
+    public final void setMapFlag(Integer mapFlag) {
+        this.mapFlag = mapFlag;
+    }
 }