mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 07:02:02 +01:00
Simplify DateTimeType handling for InfluxDB
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
bc540c6653
commit
e794c6a0f6
@ -14,8 +14,6 @@ package org.openhab.persistence.influxdb.internal;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.Instant;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import javax.measure.Unit;
|
||||
|
||||
@ -85,7 +83,7 @@ public class InfluxDBStateConvertUtils {
|
||||
} else if (state instanceof OpenClosedType) {
|
||||
value = state == OpenClosedType.OPEN ? DIGITAL_VALUE_ON : DIGITAL_VALUE_OFF;
|
||||
} else if (state instanceof DateTimeType type) {
|
||||
value = type.getZonedDateTime().toInstant().toEpochMilli();
|
||||
value = type.getInstant().toEpochMilli();
|
||||
} else {
|
||||
value = state.toFullString();
|
||||
}
|
||||
@ -140,9 +138,7 @@ public class InfluxDBStateConvertUtils {
|
||||
} else if (item instanceof RollershutterItem) {
|
||||
return new PercentType(valueStr);
|
||||
} else if (item instanceof DateTimeItem) {
|
||||
Instant i = Instant.ofEpochMilli(new BigDecimal(valueStr).longValue());
|
||||
ZonedDateTime z = ZonedDateTime.ofInstant(i, TimeZone.getDefault().toZoneId());
|
||||
return new DateTimeType(z);
|
||||
return new DateTimeType(Instant.ofEpochMilli(new BigDecimal(valueStr).longValue()));
|
||||
} else if (item instanceof PlayerItem) {
|
||||
try {
|
||||
return PlayPauseType.valueOf(valueStr);
|
||||
|
@ -21,7 +21,6 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
import javax.measure.Unit;
|
||||
@ -130,8 +129,7 @@ public class InfluxDBStateConvertUtilsTest {
|
||||
long val = System.currentTimeMillis();
|
||||
DateTimeItem item = new DateTimeItem("name");
|
||||
|
||||
DateTimeType expected = new DateTimeType(
|
||||
ZonedDateTime.ofInstant(Instant.ofEpochMilli(val), ZoneId.systemDefault()));
|
||||
DateTimeType expected = new DateTimeType(Instant.ofEpochMilli(val));
|
||||
assertThat(InfluxDBStateConvertUtils.objectToState(val, item), equalTo(expected));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user