homebridge-tasmota-control 1.6.15-beta.2 → 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 -44
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.2",
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,60 +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,
358
- '5': 6 // Added for completeness if needed
356
+ '4': 5
359
357
  };
360
358
 
361
- // Get mapped index, fallback to 0 if not found
362
- const fanSpeedIndex = fanSpeedMap[fanSpeed] ?? 0;
363
-
364
- // Function to generate speed arrays dynamically
365
- const generateSpeedArray = (count, hasAuto) => {
366
- // if hasAuto, first element is count+1 (offset), else 0
367
- // Then numbers 1 .. count-1 (except 0 and auto)
368
- // your original arrays always have [hasAuto ? count+1 : 0, 1, 2, ..., count-1]
369
- // So let's build that:
370
- const arr = [];
371
- if (hasAuto) {
372
- arr.push(count + 1); // e.g. 3+1=4 for 3 speeds
373
- } else {
374
- arr.push(0);
375
- }
376
- for (let i = 1; i < count; i++) {
377
- 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;
378
384
  }
379
- return arr;
380
- };
381
385
 
382
- switch (numberOfFanSpeeds) {
383
- case 2:
384
- obj.fanSpeed = generateSpeedArray(3, hasAutomaticFanSpeed)[fanSpeedIndex];
385
- obj.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 3 : 2;
386
- break;
387
- case 3:
388
- obj.fanSpeed = generateSpeedArray(4, hasAutomaticFanSpeed)[fanSpeedIndex];
389
- obj.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 4 : 3;
390
- break;
391
- case 4:
392
- obj.fanSpeed = generateSpeedArray(5, hasAutomaticFanSpeed)[fanSpeedIndex];
393
- obj.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 5 : 4;
394
- break;
395
- case 5:
396
- obj.fanSpeed = generateSpeedArray(6, hasAutomaticFanSpeed)[fanSpeedIndex];
397
- obj.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 6 : 5;
398
- break;
399
- default:
400
- // Fallback for unexpected fan speed count
401
- obj.fanSpeed = 0;
402
- obj.fanSpeedSetPropsMaxValue = 0;
403
- break;
386
+ // Cap value to max
387
+ if (obj.fanSpeed > obj.fanSpeedSetPropsMaxValue) {
388
+ obj.fanSpeed = obj.fanSpeedSetPropsMaxValue;
389
+ }
404
390
  }
405
391
  }
406
392