[aWATTar] fix counddown and remaining time (#17067)

Signed-off-by: Thomas Leber <thomas@tl-photography.at>
This commit is contained in:
tl-photography 2024-07-21 10:24:54 +02:00 committed by GitHub
parent 5aec1c8a89
commit 2f8e9adf16
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -44,7 +44,9 @@ 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.OnOffType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ChannelUID;
@ -195,12 +197,16 @@ public class AwattarBestPriceHandler extends BaseThingHandler {
diff = result.getStart() - Instant.now().toEpochMilli();
if (diff >= 0) {
state = getDuration(diff);
} else {
state = QuantityType.valueOf(0, Units.MINUTE);
}
break;
case CHANNEL_REMAINING:
diff = result.getEnd() - Instant.now().toEpochMilli();
if (result.isActive()) {
diff = result.getEnd() - Instant.now().toEpochMilli();
state = getDuration(diff);
} else {
state = QuantityType.valueOf(0, Units.MINUTE);
}
break;
case CHANNEL_HOURS: