iobroker.tapo 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var l530_exports = {};
26
+ __export(l530_exports, {
27
+ default: () => L530
28
+ });
29
+ module.exports = __toCommonJS(l530_exports);
30
+ var import_l510e = __toESM(require("./l510e"));
31
+ class L530 extends import_l510e.default {
32
+ constructor(log, ipAddress, email, password, timeout) {
33
+ super(log, ipAddress, email, password, timeout);
34
+ this.log = log;
35
+ this.ipAddress = ipAddress;
36
+ this.email = email;
37
+ this.password = password;
38
+ this.timeout = timeout;
39
+ this.log.debug("Constructing L530 on host: " + ipAddress);
40
+ this._consumption = {
41
+ total: 0,
42
+ current: 0
43
+ };
44
+ }
45
+ async getDeviceInfo() {
46
+ return super.getDeviceInfo().then(() => {
47
+ return this.getSysInfo();
48
+ });
49
+ }
50
+ async setColorTemp(color_temp) {
51
+ const transformedColorTemp = this.transformColorTemp(color_temp);
52
+ this.log.debug("Color Temp Tapo :" + transformedColorTemp);
53
+ const roundedValue = transformedColorTemp > 6500 ? 6500 : transformedColorTemp < 2500 ? 2500 : transformedColorTemp;
54
+ const payload = '{"method": "set_device_info","params": {"hue": 0,"saturation": 0,"color_temp": ' + roundedValue + '},"requestTimeMils": ' + Math.round(Date.now() * 1e3) + "};";
55
+ return this.handleRequest(payload).then(() => {
56
+ return true;
57
+ });
58
+ }
59
+ async setColor(hue, saturation) {
60
+ if (!hue) {
61
+ hue = 0;
62
+ }
63
+ if (!saturation) {
64
+ saturation = 0;
65
+ }
66
+ const payload = '{"method": "set_device_info","params": {"hue": ' + Math.round(hue) + ',"color_temp": 0,"saturation": ' + Math.round(saturation) + '},"requestTimeMils": ' + Math.round(Date.now() * 1e3) + "};";
67
+ return this.sendRequest(payload);
68
+ }
69
+ setSysInfo(sysInfo) {
70
+ this._colorLightSysInfo = sysInfo;
71
+ this._colorLightSysInfo.last_update = Date.now();
72
+ }
73
+ getSysInfo() {
74
+ return this._colorLightSysInfo;
75
+ }
76
+ transformColorTemp(value) {
77
+ return Math.floor(1e6 / value);
78
+ }
79
+ async getColorTemp() {
80
+ return super.getDeviceInfo().then(() => {
81
+ return this.calculateColorTemp(this.getSysInfo().color_temp);
82
+ });
83
+ }
84
+ calculateColorTemp(tapo_color_temp) {
85
+ const newValue = this.transformColorTemp(tapo_color_temp);
86
+ return newValue > 400 ? 400 : newValue < 154 ? 154 : newValue;
87
+ }
88
+ async getEnergyUsage() {
89
+ const payload = '{"method": "get_device_usage","requestTimeMils": ' + Math.round(Date.now() * 1e3) + "};";
90
+ return this.handleRequest(payload).then((response) => {
91
+ if (response && response.result) {
92
+ this._consumption = {
93
+ total: response.result.power_usage.today / 1e3,
94
+ current: this._consumption ? response.result.power_usage.today - this._consumption.current : 0
95
+ };
96
+ } else {
97
+ this._consumption = {
98
+ total: 0,
99
+ current: 0
100
+ };
101
+ }
102
+ return response.result;
103
+ }).catch((error) => {
104
+ if (error.message.indexOf("9999") > 0) {
105
+ return this.reconnect().then(() => {
106
+ return this.handleRequest(payload).then(() => {
107
+ return true;
108
+ });
109
+ });
110
+ }
111
+ return false;
112
+ });
113
+ }
114
+ getPowerConsumption() {
115
+ return this._consumption;
116
+ }
117
+ }
118
+ // Annotate the CommonJS export names for ESM import in node:
119
+ 0 && (module.exports = {});
120
+ //# sourceMappingURL=l530.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/lib/utils/l530.ts"],
4
+ "sourcesContent": ["import { ColorLightSysinfo, ConsumptionInfo } from \"./types\";\nimport L510E from \"./l510e\";\nimport { PowerUsage } from \"./powerUsage\";\n\nexport default class L530 extends L510E {\n private _colorLightSysInfo!: ColorLightSysinfo;\n private _consumption!: ConsumptionInfo;\n\n constructor(\n public readonly log: any,\n public readonly ipAddress: string,\n public readonly email: string,\n public readonly password: string,\n public readonly timeout: number\n ) {\n super(log, ipAddress, email, password, timeout);\n this.log.debug(\"Constructing L530 on host: \" + ipAddress);\n this._consumption = {\n total: 0,\n current: 0,\n };\n }\n\n async getDeviceInfo(): Promise<ColorLightSysinfo> {\n return super.getDeviceInfo().then(() => {\n return this.getSysInfo();\n });\n }\n\n async setColorTemp(color_temp: number): Promise<true> {\n const transformedColorTemp = this.transformColorTemp(color_temp);\n this.log.debug(\"Color Temp Tapo :\" + transformedColorTemp);\n\n const roundedValue = transformedColorTemp > 6500 ? 6500 : transformedColorTemp < 2500 ? 2500 : transformedColorTemp;\n\n const payload =\n \"{\" +\n '\"method\": \"set_device_info\",' +\n '\"params\": {' +\n '\"hue\": 0,' +\n '\"saturation\": 0,' +\n '\"color_temp\": ' +\n roundedValue +\n \"},\" +\n '\"requestTimeMils\": ' +\n Math.round(Date.now() * 1000) +\n \"\" +\n \"};\";\n\n return this.handleRequest(payload).then(() => {\n return true;\n });\n }\n\n async setColor(hue: number, saturation: number): Promise<boolean> {\n if (!hue) {\n hue = 0;\n }\n if (!saturation) {\n saturation = 0;\n }\n const payload =\n \"{\" +\n '\"method\": \"set_device_info\",' +\n '\"params\": {' +\n '\"hue\": ' +\n Math.round(hue) +\n \",\" +\n '\"color_temp\": 0,' +\n '\"saturation\": ' +\n Math.round(saturation) +\n \"},\" +\n '\"requestTimeMils\": ' +\n Math.round(Date.now() * 1000) +\n \"\" +\n \"};\";\n\n return this.sendRequest(payload);\n }\n\n protected setSysInfo(sysInfo: ColorLightSysinfo) {\n this._colorLightSysInfo = sysInfo;\n this._colorLightSysInfo.last_update = Date.now();\n }\n\n public getSysInfo(): ColorLightSysinfo {\n return this._colorLightSysInfo;\n }\n\n private transformColorTemp(value: number) {\n return Math.floor(1000000 / value);\n }\n\n async getColorTemp(): Promise<number> {\n return super.getDeviceInfo().then(() => {\n return this.calculateColorTemp(this.getSysInfo().color_temp);\n });\n }\n\n calculateColorTemp(tapo_color_temp: number) {\n const newValue = this.transformColorTemp(tapo_color_temp);\n return newValue > 400 ? 400 : newValue < 154 ? 154 : newValue;\n }\n\n async getEnergyUsage(): Promise<PowerUsage> {\n const payload = \"{\" + '\"method\": \"get_device_usage\",' + '\"requestTimeMils\": ' + Math.round(Date.now() * 1000) + \"\" + \"};\";\n return this.handleRequest(payload)\n .then((response) => {\n if (response && response.result) {\n this._consumption = {\n total: response.result.power_usage.today / 1000,\n current: this._consumption ? response.result.power_usage.today - this._consumption.current : 0,\n };\n } else {\n this._consumption = {\n total: 0,\n current: 0,\n };\n }\n\n return response.result;\n })\n .catch((error) => {\n if (error.message.indexOf(\"9999\") > 0) {\n return this.reconnect().then(() => {\n return this.handleRequest(payload).then(() => {\n return true;\n });\n });\n }\n return false;\n });\n }\n\n public getPowerConsumption(): ConsumptionInfo {\n return this._consumption;\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA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,MAAU,KAAK;AAAA,EACnC;AAAA,EAEA,MAAM,eAAgC;AACpC,WAAO,MAAM,cAAc,EAAE,KAAK,MAAM;AACtC,aAAO,KAAK,mBAAmB,KAAK,WAAW,EAAE,UAAU;AAAA,IAC7D,CAAC;AAAA,EACH;AAAA,EAEA,mBAAmB,iBAAyB;AAC1C,UAAM,WAAW,KAAK,mBAAmB,eAAe;AACxD,WAAO,WAAW,MAAM,MAAM,WAAW,MAAM,MAAM;AAAA,EACvD;AAAA,EAEA,MAAM,iBAAsC;AAC1C,UAAM,UAAU,sDAAgE,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI,IAAS;AACrH,WAAO,KAAK,cAAc,OAAO,EAC9B,KAAK,CAAC,aAAa;AAClB,UAAI,YAAY,SAAS,QAAQ;AAC/B,aAAK,eAAe;AAAA,UAClB,OAAO,SAAS,OAAO,YAAY,QAAQ;AAAA,UAC3C,SAAS,KAAK,eAAe,SAAS,OAAO,YAAY,QAAQ,KAAK,aAAa,UAAU;AAAA,QAC/F;AAAA,MACF,OAAO;AACL,aAAK,eAAe;AAAA,UAClB,OAAO;AAAA,UACP,SAAS;AAAA,QACX;AAAA,MACF;AAEA,aAAO,SAAS;AAAA,IAClB,CAAC,EACA,MAAM,CAAC,UAAU;AAChB,UAAI,MAAM,QAAQ,QAAQ,MAAM,IAAI,GAAG;AACrC,eAAO,KAAK,UAAU,EAAE,KAAK,MAAM;AACjC,iBAAO,KAAK,cAAc,OAAO,EAAE,KAAK,MAAM;AAC5C,mBAAO;AAAA,UACT,CAAC;AAAA,QACH,CAAC;AAAA,MACH;AACA,aAAO;AAAA,IACT,CAAC;AAAA,EACL;AAAA,EAEO,sBAAuC;AAC5C,WAAO,KAAK;AAAA,EACd;AACF;",
6
+ "names": ["L510E"]
7
+ }
@@ -0,0 +1,407 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var p100_exports = {};
26
+ __export(p100_exports, {
27
+ default: () => P100
28
+ });
29
+ module.exports = __toCommonJS(p100_exports);
30
+ var import_uuid = require("uuid");
31
+ var import_tpLinkCipher = __toESM(require("./tpLinkCipher"));
32
+ class P100 {
33
+ constructor(log, ipAddress, email, password, timeout) {
34
+ this.log = log;
35
+ this.ipAddress = ipAddress;
36
+ this.email = email;
37
+ this.password = password;
38
+ this.timeout = timeout;
39
+ this.crypto = require("crypto");
40
+ this.axios = require("axios");
41
+ this.ERROR_CODES = {
42
+ "0": "Success",
43
+ "-1010": "Invalid Public Key Length",
44
+ "-1012": "Invalid terminalUUID",
45
+ "-1501": "Invalid Request or Credentials",
46
+ "1002": "Incorrect Request",
47
+ "-1003": "JSON formatting error ",
48
+ "9999": "Session Timeout",
49
+ "-1301": "Device Error",
50
+ "1100": "Handshake Failed",
51
+ "1111": "Login Failed",
52
+ "1112": "Http Transport Failed",
53
+ "1200": "Multiple Requests Failed",
54
+ "-1004": "JSON Encode Failed",
55
+ "-1005": "AES Decode Failed",
56
+ "-1006": "Request Length Error",
57
+ "-2101": "Account Error",
58
+ "-1": "ERR_COMMON_FAILED",
59
+ "1000": "ERR_NULL_TRANSPORT",
60
+ "1001": "ERR_CMD_COMMAND_CANCEL",
61
+ "-1001": "ERR_UNSPECIFIC",
62
+ "-1002": "ERR_UNKNOWN_METHOD",
63
+ "-1007": "ERR_CLOUD_FAILED",
64
+ "-1008": "ERR_PARAMS",
65
+ "-1101": "ERR_SESSION_PARAM",
66
+ "-1201": "ERR_QUICK_SETUP",
67
+ "-1302": "ERR_DEVICE_NEXT_EVENT",
68
+ "-1401": "ERR_FIRMWARE",
69
+ "-1402": "ERR_FIRMWARE_VER_ERROR",
70
+ "-1601": "ERR_TIME",
71
+ "-1602": "ERR_TIME_SYS",
72
+ "-1603": "ERR_TIME_SAVE",
73
+ "-1701": "ERR_WIRELESS",
74
+ "-1702": "ERR_WIRELESS_UNSUPPORTED",
75
+ "-1801": "ERR_SCHEDULE",
76
+ "-1802": "ERR_SCHEDULE_FULL",
77
+ "-1803": "ERR_SCHEDULE_CONFLICT",
78
+ "-1804": "ERR_SCHEDULE_SAVE",
79
+ "-1805": "ERR_SCHEDULE_INDEX",
80
+ "-1901": "ERR_COUNTDOWN",
81
+ "-1902": "ERR_COUNTDOWN_CONFLICT",
82
+ "-1903": "ERR_COUNTDOWN_SAVE",
83
+ "-2001": "ERR_ANTITHEFT",
84
+ "-2002": "ERR_ANTITHEFT_CONFLICT",
85
+ "-2003": "ERR_ANTITHEFT_SAVE",
86
+ "-2201": "ERR_STAT",
87
+ "-2202": "ERR_STAT_SAVE",
88
+ "-2301": "ERR_DST",
89
+ "-2302": "ERR_DST_SAVE"
90
+ };
91
+ this.log.debug("Constructing P100 on host: " + ipAddress);
92
+ this.ip = ipAddress;
93
+ this.encryptCredentials(email, password);
94
+ this.createKeyPair();
95
+ this.terminalUUID = (0, import_uuid.v4)();
96
+ this._reconnect_counter = 0;
97
+ this._timeout = timeout;
98
+ }
99
+ encryptCredentials(email, password) {
100
+ this.encodedPassword = import_tpLinkCipher.default.mime_encoder(password);
101
+ this.encodedEmail = this.sha_digest_username(email);
102
+ this.encodedEmail = import_tpLinkCipher.default.mime_encoder(this.encodedEmail);
103
+ }
104
+ sha_digest_username(data) {
105
+ const digest = this.crypto.createHash("sha1").update(data).digest("hex");
106
+ return digest;
107
+ }
108
+ createKeyPair() {
109
+ const { publicKey, privateKey } = this.crypto.generateKeyPairSync("rsa", {
110
+ publicKeyEncoding: {
111
+ type: "spki",
112
+ format: "pem"
113
+ },
114
+ privateKeyEncoding: {
115
+ type: "pkcs1",
116
+ format: "pem"
117
+ },
118
+ modulusLength: 1024
119
+ });
120
+ this.privateKey = privateKey;
121
+ this.publicKey = publicKey.toString("utf8");
122
+ }
123
+ async handshake() {
124
+ const URL = "http://" + this.ip + "/app";
125
+ const payload = {
126
+ method: "handshake",
127
+ params: {
128
+ key: this.publicKey,
129
+ requestTimeMils: Math.round(Date.now() * 1e3)
130
+ }
131
+ };
132
+ this.log.debug("Handshake P100 on host: " + this.ip);
133
+ const headers = {
134
+ Connection: "Keep-Alive"
135
+ };
136
+ const config = {
137
+ timeout: 5e3,
138
+ headers
139
+ };
140
+ await this.axios.post(URL, payload, config).then((res) => {
141
+ this.log.debug("Received Handshake P100 on host response: " + this.ip);
142
+ if (res.data.error_code) {
143
+ return this.handleError(res.data.error_code, "97");
144
+ }
145
+ try {
146
+ const encryptedKey = res.data.result.key.toString("utf8");
147
+ this.decode_handshake_key(encryptedKey);
148
+ this.cookie = res.headers["set-cookie"][0].split(";")[0];
149
+ return;
150
+ } catch (error) {
151
+ return this.handleError(res.data.error_code, "106");
152
+ }
153
+ }).catch((error) => {
154
+ this.log.error("111 Error: " + error.message);
155
+ return error;
156
+ });
157
+ }
158
+ async login() {
159
+ const URL = "http://" + this.ip + "/app";
160
+ const payload = '{"method": "login_device","params": {"username": "' + this.encodedEmail + '","password": "' + this.encodedPassword + '"},"requestTimeMils": ' + Math.round(Date.now() * 1e3) + "};";
161
+ const headers = {
162
+ Cookie: this.cookie,
163
+ Connection: "Keep-Alive"
164
+ };
165
+ if (this.tpLinkCipher) {
166
+ const encryptedPayload = this.tpLinkCipher.encrypt(payload);
167
+ const securePassthroughPayload = {
168
+ method: "securePassthrough",
169
+ params: {
170
+ request: encryptedPayload
171
+ }
172
+ };
173
+ const config = {
174
+ headers,
175
+ timeout: this._timeout * 1e3
176
+ };
177
+ await this.axios.post(URL, securePassthroughPayload, config).then((res) => {
178
+ if (res.data.error_code) {
179
+ return this.handleError(res.data.error_code, "146");
180
+ }
181
+ const decryptedResponse = this.tpLinkCipher.decrypt(res.data.result.response);
182
+ try {
183
+ const response = JSON.parse(decryptedResponse);
184
+ if (response.error_code !== 0) {
185
+ return this.handleError(res.data.error_code, "152");
186
+ }
187
+ this.token = response.result.token;
188
+ return;
189
+ } catch (error) {
190
+ return this.handleError(JSON.parse(decryptedResponse).error_code, "157");
191
+ }
192
+ }).catch((error) => {
193
+ this.log.error("Error: " + error.message);
194
+ return error;
195
+ });
196
+ }
197
+ }
198
+ decode_handshake_key(key) {
199
+ const buff = Buffer.from(key, "base64");
200
+ const decoded = this.crypto.privateDecrypt(
201
+ {
202
+ key: this.privateKey,
203
+ padding: this.crypto.constants.RSA_PKCS1_PADDING
204
+ },
205
+ buff
206
+ );
207
+ const b_arr = decoded.slice(0, 16);
208
+ const b_arr2 = decoded.slice(16, 32);
209
+ this.tpLinkCipher = new import_tpLinkCipher.default(this.log, b_arr, b_arr2);
210
+ }
211
+ async turnOff() {
212
+ const payload = '{"method": "set_device_info","params": {"device_on": false},"terminalUUID": "' + this.terminalUUID + '","requestTimeMils": ' + Math.round(Date.now() * 1e3) + "};";
213
+ return this.sendRequest(payload);
214
+ }
215
+ async turnOn() {
216
+ const payload = '{"method": "set_device_info","params": {"device_on": true},"terminalUUID": "' + this.terminalUUID + '","requestTimeMils": ' + Math.round(Date.now() * 1e3) + "};";
217
+ return this.sendRequest(payload);
218
+ }
219
+ async setPowerState(state) {
220
+ if (state) {
221
+ return this.turnOn();
222
+ } else {
223
+ return this.turnOff();
224
+ }
225
+ }
226
+ async getDeviceInfo() {
227
+ if (this.getSysInfo() && Date.now() - this.getSysInfo().last_update < 2e3) {
228
+ return new Promise((resolve) => {
229
+ resolve(this.getSysInfo());
230
+ });
231
+ }
232
+ const URL = "http://" + this.ip + "/app?token=" + this.token;
233
+ const payload = '{"method": "get_device_info","requestTimeMils": ' + Math.round(Date.now() * 1e3) + "};";
234
+ const headers = {
235
+ Cookie: this.cookie
236
+ };
237
+ if (this.tpLinkCipher) {
238
+ const encryptedPayload = this.tpLinkCipher.encrypt(payload);
239
+ const securePassthroughPayload = {
240
+ method: "securePassthrough",
241
+ params: {
242
+ request: encryptedPayload
243
+ }
244
+ };
245
+ const config = {
246
+ headers,
247
+ timeout: this._timeout * 1e3
248
+ };
249
+ return this.axios.post(URL, securePassthroughPayload, config).then((res) => {
250
+ if (res.data.error_code) {
251
+ if ((res.data.error_code === "9999" || res.data.error_code === 9999) && this._reconnect_counter <= 3) {
252
+ this.log.error(" Error Code: " + res.data.error_code + ", " + this.ERROR_CODES[res.data.error_code]);
253
+ this.log.debug("Trying to reconnect...");
254
+ return this.reconnect().then(() => {
255
+ return this.getDeviceInfo();
256
+ });
257
+ }
258
+ this._reconnect_counter = 0;
259
+ return this.handleError(res.data.error_code, "326");
260
+ }
261
+ const decryptedResponse = this.tpLinkCipher.decrypt(res.data.result.response);
262
+ try {
263
+ const response = JSON.parse(decryptedResponse);
264
+ if (response.error_code !== 0) {
265
+ return this.handleError(response.error_code, "333");
266
+ }
267
+ this.setSysInfo(response.result);
268
+ this.log.debug("Device Info: ", response.result);
269
+ return this.getSysInfo();
270
+ } catch (error) {
271
+ return this.handleError(JSON.parse(decryptedResponse).error_code, "340");
272
+ }
273
+ }).catch((error) => {
274
+ this.log.debug("371 Error: " + error.message);
275
+ return error;
276
+ });
277
+ } else {
278
+ return new Promise((resolve, reject) => {
279
+ reject();
280
+ });
281
+ }
282
+ }
283
+ get id() {
284
+ if (this.getSysInfo()) {
285
+ return this.getSysInfo().device_id;
286
+ }
287
+ return "";
288
+ }
289
+ get name() {
290
+ if (this.getSysInfo()) {
291
+ return Buffer.from(this.getSysInfo().nickname, "base64").toString("utf8");
292
+ }
293
+ return "";
294
+ }
295
+ get model() {
296
+ if (this.getSysInfo()) {
297
+ return this.getSysInfo().model;
298
+ }
299
+ return "";
300
+ }
301
+ get serialNumber() {
302
+ if (this.getSysInfo()) {
303
+ this.getSysInfo().hw_id;
304
+ }
305
+ return "";
306
+ }
307
+ get firmwareRevision() {
308
+ if (this.getSysInfo()) {
309
+ return this.getSysInfo().fw_ver;
310
+ }
311
+ return "";
312
+ }
313
+ get hardwareRevision() {
314
+ if (this.getSysInfo()) {
315
+ return this.getSysInfo().hw_ver;
316
+ }
317
+ return "";
318
+ }
319
+ setSysInfo(sysInfo) {
320
+ this._plugSysInfo = sysInfo;
321
+ this._plugSysInfo.last_update = Date.now();
322
+ }
323
+ getSysInfo() {
324
+ return this._plugSysInfo;
325
+ }
326
+ handleError(errorCode, line) {
327
+ const errorMessage = this.ERROR_CODES[errorCode];
328
+ this.log.error(line + " Error Code: " + errorCode + ", " + errorMessage + " " + this.ip);
329
+ return false;
330
+ }
331
+ async sendRequest(payload) {
332
+ return this.handleRequest(payload).then((result) => {
333
+ return result ? true : false;
334
+ }).catch((error) => {
335
+ this.log.debug(JSON.stringify(error));
336
+ if (error && error.message.indexOf("9999") > 0 && this._reconnect_counter <= 3) {
337
+ return this.reconnect().then(() => {
338
+ return this.handleRequest(payload).then((result) => {
339
+ return result ? true : false;
340
+ });
341
+ });
342
+ }
343
+ this._reconnect_counter = 0;
344
+ return false;
345
+ });
346
+ }
347
+ handleRequest(payload) {
348
+ const URL = "http://" + this.ip + "/app?token=" + this.token;
349
+ const headers = {
350
+ Cookie: this.cookie,
351
+ Connection: "Keep-Alive"
352
+ };
353
+ if (this.tpLinkCipher) {
354
+ const encryptedPayload = this.tpLinkCipher.encrypt(payload);
355
+ const securePassthroughPayload = {
356
+ method: "securePassthrough",
357
+ params: {
358
+ request: encryptedPayload
359
+ }
360
+ };
361
+ const config = {
362
+ headers,
363
+ timeout: this._timeout * 1e3
364
+ };
365
+ return this.axios.post(URL, securePassthroughPayload, config).then((res) => {
366
+ if (res.data.error_code) {
367
+ if (res.data.error_code === "9999" || res.data.error_code === 9999 && this._reconnect_counter <= 3) {
368
+ this.log.error(" Error Code: " + res.data.error_code + ", " + this.ERROR_CODES[res.data.error_code]);
369
+ this.log.debug("Trying to reconnect...");
370
+ return this.reconnect().then(() => {
371
+ return this.getDeviceInfo();
372
+ });
373
+ }
374
+ this._reconnect_counter = 0;
375
+ return this.handleError(res.data.error_code, "357");
376
+ }
377
+ const decryptedResponse = this.tpLinkCipher.decrypt(res.data.result.response);
378
+ try {
379
+ const response = JSON.parse(decryptedResponse);
380
+ this.log.debug(response);
381
+ if (response.error_code !== 0) {
382
+ return this.handleError(response.error_code, "364");
383
+ }
384
+ return response;
385
+ } catch (error) {
386
+ return this.handleError(JSON.parse(decryptedResponse).error_code, "368");
387
+ }
388
+ }).catch((error) => {
389
+ return this.handleError(error.message, "372");
390
+ });
391
+ }
392
+ return new Promise((resolve, reject) => {
393
+ reject();
394
+ });
395
+ }
396
+ async reconnect() {
397
+ this._reconnect_counter++;
398
+ return this.handshake().then(() => {
399
+ this.login().then(() => {
400
+ return;
401
+ });
402
+ });
403
+ }
404
+ }
405
+ // Annotate the CommonJS export names for ESM import in node:
406
+ 0 && (module.exports = {});
407
+ //# sourceMappingURL=p100.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/lib/utils/p100.ts"],
4
+ "sourcesContent": ["import { AxiosResponse } from \"axios\";\nimport { v4 as uuidv4 } from \"uuid\";\nimport TpLinkCipher from \"./tpLinkCipher\";\nimport { PlugSysinfo } from \"./types\";\n\nexport default class P100 {\n private crypto = require(\"crypto\");\n protected axios = require(\"axios\");\n\n private encodedPassword!: string;\n private encodedEmail!: string;\n private privateKey!: string;\n private publicKey!: string;\n protected ip: string;\n protected cookie!: string;\n protected token!: string;\n protected terminalUUID: string;\n private _plugSysInfo!: PlugSysinfo;\n private _reconnect_counter: number;\n protected _timeout!: number;\n\n protected tpLinkCipher!: TpLinkCipher;\n\n protected ERROR_CODES = {\n \"0\": \"Success\",\n \"-1010\": \"Invalid Public Key Length\",\n \"-1012\": \"Invalid terminalUUID\",\n \"-1501\": \"Invalid Request or Credentials\",\n \"1002\": \"Incorrect Request\",\n \"-1003\": \"JSON formatting error \",\n \"9999\": \"Session Timeout\",\n \"-1301\": \"Device Error\",\n \"1100\": \"Handshake Failed\",\n \"1111\": \"Login Failed\",\n \"1112\": \"Http Transport Failed\",\n \"1200\": \"Multiple Requests Failed\",\n \"-1004\": \"JSON Encode Failed\",\n \"-1005\": \"AES Decode Failed\",\n \"-1006\": \"Request Length Error\",\n \"-2101\": \"Account Error\",\n \"-1\": \"ERR_COMMON_FAILED\",\n \"1000\": \"ERR_NULL_TRANSPORT\",\n \"1001\": \"ERR_CMD_COMMAND_CANCEL\",\n \"-1001\": \"ERR_UNSPECIFIC\",\n \"-1002\": \"ERR_UNKNOWN_METHOD\",\n \"-1007\": \"ERR_CLOUD_FAILED\",\n \"-1008\": \"ERR_PARAMS\",\n \"-1101\": \"ERR_SESSION_PARAM\",\n \"-1201\": \"ERR_QUICK_SETUP\",\n \"-1302\": \"ERR_DEVICE_NEXT_EVENT\",\n \"-1401\": \"ERR_FIRMWARE\",\n \"-1402\": \"ERR_FIRMWARE_VER_ERROR\",\n \"-1601\": \"ERR_TIME\",\n \"-1602\": \"ERR_TIME_SYS\",\n \"-1603\": \"ERR_TIME_SAVE\",\n \"-1701\": \"ERR_WIRELESS\",\n \"-1702\": \"ERR_WIRELESS_UNSUPPORTED\",\n \"-1801\": \"ERR_SCHEDULE\",\n \"-1802\": \"ERR_SCHEDULE_FULL\",\n \"-1803\": \"ERR_SCHEDULE_CONFLICT\",\n \"-1804\": \"ERR_SCHEDULE_SAVE\",\n \"-1805\": \"ERR_SCHEDULE_INDEX\",\n \"-1901\": \"ERR_COUNTDOWN\",\n \"-1902\": \"ERR_COUNTDOWN_CONFLICT\",\n \"-1903\": \"ERR_COUNTDOWN_SAVE\",\n \"-2001\": \"ERR_ANTITHEFT\",\n \"-2002\": \"ERR_ANTITHEFT_CONFLICT\",\n \"-2003\": \"ERR_ANTITHEFT_SAVE\",\n \"-2201\": \"ERR_STAT\",\n \"-2202\": \"ERR_STAT_SAVE\",\n \"-2301\": \"ERR_DST\",\n \"-2302\": \"ERR_DST_SAVE\",\n };\n\n constructor(\n public readonly log: any,\n public readonly ipAddress: string,\n public readonly email: string,\n public readonly password: string,\n public readonly timeout: number,\n ) {\n this.log.debug(\"Constructing P100 on host: \" + ipAddress);\n this.ip = ipAddress;\n this.encryptCredentials(email, password);\n this.createKeyPair();\n this.terminalUUID = uuidv4();\n this._reconnect_counter = 0;\n this._timeout = timeout;\n }\n\n private encryptCredentials(email: string, password: string) {\n //Password Encoding\n this.encodedPassword = TpLinkCipher.mime_encoder(password);\n\n //Email Encoding\n this.encodedEmail = this.sha_digest_username(email);\n this.encodedEmail = TpLinkCipher.mime_encoder(this.encodedEmail);\n }\n\n private sha_digest_username(data: string): string {\n const digest = this.crypto.createHash(\"sha1\").update(data).digest(\"hex\");\n\n return digest;\n }\n\n private createKeyPair() {\n // Including publicKey and privateKey from\n // generateKeyPairSync() method with its\n // parameters\n const { publicKey, privateKey } = this.crypto.generateKeyPairSync(\"rsa\", {\n publicKeyEncoding: {\n type: \"spki\",\n format: \"pem\",\n },\n privateKeyEncoding: {\n type: \"pkcs1\",\n format: \"pem\",\n },\n modulusLength: 1024,\n });\n\n this.privateKey = privateKey;\n this.publicKey = publicKey.toString(\"utf8\");\n }\n\n async handshake(): Promise<void> {\n const URL = \"http://\" + this.ip + \"/app\";\n const payload = {\n method: \"handshake\",\n params: {\n key: this.publicKey,\n requestTimeMils: Math.round(Date.now() * 1000),\n },\n };\n this.log.debug(\"Handshake P100 on host: \" + this.ip);\n\n const headers = {\n Connection: \"Keep-Alive\",\n };\n const config = {\n timeout: 5000,\n headers: headers,\n };\n\n await this.axios\n .post(URL, payload, config)\n .then((res: AxiosResponse) => {\n this.log.debug(\"Received Handshake P100 on host response: \" + this.ip);\n\n if (res.data.error_code) {\n return this.handleError(res.data.error_code, \"97\");\n }\n\n try {\n const encryptedKey = res.data.result.key.toString(\"utf8\");\n this.decode_handshake_key(encryptedKey);\n this.cookie = res.headers[\"set-cookie\"][0].split(\";\")[0];\n return;\n } catch (error) {\n return this.handleError(res.data.error_code, \"106\");\n }\n })\n .catch((error: Error) => {\n this.log.error(\"111 Error: \" + error.message);\n return error;\n });\n }\n\n async login(): Promise<void> {\n const URL = \"http://\" + this.ip + \"/app\";\n const payload =\n \"{\" +\n '\"method\": \"login_device\",' +\n '\"params\": {' +\n '\"username\": \"' +\n this.encodedEmail +\n '\",' +\n '\"password\": \"' +\n this.encodedPassword +\n '\"' +\n \"},\" +\n '\"requestTimeMils\": ' +\n Math.round(Date.now() * 1000) +\n \"\" +\n \"};\";\n\n const headers = {\n Cookie: this.cookie,\n Connection: \"Keep-Alive\",\n };\n\n if (this.tpLinkCipher) {\n const encryptedPayload = this.tpLinkCipher.encrypt(payload);\n\n const securePassthroughPayload = {\n method: \"securePassthrough\",\n params: {\n request: encryptedPayload,\n },\n };\n\n const config = {\n headers: headers,\n timeout: this._timeout * 1000,\n };\n\n await this.axios\n .post(URL, securePassthroughPayload, config)\n .then((res: AxiosResponse) => {\n if (res.data.error_code) {\n return this.handleError(res.data.error_code, \"146\");\n }\n const decryptedResponse = this.tpLinkCipher.decrypt(res.data.result.response);\n try {\n const response = JSON.parse(decryptedResponse);\n if (response.error_code !== 0) {\n return this.handleError(res.data.error_code, \"152\");\n }\n this.token = response.result.token;\n return;\n } catch (error) {\n return this.handleError(JSON.parse(decryptedResponse).error_code, \"157\");\n }\n })\n .catch((error: Error) => {\n this.log.error(\"Error: \" + error.message);\n return error;\n });\n }\n }\n\n private decode_handshake_key(key: string) {\n const buff = Buffer.from(key, \"base64\");\n\n const decoded = this.crypto.privateDecrypt(\n {\n key: this.privateKey,\n padding: this.crypto.constants.RSA_PKCS1_PADDING,\n },\n buff,\n );\n\n const b_arr = decoded.slice(0, 16);\n const b_arr2 = decoded.slice(16, 32);\n\n this.tpLinkCipher = new TpLinkCipher(this.log, b_arr, b_arr2);\n }\n\n async turnOff(): Promise<boolean> {\n const payload =\n \"{\" +\n '\"method\": \"set_device_info\",' +\n '\"params\": {' +\n '\"device_on\": false' +\n \"},\" +\n '\"terminalUUID\": \"' +\n this.terminalUUID +\n '\",' +\n '\"requestTimeMils\": ' +\n Math.round(Date.now() * 1000) +\n \"\" +\n \"};\";\n return this.sendRequest(payload);\n }\n\n async turnOn(): Promise<boolean> {\n const payload =\n \"{\" +\n '\"method\": \"set_device_info\",' +\n '\"params\": {' +\n '\"device_on\": true' +\n \"},\" +\n '\"terminalUUID\": \"' +\n this.terminalUUID +\n '\",' +\n '\"requestTimeMils\": ' +\n Math.round(Date.now() * 1000) +\n \"\" +\n \"};\";\n\n return this.sendRequest(payload);\n }\n\n async setPowerState(state: boolean): Promise<boolean> {\n if (state) {\n return this.turnOn();\n } else {\n return this.turnOff();\n }\n }\n\n async getDeviceInfo(): Promise<PlugSysinfo> {\n if (this.getSysInfo() && Date.now() - this.getSysInfo().last_update < 2000) {\n return new Promise((resolve) => {\n resolve(this.getSysInfo());\n });\n }\n const URL = \"http://\" + this.ip + \"/app?token=\" + this.token;\n\n const payload =\n \"{\" + '\"method\": \"get_device_info\",' + '\"requestTimeMils\": ' + Math.round(Date.now() * 1000) + \"\" + \"};\";\n const headers = {\n Cookie: this.cookie,\n };\n\n if (this.tpLinkCipher) {\n const encryptedPayload = this.tpLinkCipher.encrypt(payload);\n\n const securePassthroughPayload = {\n method: \"securePassthrough\",\n params: {\n request: encryptedPayload,\n },\n };\n\n const config = {\n headers: headers,\n timeout: this._timeout * 1000,\n };\n\n return this.axios\n .post(URL, securePassthroughPayload, config)\n .then((res) => {\n if (res.data.error_code) {\n if ((res.data.error_code === \"9999\" || res.data.error_code === 9999) && this._reconnect_counter <= 3) {\n this.log.error(\" Error Code: \" + res.data.error_code + \", \" + this.ERROR_CODES[res.data.error_code]);\n this.log.debug(\"Trying to reconnect...\");\n return this.reconnect().then(() => {\n return this.getDeviceInfo();\n });\n }\n this._reconnect_counter = 0;\n return this.handleError(res.data.error_code, \"326\");\n }\n\n const decryptedResponse = this.tpLinkCipher.decrypt(res.data.result.response);\n try {\n const response = JSON.parse(decryptedResponse);\n if (response.error_code !== 0) {\n return this.handleError(response.error_code, \"333\");\n }\n this.setSysInfo(response.result);\n this.log.debug(\"Device Info: \", response.result);\n\n return this.getSysInfo();\n } catch (error) {\n return this.handleError(JSON.parse(decryptedResponse).error_code, \"340\");\n }\n })\n .catch((error: Error) => {\n this.log.debug(\"371 Error: \" + error.message);\n return error;\n });\n } else {\n return new Promise<PlugSysinfo>((resolve, reject) => {\n reject();\n });\n }\n }\n\n /**\n * Cached value of `sysinfo.device_id` if set.\n */\n get id(): string {\n if (this.getSysInfo()) {\n return this.getSysInfo().device_id;\n }\n return \"\";\n }\n\n /**\n * Cached value of `sysinfo.device_id` if set.\n */\n get name(): string {\n if (this.getSysInfo()) {\n return Buffer.from(this.getSysInfo().nickname, \"base64\").toString(\"utf8\");\n }\n return \"\";\n }\n\n get model(): string {\n if (this.getSysInfo()) {\n return this.getSysInfo().model;\n }\n return \"\";\n }\n\n get serialNumber(): string {\n if (this.getSysInfo()) {\n this.getSysInfo().hw_id;\n }\n return \"\";\n }\n\n get firmwareRevision(): string {\n if (this.getSysInfo()) {\n return this.getSysInfo().fw_ver;\n }\n return \"\";\n }\n\n get hardwareRevision(): string {\n if (this.getSysInfo()) {\n return this.getSysInfo().hw_ver;\n }\n return \"\";\n }\n\n protected setSysInfo(sysInfo: PlugSysinfo) {\n this._plugSysInfo = sysInfo;\n this._plugSysInfo.last_update = Date.now();\n }\n\n public getSysInfo(): PlugSysinfo {\n return this._plugSysInfo;\n }\n\n protected handleError(errorCode: string, line: string): boolean {\n const errorMessage = this.ERROR_CODES[errorCode];\n this.log.error(line + \" Error Code: \" + errorCode + \", \" + errorMessage + \" \" + this.ip);\n return false;\n }\n\n protected async sendRequest(payload: string): Promise<boolean> {\n return this.handleRequest(payload)\n .then((result) => {\n return result ? true : false;\n })\n .catch((error) => {\n this.log.debug(JSON.stringify(error));\n if (error && error.message.indexOf(\"9999\") > 0 && this._reconnect_counter <= 3) {\n return this.reconnect().then(() => {\n return this.handleRequest(payload).then((result) => {\n return result ? true : false;\n });\n });\n }\n this._reconnect_counter = 0;\n return false;\n });\n }\n\n protected handleRequest(payload: string): Promise<any> {\n const URL = \"http://\" + this.ip + \"/app?token=\" + this.token;\n\n const headers = {\n Cookie: this.cookie,\n Connection: \"Keep-Alive\",\n };\n\n if (this.tpLinkCipher) {\n const encryptedPayload = this.tpLinkCipher.encrypt(payload);\n\n const securePassthroughPayload = {\n method: \"securePassthrough\",\n params: {\n request: encryptedPayload,\n },\n };\n\n const config = {\n headers: headers,\n timeout: this._timeout * 1000,\n };\n\n return this.axios\n .post(URL, securePassthroughPayload, config)\n .then((res: AxiosResponse) => {\n if (res.data.error_code) {\n if (res.data.error_code === \"9999\" || (res.data.error_code === 9999 && this._reconnect_counter <= 3)) {\n this.log.error(\" Error Code: \" + res.data.error_code + \", \" + this.ERROR_CODES[res.data.error_code]);\n this.log.debug(\"Trying to reconnect...\");\n return this.reconnect().then(() => {\n return this.getDeviceInfo();\n });\n }\n this._reconnect_counter = 0;\n return this.handleError(res.data.error_code, \"357\");\n }\n\n const decryptedResponse = this.tpLinkCipher.decrypt(res.data.result.response);\n try {\n const response = JSON.parse(decryptedResponse);\n this.log.debug(response);\n if (response.error_code !== 0) {\n return this.handleError(response.error_code, \"364\");\n }\n return response;\n } catch (error) {\n return this.handleError(JSON.parse(decryptedResponse).error_code, \"368\");\n }\n })\n .catch((error: Error) => {\n return this.handleError(error.message, \"372\");\n });\n }\n return new Promise<true>((resolve, reject) => {\n reject();\n });\n }\n\n protected async reconnect(): Promise<void> {\n this._reconnect_counter++;\n return this.handshake().then(() => {\n this.login().then(() => {\n return;\n });\n });\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAA6B;AAC7B,0BAAyB;AAGzB,MAAO,KAAmB;AAAA,EAqExB,YACkB,KACA,WACA,OACA,UACA,SAChB;AALgB;AACA;AACA;AACA;AACA;AAzElB,SAAQ,SAAS,QAAQ,QAAQ;AACjC,SAAU,QAAQ,QAAQ,OAAO;AAgBjC,SAAU,cAAc;AAAA,MACtB,KAAK;AAAA,MACL,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,QAAQ;AAAA,MACR,QAAQ;AAAA,MACR,QAAQ;AAAA,MACR,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,QAAQ;AAAA,MACR,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAA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AAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;",
6
+ "names": ["uuidv4", "TpLinkCipher"]
7
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var p110_exports = {};
26
+ __export(p110_exports, {
27
+ default: () => P110
28
+ });
29
+ module.exports = __toCommonJS(p110_exports);
30
+ var import_p100 = __toESM(require("./p100"));
31
+ class P110 extends import_p100.default {
32
+ constructor(log, ipAddress, email, password, timeout) {
33
+ super(log, ipAddress, email, password, timeout);
34
+ this.log = log;
35
+ this.ipAddress = ipAddress;
36
+ this.email = email;
37
+ this.password = password;
38
+ this.timeout = timeout;
39
+ this.log.debug("Constructing P110 on host: " + ipAddress);
40
+ }
41
+ async getEnergyUsage() {
42
+ const payload = '{"method": "get_energy_usage","requestTimeMils": ' + Math.round(Date.now() * 1e3) + "};";
43
+ return this.handleRequest(payload).then((response) => {
44
+ if (response && response.result) {
45
+ this._consumption = {
46
+ current: response.result.current_power / 1e3,
47
+ total: response.result.today_energy / 1e3
48
+ };
49
+ } else {
50
+ this._consumption = {
51
+ current: 0,
52
+ total: 0
53
+ };
54
+ }
55
+ return response.result;
56
+ });
57
+ }
58
+ getPowerConsumption() {
59
+ return this._consumption;
60
+ }
61
+ }
62
+ // Annotate the CommonJS export names for ESM import in node:
63
+ 0 && (module.exports = {});
64
+ //# sourceMappingURL=p110.js.map