]> git.basschouten.com Git - openhab-addons.git/blob
ff538937a8a9048748bce6fa08fdd5591dddabd9
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.api.dto;
14
15 import java.time.Duration;
16 import java.time.Instant;
17 import java.time.ZonedDateTime;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.netatmo.internal.api.ApiResponse;
21 import org.openhab.binding.netatmo.internal.api.ListBodyResponse;
22
23 /**
24  * The {@link NAMain} defines a weather or nhc device.
25  *
26  * @author GaĆ«l L'hopital - Initial contribution
27  *
28  */
29
30 @NonNullByDefault
31 public class NAMain extends Device {
32     public class StationDataResponse extends ApiResponse<ListBodyResponse<NAMain>> {
33     }
34
35     private boolean readOnly;
36
37     /**
38      * true when the user was invited to (or has favorited) a station, false when the user owns it
39      *
40      * @return readOnly
41      **/
42     public boolean isReadOnly() {
43         return readOnly;
44     }
45
46     public boolean hasFreshData(int dataFreshnessLimit) {
47         // check by comparing data freshness
48         ZonedDateTime localLastSeen = lastSeen;
49         if (localLastSeen != null && !getType().isLogical()) {
50             return Duration.between(localLastSeen.toInstant(), Instant.now()).getSeconds() < dataFreshnessLimit;
51         }
52         return true;
53     }
54 }