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

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 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.8",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -26,6 +26,7 @@ class MelCloudAta extends EventEmitter {
26
26
  //set default values
27
27
  this.deviceData = {};
28
28
  this.headers = {};
29
+ this.hash = null;
29
30
  this.start = true;
30
31
 
31
32
  //lock flag
@@ -60,6 +61,7 @@ class MelCloudAta extends EventEmitter {
60
61
  if (!devicesData) return;
61
62
 
62
63
  this.headers = devicesData.Headers;
64
+ this.hash = devicesData.Hash;
63
65
  const deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
64
66
  if (this.accountType === 'melcloudhome') {
65
67
  deviceData.Scenes = devicesData.Scenes ?? [];
@@ -75,9 +77,7 @@ class MelCloudAta extends EventEmitter {
75
77
  deviceData.Device.DefaultCoolingSetTemperature = temps?.defaultCoolingSetTemperature ?? 24;
76
78
 
77
79
  if (this.start) {
78
- const hash = '2db32d6f-c19c-4b1f-a0dd-1915420a5152';
79
-
80
- const ws = new WebSocket(`wss://ws.melcloudhome.com/?hash=${hash}`, {
80
+ const ws = new WebSocket(`wss://ws.melcloudhome.com/?hash=${this.hash}`, {
81
81
  headers: {
82
82
  'Origin': 'https://melcloudhome.com',
83
83
  'Pragma': 'no-cache',
@@ -23,6 +23,7 @@ class MelCloudHome extends EventEmitter {
23
23
  this.buildingsFile = buildingsFile;
24
24
  this.devicesFile = devicesFile;
25
25
  this.headers = {};
26
+ this.hash = null;
26
27
 
27
28
  this.functions = new Functions(this.logWarn, this.logError, this.logDebug)
28
29
  .on('warn', warn => this.emit('warn', warn))
@@ -208,6 +209,7 @@ class MelCloudHome extends EventEmitter {
208
209
  devicesList.Devices = devices;
209
210
  devicesList.Scenes = scenes;
210
211
  devicesList.Headers = this.headers;
212
+ devicesList.Hash = this.hash;
211
213
 
212
214
  await this.functions.saveData(this.devicesFile, devicesList);
213
215
  if (this.logDebug) this.emit('debug', `${devicesCount} devices saved`);
@@ -276,6 +278,21 @@ class MelCloudHome extends EventEmitter {
276
278
  page.setDefaultTimeout(GLOBAL_TIMEOUT);
277
279
  page.setDefaultNavigationTimeout(GLOBAL_TIMEOUT);
278
280
 
281
+ // === CDP session (modern API) ===
282
+ const client = await page.createCDPSession();
283
+ await client.send('Network.enable')
284
+ client.on('Network.webSocketCreated', ({ url }) => {
285
+ try {
286
+ if (url.startsWith('wss://ws.melcloudhome.com/?hash=')) {
287
+ const params = new URL(url).searchParams;
288
+ this.hash = params.get('hash');
289
+ if (this.logDebug) this.emit('debug', `MelCloudHome WS hash detected: ${melcloudHash}`);
290
+ }
291
+ } catch (err) {
292
+ this.emit('error', `CDP WebSocketCreated handler error: ${err.message}`);
293
+ }
294
+ });
295
+
279
296
  try {
280
297
  await page.goto(ApiUrlsHome.BaseURL, { waitUntil: ['domcontentloaded', 'networkidle2'], timeout: GLOBAL_TIMEOUT });
281
298
  } catch (error) {
@@ -313,17 +330,6 @@ class MelCloudHome extends EventEmitter {
313
330
  }
314
331
  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
332
 
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
333
  // Extract cookies
328
334
  let c1 = null, c2 = null;
329
335
  const start = Date.now();