2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.tplinksmarthome.internal.model;
15 import java.util.ArrayList;
16 import java.util.List;
18 import org.openhab.core.library.types.OnOffType;
20 import com.google.gson.annotations.SerializedName;
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.
26 * @author Hilbrand Bouwkamp - Initial contribution
28 public class Sysinfo extends ErrorResponse {
30 public static class CtrlProtocols {
32 private String version;
34 public String getName() {
38 public String getVersion() {
43 public String toString() {
44 return "name:" + name + ", version:" + version;
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.
52 public static class WithDefaultLightState extends LightState {
53 private LightState dftOnState;
55 public LightState getLightState() {
56 if (dftOnState == null) {
59 dftOnState.setOnOff(getOnOff());
65 public String toString() {
66 return super.toString() + ", dftOnState:{" + dftOnState + "}";
71 * Status of the plug as set in the range extender products.
73 public static class Plug {
74 private String feature;
75 private String relayStatus;
77 public String getFeature() {
81 public OnOffType getRelayStatus() {
82 return OnOffType.from("ON".equals(relayStatus));
87 * Status of a single outlet on power strip.
89 public static class Outlet {
95 public String getAlias() {
99 public String getId() {
103 public long getOnTime() {
107 public OnOffType getState() {
108 return OnOffType.from(state == 1);
113 * Status of the range extended Wi-Fi.
115 public static class RangeextenderWireless {
118 public int getW2gRssi() {
123 private String swVer;
124 private String hwVer;
125 private String model;
126 @SerializedName("deviceId")
127 private String deviceId;
128 @SerializedName("hwId")
130 @SerializedName("oemId")
131 private String oemId;
132 private String alias;
133 private String activeMode;
135 @SerializedName(value = "type", alternate = "mic_type")
137 @SerializedName(value = "mac", alternate = { "mic_mac", "ethernet_mac" })
140 // switch and plug specific system info
141 @SerializedName("fwId")
143 private String devName;
144 private String iconHash;
145 private int relayState; // 0 is off, 1 is on
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;
151 private double latitude;
152 private double longitude;
154 // powerstrip/multiple plugs support.
155 private int childNum;
156 private List<Outlet> children = new ArrayList<>();
158 // dimmer specific system info
159 private int brightness;
161 // bulb specific system info
162 private boolean isFactory;
163 private String discoVer;
164 private CtrlProtocols ctrlProtocols;
165 private WithDefaultLightState lightState = new WithDefaultLightState();
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;
174 public String getSwVer() {
178 public String getHwVer() {
182 public String getType() {
186 public String getModel() {
190 public String getMac() {
194 public String getDeviceId() {
198 public String getHwId() {
202 public String getFwId() {
206 public String getOemId() {
210 public String getAlias() {
214 public String getDevName() {
218 public String getIconHash() {
222 public OnOffType getRelayState() {
223 return OnOffType.from(relayState == 1);
226 public int getBrightness() {
230 public long getOnTime() {
234 public String getActiveMode() {
238 public String getFeature() {
242 public int getRssi() {
243 // for range extender use the 2g rssi.
244 return reWireless == null ? rssi : reWireless.getW2gRssi();
247 public OnOffType getLedOff() {
248 return OnOffType.from(ledOff != 1);
251 public double getLatitude() {
255 public double getLongitude() {
259 public boolean isFactory() {
263 public String getDiscoVer() {
267 public String getProtocolName() {
268 return ctrlProtocols == null ? null : ctrlProtocols.getName();
271 public String getProtocolVersion() {
272 return ctrlProtocols == null ? null : ctrlProtocols.getVersion();
275 public LightState getLightState() {
276 return lightState.getLightState();
279 public OnOffType getLedStatus() {
280 return OnOffType.from(!"ON".equals(ledStatus));
283 public Plug getPlug() {
287 public int getChildNum() {
291 public List<Outlet> getChildren() {
295 public Sysinfo getSystem() {
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
304 * @return device independent {@link Sysinfo} object.
306 public Sysinfo getActualSysinfo() {
307 return system == null ? this : system;
310 public RangeextenderWireless getReWireless() {
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 + "]";