mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
Simplify DateTimeType handling for WeMo
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
82813cdcd4
commit
328e91a7fc
@ -15,8 +15,6 @@ package org.openhab.binding.wemo.internal;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -116,12 +114,10 @@ public class InsightParser {
|
||||
return UnDefType.UNDEF;
|
||||
}
|
||||
|
||||
State lastChangedAtState = new DateTimeType(
|
||||
ZonedDateTime.ofInstant(Instant.ofEpochSecond(lastChangedAt), ZoneId.systemDefault()));
|
||||
if (lastChangedAt == 0) {
|
||||
return UnDefType.UNDEF;
|
||||
}
|
||||
return lastChangedAtState;
|
||||
return new DateTimeType(Instant.ofEpochSecond(lastChangedAt));
|
||||
}
|
||||
|
||||
private State getNumber(String value) {
|
||||
|
@ -17,9 +17,7 @@ import static org.openhab.binding.wemo.internal.WemoUtil.*;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.time.Instant;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -345,8 +343,7 @@ public class WemoCoffeeHandler extends WemoBaseThingHandler {
|
||||
getThing().getUID());
|
||||
return null;
|
||||
}
|
||||
ZonedDateTime zoned = ZonedDateTime.ofInstant(Instant.ofEpochSecond(value), TimeZone.getDefault().toZoneId());
|
||||
State dateTimeState = new DateTimeType(zoned);
|
||||
State dateTimeState = new DateTimeType(Instant.ofEpochSecond(value));
|
||||
logger.trace("New attribute brewed '{}' received", dateTimeState);
|
||||
return dateTimeState;
|
||||
}
|
||||
|
@ -16,12 +16,10 @@ import static org.openhab.binding.wemo.internal.WemoBindingConstants.*;
|
||||
import static org.openhab.binding.wemo.internal.WemoUtil.*;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -502,8 +500,7 @@ public class WemoDimmerHandler extends WemoBaseThingHandler {
|
||||
getThing().getUID());
|
||||
return null;
|
||||
}
|
||||
ZonedDateTime zoned = ZonedDateTime.ofInstant(Instant.ofEpochSecond(value), TimeZone.getDefault().toZoneId());
|
||||
return new DateTimeType(zoned);
|
||||
return new DateTimeType(Instant.ofEpochSecond(value));
|
||||
}
|
||||
|
||||
public void setBinaryState(String action, String argument, String value) {
|
||||
|
@ -15,7 +15,6 @@ package org.openhab.binding.wemo;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -47,7 +46,7 @@ public class InsightParserTest {
|
||||
"1|1645800647|109676|80323|1196960|1209600|44|41400|30288361|483361410|8000");
|
||||
Map<String, State> result = parser.parse();
|
||||
assertEquals(OnOffType.ON, result.get(WemoBindingConstants.CHANNEL_STATE));
|
||||
assertEquals(DateTimeType.valueOf("2022-02-25T15:50:47.000+0100").toZone(ZoneId.systemDefault()),
|
||||
assertEquals(DateTimeType.valueOf("2022-02-25T15:50:47.000+0100"),
|
||||
result.get(WemoBindingConstants.CHANNEL_LAST_CHANGED_AT));
|
||||
assertEquals(new DecimalType(109_676), result.get(WemoBindingConstants.CHANNEL_LAST_ON_FOR));
|
||||
assertEquals(new DecimalType(80_323), result.get(WemoBindingConstants.CHANNEL_ON_TODAY));
|
||||
@ -69,7 +68,7 @@ public class InsightParserTest {
|
||||
InsightParser parser = new InsightParser("8|1645967627|0|0|0|1209600|13|0|0|0.000000|8000");
|
||||
Map<String, State> result = parser.parse();
|
||||
assertEquals(OnOffType.ON, result.get(WemoBindingConstants.CHANNEL_STATE));
|
||||
assertEquals(DateTimeType.valueOf("2022-02-27T14:13:47.000+0100").toZone(ZoneId.systemDefault()),
|
||||
assertEquals(DateTimeType.valueOf("2022-02-27T14:13:47.000+0100"),
|
||||
result.get(WemoBindingConstants.CHANNEL_LAST_CHANGED_AT));
|
||||
assertEquals(new DecimalType(0), result.get(WemoBindingConstants.CHANNEL_LAST_ON_FOR));
|
||||
assertEquals(new DecimalType(0), result.get(WemoBindingConstants.CHANNEL_ON_TODAY));
|
||||
@ -92,7 +91,7 @@ public class InsightParserTest {
|
||||
"1|1645800647|109676|80323|1196960|1209600|44|41400|30288361|483361410");
|
||||
Map<String, State> result = parser.parse();
|
||||
assertEquals(OnOffType.ON, result.get(WemoBindingConstants.CHANNEL_STATE));
|
||||
assertEquals(DateTimeType.valueOf("2022-02-25T15:50:47.000+0100").toZone(ZoneId.systemDefault()),
|
||||
assertEquals(DateTimeType.valueOf("2022-02-25T15:50:47.000+0100"),
|
||||
result.get(WemoBindingConstants.CHANNEL_LAST_CHANGED_AT));
|
||||
assertEquals(new DecimalType(109_676), result.get(WemoBindingConstants.CHANNEL_LAST_ON_FOR));
|
||||
assertEquals(new DecimalType(80_323), result.get(WemoBindingConstants.CHANNEL_ON_TODAY));
|
||||
|
Loading…
Reference in New Issue
Block a user