2 * Copyright (c) 2010-2024 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.netatmo.internal.handler.capability;
15 import java.time.Duration;
16 import java.util.List;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.netatmo.internal.api.NetatmoException;
20 import org.openhab.binding.netatmo.internal.api.WeatherApi;
21 import org.openhab.binding.netatmo.internal.api.dto.NAObject;
22 import org.openhab.binding.netatmo.internal.handler.CommonInterface;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * {@link WeatherCapability} give the ability to read weather station API
29 * @author Gaƫl L'hopital - Initial contribution
33 public class WeatherCapability extends CacheCapability<WeatherApi> {
34 private final Logger logger = LoggerFactory.getLogger(WeatherCapability.class);
36 public WeatherCapability(CommonInterface handler) {
37 super(handler, Duration.ofSeconds(2), WeatherApi.class);
41 protected List<NAObject> getFreshData(WeatherApi api) {
43 return List.of(owned ? api.getOwnedStationData(handler.getId()) : api.getStationData(handler.getId()));
44 } catch (NetatmoException e) {
45 logger.warn("Error retrieving weather data '{}': {}", handler.getId(), e.getMessage());