homebridge-melcloud-control 2.5.0-beta.95 → 2.5.0-beta.97
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 +3 -1
- package/index.js +23 -19
- package/package.json +1 -1
- package/src/melcloud.js +15 -29
package/homebridge-ui/server.js
CHANGED
|
@@ -26,7 +26,9 @@ class PluginUiServer extends HomebridgePluginUiServer {
|
|
|
26
26
|
try {
|
|
27
27
|
let data = {};
|
|
28
28
|
const melCloud = new MelCloud(user, passwd, language, accountInfoFile, deviceInfoFile, buildingsFile, false, 0, true);
|
|
29
|
-
const
|
|
29
|
+
const response = await melCloud.connect();
|
|
30
|
+
const accountInfo = response.accountInfo;
|
|
31
|
+
const contextKey = response.contextKey;
|
|
30
32
|
const devices = await melCloud.chackDevicesList(contextKey);
|
|
31
33
|
return data = {
|
|
32
34
|
info: '',
|
package/index.js
CHANGED
|
@@ -17,7 +17,7 @@ class MelCloudPlatform {
|
|
|
17
17
|
this.accessories = [];
|
|
18
18
|
const accountsName = [];
|
|
19
19
|
|
|
20
|
-
api.on('didFinishLaunching', () => {
|
|
20
|
+
api.on('didFinishLaunching', async () => {
|
|
21
21
|
//loop through accounts
|
|
22
22
|
for (const account of config.accounts) {
|
|
23
23
|
const accountName = account.name;
|
|
@@ -73,8 +73,12 @@ class MelCloudPlatform {
|
|
|
73
73
|
const deviceRefreshInterval = account.deviceRefreshInterval * 1000 || 5000;
|
|
74
74
|
|
|
75
75
|
//melcloud account
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
try {
|
|
77
|
+
const melCloud = new MelCloud(user, passwd, language, accountInfoFile, buildingsFile, deviceFile, enableDebugMode, refreshInterval, false);
|
|
78
|
+
const response = await melCloud.connect();
|
|
79
|
+
const accountInfo = response.accountInfo;
|
|
80
|
+
const contextKey = response.contextKey;
|
|
81
|
+
const devices = await melCloud.chackDevicesList(contextKey);
|
|
78
82
|
|
|
79
83
|
//Air Conditioner
|
|
80
84
|
for (const device of account.ataDevices) {
|
|
@@ -189,24 +193,24 @@ class MelCloudPlatform {
|
|
|
189
193
|
log.error(`${deviceTypeText}, ${deviceName}, ${error}`);
|
|
190
194
|
});
|
|
191
195
|
};
|
|
192
|
-
|
|
193
|
-
.on('success', (message) => {
|
|
196
|
+
melCloud.on('success', (message) => {
|
|
194
197
|
log.success(`Account ${accountName}, ${message}`);
|
|
195
198
|
})
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
});
|
|
199
|
+
.on('message', (message) => {
|
|
200
|
+
log.info(`Account ${accountName}, ${message}`);
|
|
201
|
+
})
|
|
202
|
+
.on('debug', (debug) => {
|
|
203
|
+
log.info(`Account ${accountName}, debug: ${debug}`);
|
|
204
|
+
})
|
|
205
|
+
.on('warn', (warn) => {
|
|
206
|
+
log.warn(`Account ${accountName}, ${warn}`);
|
|
207
|
+
})
|
|
208
|
+
.on('error', async (error) => {
|
|
209
|
+
log.error(`Account ${accountName}, ${error}.`);
|
|
210
|
+
});
|
|
211
|
+
} catch (error) {
|
|
212
|
+
log.error(`Account: ${accountName}, MELCloud error: ${error.message ?? error}`);
|
|
213
|
+
}
|
|
210
214
|
};
|
|
211
215
|
});
|
|
212
216
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"displayName": "MELCloud Control",
|
|
3
3
|
"name": "homebridge-melcloud-control",
|
|
4
|
-
"version": "2.5.0-beta.
|
|
4
|
+
"version": "2.5.0-beta.97",
|
|
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
|
@@ -16,7 +16,6 @@ class MelCloud extends EventEmitter {
|
|
|
16
16
|
this.enableDebugMode = enableDebugMode;
|
|
17
17
|
this.refreshInterval = refreshInterval;
|
|
18
18
|
this.requestConfig = requestConfig;
|
|
19
|
-
this.emitData = true;
|
|
20
19
|
this.contextKey = '';
|
|
21
20
|
this.devicesId = [];
|
|
22
21
|
|
|
@@ -36,7 +35,7 @@ class MelCloud extends EventEmitter {
|
|
|
36
35
|
this.impulseGenerator = new ImpulseGenerator();
|
|
37
36
|
this.impulseGenerator.on('checkDevicesList', async () => {
|
|
38
37
|
try {
|
|
39
|
-
await this.chackDevicesList(this.contextKey);
|
|
38
|
+
const devices = await this.chackDevicesList(this.contextKey);
|
|
40
39
|
} catch (error) {
|
|
41
40
|
this.emit('error', `Check devices list: ${error}.`);
|
|
42
41
|
};
|
|
@@ -66,6 +65,7 @@ class MelCloud extends EventEmitter {
|
|
|
66
65
|
const account = accountData.data;
|
|
67
66
|
const accountInfo = account.LoginData;
|
|
68
67
|
const contextKey = accountInfo.ContextKey;
|
|
68
|
+
this.contextKey = contextKey;
|
|
69
69
|
|
|
70
70
|
//remove sensitive data
|
|
71
71
|
const debugData = {
|
|
@@ -83,30 +83,21 @@ class MelCloud extends EventEmitter {
|
|
|
83
83
|
this.emit('warn', `Context key: ${contextKey}, missing.`)
|
|
84
84
|
return;
|
|
85
85
|
};
|
|
86
|
-
this.accountInfo = accountInfo;
|
|
87
|
-
this.contextKey = contextKey;
|
|
88
86
|
|
|
89
87
|
//save melcloud info to the file
|
|
90
88
|
await this.saveData(this.accountInfoFile, accountInfo);
|
|
91
89
|
|
|
92
|
-
//return if connect for config
|
|
93
|
-
if (this.requestConfig) {
|
|
94
|
-
return contextKey;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
//check devices list
|
|
98
|
-
await this.chackDevicesList(contextKey);
|
|
99
|
-
|
|
100
90
|
//emit connect success
|
|
101
91
|
this.emit('success', `Connect to MELCloud Success.`)
|
|
102
92
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
93
|
+
const obj = {
|
|
94
|
+
accountInfo: accountInfo,
|
|
95
|
+
contextKey: contextKey
|
|
96
|
+
}
|
|
106
97
|
|
|
107
|
-
return
|
|
98
|
+
return obj;
|
|
108
99
|
} catch (error) {
|
|
109
|
-
|
|
100
|
+
throw new Error(`Connect to MELCloud error: ${error.message ?? error}.`);
|
|
110
101
|
};
|
|
111
102
|
}
|
|
112
103
|
|
|
@@ -177,20 +168,15 @@ class MelCloud extends EventEmitter {
|
|
|
177
168
|
const debug = this.enableDebugMode ? this.emit('debug', `Device: ${deviceName} info saved.`) : false;
|
|
178
169
|
};
|
|
179
170
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
//emit check devices list complete
|
|
186
|
-
if (!this.requestConfig && this.emitData) {
|
|
187
|
-
this.emit('checkDevicesListComplete', this.accountInfo, contextKey)
|
|
188
|
-
this.emitData = false;
|
|
189
|
-
};
|
|
171
|
+
if (!this.requestConfig) {
|
|
172
|
+
//start impulse generator
|
|
173
|
+
const timers = [{ name: 'checkDevicesList', sampling: this.refreshInterval }];
|
|
174
|
+
this.impulseGenerator.start(timers);
|
|
175
|
+
}
|
|
190
176
|
|
|
191
|
-
return
|
|
177
|
+
return devices;
|
|
192
178
|
} catch (error) {
|
|
193
|
-
const stop =
|
|
179
|
+
const stop = !this.requestConfig ? false : this.impulseGenerator.stop();
|
|
194
180
|
throw new Error(`Scanning for devices error: ${error.message ?? error}.`);
|
|
195
181
|
};
|
|
196
182
|
}
|