]> git.basschouten.com Git - openhab-addons.git/commitdiff
[aWATTar] fix counddown and remaining time (#17067)
authortl-photography <thomas@tl-photography.at>
Sun, 21 Jul 2024 08:24:54 +0000 (10:24 +0200)
committerGitHub <noreply@github.com>
Sun, 21 Jul 2024 08:24:54 +0000 (10:24 +0200)
Signed-off-by: Thomas Leber <thomas@tl-photography.at>
bundles/org.openhab.binding.awattar/src/main/java/org/openhab/binding/awattar/internal/handler/AwattarBestPriceHandler.java

index ca0e911942ba70c30d0f529da6cdfe65e386a66c..7645308313ece6ecc571ed6a22f463ed24673125 100644 (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: