homebridge-melcloud-control 4.3.0-beta.29 → 4.3.0-beta.30

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 +24 -19
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.29",
4
+ "version": "4.3.0-beta.30",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -87,8 +87,8 @@ class MelCloudAta extends EventEmitter {
87
87
  const url = `${ApiUrlsHome.WebSocketURL}${wsHeaders.hash}`;
88
88
  try {
89
89
  const socket = new WebSocket(url, { headers: wsHeaders.headers })
90
- .on('error', (err) => {
91
- if (this.logDebug) this.emit('debug', `Socket error: ${err}`);
90
+ .on('error', (error) => {
91
+ if (this.logError) this.emit('error', `Socket error: ${error}`);
92
92
  })
93
93
  .on('close', () => {
94
94
  if (this.logDebug) this.emit('debug', `Socket closed`);
@@ -113,27 +113,32 @@ class MelCloudAta extends EventEmitter {
113
113
  if (!this.logDebug) this.emit('warn', `Socket received heartbeat`);
114
114
  })
115
115
  .on('message', (message) => {
116
- const parsed = JSON.parse(message);
117
- const msgData = parsed[0].Data;
118
- const unitId = msgData.id;
119
-
120
- if (!this.logDebug) {
121
- const stringifyMessage = JSON.stringify(parsed, null, 2);
122
- this.emit('warn', `Incoming message: ${stringifyMessage}`);
123
- }
124
-
125
- if (unitId === this.deviceId) {
126
- const type = parsed[0].messageType;
127
-
128
- const settings = Object.fromEntries(msgData.settings.map(s => [s.name, s.value]));
129
- Object.assign(deviceData.Device, settings);
130
-
131
- this.emit('deviceState', deviceData);
116
+ const parsedMessage = JSON.parse(message);
117
+ const messageData = parsed[0].Data;
118
+ const unitId = messageData.id;
119
+ const stringifyMessage = JSON.stringify(parsedMessage, null, 2);
120
+ if (!this.logDebug) this.emit('warn', `Incoming message: ${stringifyMessage}`);
121
+
122
+ switch (unitId) {
123
+ case this.deviceId:
124
+ const messageType = parsedMessage[0].messageType;
125
+ switch (messageType) {
126
+ case 'unitStateChanged':
127
+ const settings = Object.fromEntries(messageData.settings.map(s => [s.name, s.value]));
128
+ Object.assign(deviceData.Device, settings);
129
+ this.emit('deviceState', deviceData);
130
+ break;
131
+ case 'unitWiFiChanged':
132
+ const state = Object.fromEntries(messageData.settings.map(s => [s.name, s.value]));
133
+ Object.assign(deviceData.Device, state); //emit state this.emit('deviceState', deviceData);
134
+ break;
135
+ }
136
+ break;
132
137
  }
133
138
  });
134
139
 
135
140
  } catch (error) {
136
- this.emit('debug', `Socket connection failed: ${error}`);
141
+ if (this.logError) this.emit('error', `Socket connection failed: ${error}`);
137
142
  this.reconnect();
138
143
  }
139
144
  }