2 * Copyright (c) 2010-2022 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.tapocontrol.internal.structures;
15 import static org.openhab.binding.tapocontrol.internal.constants.TapoBindingSettings.*;
16 import static org.openhab.binding.tapocontrol.internal.constants.TapoThingConstants.*;
17 import static org.openhab.binding.tapocontrol.internal.helpers.TapoUtils.*;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.core.library.types.DecimalType;
21 import org.openhab.core.library.types.HSBType;
22 import org.openhab.core.library.types.PercentType;
24 import com.google.gson.JsonObject;
27 * Tapo-Device Information class
29 * @author Christian Wild - Initial contribution
32 public class TapoDeviceInfo {
33 private Boolean deviceOn = false;
34 private Boolean overheated = false;
35 private Integer brightness = 0;
36 private Integer colorTemp = 0;
37 private Integer hue = 0;
38 private Integer rssi = 0;
39 private Integer saturation = 100;
40 private Integer signalLevel = 0;
41 private Number onTime = 0;
42 private Number timeUsagePast7 = 0;
43 private Number timeUsagePast30 = 0;
44 private Number timeUsageToday = 0;
45 private String deviceId = "";
46 private String fwVer = "";
47 private String hwVer = "";
48 private String ip = "";
49 private String mac = "";
50 private String model = "";
51 private String nickname = "";
52 private String region = "";
53 private String type = "";
54 private TapoLightEffect lightEffect = new TapoLightEffect();
56 private JsonObject jsonObject = new JsonObject();
61 public TapoDeviceInfo() {
66 * Init DeviceInfo with new Data;
68 * @param jso JsonObject new Data
70 public TapoDeviceInfo(JsonObject jso) {
76 * Set Data (new JsonObject)
78 * @param jso JsonObject new Data
80 public TapoDeviceInfo setData(JsonObject jso) {
81 this.jsonObject = jso;
86 private void setData() {
87 this.brightness = jsonObjectToInt(jsonObject, DEVICE_PROPERTY_BRIGHTNES);
88 this.colorTemp = jsonObjectToInt(jsonObject, DEVICE_PROPERTY_COLORTEMP, BULB_MIN_COLORTEMP);
89 this.deviceId = jsonObjectToString(jsonObject, DEVICE_PROPERTY_ID);
90 this.deviceOn = jsonObjectToBool(jsonObject, DEVICE_PROPERTY_ON);
91 this.fwVer = jsonObjectToString(jsonObject, DEVICE_PROPERTY_FW);
92 this.hue = jsonObjectToInt(jsonObject, DEVICE_PROPERTY_HUE);
93 this.hwVer = jsonObjectToString(jsonObject, DEVICE_PROPERTY_HW);
94 this.ip = jsonObjectToString(jsonObject, DEVICE_PROPERTY_IP);
95 this.mac = jsonObjectToString(jsonObject, DEVICE_PROPERTY_MAC);
96 this.model = jsonObjectToString(jsonObject, DEVICE_PROPERTY_MODEL);
97 this.nickname = jsonObjectToString(jsonObject, DEVICE_PROPERTY_NICKNAME);
98 this.onTime = jsonObjectToNumber(jsonObject, DEVICE_PROPERTY_ONTIME);
99 this.overheated = jsonObjectToBool(jsonObject, DEVICE_PROPERTY_OVERHEAT);
100 this.region = jsonObjectToString(jsonObject, DEVICE_PROPERTY_REGION);
101 this.saturation = jsonObjectToInt(jsonObject, DEVICE_PROPERTY_SATURATION);
102 this.signalLevel = jsonObjectToInt(jsonObject, DEVICE_PROPERTY_SIGNAL);
103 this.rssi = jsonObjectToInt(jsonObject, DEVICE_PROPERTY_SIGNAL_RSSI);
104 this.timeUsagePast7 = jsonObjectToInt(jsonObject, DEVICE_PROPERTY_USAGE_7);
105 this.timeUsagePast30 = jsonObjectToInt(jsonObject, DEVICE_PROPERTY_USAGE_30);
106 this.timeUsageToday = jsonObjectToInt(jsonObject, DEVICE_PROPERTY_USAGE_TODAY);
107 this.type = jsonObjectToString(jsonObject, DEVICE_PROPERTY_TYPE);
109 if (this.hasLightEffect()) {
110 this.lightEffect = lightEffect.setData(jsonObject);
114 /***********************************
116 * CHECK FOR CHILD TYPES
118 ************************************/
119 public Boolean hasLightEffect() {
120 return this.jsonObject.has(DEVICE_PROPERTY_EFFECT);
123 /***********************************
127 ************************************/
129 public Integer getBrightness() {
133 public Integer getColorTemp() {
137 public String getFirmwareVersion() {
141 public String getHardwareVersion() {
145 public HSBType getHSB() {
146 DecimalType h = new DecimalType(hue);
147 PercentType s = new PercentType(saturation);
148 PercentType b = new PercentType(brightness);
149 return new HSBType(h, s, b);
152 public Integer getHue() {
156 public TapoLightEffect getLightEffect() {
160 public String getIP() {
164 public Boolean isOff() {
168 public Boolean isOn() {
172 public Boolean isOverheated() {
176 public String getMAC() {
177 return formatMac(mac, MAC_DIVISION_CHAR);
180 public String getModel() {
181 return model.replace(" Series", "");
184 public String getNickname() {
188 public Number getOnTime() {
192 public String getRegion() {
196 public String getRepresentationProperty() {
200 public Integer getSaturation() {
204 public String getSerial() {
208 public Integer getSignalLevel() {
212 public Integer getRSSI() {
216 public Number getTimeUsagePast7() {
217 return timeUsagePast7;
220 public Number getTimeUsagePast30() {
221 return timeUsagePast30;
224 public Number getTimeUsagePastToday() {
225 return timeUsageToday;
228 public String getType() {
233 public String toString() {
234 return jsonObject.toString();