[miio] Use QuantityTypes for time & area in the vacuumhandler (#9058)

closes #7752

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
This commit is contained in:
Marcel 2020-11-18 01:23:23 +01:00 committed by GitHub
parent d41927c703
commit 158cbe0c65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 37 deletions

View File

@ -50,8 +50,11 @@ import org.openhab.core.cache.ExpiringCache;
import org.openhab.core.library.types.DateTimeType; import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType; 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.RawType;
import org.openhab.core.library.types.StringType; 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.Channel;
import org.openhab.core.thing.ChannelUID; import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing; import org.openhab.core.thing.Thing;
@ -262,10 +265,12 @@ public class MiIoVacuumHandler extends MiIoAbstractHandler {
StatusDTO statusInfo = GSON.fromJson(statusData, StatusDTO.class); StatusDTO statusInfo = GSON.fromJson(statusData, StatusDTO.class);
safeUpdateState(CHANNEL_BATTERY, statusInfo.getBattery()); safeUpdateState(CHANNEL_BATTERY, statusInfo.getBattery());
if (statusInfo.getCleanArea() != null) { 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) { 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()); 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 sideBrush = consumablesData.get("side_brush_work_time").getAsInt();
int filter = consumablesData.get("filter_work_time").getAsInt(); int filter = consumablesData.get("filter_work_time").getAsInt();
int sensor = consumablesData.get("sensor_dirty_time").getAsInt(); int sensor = consumablesData.get("sensor_dirty_time").getAsInt();
updateState(CHANNEL_CONSUMABLE_MAIN_TIME, updateState(CHANNEL_CONSUMABLE_MAIN_TIME, new QuantityType<>(
new DecimalType(ConsumablesType.remainingHours(mainBrush, ConsumablesType.MAIN_BRUSH))); ConsumablesType.remainingHours(mainBrush, ConsumablesType.MAIN_BRUSH), SmartHomeUnits.HOUR));
updateState(CHANNEL_CONSUMABLE_MAIN_PERC, updateState(CHANNEL_CONSUMABLE_MAIN_PERC,
new DecimalType(ConsumablesType.remainingPercent(mainBrush, ConsumablesType.MAIN_BRUSH))); new DecimalType(ConsumablesType.remainingPercent(mainBrush, ConsumablesType.MAIN_BRUSH)));
updateState(CHANNEL_CONSUMABLE_SIDE_TIME, updateState(CHANNEL_CONSUMABLE_SIDE_TIME, new QuantityType<>(
new DecimalType(ConsumablesType.remainingHours(sideBrush, ConsumablesType.SIDE_BRUSH))); ConsumablesType.remainingHours(sideBrush, ConsumablesType.SIDE_BRUSH), SmartHomeUnits.HOUR));
updateState(CHANNEL_CONSUMABLE_SIDE_PERC, updateState(CHANNEL_CONSUMABLE_SIDE_PERC,
new DecimalType(ConsumablesType.remainingPercent(sideBrush, ConsumablesType.SIDE_BRUSH))); new DecimalType(ConsumablesType.remainingPercent(sideBrush, ConsumablesType.SIDE_BRUSH)));
updateState(CHANNEL_CONSUMABLE_FILTER_TIME, updateState(CHANNEL_CONSUMABLE_FILTER_TIME, new QuantityType<>(
new DecimalType(ConsumablesType.remainingHours(filter, ConsumablesType.FILTER))); ConsumablesType.remainingHours(filter, ConsumablesType.FILTER), SmartHomeUnits.HOUR));
updateState(CHANNEL_CONSUMABLE_FILTER_PERC, updateState(CHANNEL_CONSUMABLE_FILTER_PERC,
new DecimalType(ConsumablesType.remainingPercent(filter, ConsumablesType.FILTER))); new DecimalType(ConsumablesType.remainingPercent(filter, ConsumablesType.FILTER)));
updateState(CHANNEL_CONSUMABLE_SENSOR_TIME, updateState(CHANNEL_CONSUMABLE_SENSOR_TIME, new QuantityType<>(
new DecimalType(ConsumablesType.remainingHours(sensor, ConsumablesType.SENSOR))); ConsumablesType.remainingHours(sensor, ConsumablesType.SENSOR), SmartHomeUnits.HOUR));
updateState(CHANNEL_CONSUMABLE_SENSOR_PERC, updateState(CHANNEL_CONSUMABLE_SENSOR_PERC,
new DecimalType(ConsumablesType.remainingPercent(sensor, ConsumablesType.SENSOR))); new DecimalType(ConsumablesType.remainingPercent(sensor, ConsumablesType.SENSOR)));
return true; return true;
@ -377,8 +382,9 @@ public class MiIoVacuumHandler extends MiIoAbstractHandler {
private boolean updateHistory(JsonArray historyData) { private boolean updateHistory(JsonArray historyData) {
logger.trace("Cleaning history data: {}", historyData.toString()); logger.trace("Cleaning history data: {}", historyData.toString());
updateState(CHANNEL_HISTORY_TOTALTIME, updateState(CHANNEL_HISTORY_TOTALTIME,
new DecimalType(TimeUnit.SECONDS.toMinutes(historyData.get(0).getAsLong()))); new QuantityType<>(TimeUnit.SECONDS.toMinutes(historyData.get(0).getAsLong()), SmartHomeUnits.MINUTE));
updateState(CHANNEL_HISTORY_TOTALAREA, new DecimalType(historyData.get(1).getAsDouble() / 1000000D)); updateState(CHANNEL_HISTORY_TOTALAREA,
new QuantityType<>(historyData.get(1).getAsDouble() / 1000000D, SIUnits.SQUARE_METRE));
updateState(CHANNEL_HISTORY_COUNT, new DecimalType(historyData.get(2).toString())); updateState(CHANNEL_HISTORY_COUNT, new DecimalType(historyData.get(2).toString()));
if (historyData.get(3).getAsJsonArray().size() > 0) { if (historyData.get(3).getAsJsonArray().size() > 0) {
String lastClean = historyData.get(3).getAsJsonArray().get(0).getAsString(); String lastClean = historyData.get(3).getAsJsonArray().get(0).getAsString();
@ -408,8 +414,8 @@ public class MiIoVacuumHandler extends MiIoAbstractHandler {
historyRecord.addProperty("finished", finished); historyRecord.addProperty("finished", finished);
updateState(CHANNEL_HISTORY_START_TIME, new DateTimeType(startTime)); updateState(CHANNEL_HISTORY_START_TIME, new DateTimeType(startTime));
updateState(CHANNEL_HISTORY_END_TIME, new DateTimeType(endTime)); updateState(CHANNEL_HISTORY_END_TIME, new DateTimeType(endTime));
updateState(CHANNEL_HISTORY_DURATION, new DecimalType(duration)); updateState(CHANNEL_HISTORY_DURATION, new QuantityType<>(duration, SmartHomeUnits.MINUTE));
updateState(CHANNEL_HISTORY_AREA, new DecimalType(area)); updateState(CHANNEL_HISTORY_AREA, new QuantityType<>(area, SIUnits.SQUARE_METRE));
updateState(CHANNEL_HISTORY_ERROR, new DecimalType(error)); updateState(CHANNEL_HISTORY_ERROR, new DecimalType(error));
updateState(CHANNEL_HISTORY_FINISH, new DecimalType(finished)); updateState(CHANNEL_HISTORY_FINISH, new DecimalType(finished));
updateState(CHANNEL_HISTORY_RECORD, new StringType(historyRecord.toString())); updateState(CHANNEL_HISTORY_RECORD, new StringType(historyRecord.toString()));

View File

@ -99,12 +99,12 @@
<channel-type id="clean_area"> <channel-type id="clean_area">
<item-type>Number</item-type> <item-type>Number</item-type>
<label>Cleaning Area</label> <label>Cleaning Area</label>
<state pattern="%.2f " readOnly="true"/> <state pattern="%.2f %unit%" readOnly="true"/>
</channel-type> </channel-type>
<channel-type id="clean_time"> <channel-type id="clean_time">
<item-type>Number</item-type> <item-type>Number</item-type>
<label>Cleaning Time</label> <label>Cleaning Time</label>
<state pattern="%.0f'" readOnly="true"/> <state pattern="%.0f %unit%" readOnly="true"/>
</channel-type> </channel-type>
<channel-type id="dnd_enabled"> <channel-type id="dnd_enabled">
<item-type>Switch</item-type> <item-type>Switch</item-type>
@ -201,24 +201,24 @@
<state pattern="%.0f%%" readOnly="true"/> <state pattern="%.0f%%" readOnly="true"/>
</channel-type> </channel-type>
<channel-type id="main_brush_time" advanced="true"> <channel-type id="main_brush_time" advanced="true">
<item-type>Number</item-type> <item-type>Number:Time</item-type>
<label>Main Brush Hours till Replacement</label> <label>Main Brush Time till Replacement</label>
<state pattern="%.0fh" readOnly="true"/> <state pattern="%.0f %unit%" readOnly="true"/>
</channel-type> </channel-type>
<channel-type id="side_brush_time" advanced="true"> <channel-type id="side_brush_time" advanced="true">
<item-type>Number</item-type> <item-type>Number:Time</item-type>
<label>Side Brush Hours till Replacement</label> <label>Side Brush Time till Replacement</label>
<state pattern="%.0fh" readOnly="true"/> <state pattern="%.0f %unit%" readOnly="true"/>
</channel-type> </channel-type>
<channel-type id="filter_time" advanced="true"> <channel-type id="filter_time" advanced="true">
<item-type>Number</item-type> <item-type>Number:Time</item-type>
<label>Filter Hours till Replacement</label> <label>Filter Time till Replacement</label>
<state pattern="%.0fh" readOnly="true"/> <state pattern="%.0f %unit%" readOnly="true"/>
</channel-type> </channel-type>
<channel-type id="sensor_dirt_time" advanced="true"> <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> <label>Sensor Dirt Time till Cleaning</label>
<state pattern="%.0fh" readOnly="true"/> <state pattern="%.0f %unit%" readOnly="true"/>
</channel-type> </channel-type>
<!-- actions --> <!-- actions -->
@ -292,15 +292,14 @@
<!-- Clean History --> <!-- Clean History -->
<channel-type id="total_clean_time"> <channel-type id="total_clean_time">
<item-type>Number</item-type> <item-type>Number:Time</item-type>
<label>Total Cleaning Time</label> <label>Total Cleaning Time</label>
<description>Total Cleaning Time in minutes</description> <state pattern="%.0f %unit%" readOnly="true"/>
<state pattern="%.0f'" readOnly="true"/>
</channel-type> </channel-type>
<channel-type id="total_clean_area"> <channel-type id="total_clean_area">
<item-type>Number</item-type> <item-type>Number:Area</item-type>
<label>Total Cleaning Area</label> <label>Total Cleaning Area</label>
<state pattern="%.1f " readOnly="true"/> <state pattern="%.1f %unit%" readOnly="true"/>
</channel-type> </channel-type>
<channel-type id="total_clean_count"> <channel-type id="total_clean_count">
<item-type>Number</item-type> <item-type>Number</item-type>
@ -324,15 +323,14 @@
<state readOnly="true"/> <state readOnly="true"/>
</channel-type> </channel-type>
<channel-type id="last_clean_duration"> <channel-type id="last_clean_duration">
<item-type>Number</item-type> <item-type>Number:Time</item-type>
<label>Cleaning Duration</label> <label>Cleaning Duration</label>
<description>Cleaning Duration in minutes</description> <state pattern="%.0f %unit%" readOnly="true"/>
<state pattern="%.0f'" readOnly="true"/>
</channel-type> </channel-type>
<channel-type id="last_clean_area"> <channel-type id="last_clean_area">
<item-type>Number</item-type> <item-type>Number:Area</item-type>
<label>Cleaning Area</label> <label>Cleaning Area</label>
<state pattern="%.1f " readOnly="true"/> <state pattern="%.1f %unit%" readOnly="true"/>
</channel-type> </channel-type>
<channel-type id="last_clean_error"> <channel-type id="last_clean_error">
<item-type>Number</item-type> <item-type>Number</item-type>