mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[awattar] revert api logic, was nicer that way
Signed-off-by: Thomas Leber <thomas@tl-photography.at>
This commit is contained in:
parent
77d372f2c1
commit
c5eec4e87e
@ -12,12 +12,15 @@
|
|||||||
*/
|
*/
|
||||||
package org.openhab.binding.awattar.internal.handler;
|
package org.openhab.binding.awattar.internal.handler;
|
||||||
|
|
||||||
|
import static java.time.temporal.ChronoUnit.DAYS;
|
||||||
|
import static java.time.temporal.ChronoUnit.HOURS;
|
||||||
import static org.openhab.binding.awattar.internal.AwattarBindingConstants.CHANNEL_MARKET_NET;
|
import static org.openhab.binding.awattar.internal.AwattarBindingConstants.CHANNEL_MARKET_NET;
|
||||||
import static org.openhab.binding.awattar.internal.AwattarBindingConstants.CHANNEL_TOTAL_NET;
|
import static org.openhab.binding.awattar.internal.AwattarBindingConstants.CHANNEL_TOTAL_NET;
|
||||||
|
|
||||||
import java.time.Clock;
|
import java.time.Clock;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@ -197,14 +200,13 @@ public class AwattarBridgeHandler extends BaseBridgeHandler {
|
|||||||
|
|
||||||
// do not refresh before 15:00, since the prices for the next day are available
|
// do not refresh before 15:00, since the prices for the next day are available
|
||||||
// only after 14:00
|
// only after 14:00
|
||||||
Instant now = clock.instant();
|
ZonedDateTime now = ZonedDateTime.now(clock);
|
||||||
if (now.isBefore(clock.instant().truncatedTo(java.time.temporal.ChronoUnit.DAYS).plus(15,
|
if (now.getHour() < 15) {
|
||||||
java.time.temporal.ChronoUnit.HOURS))) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// refresh then every 3 hours, if the last refresh was more than an hour ago
|
// refresh at 15:00, 18:00 and 21:00 if the last refresh was more than an hour ago
|
||||||
if (lastRefresh.plus(3, java.time.temporal.ChronoUnit.HOURS).isBefore(now)) {
|
if (now.getHour() % 3 == 0 && lastRefresh.getEpochSecond() < now.minusHours(1).toEpochSecond()) {
|
||||||
// update the last refresh time
|
// update the last refresh time
|
||||||
lastRefresh = Instant.now();
|
lastRefresh = Instant.now();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user