mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
Synchronized Weather cache update requests (#16572)
Signed-off-by: clinique <gael@lhopital.org> Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
parent
f99ff75b9d
commit
4206dd811a
@ -41,7 +41,7 @@ public class AirCareCapability extends RestCapability<AircareApi> {
|
||||
try {
|
||||
return List.of(api.getHomeCoach(handler.getId()));
|
||||
} catch (NetatmoException e) {
|
||||
logger.warn("Error retrieving home-coach data '{}' : {}", handler.getId(), e.getMessage());
|
||||
logger.warn("Error retrieving home-coach data '{}': {}", handler.getId(), e.getMessage());
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
@ -43,13 +43,16 @@ public abstract class CacheWeatherCapability extends RestCapability<WeatherApi>
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<NAObject> updateReadings(WeatherApi api) {
|
||||
protected synchronized List<NAObject> updateReadings(WeatherApi api) {
|
||||
Instant now = Instant.now();
|
||||
|
||||
if (requestTS.plus(validity).isBefore(now)) {
|
||||
logger.debug("Requesting fresh data");
|
||||
lastResult = getFreshData(api);
|
||||
requestTS = now;
|
||||
logger.debug("{} requesting fresh data for {}", getClass().getSimpleName(), thingUID);
|
||||
List<NAObject> result = getFreshData(api);
|
||||
if (!result.isEmpty()) {
|
||||
lastResult = result;
|
||||
requestTS = now;
|
||||
}
|
||||
}
|
||||
|
||||
return lastResult;
|
||||
|
@ -42,7 +42,7 @@ public class WeatherCapability extends CacheWeatherCapability {
|
||||
try {
|
||||
return List.of(owned ? api.getOwnedStationData(handler.getId()) : api.getStationData(handler.getId()));
|
||||
} catch (NetatmoException e) {
|
||||
logger.warn("Error retrieving weather data '{}' : {}", handler.getId(), e.getMessage());
|
||||
logger.warn("Error retrieving weather data '{}': {}", handler.getId(), e.getMessage());
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user