homebridge-tasmota-control 1.3.5 → 1.3.7

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": "Tasmota Control",
3
3
  "name": "homebridge-tasmota-control",
4
- "version": "1.3.5",
4
+ "version": "1.3.7",
5
5
  "description": "Homebridge plugin to control Tasmota flashed devices.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -329,7 +329,7 @@ class TasmotaDevice extends EventEmitter {
329
329
  const hideDryModeControl = false;
330
330
  const hideVaneControls = false;
331
331
 
332
- this.accessory = {
332
+ const accessory = {
333
333
  time: time,
334
334
  power: power,
335
335
  roomTemperature: roomTemperature,
@@ -337,6 +337,8 @@ class TasmotaDevice extends EventEmitter {
337
337
  setTemperature: setTemperature,
338
338
  operationMode: operationMode,
339
339
  operationModeStage: operationModeStage,
340
+ currentOperationMode: 0,
341
+ targetOperationMode: 0,
340
342
  vaneVerticalDirection: vaneVerticalDirection,
341
343
  vaneHorizontalDirection: vaneHorizontalDirection,
342
344
  prohibit: prohibit,
@@ -383,46 +385,46 @@ class TasmotaDevice extends EventEmitter {
383
385
  };
384
386
  switch (operationMode) {
385
387
  case 'heat':
386
- this.accessory.currentOperationMode = [2, 1, 2, 3, 0][operationModeStageMap[operationModeStage]]; //INACTIVE, IDLE, HEATING, COOLING
387
- this.accessory.targetOperationMode = 1; //AUTO, HEAT, COOL
388
+ accessory.currentOperationMode = [2, 1, 2, 3, 0][operationModeStageMap[operationModeStage]]; //INACTIVE, IDLE, HEATING, COOLING
389
+ accessory.targetOperationMode = 1; //AUTO, HEAT, COOL
388
390
  break;
389
391
  case 'dry':
390
- this.accessory.currentOperationMode = [1, 1, 2, 3, 0][operationModeStageMap[operationModeStage]];
391
- this.accessory.targetOperationMode = this.autoDryFanMode === 2 ? 0 : this.heatDryFanMode === 2 ? 1 : this.coolDryFanMode === 2 ? 2 : this.accessory.targetOperationMode ?? 0;
392
+ accessory.currentOperationMode = [1, 1, 2, 3, 0][operationModeStageMap[operationModeStage]];
393
+ accessory.targetOperationMode = this.autoDryFanMode === 2 ? 0 : this.heatDryFanMode === 2 ? 1 : this.coolDryFanMode === 2 ? 2 : accessory.targetOperationMode ?? 0;
392
394
  break;
393
395
  case 'cool':
394
- this.accessory.currentOperationMode = [3, 1, 2, 3, 0][operationModeStageMap[operationModeStage]];
395
- this.accessory.targetOperationMode = 2;
396
+ accessory.currentOperationMode = [3, 1, 2, 3, 0][operationModeStageMap[operationModeStage]];
397
+ accessory.targetOperationMode = 2;
396
398
  break;
397
399
  case 'fan':
398
- this.accessory.currentOperationMode = [1, 1, 2, 3, 0][operationModeStageMap[operationModeStage]];
399
- this.accessory.targetOperationMode = this.autoDryFanMode === 3 ? 0 : this.heatDryFanMode === 3 ? 1 : this.coolDryFanMode === 3 ? 2 : this.accessory.targetOperationMode ?? 0;
400
+ accessory.currentOperationMode = [1, 1, 2, 3, 0][operationModeStageMap[operationModeStage]];
401
+ accessory.targetOperationMode = this.autoDryFanMode === 3 ? 0 : this.heatDryFanMode === 3 ? 1 : this.coolDryFanMode === 3 ? 2 : accessory.targetOperationMode ?? 0;
400
402
  break;
401
403
  case 'auto':
402
- this.accessory.currentOperationMode = [2, 1, 2, 3, 0][operationModeStageMap[operationModeStage]];
403
- this.accessory.targetOperationMode = 0;
404
+ accessory.currentOperationMode = [2, 1, 2, 3, 0][operationModeStageMap[operationModeStage]];
405
+ accessory.targetOperationMode = 0;
404
406
  break;
405
407
  case 'heat_isee':
406
- this.accessory.currentOperationMode = [2, 1, 2, 3, 0][operationModeStageMap[operationModeStage]];
407
- this.accessory.targetOperationMode = 1;
408
+ accessory.currentOperationMode = [2, 1, 2, 3, 0][operationModeStageMap[operationModeStage]];
409
+ accessory.targetOperationMode = 1;
408
410
  break;
409
411
  case 'dry_isee':
410
- this.accessory.currentOperationMode = [1, 1, 2, 3, 0][operationModeStageMap[operationModeStage]];
411
- this.accessory.targetOperationMode = this.autoDryFanMode === 2 ? 0 : this.heatDryFanMode === 2 ? 1 : this.coolDryFanMode === 2 ? 2 : this.accessory.targetOperationMode ?? 0;
412
+ accessory.currentOperationMode = [1, 1, 2, 3, 0][operationModeStageMap[operationModeStage]];
413
+ accessory.targetOperationMode = this.autoDryFanMode === 2 ? 0 : this.heatDryFanMode === 2 ? 1 : this.coolDryFanMode === 2 ? 2 : accessory.targetOperationMode ?? 0;
412
414
  break;
413
415
  case 'cool_isee':
414
- this.accessory.currentOperationMode = [3, 1, 2, 3, 0][operationModeStageMap[operationModeStage]];
415
- this.accessory.targetOperationMode = 2;
416
+ accessory.currentOperationMode = [3, 1, 2, 3, 0][operationModeStageMap[operationModeStage]];
417
+ accessory.targetOperationMode = 2;
416
418
  break;
417
419
  default:
418
420
  this.emit('warn', `Unknown operating mode: ${operationMode}`);
419
421
  return
420
422
  };
421
423
 
422
- this.accessory.currentOperationMode = !power ? 0 : this.accessory.currentOperationMode;
423
- this.accessory.operationModeSetPropsMinValue = modelSupportsAuto && modelSupportsHeat ? 0 : !modelSupportsAuto && modelSupportsHeat ? 1 : modelSupportsAuto && !modelSupportsHeat ? 0 : 2;
424
- this.accessory.operationModeSetPropsMaxValue = 2
425
- this.accessory.operationModeSetPropsValidValues = modelSupportsAuto && modelSupportsHeat ? [0, 1, 2] : !modelSupportsAuto && modelSupportsHeat ? [1, 2] : modelSupportsAuto && !modelSupportsHeat ? [0, 2] : [2];
424
+ accessory.currentOperationMode = !power ? 0 : accessory.currentOperationMode;
425
+ accessory.operationModeSetPropsMinValue = modelSupportsAuto && modelSupportsHeat ? 0 : !modelSupportsAuto && modelSupportsHeat ? 1 : modelSupportsAuto && !modelSupportsHeat ? 0 : 2;
426
+ accessory.operationModeSetPropsMaxValue = 2
427
+ accessory.operationModeSetPropsValidValues = modelSupportsAuto && modelSupportsHeat ? [0, 1, 2] : !modelSupportsAuto && modelSupportsHeat ? [1, 2] : modelSupportsAuto && !modelSupportsHeat ? [0, 2] : [2];
426
428
 
427
429
  if (modelSupportsFanSpeed) {
428
430
  //fan speed mode
@@ -437,37 +439,38 @@ class TasmotaDevice extends EventEmitter {
437
439
 
438
440
  switch (numberOfFanSpeeds) {
439
441
  case 2: //Fan speed mode 2
440
- this.accessory.fanSpeed = hasAutomaticFanSpeed ? [3, 1, 2][fanSpeedMap[fanSpeed]] : [0, 1, 2][fanSpeedMap[fanSpeed]];
441
- this.accessory.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 3 : 2;
442
+ accessory.fanSpeed = hasAutomaticFanSpeed ? [3, 1, 2][fanSpeedMap[fanSpeed]] : [0, 1, 2][fanSpeedMap[fanSpeed]];
443
+ accessory.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 3 : 2;
442
444
  break;
443
445
  case 3: //Fan speed mode 3
444
- this.accessory.fanSpeed = hasAutomaticFanSpeed ? [4, 1, 2, 3][fanSpeedMap[fanSpeed]] : [0, 1, 2, 3][fanSpeedMap[fanSpeed]];
445
- this.accessory.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 4 : 3;
446
+ accessory.fanSpeed = hasAutomaticFanSpeed ? [4, 1, 2, 3][fanSpeedMap[fanSpeed]] : [0, 1, 2, 3][fanSpeedMap[fanSpeed]];
447
+ accessory.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 4 : 3;
446
448
  break;
447
449
  case 4: //Fan speed mode 4
448
- this.accessory.fanSpeed = hasAutomaticFanSpeed ? [5, 1, 2, 3, 4][fanSpeedMap[fanSpeed]] : [0, 1, 2, 3, 4][fanSpeedMap[fanSpeed]];
449
- this.accessory.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 5 : 4;
450
+ accessory.fanSpeed = hasAutomaticFanSpeed ? [5, 1, 2, 3, 4][fanSpeedMap[fanSpeed]] : [0, 1, 2, 3, 4][fanSpeedMap[fanSpeed]];
451
+ accessory.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 5 : 4;
450
452
  break;
451
453
  case 5: //Fan speed mode 5
452
- this.accessory.fanSpeed = hasAutomaticFanSpeed ? [6, 1, 2, 3, 4, 5][fanSpeedMap[fanSpeed]] : [0, 1, 2, 3, 4, 5][fanSpeedMap[fanSpeed]];
453
- this.accessory.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 6 : 5;
454
+ accessory.fanSpeed = hasAutomaticFanSpeed ? [6, 1, 2, 3, 4, 5][fanSpeedMap[fanSpeed]] : [0, 1, 2, 3, 4, 5][fanSpeedMap[fanSpeed]];
455
+ accessory.fanSpeedSetPropsMaxValue = hasAutomaticFanSpeed ? 6 : 5;
454
456
  break;
455
457
  };
456
458
  };
459
+ this.accessory = accessory;
457
460
 
458
461
  //update characteristics
459
462
  if (this.miElHvacService) {
460
463
  this.miElHvacService
461
464
  .updateCharacteristic(Characteristic.Active, power)
462
- .updateCharacteristic(Characteristic.CurrentHeaterCoolerState, this.accessory.currentOperationMode)
463
- .updateCharacteristic(Characteristic.TargetHeaterCoolerState, this.accessory.targetOperationMode)
465
+ .updateCharacteristic(Characteristic.CurrentHeaterCoolerState, accessory.currentOperationMode)
466
+ .updateCharacteristic(Characteristic.TargetHeaterCoolerState, accessory.targetOperationMode)
464
467
  .updateCharacteristic(Characteristic.CurrentTemperature, roomTemperature)
465
468
  .updateCharacteristic(Characteristic.LockPhysicalControls, lockPhysicalControl)
466
469
  .updateCharacteristic(Characteristic.TemperatureDisplayUnits, useFahrenheit)
467
470
  .updateCharacteristic(Characteristic.SwingMode, swingMode);
468
- const updateDefCool = operationMode === 'auto' || operationMode === 'cool' ? this.miElHvacService.updateCharacteristic(Characteristic.CoolingThresholdTemperature, operationMode === 'auto' ? defaultCoolingSetTemperature : setTemperature) : false;
469
- const updateDefHeat = operationMode === 'auto' || operationMode === 'heat' ? this.miElHvacService.updateCharacteristic(Characteristic.HeatingThresholdTemperature, operationMode === 'auto' ? defaultHeatingSetTemperature : setTemperature) : false;
470
- const updateRS = modelSupportsFanSpeed ? this.miElHvacService.updateCharacteristic(Characteristic.RotationSpeed, this.accessory.fanSpeed) : false;
471
+ const updateDefCool = accessory.targetOperationMode === 0 || accessory.targetOperationMode === 2 ? this.miElHvacService.updateCharacteristic(Characteristic.CoolingThresholdTemperature, accessory.targetOperationMode === 0 ? defaultCoolingSetTemperature : setTemperature) : false;
472
+ const updateDefHeat = accessory.targetOperationMode === 0 || accessory.targetOperationMode === 1 ? this.miElHvacService.updateCharacteristic(Characteristic.HeatingThresholdTemperature, accessory.targetOperationMode === 0 ? defaultHeatingSetTemperature : setTemperature) : false;
473
+ const updateRS = modelSupportsFanSpeed ? this.miElHvacService.updateCharacteristic(Characteristic.RotationSpeed, accessory.fanSpeed) : false;
471
474
 
472
475
  if (this.frostProtectEnable) {
473
476
  if (roomTemperature <= this.frostProtectLowTemp && !power) {
@@ -487,9 +490,8 @@ class TasmotaDevice extends EventEmitter {
487
490
  };
488
491
 
489
492
  //update presets state
490
- if (this.presetsConfigured.length > 0) {
491
- for (let i = 0; i < this.presetsConfigured.length; i++) {
492
- const preset = this.presetsConfigured[i];
493
+ if (this.presetsConfiguredCount > 0) {
494
+ this.presetsConfigured.forEach((preset, index) => {
493
495
 
494
496
  let iseeMode = operationMode;
495
497
  iseeMode = (operationMode === 'heat' || operationMode === 'heat_isee') ? 'heat' : iseeMode;
@@ -504,16 +506,15 @@ class TasmotaDevice extends EventEmitter {
504
506
 
505
507
  if (this.presetsServices) {
506
508
  const characteristicType = preset.characteristicType;
507
- this.presetsServices[i]
509
+ this.presetsServices[index]
508
510
  .updateCharacteristic(characteristicType, preset.state)
509
511
  };
510
- };
512
+ });
511
513
  };
512
514
 
513
515
  //update buttons state
514
516
  if (this.buttonsConfiguredCount > 0) {
515
- for (let i = 0; i < this.buttonsConfiguredCount; i++) {
516
- const button = this.buttonsConfigured[i];
517
+ this.buttonsConfigured.forEach((button, index) => {
517
518
  const mode = button.mode;
518
519
  switch (mode) {
519
520
  case 0: //POWER ON,OFF
@@ -629,16 +630,15 @@ class TasmotaDevice extends EventEmitter {
629
630
  //update services
630
631
  if (this.buttonsServices) {
631
632
  const characteristicType = button.characteristicType;
632
- this.buttonsServices[i]
633
+ this.buttonsServices[index]
633
634
  .updateCharacteristic(characteristicType, button.state)
634
635
  };
635
- };
636
+ });
636
637
  };
637
638
 
638
639
  //update sensors state
639
640
  if (this.sensorsConfiguredCount > 0) {
640
- for (let i = 0; i < this.sensorsConfiguredCount; i++) {
641
- const sensor = this.sensorsConfigured[i];
641
+ this.sensorsConfigured.forEach((sensor, index) => {
642
642
  const mode = sensor.mode;
643
643
  switch (mode) {
644
644
  case 0: //POWER ON,OFF
@@ -808,10 +808,10 @@ class TasmotaDevice extends EventEmitter {
808
808
  //update services
809
809
  if (this.sensorsServices) {
810
810
  const characteristicType = sensor.characteristicType;
811
- this.sensorsServices[i]
811
+ this.sensorsServices[index]
812
812
  .updateCharacteristic(characteristicType, sensor.state)
813
813
  };
814
- };
814
+ });
815
815
  };
816
816
 
817
817
  //update room temperature sensor
@@ -1568,9 +1568,7 @@ class TasmotaDevice extends EventEmitter {
1568
1568
  const debug = this.enableDebugMode ? this.emit('debug', `Prepare presets services`) : false;
1569
1569
  this.presetsServices = [];
1570
1570
 
1571
- for (let i = 0; i < this.presetsConfiguredCount; i++) {
1572
- const preset = this.presetsConfigured[i];
1573
-
1571
+ this.presetsConfigured.forEach((preset, index) => {
1574
1572
  //get preset name
1575
1573
  const presetName = preset.name;
1576
1574
 
@@ -1580,7 +1578,7 @@ class TasmotaDevice extends EventEmitter {
1580
1578
  const serviceName = presetNamePrefix ? `${accessoryName} ${presetName}` : presetName;
1581
1579
  const serviceType = preset.serviceType;
1582
1580
  const characteristicType = preset.characteristicType;
1583
- const presetService = new serviceType(serviceName, `Preset ${i}`);
1581
+ const presetService = new serviceType(serviceName, `Preset ${index}`);
1584
1582
  presetService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1585
1583
  presetService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
1586
1584
  presetService.getCharacteristic(characteristicType)
@@ -1617,7 +1615,7 @@ class TasmotaDevice extends EventEmitter {
1617
1615
  });
1618
1616
  this.presetsServices.push(presetService);
1619
1617
  accessory.addService(presetService);
1620
- };
1618
+ });
1621
1619
  };
1622
1620
 
1623
1621
  //buttons services
@@ -1625,9 +1623,7 @@ class TasmotaDevice extends EventEmitter {
1625
1623
  const debug = this.enableDebugMode ? this.emit('debug', `Prepare buttons services`) : false;
1626
1624
  this.buttonsServices = [];
1627
1625
 
1628
- for (let i = 0; i < this.buttonsConfiguredCount; i++) {
1629
- const button = this.buttonsConfigured[i];
1630
-
1626
+ this.buttonsConfigured.forEach((button, index) => {
1631
1627
  //get button mode
1632
1628
  const mode = button.mode;
1633
1629
 
@@ -1640,7 +1636,7 @@ class TasmotaDevice extends EventEmitter {
1640
1636
  const serviceName = buttonNamePrefix ? `${accessoryName} ${buttonName}` : buttonName;
1641
1637
  const serviceType = button.serviceType;
1642
1638
  const characteristicType = button.characteristicType;
1643
- const buttonService = new serviceType(serviceName, `Button ${i}`);
1639
+ const buttonService = new serviceType(serviceName, `Button ${index}`);
1644
1640
  buttonService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1645
1641
  buttonService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
1646
1642
  buttonService.getCharacteristic(characteristicType)
@@ -1806,7 +1802,7 @@ class TasmotaDevice extends EventEmitter {
1806
1802
  });
1807
1803
  this.buttonsServices.push(buttonService);
1808
1804
  accessory.addService(buttonService);
1809
- };
1805
+ });
1810
1806
  };
1811
1807
 
1812
1808
  //sensors services
@@ -1814,9 +1810,7 @@ class TasmotaDevice extends EventEmitter {
1814
1810
  const debug = this.enableDebugMode ? this.emit('debug', `Prepare sensors services`) : false;
1815
1811
  this.sensorsServices = [];
1816
1812
 
1817
- for (let i = 0; i < this.sensorsConfiguredCount; i++) {
1818
- const sensor = this.sensorsConfigured[i];
1819
-
1813
+ this.sensorsConfigured.forEach((sensor, index) => {
1820
1814
  //get sensor mode
1821
1815
  const mode = sensor.mode;
1822
1816
 
@@ -1829,7 +1823,7 @@ class TasmotaDevice extends EventEmitter {
1829
1823
  const serviceName = sensorNamePrefix ? `${accessoryName} ${sensorName}` : sensorName;
1830
1824
  const serviceType = sensor.serviceType;
1831
1825
  const characteristicType = sensor.characteristicType;
1832
- const sensorService = new serviceType(serviceName, `Sensor ${i}`);
1826
+ const sensorService = new serviceType(serviceName, `Sensor ${index}`);
1833
1827
  sensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
1834
1828
  sensorService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
1835
1829
  sensorService.getCharacteristic(characteristicType)
@@ -1839,7 +1833,7 @@ class TasmotaDevice extends EventEmitter {
1839
1833
  });
1840
1834
  this.sensorsServices.push(sensorService);
1841
1835
  accessory.addService(sensorService);
1842
- };
1836
+ });
1843
1837
  };
1844
1838
 
1845
1839
  //room temperature sensor service