homebridge-melcloud-control 4.4.0-beta.2 → 4.4.0-beta.21

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.4.0-beta.2",
4
+ "version": "4.4.0-beta.21",
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
@@ -758,7 +758,8 @@ class DeviceAta extends EventEmitter {
758
758
  })
759
759
  .onSet(async (value) => {
760
760
  try {
761
- let { min, max } = await this.functions.normalizeFrostProtection(deviceData.FrostProtection.Min, value);
761
+ let { min, max } = await this.functions.adjustTempProtection(deviceData.FrostProtection.Min, deviceData.FrostProtection.Max, value, 'max', 4, 14, 6, 16);
762
+ deviceData.FrostProtection.Min = min;
762
763
  deviceData.FrostProtection.Max = max;
763
764
  if (this.logInfo) this.emit('info', `Set frost protection max. temperature: ${max}${this.accessory.temperatureUnit}`);
764
765
  await this.melCloudAta.send(this.accountType, this.displayType, deviceData, 'frostprotection');
@@ -778,9 +779,9 @@ class DeviceAta extends EventEmitter {
778
779
  })
779
780
  .onSet(async (value) => {
780
781
  try {
781
- let { min, max } = await this.functions.normalizeFrostProtection(value, deviceData.FrostProtection.Max);
782
+ let { min, max } = await this.functions.adjustTempProtection(deviceData.FrostProtection.Min, deviceData.FrostProtection.Max, value, 'min', 4, 14, 6, 16);
782
783
  deviceData.FrostProtection.Min = min;
783
- ;
784
+ deviceData.FrostProtection.Max = max;
784
785
  if (this.logInfo) this.emit('info', `Set frost protection min. temperature: ${min}${this.accessory.temperatureUnit}`);
785
786
  await this.melCloudAta.send(this.accountType, this.displayType, deviceData, 'frostprotection');
786
787
  } catch (error) {
@@ -876,7 +877,8 @@ class DeviceAta extends EventEmitter {
876
877
  })
877
878
  .onSet(async (value) => {
878
879
  try {
879
- let { min, max } = await this.functions.normalizeOverheatProtection(deviceData.OverheatProtection.Min, value);
880
+ let { min, max } = await this.functions.adjustTempProtection(deviceData.OverheatProtection.Min, deviceData.OverheatProtection.Max, value, 'max', 31, 38, 33, 40);
881
+ deviceData.OverheatProtection.Min = min;
880
882
  deviceData.OverheatProtection.Max = max;
881
883
  if (this.logInfo) this.emit('info', `Set overheat protection max. temperature: ${max}${this.accessory.temperatureUnit}`);
882
884
  await this.melCloudAta.send(this.accountType, this.displayType, deviceData, 'overheatprotection');
@@ -896,8 +898,9 @@ class DeviceAta extends EventEmitter {
896
898
  })
897
899
  .onSet(async (value) => {
898
900
  try {
899
- let { min, max } = await this.functions.normalizeOverheatProtection(value, deviceData.OverheatProtection.Max);
901
+ let { min, max } = await this.functions.adjustTempProtection(deviceData.OverheatProtection.Min, deviceData.OverheatProtection.Max, value, 'min', 31, 38, 33, 40);
900
902
  deviceData.OverheatProtection.Min = min;
903
+ deviceData.OverheatProtection.Max = max;
901
904
  if (this.logInfo) this.emit('info', `Set overheat protection min. temperature: ${min}${this.accessory.temperatureUnit}`);
902
905
  await this.melCloudAta.send(this.accountType, this.displayType, deviceData, 'overheatprotection');
903
906
  } catch (error) {
package/src/deviceatw.js CHANGED
@@ -1115,8 +1115,10 @@ class DeviceAtw extends EventEmitter {
1115
1115
  })
1116
1116
  .onSet(async (value) => {
1117
1117
  try {
1118
- deviceData.FrostProtection.Max = value;
1119
- if (this.logInfo) this.emit('info', `Set frost protection max. temperature: ${value}${this.accessory.temperatureUnit}`);
1118
+ let { min, max } = await this.functions.adjustTempProtection(deviceData.FrostProtection.Min, deviceData.FrostProtection.Max, value, 4, 14, 6, 16);
1119
+ deviceData.FrostProtection.Min = min;
1120
+ deviceData.FrostProtection.Max = max;
1121
+ if (this.logInfo) this.emit('info', `Set frost protection max. temperature: ${max}${this.accessory.temperatureUnit}`);
1120
1122
  await this.melCloudAta.send(this.accountType, this.displayType, deviceData, 'frostprotection');
1121
1123
  } catch (error) {
1122
1124
  if (this.logWarn) this.emit('warn', `Set frost protection max. temperature error: ${error}`);
@@ -1134,8 +1136,10 @@ class DeviceAtw extends EventEmitter {
1134
1136
  })
1135
1137
  .onSet(async (value) => {
1136
1138
  try {
1137
- deviceData.FrostProtection.Min = value;
1138
- if (this.logInfo) this.emit('info', `Set frost protection min. temperature: ${value}${this.accessory.temperatureUnit}`);
1139
+ let { min, max } = await this.functions.adjustTempProtection(deviceData.FrostProtection.Min, deviceData.FrostProtection.Max, value, 4, 14, 6, 16);
1140
+ deviceData.FrostProtection.Min = min;
1141
+ deviceData.FrostProtection.Max = max;
1142
+ if (this.logInfo) this.emit('info', `Set frost protection min. temperature: ${min}${this.accessory.temperatureUnit}`);
1139
1143
  await this.melCloudAta.send(this.accountType, this.displayType, deviceData, 'frostprotection');
1140
1144
  } catch (error) {
1141
1145
  if (this.logWarn) this.emit('warn', `Set frost protection min. temperature error: ${error}`);
@@ -2189,7 +2193,7 @@ class DeviceAtw extends EventEmitter {
2189
2193
  if (this.frostProtectionSupport && frostProtection.Enabled !== null) {
2190
2194
  this.frostProtectionControlService?.updateCharacteristic(Characteristic.Active, frostProtection.Enabled);
2191
2195
  this.frostProtectionControlService?.updateCharacteristic(Characteristic.CurrentHeaterCoolerState, frostProtection.Active ? 2 : 1);
2192
- this.frostProtectionControlService?.updateCharacteristic(Characteristic.TargetHeaterCoolerState, frostProtection.Active ? 2 : 1);
2196
+ this.frostProtectionControlService?.updateCharacteristic(Characteristic.TargetHeaterCoolerState, 0);
2193
2197
  this.frostProtectionControlService?.updateCharacteristic(Characteristic.CurrentTemperature, roomTemperature);
2194
2198
  this.frostProtectionControlService?.updateCharacteristic(Characteristic.CoolingThresholdTemperature, frostProtection.Max);
2195
2199
  this.frostProtectionControlService?.updateCharacteristic(Characteristic.HeatingThresholdTemperature, frostProtection.Min);
package/src/functions.js CHANGED
@@ -238,47 +238,49 @@ class Functions extends EventEmitter {
238
238
  );
239
239
  }
240
240
 
241
- async normalizeFrostProtection(min, max) {
242
- // Clamp to allowed ranges
243
- min = Math.min(Math.max(min, 4), 14);
244
- max = Math.min(Math.max(max, 6), 16);
245
-
246
- // Ensure difference of at least 2 degrees
247
- if (max - min < 2) {
248
- // Try increasing max if possible
249
- const newMax = min + 2;
250
- if (newMax <= 16) {
251
- max = newMax;
252
- } else {
253
- // Otherwise lower min
254
- const newMin = max - 2;
255
- min = Math.max(newMin, 4);
241
+ async adjustTempProtection(oldMin, oldMax, newValue, type, minRangeMin, maxRangeMin, minRangeMax, maxRangeMax) {
242
+ let min = oldMin;
243
+ let max = oldMax;
244
+
245
+ if (type === "min") {
246
+ min = Math.min(Math.max(newValue, minRangeMin), maxRangeMin);
247
+
248
+ if (min > oldMin && max - min < 2) {
249
+ max = Math.min(min + 2, maxRangeMax);
250
+
251
+ // jeśli max uderza w górną granicę → obniż min o 2
252
+ if (max === maxRangeMax && max - min < 2) {
253
+ min = Math.max(min - 2, minRangeMin);
254
+ }
255
+
256
+ return { min, max };
256
257
  }
258
+
259
+ // min maleje → zwracamy tylko min
260
+ return { min, max };
257
261
  }
258
262
 
259
- return { min, max };
260
- }
263
+ if (type === "max") {
264
+ max = Math.min(Math.max(newValue, minRangeMax), maxRangeMax);
265
+
266
+ if (max < oldMax && max - min < 2) {
267
+ min = Math.max(max - 2, minRangeMin);
268
+
269
+ // jeśli min uderza w dolną granicę → podbij max o 2
270
+ if (min === minRangeMin && max - min < 2) {
271
+ max = Math.min(max + 2, maxRangeMax);
272
+ }
261
273
 
262
- async normalizeOverheatProtection(min, max) {
263
- // Clamp to allowed ranges
264
- min = Math.min(Math.max(min, 31), 38);
265
- max = Math.min(Math.max(max, 33), 40);
266
-
267
- // Ensure difference of at least 2 degrees
268
- if (max - min < 2) {
269
- // Try increasing max if possible
270
- const newMax = min + 2;
271
- if (newMax <= 40) {
272
- max = newMax;
273
- } else {
274
- // Otherwise lower min
275
- const newMin = max - 2;
276
- min = Math.max(newMin, 31);
274
+ return { min, max };
277
275
  }
276
+
277
+ // max rośnie → zwracamy tylko max
278
+ return { min, max };
278
279
  }
279
280
 
280
281
  return { min, max };
281
282
  }
283
+
282
284
  }
283
285
 
284
286
  export default Functions
@@ -24,6 +24,7 @@ class MelCloudAta extends EventEmitter {
24
24
  //set default values
25
25
  this.deviceData = {};
26
26
  this.client = melcloud.client;
27
+ this.lock = false;
27
28
 
28
29
  //handle melcloud events
29
30
  let deviceData = null;
@@ -31,6 +32,8 @@ class MelCloudAta extends EventEmitter {
31
32
  this.client = client;
32
33
  }).on('devicesList', async (devicesData) => {
33
34
  try {
35
+ if (this.lock) return;
36
+
34
37
  deviceData = devicesData.Devices.find(device => device.DeviceID === this.deviceId);
35
38
  if (!deviceData) return;
36
39
  deviceData.Scenes = devicesData.Scenes ?? [];
@@ -44,7 +47,7 @@ class MelCloudAta extends EventEmitter {
44
47
  }).on('webSocket', async (parsedMessage) => {
45
48
  try {
46
49
  const messageData = parsedMessage?.[0]?.Data;
47
- if (!messageData || !deviceData) return;
50
+ if (!messageData || !deviceData || this.lock) return;
48
51
 
49
52
  let updateState = false;
50
53
  const unitId = messageData?.id;
@@ -196,6 +199,7 @@ class MelCloudAta extends EventEmitter {
196
199
  let method = null
197
200
  let payload = {};
198
201
  let path = '';
202
+ let update = false;
199
203
  switch (accountType) {
200
204
  case "melcloud":
201
205
  switch (flag) {
@@ -248,6 +252,7 @@ class MelCloudAta extends EventEmitter {
248
252
  };
249
253
  method = 'POST';
250
254
  path = ApiUrlsHome.PostProtectionFrost;
255
+ update = true;
251
256
  break;
252
257
  case 'overheatprotection':
253
258
  payload = {
@@ -258,6 +263,7 @@ class MelCloudAta extends EventEmitter {
258
263
  };
259
264
  method = 'POST';
260
265
  path = ApiUrlsHome.PostProtectionOverheat;
266
+ update = true;
261
267
  break;
262
268
  case 'holidaymode':
263
269
  payload = {
@@ -309,6 +315,7 @@ class MelCloudAta extends EventEmitter {
309
315
  //send payload
310
316
  if (this.logDebug) this.emit('debug', `Send data: ${JSON.stringify(payload, null, 2)}`);
311
317
  await this.client(path, { method: method, data: payload });
318
+ if (update) this.update(deviceData);
312
319
 
313
320
  return true;
314
321
  default:
@@ -318,6 +325,14 @@ class MelCloudAta extends EventEmitter {
318
325
  throw new Error(`Send data error: ${error.message}`);
319
326
  }
320
327
  }
328
+
329
+ update(deviceData) {
330
+ this.lock = true;
331
+ this.emit('deviceState', deviceData)
332
+ setTimeout(() => {
333
+ this.lock = false;
334
+ }, 5000);
335
+ }
321
336
  }
322
337
 
323
338
  export default MelCloudAta;