]> git.basschouten.com Git - openhab-addons.git/blob
2b7db3da593c042fac41e5985c4069f75b280e7b
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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 static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.netatmo.internal.api.dto.NAMain;
19 import org.openhab.binding.netatmo.internal.handler.CommonInterface;
20
21 /**
22  * The {@link DeviceCapability} takes care of handling properties for netatmo devices
23  *
24  * @author GaĆ«l L'hopital - Initial contribution
25  *
26  */
27 @NonNullByDefault
28 public class DeviceCapability extends Capability {
29     private static final int DATA_AGE_LIMIT_S = 3600;
30
31     public DeviceCapability(CommonInterface handler) {
32         super(handler);
33     }
34
35     @Override
36     protected void updateNAMain(NAMain newData) {
37         if (firstLaunch) {
38             newData.getPlace().ifPresent(place -> {
39                 place.getCity().map(city -> properties.put(PROPERTY_CITY, city));
40                 place.getCountry().map(country -> properties.put(PROPERTY_COUNTRY, country));
41                 place.getTimezone().map(tz -> properties.put(PROPERTY_TIMEZONE, tz));
42             });
43         }
44         if (!newData.hasFreshData(DATA_AGE_LIMIT_S)) {
45             statusReason = "@text/data-over-limit";
46         }
47     }
48 }