[awattar] revert api logic, was nicer that way

Signed-off-by: Thomas Leber <thomas@tl-photography.at>
This commit is contained in:
Thomas Leber 2024-12-22 23:07:46 +01:00
parent 77d372f2c1
commit c5eec4e87e

View File

@ -12,12 +12,15 @@
*/
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_TOTAL_NET;
import java.time.Clock;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.SortedSet;
import java.util.concurrent.ScheduledFuture;
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
// only after 14:00
Instant now = clock.instant();
if (now.isBefore(clock.instant().truncatedTo(java.time.temporal.ChronoUnit.DAYS).plus(15,
java.time.temporal.ChronoUnit.HOURS))) {
ZonedDateTime now = ZonedDateTime.now(clock);
if (now.getHour() < 15) {
return false;
}
// refresh then every 3 hours, if the last refresh was more than an hour ago
if (lastRefresh.plus(3, java.time.temporal.ChronoUnit.HOURS).isBefore(now)) {
// refresh at 15:00, 18:00 and 21:00 if the last refresh was more than an hour ago
if (now.getHour() % 3 == 0 && lastRefresh.getEpochSecond() < now.minusHours(1).toEpochSecond()) {
// update the last refresh time
lastRefresh = Instant.now();