]> git.basschouten.com Git - openhab-addons.git/blob
d7691b503330dc38076a03bcae6aeb4baa2270ca
[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.tplinksmarthome.internal.model;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.openhab.core.library.types.OnOffType;
19
20 import com.google.gson.annotations.SerializedName;
21
22 /**
23  * Data class for reading TP-Link Smart Home device state.
24  * Only getter methods as the values are set by gson based on the retrieved json.
25  *
26  * @author Hilbrand Bouwkamp - Initial contribution
27  */
28 public class Sysinfo extends ErrorResponse {
29
30     public static class CtrlProtocols {
31         private String name;
32         private String version;
33
34         public String getName() {
35             return name;
36         }
37
38         public String getVersion() {
39             return version;
40         }
41
42         @Override
43         public String toString() {
44             return "name:" + name + ", version:" + version;
45         }
46     }
47
48     /**
49      * With default light state state. The default light state is set when the device is off. If the device is on the
50      * state is in the parent fields.
51      */
52     public static class WithDefaultLightState extends LightState {
53         private LightState dftOnState;
54
55         public LightState getLightState() {
56             if (dftOnState == null) {
57                 return this;
58             } else {
59                 dftOnState.setOnOff(getOnOff());
60                 return dftOnState;
61             }
62         }
63
64         @Override
65         public String toString() {
66             return super.toString() + ", dftOnState:{" + dftOnState + "}";
67         }
68     }
69
70     /**
71      * Status of the plug as set in the range extender products.
72      */
73     public static class Plug {
74         private String feature;
75         private String relayStatus;
76
77         public String getFeature() {
78             return feature;
79         }
80
81         public OnOffType getRelayStatus() {
82             return OnOffType.from("ON".equals(relayStatus));
83         }
84     }
85
86     /**
87      * Status of a single outlet on power strip.
88      */
89     public static class Outlet {
90         private String alias;
91         private String id;
92         private long onTime;
93         private int state;
94
95         public String getAlias() {
96             return alias;
97         }
98
99         public String getId() {
100             return id;
101         }
102
103         public long getOnTime() {
104             return onTime;
105         }
106
107         public OnOffType getState() {
108             return OnOffType.from(state == 1);
109         }
110     }
111
112     /**
113      * Status of the range extended Wi-Fi.
114      */
115     public static class RangeextenderWireless {
116         private int w2gRssi;
117
118         public int getW2gRssi() {
119             return w2gRssi;
120         }
121     }
122
123     private String swVer;
124     private String hwVer;
125     private String model;
126     @SerializedName("deviceId")
127     private String deviceId;
128     @SerializedName("hwId")
129     private String hwId;
130     @SerializedName("oemId")
131     private String oemId;
132     private String alias;
133     private String activeMode;
134     private int rssi;
135     @SerializedName(value = "type", alternate = "mic_type")
136     private String type;
137     @SerializedName(value = "mac", alternate = { "mic_mac", "ethernet_mac" })
138     private String mac;
139
140     // switch and plug specific system info
141     @SerializedName("fwId")
142     private String fwId;
143     private String devName;
144     private String iconHash;
145     private int relayState; // 0 is off, 1 is on
146     private long onTime;
147     private String feature; // HS100 -> TIM, HS110 -> TIM:ENE
148     // Disabled updating as it's a different type for different devices.
149     // private int updating;
150     private int ledOff;
151     private double latitude;
152     private double longitude;
153
154     // powerstrip/multiple plugs support.
155     private int childNum;
156     private List<Outlet> children = new ArrayList<>();
157
158     // dimmer specific system info
159     private int brightness;
160
161     // bulb specific system info
162     private boolean isFactory;
163     private String discoVer;
164     private CtrlProtocols ctrlProtocols;
165     private WithDefaultLightState lightState = new WithDefaultLightState();
166
167     // range extender specific system info
168     private String ledStatus;
169     private Plug plug = new Plug();
170     private Sysinfo system;
171     @SerializedName("rangeextender.wireless")
172     private RangeextenderWireless reWireless;
173
174     public String getSwVer() {
175         return swVer;
176     }
177
178     public String getHwVer() {
179         return hwVer;
180     }
181
182     public String getType() {
183         return type;
184     }
185
186     public String getModel() {
187         return model;
188     }
189
190     public String getMac() {
191         return mac;
192     }
193
194     public String getDeviceId() {
195         return deviceId;
196     }
197
198     public String getHwId() {
199         return hwId;
200     }
201
202     public String getFwId() {
203         return fwId;
204     }
205
206     public String getOemId() {
207         return oemId;
208     }
209
210     public String getAlias() {
211         return alias;
212     }
213
214     public String getDevName() {
215         return devName;
216     }
217
218     public String getIconHash() {
219         return iconHash;
220     }
221
222     public OnOffType getRelayState() {
223         return OnOffType.from(relayState == 1);
224     }
225
226     public int getBrightness() {
227         return brightness;
228     }
229
230     public long getOnTime() {
231         return onTime;
232     }
233
234     public String getActiveMode() {
235         return activeMode;
236     }
237
238     public String getFeature() {
239         return feature;
240     }
241
242     public int getRssi() {
243         // for range extender use the 2g rssi.
244         return reWireless == null ? rssi : reWireless.getW2gRssi();
245     }
246
247     public OnOffType getLedOff() {
248         return OnOffType.from(ledOff != 1);
249     }
250
251     public double getLatitude() {
252         return latitude;
253     }
254
255     public double getLongitude() {
256         return longitude;
257     }
258
259     public boolean isFactory() {
260         return isFactory;
261     }
262
263     public String getDiscoVer() {
264         return discoVer;
265     }
266
267     public String getProtocolName() {
268         return ctrlProtocols == null ? null : ctrlProtocols.getName();
269     }
270
271     public String getProtocolVersion() {
272         return ctrlProtocols == null ? null : ctrlProtocols.getVersion();
273     }
274
275     public LightState getLightState() {
276         return lightState.getLightState();
277     }
278
279     public OnOffType getLedStatus() {
280         return OnOffType.from(!"ON".equals(ledStatus));
281     }
282
283     public Plug getPlug() {
284         return plug;
285     }
286
287     public int getChildNum() {
288         return childNum;
289     }
290
291     public List<Outlet> getChildren() {
292         return children;
293     }
294
295     public Sysinfo getSystem() {
296         return system;
297     }
298
299     /**
300      * Returns the {@link Sysinfo} object independent of the device. The range extender devices have the system
301      * information in another place as the other devices. This method returns the object independent of how the device
302      * returns it.
303      *
304      * @return device independent {@link Sysinfo} object.
305      */
306     public Sysinfo getActualSysinfo() {
307         return system == null ? this : system;
308     }
309
310     public RangeextenderWireless getReWireless() {
311         return reWireless;
312     }
313
314     @Override
315     public String toString() {
316         return "Sysinfo [swVer=" + swVer + ", hwVer=" + hwVer + ", model=" + model + ", deviceId=" + deviceId
317                 + ", hwId=" + hwId + ", oemId=" + oemId + ", alias=" + alias + ", activeMode=" + activeMode + ", rssi="
318                 + rssi + ", type=" + type + ", mac=" + mac + ", fwId=" + fwId + ", devName=" + devName + ", iconHash="
319                 + iconHash + ", relayState=" + relayState + ", brightness=" + brightness + ", onTime=" + onTime
320                 + ", feature=" + feature + ", ledOff=" + ledOff + ", latitude=" + latitude + ", longitude=" + longitude
321                 + ", isFactory=" + isFactory + ", discoVer=" + discoVer + ", ctrlProtocols=" + ctrlProtocols
322                 + ", lightState=" + lightState + ", ledStatus=" + ledStatus + ", plug=" + plug + ", system=" + system
323                 + ", reWireless=" + reWireless + "]";
324     }
325 }