homebridge-melcloud-control 4.4.0-beta.2 → 4.4.0-beta.20
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 +1 -1
- package/src/deviceata.js +8 -5
- package/src/deviceatw.js +9 -5
- package/src/functions.js +34 -32
- package/src/melcloudata.js +14 -1
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.
|
|
4
|
+
"version": "4.4.0-beta.20",
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
1119
|
-
|
|
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
|
|
1138
|
-
|
|
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,
|
|
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
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
max
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
package/src/melcloudata.js
CHANGED
|
@@ -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;
|
|
@@ -248,6 +251,7 @@ class MelCloudAta extends EventEmitter {
|
|
|
248
251
|
};
|
|
249
252
|
method = 'POST';
|
|
250
253
|
path = ApiUrlsHome.PostProtectionFrost;
|
|
254
|
+
this.update(deviceData);
|
|
251
255
|
break;
|
|
252
256
|
case 'overheatprotection':
|
|
253
257
|
payload = {
|
|
@@ -258,6 +262,7 @@ class MelCloudAta extends EventEmitter {
|
|
|
258
262
|
};
|
|
259
263
|
method = 'POST';
|
|
260
264
|
path = ApiUrlsHome.PostProtectionOverheat;
|
|
265
|
+
this.update(deviceData);
|
|
261
266
|
break;
|
|
262
267
|
case 'holidaymode':
|
|
263
268
|
payload = {
|
|
@@ -318,6 +323,14 @@ class MelCloudAta extends EventEmitter {
|
|
|
318
323
|
throw new Error(`Send data error: ${error.message}`);
|
|
319
324
|
}
|
|
320
325
|
}
|
|
326
|
+
|
|
327
|
+
update(deviceData) {
|
|
328
|
+
this.lock = true;
|
|
329
|
+
this.emit('deviceState', deviceData)
|
|
330
|
+
setTimeout(() => {
|
|
331
|
+
this.lock = false;
|
|
332
|
+
}, 5000);
|
|
333
|
+
}
|
|
321
334
|
}
|
|
322
335
|
|
|
323
336
|
export default MelCloudAta;
|