]> git.basschouten.com Git - openhab-addons.git/blob
124fa1aa34d16f0ba147aa36b0e447ceeffab9a9
[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.tapocontrol.internal.structures;
14
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.*;
18
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;
23
24 import com.google.gson.JsonObject;
25
26 /**
27  * Tapo-Device Information class
28  *
29  * @author Christian Wild - Initial contribution
30  */
31 @NonNullByDefault
32 public class TapoDeviceInfo {
33     /**
34      * AVAILABLE BUT UNUSED FIELDS
35      * remove before push to real version
36      * 
37      * private Boolean hasSetLocationInfo = false;
38      * private Integer latitude = 0;
39      * private Integer longitude = 0;
40      * private Integer timeDiff = 0;
41      * private String avatar = "";
42      * private String fwId = "";
43      * private String hwId = "";
44      * private String specs = "";
45      * private String ssid = "";
46      * private String oemId = "";
47      * private String lang = "";
48      * private String location = "";
49      */
50
51     private Boolean deviceOn = false;
52     private Boolean overheated = false;
53     private Integer brightness = 0;
54     private Integer colorTemp = 0;
55     private Integer hue = 0;
56     private Integer rssi = 0;
57     private Integer saturation = 100;
58     private Integer signalLevel = 0;
59     private Number onTime = 0;
60     private Number timeUsagePast30 = 0;
61     private Number timeUsagePast7 = 0;
62     private Number timeUsageToday = 0;
63     private String deviceId = "";
64     private String fwVer = "";
65     private String hwVer = "";
66     private String ip = "";
67     private String mac = "";
68     private String model = "";
69     private String nickname = "";
70     private String region = "";
71     private String type = "";
72     private TapoLightEffect lightEffect = new TapoLightEffect();
73
74     private JsonObject jsonObject = new JsonObject();
75
76     /**
77      * INIT
78      */
79     public TapoDeviceInfo() {
80         setData();
81     }
82
83     /**
84      * Init DeviceInfo with new Data;
85      * 
86      * @param jso JsonObject new Data
87      */
88     public TapoDeviceInfo(JsonObject jso) {
89         jsonObject = jso;
90         setData();
91     }
92
93     /**
94      * Set Data (new JsonObject)
95      * 
96      * @param jso JsonObject new Data
97      */
98     public TapoDeviceInfo setData(JsonObject jso) {
99         this.jsonObject = jso;
100         setData();
101         return this;
102     }
103
104     private void setData() {
105         this.brightness = jsonObjectToInt(jsonObject, JSON_KEY_BRIGHTNESS);
106         this.colorTemp = jsonObjectToInt(jsonObject, JSON_KEY_COLORTEMP, BULB_MIN_COLORTEMP);
107         this.deviceId = jsonObjectToString(jsonObject, JSON_KEY_ID);
108         this.deviceOn = jsonObjectToBool(jsonObject, JSON_KEY_ON);
109         this.fwVer = jsonObjectToString(jsonObject, JSON_KEY_FW);
110         this.hue = jsonObjectToInt(jsonObject, JSON_KEY_HUE);
111         this.hwVer = jsonObjectToString(jsonObject, JSON_KEY_HW_VER);
112         this.ip = jsonObjectToString(jsonObject, JSON_KEY_IP);
113         this.lightEffect = lightEffect.setData(jsonObject);
114         this.mac = jsonObjectToString(jsonObject, JSON_KEY_MAC);
115         this.model = jsonObjectToString(jsonObject, JSON_KEY_MODEL);
116         this.nickname = jsonObjectToString(jsonObject, JSON_KEY_NICKNAME);
117         this.onTime = jsonObjectToNumber(jsonObject, JSON_KEY_ONTIME);
118         this.overheated = jsonObjectToBool(jsonObject, JSON_KEY_OVERHEAT);
119         this.region = jsonObjectToString(jsonObject, JSON_KEY_REGION);
120         this.saturation = jsonObjectToInt(jsonObject, JSON_KEY_SATURATION);
121         this.signalLevel = jsonObjectToInt(jsonObject, JSON_KEY_SIGNAL_LEVEL);
122         this.rssi = jsonObjectToInt(jsonObject, JSON_KEY_RSSI);
123         this.timeUsagePast7 = jsonObjectToInt(jsonObject, JSON_KEY_USAGE_7);
124         this.timeUsagePast30 = jsonObjectToInt(jsonObject, JSON_KEY_USAGE_30);
125         this.timeUsageToday = jsonObjectToInt(jsonObject, JSON_KEY_USAGE_TODAY);
126         this.type = jsonObjectToString(jsonObject, JSON_KEY_TYPE);
127     }
128
129     /***********************************
130      *
131      * GET VALUES
132      *
133      ************************************/
134
135     public Integer getBrightness() {
136         return brightness;
137     }
138
139     public Integer getColorTemp() {
140         return colorTemp;
141     }
142
143     public String getFirmwareVersion() {
144         return fwVer;
145     }
146
147     public String getHardwareVersion() {
148         return hwVer;
149     }
150
151     public HSBType getHSB() {
152         DecimalType h = new DecimalType(hue);
153         PercentType s = new PercentType(saturation);
154         PercentType b = new PercentType(brightness);
155         return new HSBType(h, s, b);
156     }
157
158     public Integer getHue() {
159         return hue;
160     }
161
162     public TapoLightEffect getLightEffect() {
163         return lightEffect;
164     }
165
166     public String getIP() {
167         return ip;
168     }
169
170     public Boolean isOff() {
171         return !deviceOn;
172     }
173
174     public Boolean isOn() {
175         return deviceOn;
176     }
177
178     public Boolean isOverheated() {
179         return overheated;
180     }
181
182     public String getMAC() {
183         return formatMac(mac, MAC_DIVISION_CHAR);
184     }
185
186     public String getModel() {
187         return model.replace(" ", "_");
188     }
189
190     public String getNickname() {
191         return nickname;
192     }
193
194     public Number getOnTime() {
195         return onTime;
196     }
197
198     public String getRegion() {
199         return region;
200     }
201
202     public String getRepresentationProperty() {
203         return getMAC();
204     }
205
206     public Integer getSaturation() {
207         return saturation;
208     }
209
210     public String getSerial() {
211         return deviceId;
212     }
213
214     public Integer getSignalLevel() {
215         return signalLevel;
216     }
217
218     public Integer getRSSI() {
219         return rssi;
220     }
221
222     public Number getTimeUsagePast7() {
223         return timeUsagePast7;
224     }
225
226     public Number getTimeUsagePast30() {
227         return timeUsagePast30;
228     }
229
230     public Number getTimeUsagePastToday() {
231         return timeUsageToday;
232     }
233
234     public String getType() {
235         return type;
236     }
237
238     @Override
239     public String toString() {
240         return jsonObject.toString();
241     }
242 }