]> git.basschouten.com Git - openhab-addons.git/commitdiff
[miio] Use QuantityTypes for time & area in the vacuumhandler (#9058)
authorMarcel <marcelrv@users.noreply.github.com>
Wed, 18 Nov 2020 00:23:23 +0000 (01:23 +0100)
committerGitHub <noreply@github.com>
Wed, 18 Nov 2020 00:23:23 +0000 (16:23 -0800)
closes #7752

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/resources/OH-INF/thing/vacuumThing.xml

index f9d26954f1717b7caa6bcb700fdf49b2c6d49065..18d20e9a4d6d2beda07151bc34610fd18ef1c554 100644 (file)
@@ -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()));
index 3dfd10bdad16c2402558b7d2539061e7de0e3e6a..7faebc6bf5e9bcd6979484232fba0e05237e33c4 100644 (file)
        <channel-type id="clean_area">
                <item-type>Number</item-type>
                <label>Cleaning Area</label>
-               <state pattern="%.2f " readOnly="true"/>
+               <state pattern="%.2f %unit%" readOnly="true"/>
        </channel-type>
        <channel-type id="clean_time">
                <item-type>Number</item-type>
                <label>Cleaning Time</label>
-               <state pattern="%.0f'" readOnly="true"/>
+               <state pattern="%.0f %unit%" readOnly="true"/>
        </channel-type>
        <channel-type id="dnd_enabled">
                <item-type>Switch</item-type>
                <state pattern="%.0f%%" readOnly="true"/>
        </channel-type>
        <channel-type id="main_brush_time" advanced="true">
-               <item-type>Number</item-type>
-               <label>Main Brush Hours till Replacement</label>
-               <state pattern="%.0fh" readOnly="true"/>
+               <item-type>Number:Time</item-type>
+               <label>Main Brush Time till Replacement</label>
+               <state pattern="%.0f %unit%" readOnly="true"/>
        </channel-type>
        <channel-type id="side_brush_time" advanced="true">
-               <item-type>Number</item-type>
-               <label>Side Brush Hours till Replacement</label>
-               <state pattern="%.0fh" readOnly="true"/>
+               <item-type>Number:Time</item-type>
+               <label>Side Brush Time till Replacement</label>
+               <state pattern="%.0f %unit%" readOnly="true"/>
        </channel-type>
        <channel-type id="filter_time" advanced="true">
-               <item-type>Number</item-type>
-               <label>Filter Hours till Replacement</label>
-               <state pattern="%.0fh" readOnly="true"/>
+               <item-type>Number:Time</item-type>
+               <label>Filter Time till Replacement</label>
+               <state pattern="%.0f %unit%" readOnly="true"/>
        </channel-type>
        <channel-type id="sensor_dirt_time" advanced="true">
-               <item-type>Number</item-type>
+               <item-type>Number:Time</item-type>
                <label>Sensor Dirt Time till Cleaning</label>
-               <state pattern="%.0fh" readOnly="true"/>
+               <state pattern="%.0f %unit%" readOnly="true"/>
        </channel-type>
 
        <!-- actions -->
 
        <!-- Clean History -->
        <channel-type id="total_clean_time">
-               <item-type>Number</item-type>
+               <item-type>Number:Time</item-type>
                <label>Total Cleaning Time</label>
-               <description>Total Cleaning Time in minutes</description>
-               <state pattern="%.0f'" readOnly="true"/>
+               <state pattern="%.0f %unit%" readOnly="true"/>
        </channel-type>
        <channel-type id="total_clean_area">
-               <item-type>Number</item-type>
+               <item-type>Number:Area</item-type>
                <label>Total Cleaning Area</label>
-               <state pattern="%.1f " readOnly="true"/>
+               <state pattern="%.1f %unit%" readOnly="true"/>
        </channel-type>
        <channel-type id="total_clean_count">
                <item-type>Number</item-type>
                <state readOnly="true"/>
        </channel-type>
        <channel-type id="last_clean_duration">
-               <item-type>Number</item-type>
+               <item-type>Number:Time</item-type>
                <label>Cleaning Duration</label>
-               <description>Cleaning Duration in minutes</description>
-               <state pattern="%.0f'" readOnly="true"/>
+               <state pattern="%.0f %unit%" readOnly="true"/>
        </channel-type>
        <channel-type id="last_clean_area">
-               <item-type>Number</item-type>
+               <item-type>Number:Area</item-type>
                <label>Cleaning Area</label>
-               <state pattern="%.1f " readOnly="true"/>
+               <state pattern="%.1f %unit%" readOnly="true"/>
        </channel-type>
        <channel-type id="last_clean_error">
                <item-type>Number</item-type>