Skip to content

Commit

Permalink
Fix DateTimeType deprecations (openhab#7948)
Browse files Browse the repository at this point in the history
Related to:

* openhab/openhab-core#1500
* openhab#7918

Signed-off-by: Wouter Born <github@maindrain.net>
Signed-off-by: Daan Meijer <daan@studioseptember.nl>
  • Loading branch information
wborn authored and DaanMeijer committed Sep 1, 2020
1 parent 766014a commit c44935b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

import static org.openhab.binding.lametrictime.internal.LaMetricTimeBindingConstants.*;

import java.time.Instant;
import java.time.LocalTime;
import java.time.ZoneId;

import org.eclipse.smarthome.core.library.types.DateTimeType;
import org.eclipse.smarthome.core.library.types.StringType;
Expand Down Expand Up @@ -52,8 +50,7 @@ public void handleAppCommand(ChannelUID channelUID, Command command) {
try {
switch (channelUID.getId()) {
case CHANNEL_APP_SET_ALARM: {
LocalTime time = Instant.ofEpochMilli(((DateTimeType) command).getCalendar().getTimeInMillis())
.atZone(ZoneId.systemDefault()).toLocalTime();
LocalTime time = ((DateTimeType) command).getZonedDateTime().toLocalTime();
getDevice().doAction(getWidget(), CoreApps.clock().setAlarm(true, time, null));
updateActiveAppOnDevice();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
package org.openhab.binding.lutron.internal.grxprg;

import java.io.IOException;
import java.util.Calendar;
import java.time.ZonedDateTime;
import java.util.GregorianCalendar;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -167,8 +168,8 @@ public void handleCommand(ChannelUID channelUID, Command command) {

} else if (id.equals(PrgConstants.CHANNEL_TIMECLOCK)) {
if (command instanceof DateTimeType) {
final Calendar c = ((DateTimeType) command).getCalendar();
_protocolHandler.setTime(c);
final ZonedDateTime zdt = ((DateTimeType) command).getZonedDateTime();
_protocolHandler.setTime(GregorianCalendar.from(zdt));
} else {
logger.error("Received a TIMECLOCK channel command with a non DateTimeType: {}", command);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;

import java.time.Month;
import java.time.ZoneId;
import java.util.Calendar;
import java.time.ZonedDateTime;

import org.eclipse.jetty.client.HttpClient;
import org.eclipse.smarthome.core.i18n.TimeZoneProvider;
Expand Down Expand Up @@ -113,15 +114,14 @@ public void shouldUpdateNextTimerChannelWithDateTimeState() throws InterruptedEx

State value = stateCaptor.getValue();
assertTrue(value instanceof DateTimeType);
DateTimeType dateTimeType = (DateTimeType) value;
assertEquals(1, dateTimeType.getCalendar().get(Calendar.DAY_OF_MONTH));

assertEquals(2017, dateTimeType.getCalendar().get(Calendar.YEAR));
// calendar january is 0
assertEquals(4, dateTimeType.getCalendar().get(Calendar.MONTH));
assertEquals(19, dateTimeType.getCalendar().get(Calendar.HOUR_OF_DAY));
assertEquals(0, dateTimeType.getCalendar().get(Calendar.MINUTE));
assertEquals(0, dateTimeType.getCalendar().get(Calendar.SECOND));

ZonedDateTime zdt = ((DateTimeType) value).getZonedDateTime();
assertEquals(1, zdt.getDayOfMonth());
assertEquals(2017, zdt.getYear());
assertEquals(Month.MAY, zdt.getMonth());
assertEquals(19, zdt.getHour());
assertEquals(0, zdt.getMinute());
assertEquals(0, zdt.getSecond());
}

@Test
Expand All @@ -136,7 +136,7 @@ public void shouldUpdateErrorChannelsIfErrorStatusReturned() throws InterruptedE
error.setDate("01.05.2017");
error.setTime("19:00:00");
error.setUnix("1493665200");
error.setErrorCode(new Integer(22));
error.setErrorCode(Integer.valueOf(22));
error.setErrorMessage("Dummy Message");
mowerInfo.getStatus().setStatus(MowerStatus.ERROR_STATUS);
mowerInfo.setError(error);
Expand Down Expand Up @@ -164,14 +164,14 @@ public void shouldUpdateErrorChannelsIfErrorStatusReturned() throws InterruptedE

State errorDate = errorDateCaptor.getValue();
assertTrue(errorDate instanceof DateTimeType);
DateTimeType dateTimeType = (DateTimeType) errorDate;
assertEquals(1, dateTimeType.getCalendar().get(Calendar.DAY_OF_MONTH));
assertEquals(2017, dateTimeType.getCalendar().get(Calendar.YEAR));
// calendar january is 0
assertEquals(4, dateTimeType.getCalendar().get(Calendar.MONTH));
assertEquals(19, dateTimeType.getCalendar().get(Calendar.HOUR_OF_DAY));
assertEquals(0, dateTimeType.getCalendar().get(Calendar.MINUTE));
assertEquals(0, dateTimeType.getCalendar().get(Calendar.SECOND));

ZonedDateTime zdt = ((DateTimeType) errorDate).getZonedDateTime();
assertEquals(1, zdt.getDayOfMonth());
assertEquals(2017, zdt.getYear());
assertEquals(Month.MAY, zdt.getMonth());
assertEquals(19, zdt.getHour());
assertEquals(0, zdt.getMinute());
assertEquals(0, zdt.getSecond());

State errorMessage = errorMessageCaptor.getValue();
assertTrue(errorMessage instanceof StringType);
Expand Down Expand Up @@ -298,8 +298,8 @@ public void shouldUpdateAllChannels() {
assertEquals("Mowy", stateCaptorName.getValue().toFullString());
assertEquals(99, ((DecimalType) stateCaptorBattery.getValue()).intValue());
assertEquals(4, ((DecimalType) stateCaptorStatus.getValue()).intValue());
assertEquals(55, ((QuantityType) stateCaptorDuration.getValue()).intValue());
assertEquals(22, ((QuantityType) stateCaptorHours.getValue()).intValue());
assertEquals(55, ((QuantityType<?>) stateCaptorDuration.getValue()).intValue());
assertEquals(22, ((QuantityType<?>) stateCaptorHours.getValue()).intValue());
assertEquals(MowerMode.AUTO.name(), stateCaptorMode.getValue().toFullString());
assertEquals(OnOffType.ON, stateCaptorStarted.getValue());
assertEquals(-88, ((DecimalType) stateCaptorWlan.getValue()).intValue());
Expand Down

0 comments on commit c44935b

Please sign in to comment.