mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[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:
parent
d41927c703
commit
158cbe0c65
@ -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()));
|
||||
|
@ -99,12 +99,12 @@
|
||||
<channel-type id="clean_area">
|
||||
<item-type>Number</item-type>
|
||||
<label>Cleaning Area</label>
|
||||
<state pattern="%.2f m²" 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>
|
||||
@ -201,24 +201,24 @@
|
||||
<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 -->
|
||||
@ -292,15 +292,14 @@
|
||||
|
||||
<!-- 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 m²" readOnly="true"/>
|
||||
<state pattern="%.1f %unit%" readOnly="true"/>
|
||||
</channel-type>
|
||||
<channel-type id="total_clean_count">
|
||||
<item-type>Number</item-type>
|
||||
@ -324,15 +323,14 @@
|
||||
<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 m²" readOnly="true"/>
|
||||
<state pattern="%.1f %unit%" readOnly="true"/>
|
||||
</channel-type>
|
||||
<channel-type id="last_clean_error">
|
||||
<item-type>Number</item-type>
|
||||
|
Loading…
Reference in New Issue
Block a user