homebridge-melcloud-control 4.2.9 → 4.2.10

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.2.9",
4
+ "version": "4.2.10",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -39,7 +39,8 @@
39
39
  "async-mqtt": "^2.6.3",
40
40
  "axios": "^1.13.2",
41
41
  "express": "^5.1.0",
42
- "puppeteer": "^24.30.0"
42
+ "puppeteer": "^24.30.0",
43
+ "ws": "^8.18.3"
43
44
  },
44
45
  "keywords": [
45
46
  "homebridge",
package/src/deviceata.js CHANGED
@@ -1079,7 +1079,7 @@ class DeviceAta extends EventEmitter {
1079
1079
  //control
1080
1080
  if (button.displayType > 3) {
1081
1081
  if (this.logDebug) this.emit('debug', `Prepare button control ${name} service`);
1082
- const buttonControlService = new serviceType(serviceName, `buttonControlService${deviceId} ${i}`);
1082
+ const buttonControlService = new Service.Switch(serviceName, `buttonControlService${deviceId} ${i}`);
1083
1083
  buttonControlService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1084
1084
  buttonControlService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
1085
1085
  buttonControlService.getCharacteristic(Characteristic.On)
package/src/deviceatw.js CHANGED
@@ -1346,7 +1346,7 @@ class DeviceAtw extends EventEmitter {
1346
1346
  //control
1347
1347
  if (button.displayType > 3) {
1348
1348
  if (this.logDebug) this.emit('debug', `Prepare button control ${name} service`);
1349
- const buttonControlService = new serviceType(serviceName1, `buttonControlService${deviceId} ${i}`);
1349
+ const buttonControlService = new Service.Switch(serviceName1, `buttonControlService${deviceId} ${i}`);
1350
1350
  buttonControlService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1351
1351
  buttonControlService.setCharacteristic(Characteristic.ConfiguredName, serviceName1);
1352
1352
  buttonControlService.getCharacteristic(Characteristic.On)
package/src/deviceerv.js CHANGED
@@ -1006,7 +1006,7 @@ class DeviceErv extends EventEmitter {
1006
1006
  //control
1007
1007
  if (button.displayType > 3) {
1008
1008
  if (this.logDebug) this.emit('debug', `Prepare button control ${name} service`);
1009
- const buttonControlService = new serviceType(serviceName1, `buttonControlService${deviceId} ${i}`);
1009
+ const buttonControlService = new Service.Switch(serviceName1, `buttonControlService${deviceId} ${i}`);
1010
1010
  buttonControlService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1011
1011
  buttonControlService.setCharacteristic(Characteristic.ConfiguredName, serviceName1);
1012
1012
  buttonControlService.getCharacteristic(Characteristic.On)
@@ -1,3 +1,4 @@
1
+ import WebSocket from 'ws';
1
2
  import axios from 'axios';
2
3
  import EventEmitter from 'events';
3
4
  import ImpulseGenerator from './impulsegenerator.js';
@@ -25,6 +26,9 @@ class MelCloudAta extends EventEmitter {
25
26
  //set default values
26
27
  this.deviceData = {};
27
28
  this.headers = {};
29
+ this.hash = null;
30
+ this.socket = null;
31
+ this.socketConnected = false;
28
32
 
29
33
  //lock flag
30
34
  this.locks = false;
@@ -50,13 +54,24 @@ class MelCloudAta extends EventEmitter {
50
54
  }
51
55
  }
52
56
 
57
+ cleanupSocket = () => {
58
+ if (this.heartbeat) {
59
+ clearInterval(this.heartbeat);
60
+ this.heartbeat = null;
61
+ }
62
+ this.socket = null;
63
+ this.socketConnected = false;
64
+ };
65
+
53
66
  async checkState() {
54
67
  try {
68
+
55
69
  //read device info from file
56
70
  const devicesData = await this.functions.readData(this.devicesFile, true);
57
71
  if (!devicesData) return;
58
72
 
59
73
  this.headers = devicesData.Headers;
74
+ this.hash = devicesData.Hash;
60
75
  const deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
61
76
  if (this.accountType === 'melcloudhome') {
62
77
  deviceData.Scenes = devicesData.Scenes ?? [];
@@ -70,6 +85,7 @@ class MelCloudAta extends EventEmitter {
70
85
  const temps = await this.functions.readData(this.defaultTempsFile, true);
71
86
  deviceData.Device.DefaultHeatingSetTemperature = temps?.defaultHeatingSetTemperature ?? 20;
72
87
  deviceData.Device.DefaultCoolingSetTemperature = temps?.defaultCoolingSetTemperature ?? 24;
88
+
73
89
  }
74
90
  if (this.logDebug) this.emit('debug', `Device Data: ${JSON.stringify(deviceData, null, 2)}`);
75
91
 
@@ -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 ===
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) {