]> git.basschouten.com Git - openhab-addons.git/blob
f132c730310a37ea6c1ccf4b0dd23867ca880a8c
[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 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     /**
32      * Whether the device is owned or not by the user (a favorite station or a guest station is not owned by the user).
33      * It will be updated when handling the result of the getstationsdata API.
34      * It must be initialized to false to be sure that the first call to the API will not fail for a favorite/guest
35      * weather stations.
36      */
37     protected boolean owned;
38
39     public DeviceCapability(CommonInterface handler) {
40         super(handler);
41     }
42
43     @Override
44     protected void updateNAMain(NAMain newData) {
45         owned = !newData.isReadOnly();
46         if (firstLaunch) {
47             newData.getPlace().ifPresent(place -> {
48                 place.getCity().map(city -> properties.put(PROPERTY_CITY, city));
49                 place.getCountry().map(country -> properties.put(PROPERTY_COUNTRY, country));
50                 place.getTimezone().map(tz -> properties.put(PROPERTY_TIMEZONE, tz));
51             });
52         }
53         if (!newData.hasFreshData(DATA_AGE_LIMIT_S)) {
54             statusReason = "@text/data-over-limit";
55         }
56     }
57 }