]> git.basschouten.com Git - openhab-addons.git/commitdiff
[miio] add new robo map blocks to map parser (#15591)
authorMarcel <marcel@verpaalen.com>
Sat, 23 Sep 2023 16:12:16 +0000 (18:12 +0200)
committerGitHub <noreply@github.com>
Sat, 23 Sep 2023 16:12:16 +0000 (18:12 +0200)
* [miio] add new robo map blocks to map parser

Adding new block types in map parser.
close #15068

* [miio] fix history for newer robot models

closes #11001

---------

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/RRMapFileParser.java

index 193e7471112568a3e76c304c12e87248c282dda1..3d6c4d3121345bbd5b341a46c491bd9f7e54640f 100644 (file)
@@ -402,7 +402,7 @@ public class MiIoVacuumHandler extends MiIoAbstractHandler {
         return true;
     }
 
-    private boolean updateHistory(JsonArray historyData) {
+    private boolean updateHistoryLegacy(JsonArray historyData) {
         logger.trace("Cleaning history data: {}", historyData.toString());
         updateState(CHANNEL_HISTORY_TOTALTIME,
                 new QuantityType<>(TimeUnit.SECONDS.toMinutes(historyData.get(0).getAsLong()), Units.MINUTE));
@@ -419,6 +419,32 @@ public class MiIoVacuumHandler extends MiIoAbstractHandler {
         return true;
     }
 
+    private boolean updateHistory(JsonObject historyData) {
+        logger.trace("Cleaning history data: {}", historyData);
+        if (historyData.has("clean_time")) {
+            updateState(CHANNEL_HISTORY_TOTALTIME, new QuantityType<>(
+                    TimeUnit.SECONDS.toMinutes(historyData.get("clean_time").getAsLong()), Units.MINUTE));
+        }
+        if (historyData.has("clean_area")) {
+            updateState(CHANNEL_HISTORY_TOTALAREA,
+                    new QuantityType<>(historyData.get("clean_area").getAsDouble() / 1000000D, SIUnits.SQUARE_METRE));
+        }
+        if (historyData.has("clean_count")) {
+            updateState(CHANNEL_HISTORY_COUNT, new DecimalType(historyData.get("clean_count").getAsLong()));
+        }
+        if (historyData.has("records") & historyData.get("records").isJsonArray()) {
+            JsonArray historyRecords = historyData.get("records").getAsJsonArray();
+            if (!historyRecords.isEmpty()) {
+                String lastClean = historyRecords.get(0).getAsString();
+                if (!lastClean.equals(lastHistoryId)) {
+                    lastHistoryId = lastClean;
+                    sendCommand(MiIoCommand.CLEAN_RECORD_GET, "[" + lastClean + "]");
+                }
+            }
+        }
+        return true;
+    }
+
     private void updateHistoryRecord(JsonArray historyData) {
         ZonedDateTime startTime = ZonedDateTime.ofInstant(Instant.ofEpochSecond(historyData.get(0).getAsLong()),
                 ZoneId.systemDefault());
@@ -536,7 +562,9 @@ public class MiIoVacuumHandler extends MiIoAbstractHandler {
                 break;
             case CLEAN_SUMMARY_GET:
                 if (response.getResult().isJsonArray()) {
-                    updateHistory(response.getResult().getAsJsonArray());
+                    updateHistoryLegacy(response.getResult().getAsJsonArray());
+                } else if (response.getResult().isJsonObject()) {
+                    updateHistory(response.getResult().getAsJsonObject());
                 }
                 break;
             case CLEAN_RECORD_GET:
index 7d98bc54251dffc8a8111db2ba786a67236bcc7b..58949703ebc4ee4b39ebe930899d306d4870ecd8 100644 (file)
@@ -68,6 +68,13 @@ public class RRMapFileParser {
     public static final int FURNITURES = 25;
     public static final int DOCK_TYPE = 26;
     public static final int ENEMIES = 27;
+    public static final int DOOR_ZONES = 28;
+    public static final int STUCK_POINTS = 29;
+    public static final int CLIFF_ZONES = 30;
+    public static final int SMARTDS = 31;
+    public static final int FLDIREC = 32;
+    public static final int MAP_DATE = 33;
+    public static final int NONCE_DATA = 34;
     public static final int DIGEST = 1024;
     public static final int HEADER = 0x7272;
 
@@ -287,6 +294,13 @@ public class RRMapFileParser {
                 case FURNITURES:
                 case DOCK_TYPE:
                 case ENEMIES:
+                case DOOR_ZONES:
+                case STUCK_POINTS:
+                case CLIFF_ZONES:
+                case SMARTDS:
+                case FLDIREC:
+                case MAP_DATE:
+                case NONCE_DATA:
                     // new blocktypes not yet decoded
                     break;
                 default: