Skip to content

Commit

Permalink
Simplify DateTimeType handling for Robonect (openhab#17872)
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Laursen <[email protected]>
  • Loading branch information
jlaur authored and matchews committed Dec 16, 2024
1 parent def3f83 commit ec13d37
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ScheduledFuture;
Expand Down Expand Up @@ -304,9 +303,7 @@ private State convertUnixToDateTimeType(String unixTimeSec) {
long adjustedTime = rawInstant.getEpochSecond() - offsetToConfiguredZone.getTotalSeconds();
Instant adjustedInstant = Instant.ofEpochMilli(adjustedTime * 1000);

// we provide the time in the format as configured in the openHAB settings
ZonedDateTime zdt = adjustedInstant.atZone(timeZoneProvider.getTimeZone());
return new DateTimeType(zdt);
return new DateTimeType(adjustedInstant);
}

private void refreshVersionInfo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,22 @@
@MockitoSettings(strictness = Strictness.LENIENT)
public class RobonectHandlerTest {

private static final ZoneId TIME_ZONE = ZoneId.of("Europe/Berlin");

private RobonectHandler subject;

private @Mock Thing robonectThingMock;
private @Mock RobonectClient robonectClientMock;
private @Mock ThingHandlerCallback callbackMock;
private @Mock HttpClientFactory httpClientFactoryMock;
private @Mock TimeZoneProvider timezoneProvider;
private @Mock TimeZoneProvider timeZoneProvider;

@BeforeEach
public void setUp() {
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.setRobonectClient(robonectClientMock);
}
Expand Down Expand Up @@ -110,7 +112,7 @@ public void shouldUpdateNextTimerChannelWithDateTimeState() throws InterruptedEx
State value = stateCaptor.getValue();
assertTrue(value instanceof DateTimeType);

ZonedDateTime zdt = ((DateTimeType) value).getZonedDateTime();
ZonedDateTime zdt = ((DateTimeType) value).getZonedDateTime(TIME_ZONE);
assertEquals(1, zdt.getDayOfMonth());
assertEquals(2017, zdt.getYear());
assertEquals(Month.MAY, zdt.getMonth());
Expand Down Expand Up @@ -159,7 +161,7 @@ public void shouldUpdateErrorChannelsIfErrorStatusReturned() throws InterruptedE
State errorDate = errorDateCaptor.getValue();
assertTrue(errorDate instanceof DateTimeType);

ZonedDateTime zdt = ((DateTimeType) errorDate).getZonedDateTime();
ZonedDateTime zdt = ((DateTimeType) errorDate).getZonedDateTime(TIME_ZONE);
assertEquals(1, zdt.getDayOfMonth());
assertEquals(2017, zdt.getYear());
assertEquals(Month.MAY, zdt.getMonth());
Expand Down

0 comments on commit ec13d37

Please sign in to comment.