]> git.basschouten.com Git - openhab-addons.git/blob
7faec8efef24a1541078d102719fc8d9c9208c41
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.netatmo.internal.handler.capability;
14
15 import java.time.Duration;
16 import java.util.List;
17
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;
25
26 /**
27  * {@link WeatherCapability} give the ability to read weather station API
28  *
29  * @author GaĆ«l L'hopital - Initial contribution
30  *
31  */
32 @NonNullByDefault
33 public class WeatherCapability extends CacheWeatherCapability {
34     private final Logger logger = LoggerFactory.getLogger(WeatherCapability.class);
35
36     public WeatherCapability(CommonInterface handler) {
37         super(handler, Duration.ofSeconds(2));
38     }
39
40     @Override
41     protected List<NAObject> getFreshData(WeatherApi api) {
42         try {
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());
46         }
47         return List.of();
48     }
49 }