diff --git a/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/handler/MiIoVacuumHandler.java b/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/handler/MiIoVacuumHandler.java index 193e7471112..3d6c4d31213 100644 --- a/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/handler/MiIoVacuumHandler.java +++ b/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/handler/MiIoVacuumHandler.java @@ -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: diff --git a/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/robot/RRMapFileParser.java b/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/robot/RRMapFileParser.java index 7d98bc54251..58949703ebc 100644 --- a/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/robot/RRMapFileParser.java +++ b/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/robot/RRMapFileParser.java @@ -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: