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

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/melcloudata.js +17 -4
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.8",
4
+ "version": "4.3.0-beta.9",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -77,7 +77,7 @@ class MelCloudAta extends EventEmitter {
77
77
  deviceData.Device.DefaultCoolingSetTemperature = temps?.defaultCoolingSetTemperature ?? 24;
78
78
 
79
79
  if (this.start) {
80
- const ws = new WebSocket(`wss://ws.melcloudhome.com/?hash=${this.hash}`, {
80
+ const ws = new WebSocket(`wss://ws.melcloudhome.com/?hash=${devicesData.Hash}`, {
81
81
  headers: {
82
82
  'Origin': 'https://melcloudhome.com',
83
83
  'Pragma': 'no-cache',
@@ -88,14 +88,27 @@ class MelCloudAta extends EventEmitter {
88
88
  if (!this.logDebug) this.emit('warn', `Connected to MelCloudHome WebSocket`);
89
89
  this.start = false;
90
90
  })
91
- .on('message', (data) => {
92
- if (!this.logDebug) this.emit('warn', `Incoming message:', ${data.toString()}`);
93
- })
94
91
  .on('close', () => {
95
92
  if (!this.logDebug) this.emit('warn', `Connection closed`);
96
93
  })
97
94
  .on('error', (error) => {
98
95
  if (!this.logDebug) this.emit('warn', `Connected error: ${error}`);
96
+ })
97
+ .on('message', (message) => {
98
+ if (!this.logDebug) this.emit('warn', `Incoming message:', ${JSON.stringify(message, null, 2)}`);
99
+
100
+ const messageType = message[0].messageType;
101
+ const messageData = message[0].Data;
102
+ switch (messageType) {
103
+ case 'unitStateChanged':
104
+ const unitId = messageData.id;
105
+ const unitType = messageData.unitType;
106
+ const settings = messageData.settings[0];
107
+ const name = settings.name;
108
+ const value = settings.value;
109
+ if (this.deviceId === unitId) deviceData.Device[name] = value;
110
+ break;
111
+ }
99
112
  });
100
113
  }
101
114