]> git.basschouten.com Git - openhab-addons.git/blob
7f0af823bbd5e22106749c4bdd562b188b4997a2
[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.api.dto;
14
15 import java.time.ZonedDateTime;
16 import java.util.Optional;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.binding.netatmo.internal.api.data.ModuleType;
21
22 import com.google.gson.annotations.SerializedName;
23
24 /**
25  * The {@link NAThing} is the base class for devices and modules.
26  *
27  * @author GaĆ«l L'hopital - Initial contribution
28  *
29  */
30
31 @NonNullByDefault
32 public class NAThing extends NAObject implements NAModule {
33     @SerializedName(value = "rf_status", alternate = { "wifi_status", "rf_strength", "wifi_strength" })
34     private int radioStatus = -1;
35     @SerializedName(value = "last_seen", alternate = { "last_therm_seen", "last_status_store", "last_plug_seen",
36             "last_message", "last_activity" })
37     protected @Nullable ZonedDateTime lastSeen;
38     @SerializedName(value = "firmware", alternate = { "firmware_revision" })
39     private @Nullable String firmware;
40     private @Nullable Boolean reachable;
41     private @Nullable Dashboard dashboardData;
42
43     private @Nullable String roomId;
44     private @Nullable String bridge;
45     private ModuleType type = ModuleType.UNKNOWN;
46
47     @Override
48     public ModuleType getType() {
49         return type;
50     }
51
52     public boolean isReachable() {
53         // This is not implemented on all devices/modules, so if absent we consider it is reachable
54         Boolean localReachable = this.reachable;
55         return localReachable != null ? localReachable : true;
56     }
57
58     public void setReachable(boolean reachable) {
59         this.reachable = reachable;
60     }
61
62     public @Nullable Dashboard getDashboardData() {
63         return dashboardData;
64     }
65
66     public @Nullable String getFirmware() {
67         return firmware;
68     }
69
70     public int getRadioStatus() {
71         return radioStatus;
72     }
73
74     public Optional<ZonedDateTime> getLastSeen() {
75         return Optional.ofNullable(lastSeen);
76     }
77
78     /**
79      * @return true if the equipment has no parent, meaning its a device.
80      */
81     public boolean isDevice() {
82         return bridge == null;
83     }
84
85     public @Nullable String getBridge() {
86         return bridge;
87     }
88
89     public @Nullable String getRoomId() {
90         return roomId;
91     }
92 }