homebridge-melcloud-control 4.3.2-beta.10 → 4.3.2-beta.12

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.2-beta.10",
4
+ "version": "4.3.2-beta.12",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
package/src/functions.js CHANGED
@@ -160,13 +160,12 @@ class Functions extends EventEmitter {
160
160
  return v !== undefined && v !== null && !(typeof v === 'number' && Number.isNaN(v));
161
161
  }
162
162
 
163
- convertValue(value) {
164
- let parsedValue = value;
165
- if (value === "True") parsedValue = true;
166
- else if (value === "False") parsedValue = false;
167
- else if (!isNaN(value) && value !== "") parsedValue = Number(value);
163
+ convertValue(v) {
164
+ let parsedValue = v;
165
+ if (v === "True") parsedValue = true;
166
+ else if (v === "False") parsedValue = false;
167
+ else if (!isNaN(v) && v !== "") parsedValue = Number(v);
168
168
  return parsedValue;
169
169
  }
170
-
171
170
  }
172
171
  export default Functions
@@ -126,11 +126,6 @@ class MelCloudAta extends EventEmitter {
126
126
  this.emit('mqtt', 'State', deviceData.Device);
127
127
  }
128
128
 
129
- //check state changes
130
- const deviceDataHasNotChanged = JSON.stringify(deviceData) === JSON.stringify(this.deviceData);
131
- if (deviceDataHasNotChanged) return;
132
- this.deviceData = deviceData;
133
-
134
129
  //emit info
135
130
  this.emit('deviceInfo', indoor.model, outdoor.model, serialNumber, firmwareAppVersion);
136
131
 
@@ -154,6 +149,15 @@ class MelCloudAta extends EventEmitter {
154
149
  const deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
155
150
  deviceData.Scenes = devicesData.Scenes ?? [];
156
151
 
152
+ //check state changes
153
+ const deviceDataChanged = JSON.stringify(deviceData) !== JSON.stringify(this.deviceData);
154
+ if (deviceDataChanged) {
155
+ this.deviceData = deviceData;
156
+
157
+ //update state
158
+ await this.updateState(deviceData);
159
+ }
160
+
157
161
  //web cocket connection
158
162
  if (this.accountType === 'melcloudhome' && !this.connecting && !this.socketConnected) {
159
163
  this.connecting = true;
@@ -195,7 +199,7 @@ class MelCloudAta extends EventEmitter {
195
199
  const messageData = parsedMessage?.[0]?.Data;
196
200
  if (!messageData) return;
197
201
 
198
- let updateDeviceState = false;
202
+ let updateState = false;
199
203
  const unitId = messageData?.id;
200
204
  switch (unitId) {
201
205
  case this.deviceId:
@@ -209,11 +213,11 @@ class MelCloudAta extends EventEmitter {
209
213
  })
210
214
  );
211
215
  Object.assign(deviceData.Device, settings);
212
- updateDeviceState = true;
216
+ updateState = true;
213
217
  break;
214
218
  case 'unitWifiSignalChanged':
215
219
  deviceData.Rssi = messageData.rssi;
216
- updateDeviceState = true;
220
+ updateState = true;
217
221
  break;
218
222
  default:
219
223
  if (!this.logDebug) this.emit('debug', `Unit ${unitId}, received unknown message type: ${stringifyMessage}`);
@@ -226,17 +230,13 @@ class MelCloudAta extends EventEmitter {
226
230
  }
227
231
 
228
232
  //update state
229
- if (updateDeviceState) await this.updateState(deviceData);
233
+ if (updateState) await this.updateState(deviceData);
230
234
  });
231
235
  } catch (error) {
232
236
  if (this.logError) this.emit('error', `Socket connection failed: ${error}`);
233
237
  this.cleanupSocket();
234
238
  }
235
239
  }
236
- if (this.logDebug) this.emit('debug', `Device Data: ${JSON.stringify(deviceData, null, 2)}`);
237
-
238
- //update state
239
- await this.updateState(deviceData);
240
240
 
241
241
  return true;
242
242
  } catch (error) {