homebridge-melcloud-control 4.3.0-beta.22 → 4.3.0-beta.24

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/index.js CHANGED
@@ -194,7 +194,7 @@ class MelCloudPlatform {
194
194
 
195
195
  //start impulse generators\
196
196
  await configuredDevice.startStopImpulseGenerator(true, [{ name: 'checkState', sampling: deviceRefreshInterval }]);
197
- const timmers = accountType === 'melcloudhome' ? [{ name: 'connect', sampling: 3000000 }, { name: 'checkDevicesList', sampling: 3000 }] : [{ name: 'checkDevicesList', sampling: refreshInterval }];
197
+ const timmers = accountType === 'melcloudhome' ? [] : [{ name: 'checkDevicesList', sampling: refreshInterval }];
198
198
  await melCloud.impulseGenerator.state(true, timmers, false);
199
199
 
200
200
  //stop impulse generator
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.22",
4
+ "version": "4.3.0-beta.24",
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,7 +26,6 @@ class MelCloudAta extends EventEmitter {
26
26
  //set default values
27
27
  this.deviceData = {};
28
28
  this.headers = {};
29
- this.hash = null;
30
29
  this.socket = null;
31
30
  this.socketConnected = false;
32
31
 
@@ -71,7 +70,6 @@ class MelCloudAta extends EventEmitter {
71
70
  if (!devicesData) return;
72
71
 
73
72
  this.headers = devicesData.Headers;
74
- this.hash = devicesData.Hash;
75
73
  const deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
76
74
  if (this.accountType === 'melcloudhome') {
77
75
  deviceData.Scenes = devicesData.Scenes ?? [];
@@ -82,13 +80,7 @@ class MelCloudAta extends EventEmitter {
82
80
  deviceData.Device.VaneHorizontalDirection = AirConditioner.VaneHorizontalDirectionMapStringToEnum[deviceData.Device.VaneHorizontalDirection] ?? deviceData.Device.VaneHorizontalDirection;
83
81
 
84
82
  if (!this.socketConnected) {
85
- const socket = new WebSocket(`wss://ws.melcloudhome.com/?hash=${devicesData.Hash}`, {
86
- headers: {
87
- 'Origin': ApiUrlsHome.BaseURL,
88
- 'Pragma': 'no-cache',
89
- 'Cache-Control': 'no-cache'
90
- }
91
- })
83
+ const socket = new WebSocket(`wss://ws.melcloudhome.com/?hash=${devicesData.WsHeaders.hash}`, { headers: devicesData.WsHeaders.headers })
92
84
  .on('error', (error) => {
93
85
  if (this.logDebug) this.emit('debug', `Socket error: ${error}`);
94
86
  socket.close();
@@ -116,7 +108,6 @@ class MelCloudAta extends EventEmitter {
116
108
  })
117
109
  .on('message', (message) => {
118
110
  const parsedMessage = JSON.parse(message);
119
- const messageType = parsedMessage[0].messageType;
120
111
  const messageData = parsedMessage[0].Data;
121
112
  const unitId = messageData.id;
122
113
  const unitType = messageData.unitType;
@@ -125,12 +116,23 @@ class MelCloudAta extends EventEmitter {
125
116
 
126
117
  switch (unitId) {
127
118
  case this.deviceId:
128
- const settings = Object.fromEntries(messageData.settings.map(s => [s.name, s.value]));
129
- if (!this.logDebug) this.emit('warn', `Settings:', ${settings}`);
130
- Object.assign(deviceData.Device, settings);
131
-
132
- //emit state
133
- this.emit('deviceState', deviceData);
119
+ const messageType = parsedMessage[0].messageType;
120
+ switch (messageType) {
121
+ case 'unitStateChanged':
122
+ const settings = Object.fromEntries(messageData.settings.map(s => [s.name, s.value]));
123
+ Object.assign(deviceData.Device, settings);
124
+
125
+ //emit state
126
+ this.emit('deviceState', deviceData);
127
+ break;
128
+ case 'unitWiFiChanged':
129
+ const state = Object.fromEntries(messageData.settings.map(s => [s.name, s.value]));
130
+ Object.assign(deviceData.Device, state);
131
+
132
+ //emit state
133
+ this.emit('deviceState', deviceData);
134
+ break;
135
+ }
134
136
  break;
135
137
  }
136
138
  });
@@ -23,7 +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
+ this.wsHeaders = {};
27
27
 
28
28
  this.functions = new Functions(this.logWarn, this.logError, this.logDebug)
29
29
  .on('warn', warn => this.emit('warn', warn))
@@ -209,7 +209,7 @@ class MelCloudHome extends EventEmitter {
209
209
  devicesList.Devices = devices;
210
210
  devicesList.Scenes = scenes;
211
211
  devicesList.Headers = this.headers;
212
- devicesList.Hash = this.hash;
212
+ devicesList.WsHeaders = this.wsHeaders;
213
213
 
214
214
  await this.functions.saveData(this.devicesFile, devicesList);
215
215
  if (this.logDebug) this.emit('debug', `${devicesCount} devices saved`);
@@ -279,13 +279,14 @@ class MelCloudHome extends EventEmitter {
279
279
  page.setDefaultNavigationTimeout(GLOBAL_TIMEOUT);
280
280
 
281
281
  // === CDP session ===
282
+ let hash = null;
282
283
  const client = await page.createCDPSession();
283
284
  await client.send('Network.enable')
284
285
  client.on('Network.webSocketCreated', ({ url }) => {
285
286
  try {
286
287
  if (url.startsWith('wss://ws.melcloudhome.com/?hash=')) {
287
288
  const params = new URL(url).searchParams;
288
- this.hash = params.get('hash');
289
+ hash = params.get('hash');
289
290
  if (this.logDebug) this.emit('debug', `MelCloudHome WS hash detected: ${melcloudHash}`);
290
291
  }
291
292
  } catch (err) {
@@ -373,6 +374,16 @@ class MelCloudHome extends EventEmitter {
373
374
  headers: headers
374
375
  })
375
376
 
377
+ this.wsHeaders = {
378
+ hash: hash,
379
+ headers: {
380
+ 'Origin': ApiUrlsHome.BaseURL,
381
+ 'Pragma': 'no-cache',
382
+ 'Cache-Control': 'no-cache'
383
+ }
384
+ };
385
+
386
+
376
387
  accountInfo.State = true;
377
388
  accountInfo.Info = 'Connect to MELCloud Home Success';
378
389
  await this.functions.saveData(this.accountFile, accountInfo);