From c790995846e4026c3c985d07e980c05244c7b4c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20L=27hopital?= Date: Sat, 2 May 2020 14:13:05 +0200 Subject: [PATCH] Adding next season to Astro (#7517) Signed-off-by: clinique --- bundles/org.openhab.binding.astro/README.md | 3 ++- .../internal/handler/AstroThingHandler.java | 2 +- .../binding/astro/internal/model/Season.java | 27 +++++++++++++++++++ .../main/resources/ESH-INF/thing/channels.xml | 8 ++++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/bundles/org.openhab.binding.astro/README.md b/bundles/org.openhab.binding.astro/README.md index 2de237b309078..26c3fb531b513 100644 --- a/bundles/org.openhab.binding.astro/README.md +++ b/bundles/org.openhab.binding.astro/README.md @@ -46,7 +46,8 @@ Optionally, a refresh `interval` (in seconds) can be defined to also calculate p * **group** `season` * **channel**: * `spring, summer, autumn, winter` (DateTime) - * `name` (String), values `SPRING, SUMMER, AUTUMN, WINTER` + * `name`,`nextName` (String), values `SPRING, SUMMER, AUTUMN, WINTER` + * `timeLeft` (Number:Time) * **group** `eclipse` * **channel**: * `total, partial, ring` (DateTime) diff --git a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/handler/AstroThingHandler.java b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/handler/AstroThingHandler.java index 20eb9e5543a91..ca7ee6a025ef9 100644 --- a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/handler/AstroThingHandler.java +++ b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/handler/AstroThingHandler.java @@ -66,7 +66,7 @@ public abstract class AstroThingHandler extends BaseThingHandler { protected AstroThingConfig thingConfig; private final Lock monitor = new ReentrantLock(); - private ScheduledCompletableFuture dailyJob; + private ScheduledCompletableFuture dailyJob; private final Set> scheduledFutures = new HashSet<>(); public AstroThingHandler(Thing thing, CronScheduler scheduler) { diff --git a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/model/Season.java b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/model/Season.java index d298aefeea07c..4a66133a5e4ad 100644 --- a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/model/Season.java +++ b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/model/Season.java @@ -12,8 +12,14 @@ */ package org.openhab.binding.astro.internal.model; +import static org.eclipse.smarthome.core.library.unit.MetricPrefix.MILLI; + import java.util.Calendar; +import javax.measure.quantity.Time; + +import org.eclipse.smarthome.core.library.types.QuantityType; +import org.eclipse.smarthome.core.library.unit.SmartHomeUnits; import org.openhab.binding.astro.internal.util.DateTimeUtils; /** @@ -105,4 +111,25 @@ public void setName(SeasonName name) { public Calendar getNextSeason() { return DateTimeUtils.getNext(spring, summer, autumn, winter); } + + /** + * Returns the next season name. + */ + public SeasonName getNextName() { + int ordinal = name.ordinal() + 1; + if (ordinal > 3) { + ordinal = 0; + } + return SeasonName.values()[ordinal]; + } + + /** + * Returns the time left for current season + */ + public QuantityType