homebridge-melcloud-control 4.3.0-beta.6 → 4.3.0-beta.7

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/melcloudhome.js +19 -11
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "4.3.0-beta.6",
4
+ "version": "4.3.0-beta.7",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -276,6 +276,25 @@ class MelCloudHome extends EventEmitter {
276
276
  page.setDefaultTimeout(GLOBAL_TIMEOUT);
277
277
  page.setDefaultNavigationTimeout(GLOBAL_TIMEOUT);
278
278
 
279
+ // === CDP session (modern API) ===
280
+ const client = await page.createCDPSession();
281
+ await client.send('Network.enable');
282
+
283
+ let melcloudHash = null;
284
+
285
+ client.on('Network.webSocketCreated', ({ url }) => {
286
+ try {
287
+ if (url.startsWith('wss://ws.melcloudhome.com/?hash=')) {
288
+ const params = new URL(url).searchParams;
289
+ melcloudHash = params.get('hash');
290
+
291
+ this.emit('warn', `MelCloudHome WS hash detected: ${melcloudHash}`);
292
+ }
293
+ } catch (err) {
294
+ this.emit('error', `CDP WebSocketCreated handler error: ${err.message}`);
295
+ }
296
+ });
297
+
279
298
  try {
280
299
  await page.goto(ApiUrlsHome.BaseURL, { waitUntil: ['domcontentloaded', 'networkidle2'], timeout: GLOBAL_TIMEOUT });
281
300
  } catch (error) {
@@ -313,17 +332,6 @@ class MelCloudHome extends EventEmitter {
313
332
  }
314
333
  await Promise.race([Promise.all([submitButton.click(), page.waitForNavigation({ waitUntil: ['domcontentloaded', 'networkidle2'], timeout: GLOBAL_TIMEOUT / 3 })]), new Promise(r => setTimeout(r, GLOBAL_TIMEOUT / 3))]);
315
334
 
316
- // Nasłuchuj WebSocketów
317
- let melcloudHash = null;
318
- page.on('request', req => {
319
- if (req.url().startsWith('wss://ws.melcloudhome.com/?hash=')) {
320
- const url = req.url();
321
- const params = new URL(url).searchParams;
322
- melcloudHash = params.get('hash');
323
- if (!this.logDebug) this.emit('warn', `FOUND HASH: ${melcloudHash}`);
324
- }
325
- });
326
-
327
335
  // Extract cookies
328
336
  let c1 = null, c2 = null;
329
337
  const start = Date.now();