Skip to content

Commit

Permalink
Adding next season to Astro (openhab#7517)
Browse files Browse the repository at this point in the history
Signed-off-by: clinique <[email protected]>
  • Loading branch information
clinique authored and markus7017 committed Sep 18, 2020
1 parent 5f688a8 commit c790995
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
3 changes: 2 additions & 1 deletion bundles/org.openhab.binding.astro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScheduledFuture<?>> scheduledFutures = new HashSet<>();

public AstroThingHandler(Thing thing, CronScheduler scheduler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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<Time> getTimeLeft() {
Calendar now = Calendar.getInstance();
Calendar next = getNextSeason();
return new QuantityType<>(next.getTimeInMillis() - now.getTimeInMillis(), MILLI(SmartHomeUnits.SECOND))
.toUnit(SmartHomeUnits.DAY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@
<channel id="summer" typeId="summer"/>
<channel id="autumn" typeId="autumn"/>
<channel id="winter" typeId="winter"/>
<channel id="nextName" typeId="seasonName">
<label>Next Season</label>
<description>The name of the next season</description>
</channel>
<channel id="timeLeft" typeId="duration">
<label>Time Left</label>
<description>The time remaining before season change</description>
</channel>
</channels>
</channel-group-type>

Expand Down

0 comments on commit c790995

Please sign in to comment.