Skip to content

Commit 18d85e6

Browse files
authored
Simplify DateTimeType handling for Robonect (openhab#17872)
Signed-off-by: Jacob Laursen <[email protected]>
1 parent 5cd8140 commit 18d85e6

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

bundles/org.openhab.binding.robonect/src/main/java/org/openhab/binding/robonect/internal/handler/RobonectHandler.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.time.Instant;
1919
import java.time.ZoneId;
2020
import java.time.ZoneOffset;
21-
import java.time.ZonedDateTime;
2221
import java.util.List;
2322
import java.util.Map;
2423
import java.util.concurrent.ScheduledFuture;
@@ -304,9 +303,7 @@ private State convertUnixToDateTimeType(String unixTimeSec) {
304303
long adjustedTime = rawInstant.getEpochSecond() - offsetToConfiguredZone.getTotalSeconds();
305304
Instant adjustedInstant = Instant.ofEpochMilli(adjustedTime * 1000);
306305

307-
// we provide the time in the format as configured in the openHAB settings
308-
ZonedDateTime zdt = adjustedInstant.atZone(timeZoneProvider.getTimeZone());
309-
return new DateTimeType(zdt);
306+
return new DateTimeType(adjustedInstant);
310307
}
311308

312309
private void refreshVersionInfo() {

bundles/org.openhab.binding.robonect/src/test/java/org/openhab/binding/robonect/internal/handler/RobonectHandlerTest.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,22 @@
6464
@MockitoSettings(strictness = Strictness.LENIENT)
6565
public class RobonectHandlerTest {
6666

67+
private static final ZoneId TIME_ZONE = ZoneId.of("Europe/Berlin");
68+
6769
private RobonectHandler subject;
6870

6971
private @Mock Thing robonectThingMock;
7072
private @Mock RobonectClient robonectClientMock;
7173
private @Mock ThingHandlerCallback callbackMock;
7274
private @Mock HttpClientFactory httpClientFactoryMock;
73-
private @Mock TimeZoneProvider timezoneProvider;
75+
private @Mock TimeZoneProvider timeZoneProvider;
7476

7577
@BeforeEach
7678
public void setUp() {
7779
Mockito.when(robonectThingMock.getUID()).thenReturn(new ThingUID("1:2:3"));
78-
Mockito.when(timezoneProvider.getTimeZone()).thenReturn(ZoneId.of("Europe/Berlin"));
80+
Mockito.when(timeZoneProvider.getTimeZone()).thenReturn(TIME_ZONE);
7981

80-
subject = new RobonectHandler(robonectThingMock, httpClientFactoryMock, timezoneProvider);
82+
subject = new RobonectHandler(robonectThingMock, httpClientFactoryMock, timeZoneProvider);
8183
subject.setCallback(callbackMock);
8284
subject.setRobonectClient(robonectClientMock);
8385
}
@@ -110,7 +112,7 @@ public void shouldUpdateNextTimerChannelWithDateTimeState() throws InterruptedEx
110112
State value = stateCaptor.getValue();
111113
assertTrue(value instanceof DateTimeType);
112114

113-
ZonedDateTime zdt = ((DateTimeType) value).getZonedDateTime();
115+
ZonedDateTime zdt = ((DateTimeType) value).getZonedDateTime(TIME_ZONE);
114116
assertEquals(1, zdt.getDayOfMonth());
115117
assertEquals(2017, zdt.getYear());
116118
assertEquals(Month.MAY, zdt.getMonth());
@@ -159,7 +161,7 @@ public void shouldUpdateErrorChannelsIfErrorStatusReturned() throws InterruptedE
159161
State errorDate = errorDateCaptor.getValue();
160162
assertTrue(errorDate instanceof DateTimeType);
161163

162-
ZonedDateTime zdt = ((DateTimeType) errorDate).getZonedDateTime();
164+
ZonedDateTime zdt = ((DateTimeType) errorDate).getZonedDateTime(TIME_ZONE);
163165
assertEquals(1, zdt.getDayOfMonth());
164166
assertEquals(2017, zdt.getYear());
165167
assertEquals(Month.MAY, zdt.getMonth());

0 commit comments

Comments
 (0)