homebridge-melcloud-control 4.9.2-beta.3 → 4.9.2-beta.5
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/package.json +1 -1
- package/src/melcloudhome.js +12 -13
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"displayName": "MELCloud Control",
|
|
3
3
|
"name": "homebridge-melcloud-control",
|
|
4
|
-
"version": "4.9.2-beta.
|
|
4
|
+
"version": "4.9.2-beta.5",
|
|
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/melcloudhome.js
CHANGED
|
@@ -95,7 +95,7 @@ class MelCloudHome extends EventEmitter {
|
|
|
95
95
|
'Cache-Control': 'no-cache',
|
|
96
96
|
};
|
|
97
97
|
|
|
98
|
-
if (this.logDebug) this.emit('debug', `Connecting WebSocket: ${url.slice(0, 60)}...`);
|
|
98
|
+
if (!this.logDebug) this.emit('debug', `Connecting WebSocket: ${url.slice(0, 60)}...`);
|
|
99
99
|
|
|
100
100
|
try {
|
|
101
101
|
const ws = new WebSocket(url, { headers });
|
|
@@ -107,7 +107,7 @@ class MelCloudHome extends EventEmitter {
|
|
|
107
107
|
});
|
|
108
108
|
|
|
109
109
|
ws.on('close', () => {
|
|
110
|
-
if (this.logDebug) this.emit('debug', 'Web socket closed');
|
|
110
|
+
if (!this.logDebug) this.emit('debug', 'Web socket closed');
|
|
111
111
|
this.cleanupSocket();
|
|
112
112
|
this.scheduleReconnect();
|
|
113
113
|
});
|
|
@@ -120,7 +120,7 @@ class MelCloudHome extends EventEmitter {
|
|
|
120
120
|
clearTimeout(this.reconnectTimer);
|
|
121
121
|
this.reconnectTimer = null;
|
|
122
122
|
}
|
|
123
|
-
if (this.logDebug) this.emit('debug', 'Web Socket Connected');
|
|
123
|
+
if (!this.logDebug) this.emit('debug', 'Web Socket Connected');
|
|
124
124
|
|
|
125
125
|
// Heartbeat co 30s
|
|
126
126
|
this.heartbeat = setInterval(() => {
|
|
@@ -132,13 +132,13 @@ class MelCloudHome extends EventEmitter {
|
|
|
132
132
|
});
|
|
133
133
|
|
|
134
134
|
ws.on('pong', () => {
|
|
135
|
-
if (this.logDebug) this.emit('debug', 'Web socket received heartbeat');
|
|
135
|
+
if (!this.logDebug) this.emit('debug', 'Web socket received heartbeat');
|
|
136
136
|
});
|
|
137
137
|
|
|
138
138
|
ws.on('message', (message) => {
|
|
139
139
|
try {
|
|
140
140
|
const parsedMessage = JSON.parse(message);
|
|
141
|
-
if (this.logDebug) this.emit('debug', `Web socket incoming message: ${JSON.stringify(parsedMessage, null, 2)}`);
|
|
141
|
+
if (!this.logDebug) this.emit('debug', `Web socket incoming message: ${JSON.stringify(parsedMessage, null, 2)}`);
|
|
142
142
|
|
|
143
143
|
// Format: array, pierwszy element ma Data.id
|
|
144
144
|
const messageData = parsedMessage?.[0]?.Data;
|
|
@@ -420,21 +420,20 @@ class MelCloudHome extends EventEmitter {
|
|
|
420
420
|
|
|
421
421
|
// ── Buduje connectInfo po udanym token exchange ───────────────────────────
|
|
422
422
|
|
|
423
|
-
buildConnectInfo(connectInfo, exchangeRes) {
|
|
423
|
+
async buildConnectInfo(connectInfo, exchangeRes) {
|
|
424
424
|
if (exchangeRes) {
|
|
425
425
|
// ensureClient() tworzy client jeśli nie istnieje.
|
|
426
426
|
// attachTokenInterceptors() dodaje interceptory tylko przy pierwszym wywołaniu.
|
|
427
427
|
this.ensureClient();
|
|
428
428
|
this.attachTokenInterceptors();
|
|
429
429
|
this.emit('client', this.client);
|
|
430
|
+
await this.connectSocket().catch(err => {
|
|
431
|
+
if (this.logError) this.emit('error', `Initial WebSocket connect failed: ${err.message}`);
|
|
432
|
+
});
|
|
430
433
|
}
|
|
431
434
|
|
|
432
|
-
this.connectSocket().catch(err => {
|
|
433
|
-
if (this.logError) this.emit('error', `Initial WebSocket connect failed: ${err.message}`);
|
|
434
|
-
});
|
|
435
|
-
|
|
436
435
|
connectInfo.State = exchangeRes;
|
|
437
|
-
connectInfo.Status = `Connect Success${this.socketConnected ?
|
|
436
|
+
connectInfo.Status = exchangeRes ? `Connect Success ${this.socketConnected ?', Web Socket Connected' : ''}` : 'Connect Failed';
|
|
438
437
|
|
|
439
438
|
return connectInfo;
|
|
440
439
|
}
|
|
@@ -640,7 +639,7 @@ class MelCloudHome extends EventEmitter {
|
|
|
640
639
|
if (authCode) {
|
|
641
640
|
if (this.logDebug) this.emit('debug', 'Re-login with existing session (skipping credentials)');
|
|
642
641
|
const exchangeRes = await this.exchangeCodeForTokens(client, authCode, codeVerifier);
|
|
643
|
-
return this.buildConnectInfo(connectInfo, exchangeRes);
|
|
642
|
+
return await this.buildConnectInfo(connectInfo, exchangeRes);
|
|
644
643
|
}
|
|
645
644
|
|
|
646
645
|
// ── Step 3: Wyślij dane logowania do Cognito ──────────────────────
|
|
@@ -773,7 +772,7 @@ class MelCloudHome extends EventEmitter {
|
|
|
773
772
|
|
|
774
773
|
// ── Step 6: Wymień kod na tokeny ──────────────────────────────────
|
|
775
774
|
const exchangeRes = await this.exchangeCodeForTokens(client, authCode, codeVerifier);
|
|
776
|
-
return this.buildConnectInfo(connectInfo, exchangeRes);
|
|
775
|
+
return await this.buildConnectInfo(connectInfo, exchangeRes);
|
|
777
776
|
|
|
778
777
|
} catch (error) {
|
|
779
778
|
throw new Error(`Connect error: ${error.message}`);
|