Simplify DateTimeType handling for Mi IO

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen 2024-11-09 22:29:18 +01:00 committed by lsiepel
parent daabae72e0
commit bad29eb653
2 changed files with 4 additions and 5 deletions

View File

@ -552,12 +552,12 @@ public class MiIoVacuumHandler extends MiIoAbstractHandler {
JsonObject historyRecord = GSON.toJsonTree(historyRecordDTO).getAsJsonObject();
if (historyRecordDTO.getStart() != null) {
DateTimeType start = new DateTimeType(historyRecordDTO.getStart());
historyRecord.addProperty("start", start.toLocaleZone().format(null));
historyRecord.addProperty("start", start.format(null));
updateState(CHANNEL_HISTORY_START_TIME, start);
}
if (historyRecordDTO.getEnd() != null) {
DateTimeType end = new DateTimeType(historyRecordDTO.getEnd());
historyRecord.addProperty("end", end.toLocaleZone().format(null));
historyRecord.addProperty("end", end.format(null));
updateState(CHANNEL_HISTORY_END_TIME, end);
}
if (historyRecordDTO.getDuration() != null) {

View File

@ -17,7 +17,6 @@ import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.io.IOException;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.concurrent.TimeUnit;
@ -132,11 +131,11 @@ public class MiIoVacuumHandlerTest {
verify(callback, description("Test the start time parsing")).stateUpdated(
eq(new ChannelUID(thingUID, MiIoBindingConstants.CHANNEL_HISTORY_START_TIME)),
eq(new DateTimeType(ZonedDateTime.parse("2024-08-20T19:20:13+02:00")).toZone(ZoneId.systemDefault())));
eq(new DateTimeType(ZonedDateTime.parse("2024-08-20T19:20:13+02:00"))));
verify(callback, description("Test the end time parsing")).stateUpdated(
eq(new ChannelUID(thingUID, MiIoBindingConstants.CHANNEL_HISTORY_END_TIME)),
eq(new DateTimeType(ZonedDateTime.parse("2024-08-20T19:20:59+02:00")).toZone(ZoneId.systemDefault())));
eq(new DateTimeType(ZonedDateTime.parse("2024-08-20T19:20:59+02:00"))));
verify(callback, description("Test the duration parsing")).stateUpdated(
eq(new ChannelUID(thingUID, MiIoBindingConstants.CHANNEL_HISTORY_DURATION)),