mirror of
https://github.com/danieldemus/openhab-addons
synced 2026-07-29 12:34:21 +02:00
Synchronized Weather cache update requests (#16572)
Signed-off-by: clinique <gael@lhopital.org>
This commit is contained in:
+1
-1
@@ -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();
|
||||
}
|
||||
|
||||
+7
-4
@@ -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;
|
||||
|
||||
+1
-1
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user