homebridge-midea-platform 1.2.0-beta.8 → 1.2.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.
- package/CHANGELOG.md +5 -2
- package/README.md +2 -2
- package/dist/accessory/AccessoryFactory.d.ts +14 -15
- package/dist/accessory/AccessoryFactory.js +34 -40
- package/dist/accessory/AccessoryFactory.js.map +1 -1
- package/dist/accessory/AirConditionerAccessory.d.ts +98 -99
- package/dist/accessory/AirConditionerAccessory.js +666 -662
- package/dist/accessory/AirConditionerAccessory.js.map +1 -1
- package/dist/accessory/BaseAccessory.d.ts +11 -12
- package/dist/accessory/BaseAccessory.js +21 -21
- package/dist/accessory/BaseAccessory.js.map +1 -1
- package/dist/accessory/DehumidifierAccessory.d.ts +45 -46
- package/dist/accessory/DehumidifierAccessory.js +343 -344
- package/dist/accessory/DehumidifierAccessory.js.map +1 -1
- package/dist/accessory/DishwasherAccessory.d.ts +30 -31
- package/dist/accessory/DishwasherAccessory.js +59 -63
- package/dist/accessory/DishwasherAccessory.js.map +1 -1
- package/dist/accessory/ElectricWaterHeaterAccessory.d.ts +44 -45
- package/dist/accessory/ElectricWaterHeaterAccessory.js +172 -176
- package/dist/accessory/ElectricWaterHeaterAccessory.js.map +1 -1
- package/dist/accessory/FanAccessory.d.ts +39 -40
- package/dist/accessory/FanAccessory.js +120 -123
- package/dist/accessory/FanAccessory.js.map +1 -1
- package/dist/accessory/FrontLoadWasherAccessory.d.ts +30 -31
- package/dist/accessory/FrontLoadWasherAccessory.js +63 -66
- package/dist/accessory/FrontLoadWasherAccessory.js.map +1 -1
- package/dist/accessory/GasWaterHeaterAccessory.d.ts +51 -52
- package/dist/accessory/GasWaterHeaterAccessory.js +217 -216
- package/dist/accessory/GasWaterHeaterAccessory.js.map +1 -1
- package/dist/accessory/{HeatPumpWifiControllerAccessory.d.ts → HeatPumpWiFiControllerAccessory.d.ts} +34 -35
- package/dist/accessory/{HeatPumpWifiControllerAccessory.js → HeatPumpWiFiControllerAccessory.js} +55 -36
- package/dist/accessory/HeatPumpWiFiControllerAccessory.js.map +1 -0
- package/dist/core/MideaCloud.d.ts +34 -36
- package/dist/core/MideaCloud.js +349 -350
- package/dist/core/MideaCloud.js.map +1 -1
- package/dist/core/MideaConstants.d.ts +51 -52
- package/dist/core/MideaConstants.js +56 -59
- package/dist/core/MideaConstants.js.map +1 -1
- package/dist/core/MideaDevice.d.ts +75 -78
- package/dist/core/MideaDevice.js +430 -420
- package/dist/core/MideaDevice.js.map +1 -1
- package/dist/core/MideaDiscover.d.ts +34 -36
- package/dist/core/MideaDiscover.js +208 -212
- package/dist/core/MideaDiscover.js.map +1 -1
- package/dist/core/MideaMessage.d.ts +75 -76
- package/dist/core/MideaMessage.js +185 -184
- package/dist/core/MideaMessage.js.map +1 -1
- package/dist/core/MideaPacketBuilder.d.ts +9 -11
- package/dist/core/MideaPacketBuilder.js +60 -60
- package/dist/core/MideaPacketBuilder.js.map +1 -1
- package/dist/core/MideaSecurity.d.ts +62 -64
- package/dist/core/MideaSecurity.js +241 -251
- package/dist/core/MideaSecurity.js.map +1 -1
- package/dist/core/MideaUtils.d.ts +31 -33
- package/dist/core/MideaUtils.js +178 -181
- package/dist/core/MideaUtils.js.map +1 -1
- package/dist/devices/DeviceFactory.d.ts +14 -15
- package/dist/devices/DeviceFactory.js +34 -40
- package/dist/devices/DeviceFactory.js.map +1 -1
- package/dist/devices/a1/MideaA1Device.d.ts +75 -77
- package/dist/devices/a1/MideaA1Device.js +142 -145
- package/dist/devices/a1/MideaA1Device.js.map +1 -1
- package/dist/devices/a1/MideaA1Message.d.ts +39 -41
- package/dist/devices/a1/MideaA1Message.js +219 -198
- package/dist/devices/a1/MideaA1Message.js.map +1 -1
- package/dist/devices/ac/MideaACDevice.d.ts +105 -107
- package/dist/devices/ac/MideaACDevice.js +417 -400
- package/dist/devices/ac/MideaACDevice.js.map +1 -1
- package/dist/devices/ac/MideaACMessage.d.ts +97 -96
- package/dist/devices/ac/MideaACMessage.js +724 -621
- package/dist/devices/ac/MideaACMessage.js.map +1 -1
- package/dist/devices/c3/MideaC3Device.d.ts +73 -75
- package/dist/devices/c3/MideaC3Device.js +249 -255
- package/dist/devices/c3/MideaC3Device.js.map +1 -1
- package/dist/devices/c3/MideaC3Message.d.ts +81 -80
- package/dist/devices/c3/MideaC3Message.js +190 -152
- package/dist/devices/c3/MideaC3Message.js.map +1 -1
- package/dist/devices/db/MideaDBDevice.d.ts +28 -30
- package/dist/devices/db/MideaDBDevice.js +94 -100
- package/dist/devices/db/MideaDBDevice.js.map +1 -1
- package/dist/devices/db/MideaDBMessage.d.ts +31 -33
- package/dist/devices/db/MideaDBMessage.js +101 -101
- package/dist/devices/db/MideaDBMessage.js.map +1 -1
- package/dist/devices/e1/MideaE1Device.d.ts +55 -57
- package/dist/devices/e1/MideaE1Device.js +122 -128
- package/dist/devices/e1/MideaE1Device.js.map +1 -1
- package/dist/devices/e1/MideaE1Message.d.ts +27 -29
- package/dist/devices/e1/MideaE1Message.js +128 -107
- package/dist/devices/e1/MideaE1Message.js.map +1 -1
- package/dist/devices/e2/MideaE2Device.d.ts +43 -45
- package/dist/devices/e2/MideaE2Device.js +124 -129
- package/dist/devices/e2/MideaE2Device.js.map +1 -1
- package/dist/devices/e2/MideaE2Message.d.ts +34 -34
- package/dist/devices/e2/MideaE2Message.js +143 -132
- package/dist/devices/e2/MideaE2Message.js.map +1 -1
- package/dist/devices/e3/MideaE3Device.d.ts +42 -44
- package/dist/devices/e3/MideaE3Device.js +132 -137
- package/dist/devices/e3/MideaE3Device.js.map +1 -1
- package/dist/devices/e3/MideaE3Message.d.ts +51 -52
- package/dist/devices/e3/MideaE3Message.js +144 -136
- package/dist/devices/e3/MideaE3Message.js.map +1 -1
- package/dist/devices/fa/MideaFADevice.d.ts +35 -37
- package/dist/devices/fa/MideaFADevice.js +102 -106
- package/dist/devices/fa/MideaFADevice.js.map +1 -1
- package/dist/devices/fa/MideaFAMessage.d.ts +38 -39
- package/dist/devices/fa/MideaFAMessage.js +108 -98
- package/dist/devices/fa/MideaFAMessage.js.map +1 -1
- package/dist/index.d.ts +6 -7
- package/dist/index.js +8 -6
- package/dist/index.js.map +1 -1
- package/dist/platform.d.ts +61 -61
- package/dist/platform.js +232 -212
- package/dist/platform.js.map +1 -1
- package/dist/platformUtils.d.ts +116 -117
- package/dist/platformUtils.js +107 -110
- package/dist/platformUtils.js.map +1 -1
- package/dist/settings.d.ts +8 -9
- package/dist/settings.js +8 -11
- package/dist/settings.js.map +1 -1
- package/docs/download_lua.md +9 -0
- package/eslint.config.js +43 -0
- package/homebridge-ui/public/js/bootstrap.min.js +1179 -1
- package/homebridge-ui/server.js +157 -84
- package/package.json +21 -31
- package/.eslintignore +0 -3
- package/.husky/pre-commit +0 -5
- package/.prettierrc +0 -19
- package/dist/accessory/AccessoryFactory.d.ts.map +0 -1
- package/dist/accessory/AirConditionerAccessory.d.ts.map +0 -1
- package/dist/accessory/BaseAccessory.d.ts.map +0 -1
- package/dist/accessory/DehumidifierAccessory.d.ts.map +0 -1
- package/dist/accessory/DishwasherAccessory.d.ts.map +0 -1
- package/dist/accessory/ElectricWaterHeaterAccessory.d.ts.map +0 -1
- package/dist/accessory/FanAccessory.d.ts.map +0 -1
- package/dist/accessory/FrontLoadWasherAccessory.d.ts.map +0 -1
- package/dist/accessory/GasWaterHeaterAccessory.d.ts.map +0 -1
- package/dist/accessory/HeatPumpWifiControllerAccessory.d.ts.map +0 -1
- package/dist/accessory/HeatPumpWifiControllerAccessory.js.map +0 -1
- package/dist/core/MideaCloud.d.ts.map +0 -1
- package/dist/core/MideaConstants.d.ts.map +0 -1
- package/dist/core/MideaDevice.d.ts.map +0 -1
- package/dist/core/MideaDiscover.d.ts.map +0 -1
- package/dist/core/MideaMessage.d.ts.map +0 -1
- package/dist/core/MideaPacketBuilder.d.ts.map +0 -1
- package/dist/core/MideaSecurity.d.ts.map +0 -1
- package/dist/core/MideaUtils.d.ts.map +0 -1
- package/dist/devices/DeviceFactory.d.ts.map +0 -1
- package/dist/devices/a1/MideaA1Device.d.ts.map +0 -1
- package/dist/devices/a1/MideaA1Message.d.ts.map +0 -1
- package/dist/devices/ac/MideaACDevice.d.ts.map +0 -1
- package/dist/devices/ac/MideaACMessage.d.ts.map +0 -1
- package/dist/devices/c3/MideaC3Device.d.ts.map +0 -1
- package/dist/devices/c3/MideaC3Message.d.ts.map +0 -1
- package/dist/devices/db/MideaDBDevice.d.ts.map +0 -1
- package/dist/devices/db/MideaDBMessage.d.ts.map +0 -1
- package/dist/devices/e1/MideaE1Device.d.ts.map +0 -1
- package/dist/devices/e1/MideaE1Message.d.ts.map +0 -1
- package/dist/devices/e2/MideaE2Device.d.ts.map +0 -1
- package/dist/devices/e2/MideaE2Message.d.ts.map +0 -1
- package/dist/devices/e3/MideaE3Device.d.ts.map +0 -1
- package/dist/devices/e3/MideaE3Message.d.ts.map +0 -1
- package/dist/devices/fa/MideaFADevice.d.ts.map +0 -1
- package/dist/devices/fa/MideaFAMessage.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/platform.d.ts.map +0 -1
- package/dist/platformUtils.d.ts.map +0 -1
- package/dist/settings.d.ts.map +0 -1
package/dist/core/MideaCloud.js
CHANGED
|
@@ -1,351 +1,350 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
this.
|
|
32
|
-
|
|
33
|
-
this.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
return response.data
|
|
270
|
-
}
|
|
271
|
-
else {
|
|
272
|
-
throw new Error(`Error response from API: ${JSON.stringify(response.data)}`);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
catch (error) {
|
|
276
|
-
throw new Error(`Error while sending request to ${url}: ${error}`);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
throw new Error(`Failed to send request to ${url}.`);
|
|
280
|
-
}
|
|
281
|
-
async login() {
|
|
282
|
-
// We need to protect against multiple attempts to login, so we only login if not already
|
|
283
|
-
// logged in. Protect this block with a semaphone.
|
|
284
|
-
const releaseSemaphore = await this.semaphore.acquire('Obtain login semaphore');
|
|
285
|
-
try {
|
|
286
|
-
if (this.loggedIn) {
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
// Not logged in so proceed...
|
|
290
|
-
const login_id = await this.getLoginId();
|
|
291
|
-
const data = {
|
|
292
|
-
...this.buildRequestData(),
|
|
293
|
-
loginAccount: this.account,
|
|
294
|
-
password: this.security.encrpytPassword(login_id, this.password),
|
|
295
|
-
};
|
|
296
|
-
if (this.sessionId) {
|
|
297
|
-
data
|
|
298
|
-
}
|
|
299
|
-
const response = await this.apiRequest('/v1/user/login', data);
|
|
300
|
-
if (response) {
|
|
301
|
-
this.access_token = response
|
|
302
|
-
this.sessionId = response
|
|
303
|
-
this.uid = response
|
|
304
|
-
this.loggedIn = true;
|
|
305
|
-
}
|
|
306
|
-
else {
|
|
307
|
-
this.loggedIn = false;
|
|
308
|
-
throw new Error('Failed to login.');
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
catch (e) {
|
|
312
|
-
const msg = e instanceof Error ? e.stack : e;
|
|
313
|
-
throw new Error(`Error in Adding new accessory:\n${msg}`);
|
|
314
|
-
}
|
|
315
|
-
finally {
|
|
316
|
-
releaseSemaphore();
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
class NetHomePlusCloud extends SimpleCloud {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
class AristonClimaCloud extends SimpleCloud {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
class CloudFactory {
|
|
335
|
-
static createCloud(account, password, cloud) {
|
|
336
|
-
switch (cloud) {
|
|
337
|
-
case 'Midea SmartHome (MSmartHome)':
|
|
338
|
-
return new MSmartHomeCloud(account, password);
|
|
339
|
-
case 'Meiju':
|
|
340
|
-
return new MeijuCloud(account, password);
|
|
341
|
-
case 'NetHome Plus':
|
|
342
|
-
return new NetHomePlusCloud(account, password);
|
|
343
|
-
case 'Ariston Clima':
|
|
344
|
-
return new AristonClimaCloud(account, password);
|
|
345
|
-
default:
|
|
346
|
-
throw new Error(`Cloud ${cloud} is not supported.`);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
exports.default = CloudFactory;
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* Midea Cloud access functions
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2023 Kovalovszky Patrik, https://github.com/kovapatrik
|
|
5
|
+
* Portions Copyright (c) 2023 David Kerr, https://github.com/dkerr64
|
|
6
|
+
*
|
|
7
|
+
* With thanks to https://github.com/georgezhao2010/midea_ac_lan and
|
|
8
|
+
* https://github.com/mill1000/midea-msmart
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
import axios from 'axios';
|
|
12
|
+
import { randomBytes } from 'crypto';
|
|
13
|
+
import { DateTime } from 'luxon';
|
|
14
|
+
import { Semaphore } from 'semaphore-promise';
|
|
15
|
+
import { ArtisonClimaSecurity, CloudSecurity, MeijuCloudSecurity, MSmartHomeCloudSecurity, NetHomePlusSecurity, } from './MideaSecurity.js';
|
|
16
|
+
import { numberToUint8Array } from './MideaUtils.js';
|
|
17
|
+
class CloudBase {
|
|
18
|
+
account;
|
|
19
|
+
password;
|
|
20
|
+
security;
|
|
21
|
+
CLIENT_TYPE = 1;
|
|
22
|
+
FORMAT = 2;
|
|
23
|
+
LANGUAGE = 'en_US';
|
|
24
|
+
DEVICE_ID = randomBytes(8).toString('hex');
|
|
25
|
+
access_token;
|
|
26
|
+
uid;
|
|
27
|
+
key;
|
|
28
|
+
semaphore;
|
|
29
|
+
loggedIn = false;
|
|
30
|
+
constructor(account, password, security) {
|
|
31
|
+
this.account = account;
|
|
32
|
+
this.password = password;
|
|
33
|
+
this.security = security;
|
|
34
|
+
// Required to serialize access to some cloud functions.
|
|
35
|
+
this.semaphore = new Semaphore();
|
|
36
|
+
}
|
|
37
|
+
timestamp() {
|
|
38
|
+
return DateTime.now().toFormat('yyyyMMddHHmmss');
|
|
39
|
+
}
|
|
40
|
+
async getLoginId() {
|
|
41
|
+
try {
|
|
42
|
+
const response = await this.apiRequest('/v1/user/login/id/get', {
|
|
43
|
+
...this.buildRequestData(),
|
|
44
|
+
loginAccount: this.account,
|
|
45
|
+
});
|
|
46
|
+
if (response) {
|
|
47
|
+
return response.loginId;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
const msg = e instanceof Error ? e.stack : e;
|
|
52
|
+
throw new Error(`Failed to get login ID:\n${msg}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async getTokenKey(device_id, endianess) {
|
|
56
|
+
const udpid = CloudSecurity.getUDPID(numberToUint8Array(device_id, 6, endianess));
|
|
57
|
+
const response = await this.apiRequest('/v1/iot/secure/getToken', {
|
|
58
|
+
...this.buildRequestData(),
|
|
59
|
+
udpid: udpid,
|
|
60
|
+
});
|
|
61
|
+
if (response) {
|
|
62
|
+
for (const token of response.tokenlist) {
|
|
63
|
+
if (token.udpId === udpid) {
|
|
64
|
+
return [Buffer.from(token.token, 'hex'), Buffer.from(token.key, 'hex')];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
throw new Error('Failed to get token.');
|
|
70
|
+
}
|
|
71
|
+
throw new Error(`No token/key found for udpid ${udpid}.`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
class ProxiedCloudBase extends CloudBase {
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
76
|
+
async apiRequest(endpoint, data) {
|
|
77
|
+
const url = `${this.API_URL}${endpoint}`;
|
|
78
|
+
const random = randomBytes(16).toString('hex');
|
|
79
|
+
const sign = this.security.sign(JSON.stringify(data), random);
|
|
80
|
+
const headers = {
|
|
81
|
+
'Content-Type': 'application/json',
|
|
82
|
+
secretVersion: '1',
|
|
83
|
+
sign: sign,
|
|
84
|
+
random: random,
|
|
85
|
+
};
|
|
86
|
+
if (this.uid) {
|
|
87
|
+
headers.uid = this.uid;
|
|
88
|
+
}
|
|
89
|
+
if (this.access_token) {
|
|
90
|
+
headers.accessToken = this.access_token;
|
|
91
|
+
}
|
|
92
|
+
for (let i = 0; i < 3; i++) {
|
|
93
|
+
try {
|
|
94
|
+
const response = await axios.post(url, data, { headers: headers, timeout: 10000 });
|
|
95
|
+
if (response.data.code !== undefined) {
|
|
96
|
+
if (Number.parseInt(response.data.code) === 0) {
|
|
97
|
+
return response.data.data;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
throw new Error(`Error response from API: ${JSON.stringify(response.data)}`);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
throw new Error(`Error while sending request to ${url}: ${error}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
throw new Error(`Failed to send request to ${url}.`);
|
|
107
|
+
}
|
|
108
|
+
buildRequestData() {
|
|
109
|
+
return {
|
|
110
|
+
appId: this.APP_ID,
|
|
111
|
+
format: this.FORMAT,
|
|
112
|
+
clientType: this.CLIENT_TYPE,
|
|
113
|
+
language: this.LANGUAGE,
|
|
114
|
+
src: this.APP_ID,
|
|
115
|
+
stamp: this.timestamp(),
|
|
116
|
+
deviceId: this.DEVICE_ID,
|
|
117
|
+
reqId: randomBytes(16).toString('hex'),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
async login() {
|
|
121
|
+
const releaseSemaphore = await this.semaphore.acquire('Obtain login semaphore');
|
|
122
|
+
try {
|
|
123
|
+
if (this.loggedIn) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
// Not logged in so proceed...
|
|
127
|
+
const login_id = await this.getLoginId();
|
|
128
|
+
const iotData = this.buildRequestData();
|
|
129
|
+
delete iotData.uid;
|
|
130
|
+
const response = await this.apiRequest('/mj/user/login', {
|
|
131
|
+
data: {
|
|
132
|
+
platform: this.FORMAT,
|
|
133
|
+
deviceId: this.DEVICE_ID,
|
|
134
|
+
},
|
|
135
|
+
iotData: {
|
|
136
|
+
appId: this.APP_ID,
|
|
137
|
+
clientType: this.CLIENT_TYPE,
|
|
138
|
+
iampwd: this.security.encrpytIAMPassword(login_id, this.password),
|
|
139
|
+
loginAccount: this.account,
|
|
140
|
+
password: this.security.encrpytPassword(login_id, this.password),
|
|
141
|
+
pushToken: randomBytes(16).toString('base64url'),
|
|
142
|
+
reqId: randomBytes(16).toString('hex'),
|
|
143
|
+
src: this.APP_ID,
|
|
144
|
+
stamp: this.timestamp(),
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
if (response) {
|
|
148
|
+
this.access_token = response.mdata.accessToken;
|
|
149
|
+
if (response.key !== undefined) {
|
|
150
|
+
this.key = response.key;
|
|
151
|
+
}
|
|
152
|
+
this.loggedIn = true;
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
this.loggedIn = false;
|
|
156
|
+
throw new Error('Failed to login.');
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
catch (e) {
|
|
160
|
+
const msg = e instanceof Error ? e.stack : e;
|
|
161
|
+
throw new Error(`Error in Adding new accessory:\n${msg}`);
|
|
162
|
+
}
|
|
163
|
+
finally {
|
|
164
|
+
releaseSemaphore();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async getProtocolLua(deviceType, serialNumber) {
|
|
168
|
+
const response = await this.apiRequest('/v2/luaEncryption/luaGet', {
|
|
169
|
+
...this.buildRequestData(),
|
|
170
|
+
applianceMFCode: '0000',
|
|
171
|
+
applianceSn: this.security.encryptAESAppKey(Buffer.from(serialNumber, 'utf8')).toString('hex'),
|
|
172
|
+
applianceType: `0x${deviceType.toString(16).padStart(2, '0')}`,
|
|
173
|
+
encryptedType: 2,
|
|
174
|
+
version: '0',
|
|
175
|
+
});
|
|
176
|
+
if (response && response.url) {
|
|
177
|
+
const lua = await axios.get(response.url);
|
|
178
|
+
const encrypted_data = Buffer.from(lua.data, 'hex');
|
|
179
|
+
const file_data = this.security.decryptAESAppKey(encrypted_data).toString('utf8');
|
|
180
|
+
if (file_data) {
|
|
181
|
+
return file_data;
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
throw new Error('Failed to decrypt plugin.');
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
throw new Error('Failed to get protocol.');
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
async getPlugin(deviceType, serialNumber) {
|
|
192
|
+
const response = await this.apiRequest('/v1/plugin/update/overseas/get', {
|
|
193
|
+
...this.buildRequestData(),
|
|
194
|
+
clientVersion: '0',
|
|
195
|
+
uid: this.uid ?? randomBytes(16).toString('hex'),
|
|
196
|
+
applianceList: [
|
|
197
|
+
{
|
|
198
|
+
appModel: serialNumber.substring(9, 17),
|
|
199
|
+
appType: `0x${deviceType.toString(16).padStart(2, '0')}`,
|
|
200
|
+
modelNumber: '0',
|
|
201
|
+
},
|
|
202
|
+
],
|
|
203
|
+
});
|
|
204
|
+
if (response) {
|
|
205
|
+
return response;
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
throw new Error('Failed to get plugin.');
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
class MSmartHomeCloud extends ProxiedCloudBase {
|
|
213
|
+
APP_ID = '1010';
|
|
214
|
+
API_URL = 'https://mp-prod.appsmb.com/mas/v5/app/proxy?alias=';
|
|
215
|
+
constructor(account, password) {
|
|
216
|
+
super(account, password, new MSmartHomeCloudSecurity());
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
class MeijuCloud extends ProxiedCloudBase {
|
|
220
|
+
APP_ID = '1010';
|
|
221
|
+
API_URL = 'https://mp-prod.smartmidea.net/mas/v5/app/proxy?alias=';
|
|
222
|
+
constructor(account, password) {
|
|
223
|
+
super(account, password, new MeijuCloudSecurity());
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
class SimpleCloud extends CloudBase {
|
|
227
|
+
sessionId;
|
|
228
|
+
constructor(account, password, security) {
|
|
229
|
+
super(account, password, security);
|
|
230
|
+
}
|
|
231
|
+
buildRequestData() {
|
|
232
|
+
const data = {
|
|
233
|
+
appId: this.APP_ID,
|
|
234
|
+
format: 2,
|
|
235
|
+
clientType: 1,
|
|
236
|
+
language: this.LANGUAGE,
|
|
237
|
+
src: this.APP_ID,
|
|
238
|
+
stamp: this.timestamp(),
|
|
239
|
+
deviceId: this.DEVICE_ID,
|
|
240
|
+
};
|
|
241
|
+
if (this.sessionId) {
|
|
242
|
+
data.sessionId = this.sessionId;
|
|
243
|
+
}
|
|
244
|
+
return data;
|
|
245
|
+
}
|
|
246
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
247
|
+
async apiRequest(endpoint, data, header) {
|
|
248
|
+
const headers = {
|
|
249
|
+
...header,
|
|
250
|
+
};
|
|
251
|
+
if (data.stamp === undefined) {
|
|
252
|
+
data.stamp = this.timestamp();
|
|
253
|
+
}
|
|
254
|
+
const url = `${this.API_URL}${endpoint}`;
|
|
255
|
+
const queryParams = new URLSearchParams(data);
|
|
256
|
+
queryParams.sort();
|
|
257
|
+
data.sign = this.security.sign(url, queryParams.toString());
|
|
258
|
+
if (this.uid) {
|
|
259
|
+
headers.uid = this.uid;
|
|
260
|
+
}
|
|
261
|
+
if (this.access_token) {
|
|
262
|
+
headers.accessToken = this.access_token;
|
|
263
|
+
}
|
|
264
|
+
const payload = new URLSearchParams(data);
|
|
265
|
+
for (let i = 0; i < 3; i++) {
|
|
266
|
+
try {
|
|
267
|
+
const response = await axios.post(url, payload.toString(), { headers: headers });
|
|
268
|
+
if (response.data.errorCode !== undefined && Number.parseInt(response.data.errorCode) === 0 && response.data.result !== undefined) {
|
|
269
|
+
return response.data.result;
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
throw new Error(`Error response from API: ${JSON.stringify(response.data)}`);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
catch (error) {
|
|
276
|
+
throw new Error(`Error while sending request to ${url}: ${error}`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
throw new Error(`Failed to send request to ${url}.`);
|
|
280
|
+
}
|
|
281
|
+
async login() {
|
|
282
|
+
// We need to protect against multiple attempts to login, so we only login if not already
|
|
283
|
+
// logged in. Protect this block with a semaphone.
|
|
284
|
+
const releaseSemaphore = await this.semaphore.acquire('Obtain login semaphore');
|
|
285
|
+
try {
|
|
286
|
+
if (this.loggedIn) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
// Not logged in so proceed...
|
|
290
|
+
const login_id = await this.getLoginId();
|
|
291
|
+
const data = {
|
|
292
|
+
...this.buildRequestData(),
|
|
293
|
+
loginAccount: this.account,
|
|
294
|
+
password: this.security.encrpytPassword(login_id, this.password),
|
|
295
|
+
};
|
|
296
|
+
if (this.sessionId) {
|
|
297
|
+
data.sessionId = this.sessionId;
|
|
298
|
+
}
|
|
299
|
+
const response = await this.apiRequest('/v1/user/login', data);
|
|
300
|
+
if (response) {
|
|
301
|
+
this.access_token = response.accessToken;
|
|
302
|
+
this.sessionId = response.sessionId;
|
|
303
|
+
this.uid = response.userId;
|
|
304
|
+
this.loggedIn = true;
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
this.loggedIn = false;
|
|
308
|
+
throw new Error('Failed to login.');
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
catch (e) {
|
|
312
|
+
const msg = e instanceof Error ? e.stack : e;
|
|
313
|
+
throw new Error(`Error in Adding new accessory:\n${msg}`);
|
|
314
|
+
}
|
|
315
|
+
finally {
|
|
316
|
+
releaseSemaphore();
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
class NetHomePlusCloud extends SimpleCloud {
|
|
321
|
+
APP_ID = '1017';
|
|
322
|
+
API_URL = 'https://mapp.appsmb.com';
|
|
323
|
+
constructor(account, password) {
|
|
324
|
+
super(account, password, new NetHomePlusSecurity());
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
class AristonClimaCloud extends SimpleCloud {
|
|
328
|
+
APP_ID = '1005';
|
|
329
|
+
API_URL = 'https://mapp.appsmb.com';
|
|
330
|
+
constructor(account, password) {
|
|
331
|
+
super(account, password, new ArtisonClimaSecurity());
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
export default class CloudFactory {
|
|
335
|
+
static createCloud(account, password, cloud) {
|
|
336
|
+
switch (cloud) {
|
|
337
|
+
case 'Midea SmartHome (MSmartHome)':
|
|
338
|
+
return new MSmartHomeCloud(account, password);
|
|
339
|
+
case 'Meiju':
|
|
340
|
+
return new MeijuCloud(account, password);
|
|
341
|
+
case 'NetHome Plus':
|
|
342
|
+
return new NetHomePlusCloud(account, password);
|
|
343
|
+
case 'Ariston Clima':
|
|
344
|
+
return new AristonClimaCloud(account, password);
|
|
345
|
+
default:
|
|
346
|
+
throw new Error(`Cloud ${cloud} is not supported.`);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
351
350
|
//# sourceMappingURL=MideaCloud.js.map
|