Skip to content

Commit

Permalink
Simplify DateTimeType handling for aWATTar
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Laursen <[email protected]>
  • Loading branch information
jlaur committed Nov 11, 2024
1 parent b479ee2 commit d397b88
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.Units;

Expand All @@ -47,10 +46,6 @@ public static ZonedDateTime getCalendarForHour(int hour, ZoneId zone) {
return ZonedDateTime.now(zone).truncatedTo(ChronoUnit.DAYS).plusHours(hour);
}

public static DateTimeType getDateTimeType(long time, TimeZoneProvider tz) {
return new DateTimeType(ZonedDateTime.ofInstant(Instant.ofEpochMilli(time), tz.getTimeZone()));
}

public static QuantityType<Time> getDuration(long millis) {
long minutes = millis / 60000;
return QuantityType.valueOf(minutes, Units.MINUTE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.openhab.binding.awattar.internal.AwattarBindingConstants.CHANNEL_REMAINING;
import static org.openhab.binding.awattar.internal.AwattarBindingConstants.CHANNEL_START;
import static org.openhab.binding.awattar.internal.AwattarUtil.getCalendarForHour;
import static org.openhab.binding.awattar.internal.AwattarUtil.getDateTimeType;
import static org.openhab.binding.awattar.internal.AwattarUtil.getDuration;
import static org.openhab.binding.awattar.internal.AwattarUtil.getMillisToNextMinute;

Expand Down Expand Up @@ -188,10 +187,10 @@ public void refreshChannel(ChannelUID channelUID) {
state = OnOffType.from(result.isActive());
break;
case CHANNEL_START:
state = getDateTimeType(result.getStart(), timeZoneProvider);
state = new DateTimeType(Instant.ofEpochMilli(result.getStart()));
break;
case CHANNEL_END:
state = getDateTimeType(result.getEnd(), timeZoneProvider);
state = new DateTimeType(Instant.ofEpochMilli(result.getEnd()));
break;
case CHANNEL_COUNTDOWN:
diff = result.getStart() - Instant.now().toEpochMilli();
Expand Down

0 comments on commit d397b88

Please sign in to comment.