diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/capability/CacheWeatherCapability.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/capability/CacheCapability.java similarity index 70% rename from bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/capability/CacheWeatherCapability.java rename to bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/capability/CacheCapability.java index c472029a1f0..b2ecd79482f 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/capability/CacheWeatherCapability.java +++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/capability/CacheCapability.java @@ -17,33 +17,33 @@ import java.time.Instant; import java.util.List; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.openhab.binding.netatmo.internal.api.WeatherApi; +import org.openhab.binding.netatmo.internal.api.RestManager; import org.openhab.binding.netatmo.internal.api.dto.NAObject; import org.openhab.binding.netatmo.internal.handler.CommonInterface; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * {@link CacheWeatherCapability} give the ability to buffer weather related requests and reduce server requests + * {@link CacheCapability} give the ability to buffer RestManager related requests and reduce server requests * * @author Gaƫl L'hopital - Initial contribution * */ @NonNullByDefault -public abstract class CacheWeatherCapability extends RestCapability { - private final Logger logger = LoggerFactory.getLogger(CacheWeatherCapability.class); +public abstract class CacheCapability extends RestCapability { + private final Logger logger = LoggerFactory.getLogger(CacheCapability.class); private final Duration validity; private List lastResult = List.of(); private Instant requestTS = Instant.MIN; - public CacheWeatherCapability(CommonInterface handler, Duration validity) { - super(handler, WeatherApi.class); + public CacheCapability(CommonInterface handler, Duration validity, Class restManagerClazz) { + super(handler, restManagerClazz); this.validity = validity; } @Override - protected synchronized List updateReadings(WeatherApi api) { + protected synchronized List updateReadings(T api) { Instant now = Instant.now(); if (requestTS.plus(validity).isBefore(now)) { @@ -58,5 +58,5 @@ public abstract class CacheWeatherCapability extends RestCapability return lastResult; } - protected abstract List getFreshData(WeatherApi api); + protected abstract List getFreshData(T api); } diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/capability/HomeCapability.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/capability/HomeCapability.java index b2e7695a8e4..6e1de1292c4 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/capability/HomeCapability.java +++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/capability/HomeCapability.java @@ -14,6 +14,7 @@ package org.openhab.binding.netatmo.internal.handler.capability; import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*; +import java.time.Duration; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -42,7 +43,7 @@ import org.slf4j.LoggerFactory; * */ @NonNullByDefault -public class HomeCapability extends RestCapability { +public class HomeCapability extends CacheCapability { private final Logger logger = LoggerFactory.getLogger(HomeCapability.class); private final Set featureAreas = new HashSet<>(); @@ -50,7 +51,7 @@ public class HomeCapability extends RestCapability { private final Set homeIds = new HashSet<>(3); public HomeCapability(CommonInterface handler, NetatmoDescriptionProvider descriptionProvider) { - super(handler, HomeApi.class); + super(handler, Duration.ofSeconds(2), HomeApi.class); this.descriptionProvider = descriptionProvider; } @@ -105,7 +106,7 @@ public class HomeCapability extends RestCapability { } @Override - protected List updateReadings(HomeApi api) { + protected List getFreshData(HomeApi api) { List result = new ArrayList<>(); homeIds.stream().filter(id -> !id.isEmpty()).forEach(id -> { try { diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/capability/MeasureCapability.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/capability/MeasureCapability.java index 11151a36d00..56d018c9a94 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/capability/MeasureCapability.java +++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/capability/MeasureCapability.java @@ -44,12 +44,12 @@ import org.slf4j.LoggerFactory; * */ @NonNullByDefault -public class MeasureCapability extends CacheWeatherCapability { +public class MeasureCapability extends CacheCapability { private final Logger logger = LoggerFactory.getLogger(MeasureCapability.class); private final Map measures = new HashMap<>(); public MeasureCapability(CommonInterface handler, List helpers) { - super(handler, Duration.ofMinutes(30)); + super(handler, Duration.ofMinutes(30), WeatherApi.class); MeasuresChannelHelper measureChannelHelper = (MeasuresChannelHelper) helpers.stream() .filter(c -> c instanceof MeasuresChannelHelper).findFirst() .orElseThrow(() -> new IllegalArgumentException( diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/capability/RefreshCapability.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/capability/RefreshCapability.java index f26b771f6a3..26aba9e1c71 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/capability/RefreshCapability.java +++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/capability/RefreshCapability.java @@ -83,7 +83,7 @@ public class RefreshCapability extends Capability { handler.proceedWithUpdate(); long delay; if (!ThingStatus.ONLINE.equals(handler.getThing().getStatus())) { - logger.debug("Module is not ONLINE; special refresh interval is used"); + logger.debug("{} is not ONLINE, special refresh interval is used", thingUID); delay = OFFLINE_INTERVAL.toSeconds(); if (probing()) { dataTimeStamp0 = Instant.MIN; @@ -93,7 +93,7 @@ public class RefreshCapability extends Capability { : (probing() ? PROBING_INTERVAL : dataValidity.minus(dataAge()).plus(DEFAULT_DELAY)).toSeconds(); } delay = delay < 2 ? PROBING_INTERVAL.toSeconds() : delay; - logger.debug("Module refreshed, next one in {}s", delay); + logger.debug("{} refreshed, next one in {}s", thingUID, delay); freeJobAndReschedule(delay); } @@ -104,13 +104,13 @@ public class RefreshCapability extends Capability { if (probing()) { if (Instant.MIN.equals(dataTimeStamp0)) { dataTimeStamp0 = tsInstant; - logger.debug("First data timestamp is {}", dataTimeStamp0); + logger.debug("First data timestamp of {} is {}", thingUID, dataTimeStamp0); } else if (tsInstant.isAfter(dataTimeStamp0)) { dataValidity = Duration.between(dataTimeStamp0, tsInstant); refreshConfigured = true; - logger.debug("Data validity period identified to be {}", dataValidity); + logger.debug("Data validity period of {} identified to be {}", thingUID, dataValidity); } else { - logger.debug("Data validity period not yet found, data timestamp unchanged"); + logger.debug("Data validity period of {} not yet found, data timestamp unchanged", thingUID); } } dataTimeStamp = tsInstant; diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/capability/WeatherCapability.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/capability/WeatherCapability.java index 7faec8efef2..4789af45877 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/capability/WeatherCapability.java +++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/capability/WeatherCapability.java @@ -30,11 +30,11 @@ import org.slf4j.LoggerFactory; * */ @NonNullByDefault -public class WeatherCapability extends CacheWeatherCapability { +public class WeatherCapability extends CacheCapability { private final Logger logger = LoggerFactory.getLogger(WeatherCapability.class); public WeatherCapability(CommonInterface handler) { - super(handler, Duration.ofSeconds(2)); + super(handler, Duration.ofSeconds(2), WeatherApi.class); } @Override