homebridge-tasmota-control 1.3.4 → 1.3.6

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