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 f9d26954f..18d20e9a4 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 @@ -50,8 +50,11 @@ import org.openhab.core.cache.ExpiringCache; import org.openhab.core.library.types.DateTimeType; import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.OnOffType; +import org.openhab.core.library.types.QuantityType; import org.openhab.core.library.types.RawType; import org.openhab.core.library.types.StringType; +import org.openhab.core.library.unit.SIUnits; +import org.openhab.core.library.unit.SmartHomeUnits; import org.openhab.core.thing.Channel; import org.openhab.core.thing.ChannelUID; import org.openhab.core.thing.Thing; @@ -262,10 +265,12 @@ public class MiIoVacuumHandler extends MiIoAbstractHandler { StatusDTO statusInfo = GSON.fromJson(statusData, StatusDTO.class); safeUpdateState(CHANNEL_BATTERY, statusInfo.getBattery()); if (statusInfo.getCleanArea() != null) { - updateState(CHANNEL_CLEAN_AREA, new DecimalType(statusInfo.getCleanArea() / 1000000.0)); + updateState(CHANNEL_CLEAN_AREA, + new QuantityType<>(statusInfo.getCleanArea() / 1000000.0, SIUnits.SQUARE_METRE)); } if (statusInfo.getCleanTime() != null) { - updateState(CHANNEL_CLEAN_TIME, new DecimalType(TimeUnit.SECONDS.toMinutes(statusInfo.getCleanTime()))); + updateState(CHANNEL_CLEAN_TIME, + new QuantityType<>(TimeUnit.SECONDS.toMinutes(statusInfo.getCleanTime()), SmartHomeUnits.MINUTE)); } safeUpdateState(CHANNEL_DND_ENABLED, statusInfo.getDndEnabled()); @@ -345,20 +350,20 @@ public class MiIoVacuumHandler extends MiIoAbstractHandler { int sideBrush = consumablesData.get("side_brush_work_time").getAsInt(); int filter = consumablesData.get("filter_work_time").getAsInt(); int sensor = consumablesData.get("sensor_dirty_time").getAsInt(); - updateState(CHANNEL_CONSUMABLE_MAIN_TIME, - new DecimalType(ConsumablesType.remainingHours(mainBrush, ConsumablesType.MAIN_BRUSH))); + updateState(CHANNEL_CONSUMABLE_MAIN_TIME, new QuantityType<>( + ConsumablesType.remainingHours(mainBrush, ConsumablesType.MAIN_BRUSH), SmartHomeUnits.HOUR)); updateState(CHANNEL_CONSUMABLE_MAIN_PERC, new DecimalType(ConsumablesType.remainingPercent(mainBrush, ConsumablesType.MAIN_BRUSH))); - updateState(CHANNEL_CONSUMABLE_SIDE_TIME, - new DecimalType(ConsumablesType.remainingHours(sideBrush, ConsumablesType.SIDE_BRUSH))); + updateState(CHANNEL_CONSUMABLE_SIDE_TIME, new QuantityType<>( + ConsumablesType.remainingHours(sideBrush, ConsumablesType.SIDE_BRUSH), SmartHomeUnits.HOUR)); updateState(CHANNEL_CONSUMABLE_SIDE_PERC, new DecimalType(ConsumablesType.remainingPercent(sideBrush, ConsumablesType.SIDE_BRUSH))); - updateState(CHANNEL_CONSUMABLE_FILTER_TIME, - new DecimalType(ConsumablesType.remainingHours(filter, ConsumablesType.FILTER))); + updateState(CHANNEL_CONSUMABLE_FILTER_TIME, new QuantityType<>( + ConsumablesType.remainingHours(filter, ConsumablesType.FILTER), SmartHomeUnits.HOUR)); updateState(CHANNEL_CONSUMABLE_FILTER_PERC, new DecimalType(ConsumablesType.remainingPercent(filter, ConsumablesType.FILTER))); - updateState(CHANNEL_CONSUMABLE_SENSOR_TIME, - new DecimalType(ConsumablesType.remainingHours(sensor, ConsumablesType.SENSOR))); + updateState(CHANNEL_CONSUMABLE_SENSOR_TIME, new QuantityType<>( + ConsumablesType.remainingHours(sensor, ConsumablesType.SENSOR), SmartHomeUnits.HOUR)); updateState(CHANNEL_CONSUMABLE_SENSOR_PERC, new DecimalType(ConsumablesType.remainingPercent(sensor, ConsumablesType.SENSOR))); return true; @@ -377,8 +382,9 @@ public class MiIoVacuumHandler extends MiIoAbstractHandler { private boolean updateHistory(JsonArray historyData) { logger.trace("Cleaning history data: {}", historyData.toString()); updateState(CHANNEL_HISTORY_TOTALTIME, - new DecimalType(TimeUnit.SECONDS.toMinutes(historyData.get(0).getAsLong()))); - updateState(CHANNEL_HISTORY_TOTALAREA, new DecimalType(historyData.get(1).getAsDouble() / 1000000D)); + new QuantityType<>(TimeUnit.SECONDS.toMinutes(historyData.get(0).getAsLong()), SmartHomeUnits.MINUTE)); + updateState(CHANNEL_HISTORY_TOTALAREA, + new QuantityType<>(historyData.get(1).getAsDouble() / 1000000D, SIUnits.SQUARE_METRE)); updateState(CHANNEL_HISTORY_COUNT, new DecimalType(historyData.get(2).toString())); if (historyData.get(3).getAsJsonArray().size() > 0) { String lastClean = historyData.get(3).getAsJsonArray().get(0).getAsString(); @@ -408,8 +414,8 @@ public class MiIoVacuumHandler extends MiIoAbstractHandler { historyRecord.addProperty("finished", finished); updateState(CHANNEL_HISTORY_START_TIME, new DateTimeType(startTime)); updateState(CHANNEL_HISTORY_END_TIME, new DateTimeType(endTime)); - updateState(CHANNEL_HISTORY_DURATION, new DecimalType(duration)); - updateState(CHANNEL_HISTORY_AREA, new DecimalType(area)); + updateState(CHANNEL_HISTORY_DURATION, new QuantityType<>(duration, SmartHomeUnits.MINUTE)); + updateState(CHANNEL_HISTORY_AREA, new QuantityType<>(area, SIUnits.SQUARE_METRE)); updateState(CHANNEL_HISTORY_ERROR, new DecimalType(error)); updateState(CHANNEL_HISTORY_FINISH, new DecimalType(finished)); updateState(CHANNEL_HISTORY_RECORD, new StringType(historyRecord.toString())); diff --git a/bundles/org.openhab.binding.miio/src/main/resources/OH-INF/thing/vacuumThing.xml b/bundles/org.openhab.binding.miio/src/main/resources/OH-INF/thing/vacuumThing.xml index 3dfd10bda..7faebc6bf 100644 --- a/bundles/org.openhab.binding.miio/src/main/resources/OH-INF/thing/vacuumThing.xml +++ b/bundles/org.openhab.binding.miio/src/main/resources/OH-INF/thing/vacuumThing.xml @@ -99,12 +99,12 @@ Number - + Number - + Switch @@ -201,24 +201,24 @@ - Number - - + Number:Time + + - Number - - + Number:Time + + - Number - - + Number:Time + + - Number + Number:Time - + @@ -292,15 +292,14 @@ - Number + Number:Time - Total Cleaning Time in minutes - + - Number + Number:Area - + Number @@ -324,15 +323,14 @@ - Number + Number:Time - Cleaning Duration in minutes - + - Number + Number:Area - + Number