mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 07:02:02 +01:00
Simplify DateTimeType handling for Freecurrency
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
f0ba39f121
commit
dd6c1f6d93
@ -16,7 +16,7 @@ import static org.openhab.binding.freecurrency.internal.FreecurrencyBindingConst
|
||||
import static org.openhab.binding.freecurrency.internal.FreecurrencyBindingConstants.CHANNEL_TYPE_LAST_UPDATE;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.Instant;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.freecurrency.internal.config.FreecurrencyExhangeRateChannelConfig;
|
||||
@ -72,7 +72,7 @@ public class FreecurrencyHandler extends BaseThingHandler implements ExchangeRat
|
||||
BigDecimal val = freecurrencyProvider.getExchangeRate(config.currency1, config.currency2);
|
||||
updateState(channel.getUID(), val != null ? new DecimalType(val) : UnDefType.UNDEF);
|
||||
} else if (CHANNEL_TYPE_LAST_UPDATE.equals(channel.getChannelTypeUID())) {
|
||||
ZonedDateTime lastUpdated = freecurrencyProvider.getLastUpdated();
|
||||
Instant lastUpdated = freecurrencyProvider.getLastUpdated();
|
||||
updateState(channel.getUID(), lastUpdated == null ? UnDefType.UNDEF : new DateTimeType(lastUpdated));
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ import java.math.MathContext;
|
||||
import java.net.URI;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@ -80,7 +79,7 @@ public class FreecurrencyProvider implements CurrencyProvider, ConfigOptionProvi
|
||||
private @Nullable ScheduledFuture<?> refreshJob;
|
||||
private Map<String, CurrencyInformation> currencies = Map.of();
|
||||
private Map<Unit<Currency>, BigDecimal> exchangeRates = Map.of();
|
||||
private @Nullable ZonedDateTime lastUpdated = null;
|
||||
private @Nullable Instant lastUpdated = null;
|
||||
private Set<ExchangeRateListener> exchangeRateListeners = new HashSet<>();
|
||||
|
||||
@Activate
|
||||
@ -133,7 +132,7 @@ public class FreecurrencyProvider implements CurrencyProvider, ConfigOptionProvi
|
||||
return rate2.divide(rate1, MathContext.DECIMAL128);
|
||||
}
|
||||
|
||||
public @Nullable ZonedDateTime getLastUpdated() {
|
||||
public @Nullable Instant getLastUpdated() {
|
||||
return lastUpdated;
|
||||
}
|
||||
|
||||
@ -181,7 +180,7 @@ public class FreecurrencyProvider implements CurrencyProvider, ConfigOptionProvi
|
||||
});
|
||||
exchangeRates = newExchangeRates;
|
||||
logger.debug("Retrieved exchange rates for {} currencies", newExchangeRates.size());
|
||||
lastUpdated = ZonedDateTime.now();
|
||||
lastUpdated = Instant.now();
|
||||
|
||||
// exchange rates are refreshed every day at midnight UTC
|
||||
// we refresh one minute later to be sure we are not too early.
|
||||
|
Loading…
Reference in New Issue
Block a user