homebridge-melcloud-control 4.0.0-beta.114 → 4.0.0-beta.115
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/index.js +7 -5
- package/package.json +1 -1
- package/src/melcloud.js +27 -20
package/index.js
CHANGED
|
@@ -30,8 +30,8 @@ class MelCloudPlatform {
|
|
|
30
30
|
api.on('didFinishLaunching', async () => {
|
|
31
31
|
//loop through accounts
|
|
32
32
|
for (const account of config.accounts) {
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
33
|
+
const accountType = account.accountType || 'disabled';
|
|
34
|
+
if (accountType === 'disabled') continue;
|
|
35
35
|
|
|
36
36
|
const accountName = account.name;
|
|
37
37
|
const user = account.user;
|
|
@@ -90,7 +90,7 @@ class MelCloudPlatform {
|
|
|
90
90
|
.on('start', async () => {
|
|
91
91
|
try {
|
|
92
92
|
//melcloud account
|
|
93
|
-
const melCloud = new MelCloud(
|
|
93
|
+
const melCloud = new MelCloud(accountType, user, passwd, language, accountFile, buildingsFile, devicesFile, logLevel.warn, logLevel.debug, false)
|
|
94
94
|
.on('success', (msg) => logLevel.success && log.success(`${accountName}, ${msg}`))
|
|
95
95
|
.on('info', (msg) => logLevel.info && log.info(`${accountName}, ${msg}`))
|
|
96
96
|
.on('debug', (msg) => logLevel.debug && log.info(`${accountName}, debug: ${msg}`))
|
|
@@ -181,8 +181,10 @@ class MelCloudPlatform {
|
|
|
181
181
|
api.publishExternalAccessories(PluginName, [accessory]);
|
|
182
182
|
if (logLevel.success) log.success(`${accountName}, ${deviceTypeText}, ${deviceName}, Published as external accessory.`);
|
|
183
183
|
|
|
184
|
-
//start impulse generators
|
|
185
|
-
|
|
184
|
+
//start impulse generators\
|
|
185
|
+
const timmers = accountType === 'melcloudhome' ? [{ name: 'connect', sampling: 150000 }, { name: 'checkDevicesList', sampling: deviceRefreshInterval }] : [{ name: 'checkDevicesList', sampling: refreshInterval }];
|
|
186
|
+
const impulseGenerator = configuredDevice.getImpulseGenerator();
|
|
187
|
+
await melCloud.impulseGenerator.state(true, timmers);
|
|
186
188
|
await configuredDevice.startStopImpulseGenerator(true, [{ name: 'checkState', sampling: deviceRefreshInterval }]);
|
|
187
189
|
|
|
188
190
|
//stop impulse generator
|
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.115",
|
|
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
|
@@ -7,9 +7,9 @@ import Functions from './functions.js';
|
|
|
7
7
|
import { ApiUrls, ApiUrlsHome } from './constants.js';
|
|
8
8
|
|
|
9
9
|
class MelCloud extends EventEmitter {
|
|
10
|
-
constructor(
|
|
10
|
+
constructor(accountType, user, passwd, language, accountFile, buildingsFile, devicesFile, logWarn, logDebug, requestConfig) {
|
|
11
11
|
super();
|
|
12
|
-
this.
|
|
12
|
+
this.accountType = accountType;
|
|
13
13
|
this.user = user;
|
|
14
14
|
this.passwd = passwd;
|
|
15
15
|
this.language = language;
|
|
@@ -45,6 +45,13 @@ class MelCloud extends EventEmitter {
|
|
|
45
45
|
|
|
46
46
|
if (!requestConfig) {
|
|
47
47
|
this.impulseGenerator = new ImpulseGenerator()
|
|
48
|
+
.on('connect', async () => {
|
|
49
|
+
try {
|
|
50
|
+
await this.connect();
|
|
51
|
+
} catch (error) {
|
|
52
|
+
this.emit('error', `Impulse generator error: ${error}`);
|
|
53
|
+
}
|
|
54
|
+
})
|
|
48
55
|
.on('checkDevicesList', async () => {
|
|
49
56
|
try {
|
|
50
57
|
await this.checkDevicesList(this.contextKey);
|
|
@@ -292,13 +299,13 @@ class MelCloud extends EventEmitter {
|
|
|
292
299
|
if (!loginBtn && this.logWarn) this.emit('warn', `Login button not found`);
|
|
293
300
|
|
|
294
301
|
// Set credentials and login
|
|
295
|
-
await Promise.all([loginBtn.click(), page.waitForNavigation({ waitUntil: 'networkidle2', timeout:
|
|
296
|
-
await page.waitForSelector('input[name="username"]', { timeout:
|
|
302
|
+
await Promise.all([loginBtn.click(), page.waitForNavigation({ waitUntil: 'networkidle2', timeout: 5000 })]);
|
|
303
|
+
await page.waitForSelector('input[name="username"]', { timeout: 5000 });
|
|
297
304
|
await page.type('input[name="username"]', this.user, { delay: 50 });
|
|
298
305
|
await page.type('input[name="password"]', this.passwd, { delay: 50 });
|
|
299
306
|
|
|
300
307
|
const button1 = await page.$('input[type="submit"]');
|
|
301
|
-
await Promise.all([button1.click(), page.waitForNavigation({ waitUntil: 'networkidle2', timeout:
|
|
308
|
+
await Promise.all([button1.click(), page.waitForNavigation({ waitUntil: 'networkidle2', timeout: 5000 })]);
|
|
302
309
|
|
|
303
310
|
// Get cookies C1 and C2
|
|
304
311
|
let c1 = null, c2 = null;
|
|
@@ -332,23 +339,9 @@ class MelCloud extends EventEmitter {
|
|
|
332
339
|
}
|
|
333
340
|
}
|
|
334
341
|
|
|
335
|
-
async connect() {
|
|
336
|
-
let response = {};
|
|
337
|
-
switch (this.displayType) {
|
|
338
|
-
case "melcloud":
|
|
339
|
-
response = await this.connectToMelCloud();
|
|
340
|
-
return response
|
|
341
|
-
case "melcloudhome":
|
|
342
|
-
response = await this.connectToMelCloudHome();
|
|
343
|
-
return response
|
|
344
|
-
default:
|
|
345
|
-
return response
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
342
|
async checkDevicesList(contextKey) {
|
|
350
343
|
let devices = [];
|
|
351
|
-
switch (this.
|
|
344
|
+
switch (this.accountType) {
|
|
352
345
|
case "melcloud":
|
|
353
346
|
devices = await this.checkMelcloudDevicesList(contextKey);
|
|
354
347
|
return devices
|
|
@@ -360,6 +353,20 @@ class MelCloud extends EventEmitter {
|
|
|
360
353
|
}
|
|
361
354
|
}
|
|
362
355
|
|
|
356
|
+
async connect() {
|
|
357
|
+
let response = {};
|
|
358
|
+
switch (this.accountType) {
|
|
359
|
+
case "melcloud":
|
|
360
|
+
response = await this.connectToMelCloud();
|
|
361
|
+
return response
|
|
362
|
+
case "melcloudhome":
|
|
363
|
+
response = await this.connectToMelCloudHome();
|
|
364
|
+
return response
|
|
365
|
+
default:
|
|
366
|
+
return response
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
363
370
|
async send(accountInfo) {
|
|
364
371
|
try {
|
|
365
372
|
const options = { data: accountInfo };
|