mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
Simplify DateTimeType handling for aWATTar
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk> Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
parent
723d7879de
commit
4deb208c8a
@ -21,7 +21,6 @@ import javax.measure.quantity.Time;
|
||||
|
||||
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;
|
||||
|
||||
@ -47,10 +46,6 @@ public class AwattarUtil {
|
||||
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);
|
||||
|
@ -20,7 +20,6 @@ import static org.openhab.binding.awattar.internal.AwattarBindingConstants.CHANN
|
||||
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;
|
||||
|
||||
@ -41,6 +40,7 @@ import org.openhab.binding.awattar.internal.AwattarConsecutiveBestPriceResult;
|
||||
import org.openhab.binding.awattar.internal.AwattarNonConsecutiveBestPriceResult;
|
||||
import org.openhab.binding.awattar.internal.AwattarPrice;
|
||||
import org.openhab.core.i18n.TimeZoneProvider;
|
||||
import org.openhab.core.library.types.DateTimeType;
|
||||
import org.openhab.core.library.types.OnOffType;
|
||||
import org.openhab.core.library.types.QuantityType;
|
||||
import org.openhab.core.library.types.StringType;
|
||||
@ -166,10 +166,10 @@ public class AwattarBestPriceHandler extends BaseThingHandler {
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user