homebridge-melcloud-control 4.3.9-beta.12 → 4.3.9-beta.14

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.9-beta.12",
4
+ "version": "4.3.9-beta.14",
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/deviceata.js CHANGED
@@ -1397,11 +1397,11 @@ class DeviceAta extends EventEmitter {
1397
1397
  const supportsDry = deviceData.Device[supportDryKey];
1398
1398
  const supportsCool1 = deviceData.Device[supportCoolKey];
1399
1399
  const supportsCool = this.coolDryFanMode >= 1 && supportsCool1;
1400
- const numberOfFanSpeeds = supportsFanSpeed ? deviceData.Device.NumberOfFanSpeeds : 0;
1401
- const minTempHeat = 10;
1402
- const maxTempHeat = 31;
1403
- const minTempCoolDryAuto = 16;
1404
- const maxTempCoolDryAuto = 31;
1400
+ const numberOfFanSpeeds = deviceData.Device.NumberOfFanSpeeds;
1401
+ const minTempHeat = deviceData.Device.MinTempHeat ?? 10;
1402
+ const maxTempHeat = deviceData.Device.MaxTempHeat ?? 31;
1403
+ const minTempCoolDryAuto = deviceData.Device.MinTempAutomatic ?? 16;
1404
+ const maxTempCoolDryAuto = deviceData.Device.MaxTempAutomatic ?? 31;
1405
1405
 
1406
1406
  //device state
1407
1407
  const power = deviceData.Device.Power ?? false;
@@ -29,14 +29,18 @@ class MelCloudAta extends EventEmitter {
29
29
  //handle melcloud events
30
30
  let deviceData = null;
31
31
  melcloud.on('devicesList', async (devicesData) => {
32
- this.headers = devicesData.Headers;
33
- deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
34
- if (!deviceData) return;
35
- deviceData.Scenes = devicesData.Scenes ?? [];
32
+ try {
33
+ this.headers = devicesData.Headers;
34
+ deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
35
+ if (!deviceData) return;
36
+ deviceData.Scenes = devicesData.Scenes ?? [];
36
37
 
37
- //update state
38
- if (!this.logDebug) this.emit('debug', `Request update settings: ${JSON.stringify(deviceData.Device, null, 2)}`);
39
- await this.updateState(deviceData);
38
+ //update state
39
+ if (!this.logDebug) this.emit('debug', `Request update settings: ${JSON.stringify(deviceData.Device, null, 2)}`);
40
+ await this.updateState(deviceData);
41
+ } catch (error) {
42
+ if (this.logError) this.emit('error', `Request process message error: ${error}`);
43
+ }
40
44
  }).on('webSocket', async (parsedMessage) => {
41
45
  try {
42
46
  const messageData = parsedMessage?.[0]?.Data;
@@ -81,12 +85,12 @@ class MelCloudAta extends EventEmitter {
81
85
  updateState = true;
82
86
  break;
83
87
  default:
84
- if (this.logDebug) this.emit('debug', `Unit ${unitId}, received unknown message type: ${stringifyMessage}`);
88
+ if (this.logDebug) this.emit('debug', `Unit ${unitId}, received unknown message type: ${parsedMessage}`);
85
89
  return;
86
90
  }
87
91
  break;
88
92
  default:
89
- if (this.logDebug) this.emit('debug', `Incoming unknown unit id: ${stringifyMessage}`);
93
+ if (this.logDebug) this.emit('debug', `Incoming unknown unit id: ${parsedMessage}`);
90
94
  return;
91
95
  }
92
96
 
@@ -323,7 +327,7 @@ class MelCloudAta extends EventEmitter {
323
327
  //sens payload
324
328
  headers['Content-Type'] = 'application/json; charset=utf-8';
325
329
  headers.Origin = ApiUrlsHome.Origin;
326
- if (!this.logDebug) this.emit('debug', `Send Data: ${JSON.stringify(payload, null, 2)}`);
330
+ if (this.logDebug) this.emit('debug', `Send Data: ${JSON.stringify(payload, null, 2)}`);
327
331
 
328
332
  await axios(path, {
329
333
  method: method,
@@ -29,14 +29,18 @@ class MelCloudAtw extends EventEmitter {
29
29
  //handle melcloud events
30
30
  let deviceData = null;
31
31
  melcloud.on('devicesList', async (devicesData) => {
32
- this.headers = devicesData.Headers;
33
- deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
34
- if (!deviceData) return;
35
- deviceData.Scenes = devicesData.Scenes ?? [];
32
+ try {
33
+ this.headers = devicesData.Headers;
34
+ deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
35
+ if (!deviceData) return;
36
+ deviceData.Scenes = devicesData.Scenes ?? [];
36
37
 
37
- //update state
38
- if (this.logDebug) this.emit('debug', `Request update settings: ${JSON.stringify(deviceData.Device, null, 2)}`);
39
- await this.updateState(deviceData);
38
+ //update state
39
+ if (this.logDebug) this.emit('debug', `Request update settings: ${JSON.stringify(deviceData.Device, null, 2)}`);
40
+ await this.updateState(deviceData);
41
+ } catch (error) {
42
+ if (this.logError) this.emit('error', `Request process message error: ${error}`);
43
+ }
40
44
  }).on('webSocket', async (parsedMessage) => {
41
45
  try {
42
46
  const messageData = parsedMessage?.[0]?.Data;
@@ -81,12 +85,12 @@ class MelCloudAtw extends EventEmitter {
81
85
  updateState = true;
82
86
  break;
83
87
  default:
84
- if (this.logDebug) this.emit('debug', `Unit ${unitId}, received unknown message type: ${stringifyMessage}`);
88
+ if (this.logDebug) this.emit('debug', `Unit ${unitId}, received unknown message type: ${parsedMessage}`);
85
89
  return;
86
90
  }
87
91
  break;
88
92
  default:
89
- if (this.logDebug) this.emit('debug', `Incoming unknown unit id: ${stringifyMessage}`);
93
+ if (this.logDebug) this.emit('debug', `Incoming unknown unit id: ${parsedMessage}`);
90
94
  return;
91
95
  }
92
96
 
@@ -98,7 +102,7 @@ class MelCloudAtw extends EventEmitter {
98
102
  });
99
103
  }
100
104
 
101
- async updateState(deviceData) {
105
+ async updateState(deviceData, type) {
102
106
  try {
103
107
  if (this.accountType === 'melcloudhome') {
104
108
  deviceData.Device.OperationMode = HeatPump.OperationModeMapStringToEnum[deviceData.Device.OperationMode] ?? deviceData.Device.OperationMode;
@@ -29,14 +29,18 @@ class MelCloudErv extends EventEmitter {
29
29
  //handle melcloud events
30
30
  let deviceData = null;
31
31
  melcloud.on('devicesList', async (devicesData) => {
32
- this.headers = devicesData.Headers;
33
- deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
34
- if (!deviceData) return;
35
- deviceData.Scenes = devicesData.Scenes ?? [];
32
+ try {
33
+ this.headers = devicesData.Headers;
34
+ deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
35
+ if (!deviceData) return;
36
+ deviceData.Scenes = devicesData.Scenes ?? [];
36
37
 
37
- //update state
38
- if (this.logDebug) this.emit('debug', `Request update settings: ${JSON.stringify(deviceData.Device, null, 2)}`);
39
- await this.updateState(deviceData);
38
+ //update state
39
+ if (this.logDebug) this.emit('debug', `Request update settings: ${JSON.stringify(deviceData.Device, null, 2)}`);
40
+ await this.updateState(deviceData);
41
+ } catch (error) {
42
+ if (this.logError) this.emit('error', `Request process message error: ${error}`);
43
+ }
40
44
  }).on('webSocket', async (parsedMessage) => {
41
45
  try {
42
46
  const messageData = parsedMessage?.[0]?.Data;
@@ -81,12 +85,12 @@ class MelCloudErv extends EventEmitter {
81
85
  updateState = true;
82
86
  break;
83
87
  default:
84
- if (this.logDebug) this.emit('debug', `Unit ${unitId}, received unknown message type: ${stringifyMessage}`);
88
+ if (this.logDebug) this.emit('debug', `Unit ${unitId}, received unknown message type: ${parsedMessage}`);
85
89
  return;
86
90
  }
87
91
  break;
88
92
  default:
89
- if (this.logDebug) this.emit('debug', `Incoming unknown unit id: ${stringifyMessage}`);
93
+ if (this.logDebug) this.emit('debug', `Incoming unknown unit id: ${parsedMessage}`);
90
94
  return;
91
95
  }
92
96
 
@@ -98,7 +102,7 @@ class MelCloudErv extends EventEmitter {
98
102
  });
99
103
  }
100
104
 
101
- async updateState(deviceData) {
105
+ async updateState(deviceData, type) {
102
106
  try {
103
107
  if (this.accountType === 'melcloudhome') {
104
108
  //read default temps
@@ -135,24 +135,13 @@ class MelCloudHome extends EventEmitter {
135
135
 
136
136
  const devices = buildingsList.flatMap(building => {
137
137
  // Funkcja kapitalizująca klucze obiektu
138
- const capitalizeKeys = obj =>
139
- Object.fromEntries(
140
- Object.entries(obj).map(([key, value]) => [
141
- key.charAt(0).toUpperCase() + key.slice(1),
142
- value
143
- ])
144
- );
138
+ const capitalizeKeys = obj => Object.fromEntries(Object.entries(obj).map(([key, value]) => [key.charAt(0).toUpperCase() + key.slice(1), value]));
145
139
 
146
140
  // Rekurencyjna kapitalizacja kluczy w obiekcie lub tablicy
147
141
  const capitalizeKeysDeep = obj => {
148
142
  if (Array.isArray(obj)) return obj.map(capitalizeKeysDeep);
149
143
  if (obj && typeof obj === 'object') {
150
- return Object.fromEntries(
151
- Object.entries(obj).map(([key, value]) => [
152
- key.charAt(0).toUpperCase() + key.slice(1),
153
- capitalizeKeysDeep(value)
154
- ])
155
- );
144
+ return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key.charAt(0).toUpperCase() + key.slice(1), capitalizeKeysDeep(value)]));
156
145
  }
157
146
  return obj;
158
147
  };