Simplify DateTimeType handling for Robonect (#17872)
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>pull/17877/head
parent
5cd8140d73
commit
18d85e68bf
|
@ -18,7 +18,6 @@ import java.time.DateTimeException;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZoneOffset;
|
import java.time.ZoneOffset;
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
@ -304,9 +303,7 @@ public class RobonectHandler extends BaseThingHandler {
|
||||||
long adjustedTime = rawInstant.getEpochSecond() - offsetToConfiguredZone.getTotalSeconds();
|
long adjustedTime = rawInstant.getEpochSecond() - offsetToConfiguredZone.getTotalSeconds();
|
||||||
Instant adjustedInstant = Instant.ofEpochMilli(adjustedTime * 1000);
|
Instant adjustedInstant = Instant.ofEpochMilli(adjustedTime * 1000);
|
||||||
|
|
||||||
// we provide the time in the format as configured in the openHAB settings
|
return new DateTimeType(adjustedInstant);
|
||||||
ZonedDateTime zdt = adjustedInstant.atZone(timeZoneProvider.getTimeZone());
|
|
||||||
return new DateTimeType(zdt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshVersionInfo() {
|
private void refreshVersionInfo() {
|
||||||
|
|
|
@ -64,20 +64,22 @@ import org.openhab.core.types.UnDefType;
|
||||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
public class RobonectHandlerTest {
|
public class RobonectHandlerTest {
|
||||||
|
|
||||||
|
private static final ZoneId TIME_ZONE = ZoneId.of("Europe/Berlin");
|
||||||
|
|
||||||
private RobonectHandler subject;
|
private RobonectHandler subject;
|
||||||
|
|
||||||
private @Mock Thing robonectThingMock;
|
private @Mock Thing robonectThingMock;
|
||||||
private @Mock RobonectClient robonectClientMock;
|
private @Mock RobonectClient robonectClientMock;
|
||||||
private @Mock ThingHandlerCallback callbackMock;
|
private @Mock ThingHandlerCallback callbackMock;
|
||||||
private @Mock HttpClientFactory httpClientFactoryMock;
|
private @Mock HttpClientFactory httpClientFactoryMock;
|
||||||
private @Mock TimeZoneProvider timezoneProvider;
|
private @Mock TimeZoneProvider timeZoneProvider;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
Mockito.when(robonectThingMock.getUID()).thenReturn(new ThingUID("1:2:3"));
|
Mockito.when(robonectThingMock.getUID()).thenReturn(new ThingUID("1:2:3"));
|
||||||
Mockito.when(timezoneProvider.getTimeZone()).thenReturn(ZoneId.of("Europe/Berlin"));
|
Mockito.when(timeZoneProvider.getTimeZone()).thenReturn(TIME_ZONE);
|
||||||
|
|
||||||
subject = new RobonectHandler(robonectThingMock, httpClientFactoryMock, timezoneProvider);
|
subject = new RobonectHandler(robonectThingMock, httpClientFactoryMock, timeZoneProvider);
|
||||||
subject.setCallback(callbackMock);
|
subject.setCallback(callbackMock);
|
||||||
subject.setRobonectClient(robonectClientMock);
|
subject.setRobonectClient(robonectClientMock);
|
||||||
}
|
}
|
||||||
|
@ -110,7 +112,7 @@ public class RobonectHandlerTest {
|
||||||
State value = stateCaptor.getValue();
|
State value = stateCaptor.getValue();
|
||||||
assertTrue(value instanceof DateTimeType);
|
assertTrue(value instanceof DateTimeType);
|
||||||
|
|
||||||
ZonedDateTime zdt = ((DateTimeType) value).getZonedDateTime();
|
ZonedDateTime zdt = ((DateTimeType) value).getZonedDateTime(TIME_ZONE);
|
||||||
assertEquals(1, zdt.getDayOfMonth());
|
assertEquals(1, zdt.getDayOfMonth());
|
||||||
assertEquals(2017, zdt.getYear());
|
assertEquals(2017, zdt.getYear());
|
||||||
assertEquals(Month.MAY, zdt.getMonth());
|
assertEquals(Month.MAY, zdt.getMonth());
|
||||||
|
@ -159,7 +161,7 @@ public class RobonectHandlerTest {
|
||||||
State errorDate = errorDateCaptor.getValue();
|
State errorDate = errorDateCaptor.getValue();
|
||||||
assertTrue(errorDate instanceof DateTimeType);
|
assertTrue(errorDate instanceof DateTimeType);
|
||||||
|
|
||||||
ZonedDateTime zdt = ((DateTimeType) errorDate).getZonedDateTime();
|
ZonedDateTime zdt = ((DateTimeType) errorDate).getZonedDateTime(TIME_ZONE);
|
||||||
assertEquals(1, zdt.getDayOfMonth());
|
assertEquals(1, zdt.getDayOfMonth());
|
||||||
assertEquals(2017, zdt.getYear());
|
assertEquals(2017, zdt.getYear());
|
||||||
assertEquals(Month.MAY, zdt.getMonth());
|
assertEquals(Month.MAY, zdt.getMonth());
|
||||||
|
|
Loading…
Reference in New Issue