homebridge-tasmota-control 1.6.15-beta.3 → 1.6.15-beta.4

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/mielhvac.js +30 -43
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Tasmota Control",
3
3
  "name": "homebridge-tasmota-control",
4
- "version": "1.6.15-beta.3",
4
+ "version": "1.6.15-beta.4",
5
5
  "description": "Homebridge plugin to control Tasmota flashed devices.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
package/src/mielhvac.js CHANGED
@@ -347,59 +347,46 @@ class MiElHvac extends EventEmitter {
347
347
 
348
348
 
349
349
  if (modelSupportsFanSpeed) {
350
- // Map fan speed string to index
351
350
  const fanSpeedMap = {
352
351
  'auto': 0,
353
352
  'quiet': 1,
354
353
  '1': 2,
355
354
  '2': 3,
356
355
  '3': 4,
357
- '4': 5,
356
+ '4': 5
358
357
  };
359
358
 
360
- // Get mapped index, fallback to 0 if not found
361
- const fanSpeedIndex = fanSpeedMap[fanSpeed] ?? 0;
362
-
363
- // Function to generate speed arrays dynamically
364
- const generateSpeedArray = (count, hasAuto) => {
365
- // if hasAuto, first element is count+1 (offset), else 0
366
- // Then numbers 1 .. count-1 (except 0 and auto)
367
- // your original arrays always have [hasAuto ? count+1 : 0, 1, 2, ..., count-1]
368
- // So let's build that:
369
- const arr = [];
370
- if (hasAuto) {
371
- arr.push(count + 1); // e.g. 3+1=4 for 3 speeds
372
- } else {
373
- arr.push(0);
374
- }
375
- for (let i = 1; i < count; i++) {
376
- arr.push(i);
359
+ const fanIndex = fanSpeedMap[fanSpeed];
360
+ obj.fanSpeed = 0;
361
+ obj.fanSpeedSetPropsMaxValue = 0;
362
+
363
+ if (typeof fanIndex === 'number') {
364
+ switch (numberOfFanSpeeds) {
365
+ case 2:
366
+ obj.fanSpeed = hasAutomaticFanSpeed ? [3, 1, 2][fanIndex] ?? 1 : [0, 1, 2][fanIndex] ?? 1;
367
+ obj.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 3 : 2;
368
+ break;
369
+
370
+ case 3:
371
+ obj.fanSpeed = hasAutomaticFanSpeed ? [4, 1, 2, 3][fanIndex] ?? 1 : [0, 1, 2, 3][fanIndex] ?? 1;
372
+ obj.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 4 : 3;
373
+ break;
374
+
375
+ case 4:
376
+ obj.fanSpeed = hasAutomaticFanSpeed ? [5, 1, 2, 3, 4][fanIndex] ?? 1 : [0, 1, 2, 3, 4][fanIndex] ?? 1;
377
+ obj.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 5 : 4;
378
+ break;
379
+
380
+ case 5:
381
+ obj.fanSpeed = hasAutomaticFanSpeed ? [6, 1, 2, 3, 4, 5][fanIndex] ?? 1 : [0, 1, 2, 3, 4, 5][fanIndex] ?? 1;
382
+ obj.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 6 : 5;
383
+ break;
377
384
  }
378
- return arr;
379
- };
380
385
 
381
- switch (numberOfFanSpeeds) {
382
- case 2:
383
- obj.fanSpeed = generateSpeedArray(3, hasAutomaticFanSpeed)[fanSpeedIndex];
384
- obj.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 3 : 2;
385
- break;
386
- case 3:
387
- obj.fanSpeed = generateSpeedArray(4, hasAutomaticFanSpeed)[fanSpeedIndex];
388
- obj.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 4 : 3;
389
- break;
390
- case 4:
391
- obj.fanSpeed = generateSpeedArray(5, hasAutomaticFanSpeed)[fanSpeedIndex];
392
- obj.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 5 : 4;
393
- break;
394
- case 5:
395
- obj.fanSpeed = generateSpeedArray(6, hasAutomaticFanSpeed)[fanSpeedIndex];
396
- obj.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 6 : 5;
397
- break;
398
- default:
399
- // Fallback for unexpected fan speed count
400
- obj.fanSpeed = 0;
401
- obj.fanSpeedSetPropsMaxValue = 0;
402
- break;
386
+ // Cap value to max
387
+ if (obj.fanSpeed > obj.fanSpeedSetPropsMaxValue) {
388
+ obj.fanSpeed = obj.fanSpeedSetPropsMaxValue;
389
+ }
403
390
  }
404
391
  }
405
392