homebridge-melcloud-control 4.0.0-beta.420 → 4.0.0-beta.421
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/homebridge-ui/server.js +2 -2
- package/index.js +1 -1
- package/package.json +1 -1
- package/src/melcloud.js +38 -28
package/homebridge-ui/server.js
CHANGED
|
@@ -24,8 +24,8 @@ class PluginUiServer extends HomebridgePluginUiServer {
|
|
|
24
24
|
const melCloud = new MelCloud(accountType, user, passwd, language, accountFile, buildingsFile, devicesFile, false, true);
|
|
25
25
|
|
|
26
26
|
try {
|
|
27
|
-
|
|
28
|
-
const devices = await melCloud.checkDevicesList(
|
|
27
|
+
await melCloud.connect();
|
|
28
|
+
const devices = await melCloud.checkDevicesList();
|
|
29
29
|
return devices;
|
|
30
30
|
} catch (error) {
|
|
31
31
|
throw new Error(`MELCloud error: ${error.message ?? error}.`);
|
package/index.js
CHANGED
|
@@ -115,7 +115,7 @@ class MelCloudPlatform {
|
|
|
115
115
|
//check devices list
|
|
116
116
|
let devicesInMelcloud;
|
|
117
117
|
try {
|
|
118
|
-
devicesInMelcloud = await melCloud.checkDevicesList(
|
|
118
|
+
devicesInMelcloud = await melCloud.checkDevicesList();
|
|
119
119
|
} catch (error) {
|
|
120
120
|
if (logLevel.error) log.error(`${accountName}, Check devices list error: ${error.message ?? error}`);
|
|
121
121
|
return;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"displayName": "MELCloud Control",
|
|
3
3
|
"name": "homebridge-melcloud-control",
|
|
4
|
-
"version": "4.0.0-beta.
|
|
4
|
+
"version": "4.0.0-beta.421",
|
|
5
5
|
"description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "grzegorz914",
|
package/src/melcloud.js
CHANGED
|
@@ -28,35 +28,45 @@ class MelCloud extends EventEmitter {
|
|
|
28
28
|
this.tokens = null;
|
|
29
29
|
|
|
30
30
|
if (!requestConfig) {
|
|
31
|
+
//lock flags
|
|
32
|
+
this.locks = {
|
|
33
|
+
connect: false,
|
|
34
|
+
checkDevicesList: false
|
|
35
|
+
};
|
|
31
36
|
this.impulseGenerator = new ImpulseGenerator()
|
|
32
|
-
.on('connect', async () => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
37
|
+
.on('connect', () => this.handleWithLock('connect', async () => {
|
|
38
|
+
await this.connect(true);
|
|
39
|
+
}))
|
|
40
|
+
.on('checkDevicesList', () => this.handleWithLock('checkDevicesList', async () => {
|
|
41
|
+
await this.checkDevicesList();
|
|
38
42
|
})
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
.on('state', (state) => {
|
|
44
|
+
this.emit('success', `Impulse generator ${state ? 'started' : 'stopped'}.`);
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async handleWithLock(lockKey, fn) {
|
|
50
|
+
if (this.locks[lockKey]) return;
|
|
51
|
+
|
|
52
|
+
this.locks[lockKey] = true;
|
|
53
|
+
try {
|
|
54
|
+
await fn();
|
|
55
|
+
} catch (error) {
|
|
56
|
+
this.emit('error', `Inpulse generator error: ${error}`);
|
|
57
|
+
} finally {
|
|
58
|
+
this.locks[lockKey] = false;
|
|
49
59
|
}
|
|
50
60
|
}
|
|
51
61
|
|
|
52
62
|
// MELCloud
|
|
53
|
-
async checkMelcloudDevicesList(
|
|
63
|
+
async checkMelcloudDevicesList() {
|
|
54
64
|
try {
|
|
55
65
|
const axiosInstance = axios.create({
|
|
56
66
|
method: 'GET',
|
|
57
67
|
baseURL: ApiUrls.BaseURL,
|
|
58
68
|
timeout: 15000,
|
|
59
|
-
headers: { 'X-MitsContextKey': contextKey }
|
|
69
|
+
headers: { 'X-MitsContextKey': this.contextKey }
|
|
60
70
|
});
|
|
61
71
|
|
|
62
72
|
if (this.logDebug) this.emit('debug', `Scanning for devices...`);
|
|
@@ -186,7 +196,7 @@ class MelCloud extends EventEmitter {
|
|
|
186
196
|
}
|
|
187
197
|
|
|
188
198
|
// MELCloud Home
|
|
189
|
-
async checkMelcloudHomeDevicesList(
|
|
199
|
+
async checkMelcloudHomeDevicesList() {
|
|
190
200
|
try {
|
|
191
201
|
const axiosInstance = axios.create({
|
|
192
202
|
method: 'GET',
|
|
@@ -195,7 +205,7 @@ class MelCloud extends EventEmitter {
|
|
|
195
205
|
headers: {
|
|
196
206
|
'Accept': '*/*',
|
|
197
207
|
'Accept-Language': 'en-US,en;q=0.9',
|
|
198
|
-
'Cookie': contextKey,
|
|
208
|
+
'Cookie': this.contextKey,
|
|
199
209
|
'User-Agent': 'homebridge-melcloud-control/4.0.0',
|
|
200
210
|
'DNT': '1',
|
|
201
211
|
'Origin': 'https://melcloudhome.com',
|
|
@@ -231,7 +241,7 @@ class MelCloud extends EventEmitter {
|
|
|
231
241
|
);
|
|
232
242
|
|
|
233
243
|
// Funkcja tworząca finalny obiekt Device
|
|
234
|
-
const createDevice = (device, type
|
|
244
|
+
const createDevice = (device, type) => {
|
|
235
245
|
// Settings już kapitalizowane w nazwach
|
|
236
246
|
const settingsArray = device.Settings || [];
|
|
237
247
|
|
|
@@ -259,7 +269,7 @@ class MelCloud extends EventEmitter {
|
|
|
259
269
|
|
|
260
270
|
return {
|
|
261
271
|
...rest,
|
|
262
|
-
ContextKey: contextKey,
|
|
272
|
+
ContextKey: this.contextKey,
|
|
263
273
|
Type: type,
|
|
264
274
|
DeviceID: Id,
|
|
265
275
|
DeviceName: GivenDisplayName,
|
|
@@ -268,9 +278,9 @@ class MelCloud extends EventEmitter {
|
|
|
268
278
|
};
|
|
269
279
|
|
|
270
280
|
return [
|
|
271
|
-
...(building.airToAirUnits || []).map(d => createDevice(capitalizeKeys(d), 0
|
|
272
|
-
...(building.airToWaterUnits || []).map(d => createDevice(capitalizeKeys(d), 1
|
|
273
|
-
...(building.airToVentilationUnits || []).map(d => createDevice(capitalizeKeys(d), 3
|
|
281
|
+
...(building.airToAirUnits || []).map(d => createDevice(capitalizeKeys(d), 0)),
|
|
282
|
+
...(building.airToWaterUnits || []).map(d => createDevice(capitalizeKeys(d), 1)),
|
|
283
|
+
...(building.airToVentilationUnits || []).map(d => createDevice(capitalizeKeys(d), 3))
|
|
274
284
|
];
|
|
275
285
|
});
|
|
276
286
|
|
|
@@ -483,14 +493,14 @@ class MelCloud extends EventEmitter {
|
|
|
483
493
|
}
|
|
484
494
|
}
|
|
485
495
|
|
|
486
|
-
async checkDevicesList(
|
|
496
|
+
async checkDevicesList() {
|
|
487
497
|
let devices = [];
|
|
488
498
|
switch (this.accountType) {
|
|
489
499
|
case "melcloud":
|
|
490
|
-
devices = await this.checkMelcloudDevicesList(
|
|
500
|
+
devices = await this.checkMelcloudDevicesList();
|
|
491
501
|
return devices
|
|
492
502
|
case "melcloudhome":
|
|
493
|
-
devices = await this.checkMelcloudHomeDevicesList(
|
|
503
|
+
devices = await this.checkMelcloudHomeDevicesList();
|
|
494
504
|
return devices;
|
|
495
505
|
default:
|
|
496
506
|
return devices;
|