--- /dev/null
+/**
+ * Copyright (c) 2010-2024 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.netatmo.internal.handler.capability;
+
+import java.time.Duration;
+import java.time.Instant;
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+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 CacheCapability} give the ability to buffer RestManager related requests and reduce server requests
+ *
+ * @author Gaël L'hopital - Initial contribution
+ *
+ */
+@NonNullByDefault
+public abstract class CacheCapability<T extends RestManager> extends RestCapability<T> {
+ private final Logger logger = LoggerFactory.getLogger(CacheCapability.class);
+ private final Duration validity;
+
+ private List<NAObject> lastResult = List.of();
+ private Instant requestTS = Instant.MIN;
+
+ public CacheCapability(CommonInterface handler, Duration validity, Class<T> restManagerClazz) {
+ super(handler, restManagerClazz);
+ this.validity = validity;
+ }
+
+ @Override
+ protected synchronized List<NAObject> updateReadings(T api) {
+ Instant now = Instant.now();
+
+ if (requestTS.plus(validity).isBefore(now)) {
+ logger.debug("{} requesting fresh data for {}", getClass().getSimpleName(), thingUID);
+ List<NAObject> result = getFreshData(api);
+ if (!result.isEmpty()) {
+ lastResult = result;
+ requestTS = now;
+ }
+ }
+
+ return lastResult;
+ }
+
+ protected abstract List<NAObject> getFreshData(T api);
+}
+++ /dev/null
-/**
- * Copyright (c) 2010-2024 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.netatmo.internal.handler.capability;
-
-import java.time.Duration;
-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.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
- *
- * @author Gaël L'hopital - Initial contribution
- *
- */
-@NonNullByDefault
-public abstract class CacheWeatherCapability extends RestCapability<WeatherApi> {
- private final Logger logger = LoggerFactory.getLogger(CacheWeatherCapability.class);
- private final Duration validity;
-
- private List<NAObject> lastResult = List.of();
- private Instant requestTS = Instant.MIN;
-
- public CacheWeatherCapability(CommonInterface handler, Duration validity) {
- super(handler, WeatherApi.class);
- this.validity = validity;
- }
-
- @Override
- protected synchronized List<NAObject> updateReadings(WeatherApi api) {
- Instant now = Instant.now();
-
- if (requestTS.plus(validity).isBefore(now)) {
- logger.debug("{} requesting fresh data for {}", getClass().getSimpleName(), thingUID);
- List<NAObject> result = getFreshData(api);
- if (!result.isEmpty()) {
- lastResult = result;
- requestTS = now;
- }
- }
-
- return lastResult;
- }
-
- protected abstract List<NAObject> getFreshData(WeatherApi api);
-}
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
*
*/
@NonNullByDefault
-public class HomeCapability extends RestCapability<HomeApi> {
+public class HomeCapability extends CacheCapability<HomeApi> {
private final Logger logger = LoggerFactory.getLogger(HomeCapability.class);
private final Set<FeatureArea> featureAreas = new HashSet<>();
private final Set<String> homeIds = new HashSet<>(3);
public HomeCapability(CommonInterface handler, NetatmoDescriptionProvider descriptionProvider) {
- super(handler, HomeApi.class);
+ super(handler, Duration.ofSeconds(2), HomeApi.class);
this.descriptionProvider = descriptionProvider;
}
}
@Override
- protected List<NAObject> updateReadings(HomeApi api) {
+ protected List<NAObject> getFreshData(HomeApi api) {
List<NAObject> result = new ArrayList<>();
homeIds.stream().filter(id -> !id.isEmpty()).forEach(id -> {
try {
*
*/
@NonNullByDefault
-public class MeasureCapability extends CacheWeatherCapability {
+public class MeasureCapability extends CacheCapability<WeatherApi> {
private final Logger logger = LoggerFactory.getLogger(MeasureCapability.class);
private final Map<String, State> measures = new HashMap<>();
public MeasureCapability(CommonInterface handler, List<ChannelHelper> 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(
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;
: (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);
}
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;
*
*/
@NonNullByDefault
-public class WeatherCapability extends CacheWeatherCapability {
+public class WeatherCapability extends CacheCapability<WeatherApi> {
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