homebridge-tasmota-control 1.7.0 → 1.7.2

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.7.0",
4
+ "version": "1.7.2",
5
5
  "description": "Homebridge plugin to control Tasmota flashed devices.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -30,11 +30,11 @@
30
30
  "LICENSE"
31
31
  ],
32
32
  "engines": {
33
- "homebridge": "^1.9.0 || ^2.0.0 || ^2.0.0-beta.29 || ^2.0.0-alpha.6",
33
+ "homebridge": "^1.9.0 || ^2.0.0 || ^2.0.0-beta.30 || ^2.0.0-alpha.40",
34
34
  "node": "^20 || ^22 || ^24"
35
35
  },
36
36
  "dependencies": {
37
- "axios": "^1.12.1"
37
+ "axios": "^1.12.2"
38
38
  },
39
39
  "keywords": [
40
40
  "homebridge",
package/src/fans.js CHANGED
@@ -132,14 +132,12 @@ class Fans extends EventEmitter {
132
132
  this.fans.push(fan);
133
133
 
134
134
  //update characteristics
135
- const fanService = this.fanServices?.[i];
136
- if (fanService) {
137
- const serviceName = this.fansNamePrefix ? `${this.info.deviceName} ${friendlyName}` : friendlyName;
138
- fanService.updateCharacteristic(Characteristic.ConfiguredName, serviceName)
139
- .updateCharacteristic(Characteristic.On, powerFan)
140
- // .updateCharacteristic(Characteristic.Direction, direction)
141
- .updateCharacteristic(Characteristic.RotationSpeed, speed);
142
- }
135
+ const serviceName = this.fansNamePrefix ? `${this.info.deviceName} ${friendlyName}` : friendlyName;
136
+ this.fanServices?.[i]
137
+ ?.setCharacteristic(Characteristic.ConfiguredName, serviceName)
138
+ .updateCharacteristic(Characteristic.On, powerFan)
139
+ // .updateCharacteristic(Characteristic.Direction, direction)
140
+ .updateCharacteristic(Characteristic.RotationSpeed, speed);
143
141
 
144
142
 
145
143
  //log info
package/src/lights.js CHANGED
@@ -41,11 +41,9 @@ class Lights extends EventEmitter {
41
41
  });
42
42
 
43
43
  //lock flags
44
- this.locks = {
45
- checkState: false,
46
- };
44
+ this.locks = false;
47
45
  this.impulseGenerator = new ImpulseGenerator()
48
- .on('checkState', () => this.handleWithLock('checkState', async () => {
46
+ .on('checkState', () => this.handleWithLock(async () => {
49
47
  await this.checkState();
50
48
  }))
51
49
  .on('state', (state) => {
@@ -53,16 +51,16 @@ class Lights extends EventEmitter {
53
51
  });
54
52
  }
55
53
 
56
- async handleWithLock(lockKey, fn) {
57
- if (this.locks[lockKey]) return;
54
+ async handleWithLock(fn) {
55
+ if (this.locks) return;
58
56
 
59
- this.locks[lockKey] = true;
57
+ this.locks = true;
60
58
  try {
61
59
  await fn();
62
60
  } catch (error) {
63
61
  this.emit('error', `Inpulse generator error: ${error}`);
64
62
  } finally {
65
- this.locks[lockKey] = false;
63
+ this.locks = false;
66
64
  }
67
65
  }
68
66
 
@@ -72,7 +70,6 @@ class Lights extends EventEmitter {
72
70
  //power status
73
71
  const powerStatusData = await this.axiosInstance(ApiCommands.PowerStatus);
74
72
  const powerStatus = powerStatusData.data ?? {};
75
- const powerStatusKeys = Object.keys(powerStatus);
76
73
  if (this.enableDebugMode) this.emit('debug', `Power status: ${JSON.stringify(powerStatus, null, 2)}`);
77
74
 
78
75
  //sensor status
@@ -128,25 +125,15 @@ class Lights extends EventEmitter {
128
125
  this.lights.push(light);
129
126
 
130
127
  //update characteristics
131
- const service = this.lightServices?.[i];
132
- if (service) {
133
- const serviceName = this.lightsNamePrefix ? `${this.info.deviceName} ${friendlyName}` : friendlyName;
134
- service.updateCharacteristic(Characteristic.ConfiguredName, serviceName);
135
- service.updateCharacteristic(Characteristic.On, power);
136
-
137
- if (brightnessType > 0) {
138
- service.updateCharacteristic(Characteristic.Brightness, bright);
139
- }
140
- if (colorTemperature !== false) {
141
- service.updateCharacteristic(Characteristic.ColorTemperature, colorTemperature);
142
- }
143
- if (hue !== false) {
144
- service.updateCharacteristic(Characteristic.Hue, hue);
145
- }
146
- if (saturation !== false) {
147
- service.updateCharacteristic(Characteristic.Saturation, saturation);
148
- }
149
- }
128
+ const serviceName = this.lightsNamePrefix ? `${this.info.deviceName} ${friendlyName}` : friendlyName;
129
+ this.lightServices?.[i]
130
+ ?.setCharacteristic(Characteristic.ConfiguredName, serviceName)
131
+ .updateCharacteristic(Characteristic.On, power);
132
+
133
+ if (brightnessType > 0) this.lightServices?.[i]?.updateCharacteristic(Characteristic.Brightness, bright);
134
+ if (colorTemperature !== false) this.lightServices?.[i]?.updateCharacteristic(Characteristic.ColorTemperature, colorTemperature);
135
+ if (hue !== false) this.lightServices?.[i]?.updateCharacteristic(Characteristic.Hue, hue);
136
+ if (saturation !== false) this.lightServices?.[i]?.updateCharacteristic(Characteristic.Saturation, saturation);
150
137
 
151
138
 
152
139
  //log info
package/src/mielhvac.js CHANGED
@@ -414,23 +414,9 @@ class MiElHvac extends EventEmitter {
414
414
  .updateCharacteristic(Characteristic.TemperatureDisplayUnits, useFahrenheit)
415
415
  .updateCharacteristic(Characteristic.SwingMode, swingMode);
416
416
 
417
- if (obj.targetOperationMode === 0 || obj.targetOperationMode === 2) {
418
- svc.updateCharacteristic(
419
- Characteristic.CoolingThresholdTemperature,
420
- obj.targetOperationMode === 0 ? defaultCoolingSetTemperature : setTemperature
421
- );
422
- }
423
-
424
- if (obj.targetOperationMode === 0 || obj.targetOperationMode === 1) {
425
- svc.updateCharacteristic(
426
- Characteristic.HeatingThresholdTemperature,
427
- obj.targetOperationMode === 0 ? defaultHeatingSetTemperature : setTemperature
428
- );
429
- }
430
-
431
- if (modelSupportsFanSpeed) {
432
- svc.updateCharacteristic(Characteristic.RotationSpeed, obj.fanSpeed);
433
- }
417
+ if (obj.targetOperationMode === 0 || obj.targetOperationMode === 2) svc.updateCharacteristic(Characteristic.CoolingThresholdTemperature, obj.targetOperationMode === 0 ? defaultCoolingSetTemperature : setTemperature);
418
+ if (obj.targetOperationMode === 0 || obj.targetOperationMode === 1) svc.updateCharacteristic(Characteristic.HeatingThresholdTemperature, obj.targetOperationMode === 0 ? defaultHeatingSetTemperature : setTemperature);
419
+ if (modelSupportsFanSpeed) svc.updateCharacteristic(Characteristic.RotationSpeed, obj.fanSpeed);
434
420
 
435
421
  if (this.frostProtectEnable) {
436
422
  if (roomTemperature <= this.frostProtectLowTemp && !power) {
@@ -462,11 +448,7 @@ class MiElHvac extends EventEmitter {
462
448
  const sameMode = preset.mode === iseeMode;
463
449
 
464
450
  preset.state = power ? (sameMode && sameTemp && sameFan && sameSwingV && sameSwingH) : false;
465
-
466
- if (this.presetsServices) {
467
- this.presetsServices[index]
468
- .updateCharacteristic(preset.characteristicType, preset.state);
469
- }
451
+ this.presetsServices?.[index]?.updateCharacteristic(preset.characteristicType, preset.state);
470
452
  });
471
453
  }
472
454
 
@@ -563,11 +545,8 @@ class MiElHvac extends EventEmitter {
563
545
 
564
546
  button.state = state;
565
547
 
566
- if (this.buttonsServices) {
567
- const characteristicType = button.characteristicType;
568
- this.buttonsServices[index]
569
- .updateCharacteristic(characteristicType, state);
570
- }
548
+ const characteristicType = button.characteristicType;
549
+ this.buttonsServices?.[index]?.updateCharacteristic(characteristicType, state);
571
550
  });
572
551
  }
573
552
 
@@ -656,25 +635,17 @@ class MiElHvac extends EventEmitter {
656
635
  this.emit('warn', `Unknown sensor mode: ${mode} detected`);
657
636
  }
658
637
 
659
- // Update characteristic
660
- if (this.sensorsServices) {
661
- const characteristicType = sensor.characteristicType;
662
- this.sensorsServices[index]?.updateCharacteristic(characteristicType, sensor.state);
663
- }
638
+ // Update characteristic{
639
+ const characteristicType = sensor.characteristicType;
640
+ this.sensorsServices?.[index]?.updateCharacteristic(characteristicType, sensor.state);
664
641
  });
665
642
  }
666
643
 
667
644
  //update room temperature sensor
668
- if (this.roomTemperatureSensorService) {
669
- this.roomTemperatureSensorService
670
- .updateCharacteristic(Characteristic.CurrentTemperature, roomTemperature);
671
- }
645
+ this.roomTemperatureSensorService?.updateCharacteristic(Characteristic.CurrentTemperature, roomTemperature);
672
646
 
673
647
  //update outdoor temperature sensor
674
- if (this.outdoorTemperatureSensorService) {
675
- this.outdoorTemperatureSensorService
676
- .updateCharacteristic(Characteristic.CurrentTemperature, outdoorTemperature);
677
- }
648
+ this.outdoorTemperatureSensorService?.updateCharacteristic(Characteristic.CurrentTemperature, outdoorTemperature);
678
649
 
679
650
  //log current state
680
651
  if (!this.disableLogInfo) {
package/src/sensors.js CHANGED
@@ -43,11 +43,9 @@ class Sensors extends EventEmitter {
43
43
  });
44
44
 
45
45
  //lock flags
46
- this.locks = {
47
- checkState: false,
48
- };
46
+ this.locks = false;
49
47
  this.impulseGenerator = new ImpulseGenerator()
50
- .on('checkState', () => this.handleWithLock('checkState', async () => {
48
+ .on('checkState', () => this.handleWithLock(async () => {
51
49
  await this.checkState();
52
50
  }))
53
51
  .on('state', (state) => {
@@ -55,16 +53,16 @@ class Sensors extends EventEmitter {
55
53
  });
56
54
  }
57
55
 
58
- async handleWithLock(lockKey, fn) {
59
- if (this.locks[lockKey]) return;
56
+ async handleWithLock(fn) {
57
+ if (this.locks) return;
60
58
 
61
- this.locks[lockKey] = true;
59
+ this.locks = true;
62
60
  try {
63
61
  await fn();
64
62
  } catch (error) {
65
63
  this.emit('error', `Inpulse generator error: ${error}`);
66
64
  } finally {
67
- this.locks[lockKey] = false;
65
+ this.locks = false;
68
66
  }
69
67
  }
70
68
 
@@ -137,49 +135,47 @@ class Sensors extends EventEmitter {
137
135
 
138
136
  //update characteristics
139
137
  const servicesMap = [
140
- [this.temperatureServices?.[i], Characteristic.CurrentTemperature, sensor.temperature],
141
- [this.temperatureReferenceServices?.[i], Characteristic.CurrentTemperature, sensor.referenceTemperature],
142
- [this.temperatureObjServices?.[i], Characteristic.CurrentTemperature, sensor.objTemperature],
143
- [this.temperatureAmbServices?.[i], Characteristic.CurrentTemperature, sensor.ambTemperature],
144
- [this.temperatureDewPointServices?.[i], Characteristic.CurrentTemperature, sensor.dewPointTemperature],
145
- [this.humidityServices?.[i], Characteristic.CurrentRelativeHumidity, sensor.humidity],
146
- [this.carbonDioxydeServices?.[i], Characteristic.CarbonDioxideDetected, sensor.carbonDioxyde > 1000],
147
- [this.carbonDioxydeServices?.[i], Characteristic.CarbonDioxideLevel, sensor.carbonDioxyde],
148
- [this.carbonDioxydeServices?.[i], Characteristic.CarbonDioxidePeakLevel, sensor.carbonDioxyde],
149
- [this.ambientLightServices?.[i], Characteristic.CurrentAmbientLightLevel, sensor.ambientLight],
150
- [this.motionServices?.[i], Characteristic.MotionDetected, sensor.motion],
138
+ [this.temperatureServices, Characteristic.CurrentTemperature, sensor.temperature],
139
+ [this.temperatureReferenceServices, Characteristic.CurrentTemperature, sensor.referenceTemperature],
140
+ [this.temperatureObjServices, Characteristic.CurrentTemperature, sensor.objTemperature],
141
+ [this.temperatureAmbServices, Characteristic.CurrentTemperature, sensor.ambTemperature],
142
+ [this.temperatureDewPointServices, Characteristic.CurrentTemperature, sensor.dewPointTemperature],
143
+ [this.humidityServices, Characteristic.CurrentRelativeHumidity, sensor.humidity],
144
+ [this.carbonDioxydeServices, Characteristic.CarbonDioxideDetected, sensor.carbonDioxyde > 1000],
145
+ [this.carbonDioxydeServices, Characteristic.CarbonDioxideLevel, sensor.carbonDioxyde],
146
+ [this.carbonDioxydeServices, Characteristic.CarbonDioxidePeakLevel, sensor.carbonDioxyde],
147
+ [this.ambientLightServices, Characteristic.CurrentAmbientLightLevel, sensor.ambientLight],
148
+ [this.motionServices, Characteristic.MotionDetected, sensor.motion],
151
149
  ];
152
150
 
153
151
  for (const [service, charType, value] of servicesMap) {
154
- const characteristic = service?.getCharacteristic(charType);
155
- if (!characteristic) {
156
- continue;
157
- }
158
- service.updateCharacteristic(charType, value);
152
+ const characteristic = service?.[i]?.getCharacteristic(charType);
153
+ if (!characteristic) continue;
154
+
155
+ service?.[i]?.updateCharacteristic(charType, value);
159
156
  }
160
157
 
161
158
  // energy
162
159
  if (isEnergy) {
163
160
  const energyMap = [
164
- [this.powerAndEnergyServices?.[i], Characteristic.Power, sensor.power],
165
- [this.powerAndEnergyServices?.[i], Characteristic.ApparentPower, sensor.apparentPower],
166
- [this.powerAndEnergyServices?.[i], Characteristic.ReactivePower, sensor.reactivePower],
167
- [this.powerAndEnergyServices?.[i], Characteristic.EnergyToday, sensor.energyToday],
168
- [this.powerAndEnergyServices?.[i], Characteristic.EnergyLastDay, sensor.energyLastDay],
169
- [this.powerAndEnergyServices?.[i], Characteristic.EnergyLifetime, sensor.energyLifetime],
170
- [this.powerAndEnergyServices?.[i], Characteristic.Current, sensor.current],
171
- [this.powerAndEnergyServices?.[i], Characteristic.Voltage, sensor.voltage],
172
- [this.powerAndEnergyServices?.[i], Characteristic.Factor, sensor.factor],
173
- [this.powerAndEnergyServices?.[i], Characteristic.Frequency, sensor.frequency],
174
- [this.powerAndEnergyServices?.[i], Characteristic.ReadingTime, sensor.time],
161
+ [this.powerAndEnergyServices, Characteristic.Power, sensor.power],
162
+ [this.powerAndEnergyServices, Characteristic.ApparentPower, sensor.apparentPower],
163
+ [this.powerAndEnergyServices, Characteristic.ReactivePower, sensor.reactivePower],
164
+ [this.powerAndEnergyServices, Characteristic.EnergyToday, sensor.energyToday],
165
+ [this.powerAndEnergyServices, Characteristic.EnergyLastDay, sensor.energyLastDay],
166
+ [this.powerAndEnergyServices, Characteristic.EnergyLifetime, sensor.energyLifetime],
167
+ [this.powerAndEnergyServices, Characteristic.Current, sensor.current],
168
+ [this.powerAndEnergyServices, Characteristic.Voltage, sensor.voltage],
169
+ [this.powerAndEnergyServices, Characteristic.Factor, sensor.factor],
170
+ [this.powerAndEnergyServices, Characteristic.Frequency, sensor.frequency],
171
+ [this.powerAndEnergyServices, Characteristic.ReadingTime, sensor.time],
175
172
  ];
176
173
 
177
174
  for (const [service, charType, value] of energyMap) {
178
- const characteristic = service?.getCharacteristic(charType);
179
- if (!characteristic) {
180
- continue;
181
- }
182
- service.updateCharacteristic(charType, value);
175
+ const characteristic = service?.[i]?.getCharacteristic(charType);
176
+ if (!characteristic) continue;
177
+
178
+ service?.[i]?.updateCharacteristic(charType, value);
183
179
  }
184
180
  }
185
181
 
package/src/switches.js CHANGED
@@ -42,11 +42,9 @@ class Switches extends EventEmitter {
42
42
  });
43
43
 
44
44
  //lock flags
45
- this.locks = {
46
- checkState: false,
47
- };
45
+ this.locks = false;
48
46
  this.impulseGenerator = new ImpulseGenerator()
49
- .on('checkState', () => this.handleWithLock('checkState', async () => {
47
+ .on('checkState', () => this.handleWithLock(async () => {
50
48
  await this.checkState();
51
49
  }))
52
50
  .on('state', (state) => {
@@ -54,16 +52,16 @@ class Switches extends EventEmitter {
54
52
  });
55
53
  }
56
54
 
57
- async handleWithLock(lockKey, fn) {
58
- if (this.locks[lockKey]) return;
55
+ async handleWithLock(fn) {
56
+ if (this.locks) return;
59
57
 
60
- this.locks[lockKey] = true;
58
+ this.locks = true;
61
59
  try {
62
60
  await fn();
63
61
  } catch (error) {
64
62
  this.emit('error', `Inpulse generator error: ${error}`);
65
63
  } finally {
66
- this.locks[lockKey] = false;
64
+ this.locks = false;
67
65
  }
68
66
  }
69
67
 
@@ -94,17 +92,13 @@ class Switches extends EventEmitter {
94
92
  this.switchesOutlets.push(switchOutlet);
95
93
 
96
94
  //update characteristics
97
- const service = this.lightServices?.[i];
98
- if (service) {
99
- const serviceName = this.relaysNamePrefix ? `${this.info.deviceName} ${friendlyName}` : friendlyName;
100
- service.updateCharacteristic(Characteristic.ConfiguredName, serviceName);
101
- service.updateCharacteristic(Characteristic.On, power);
102
- }
95
+ const serviceName = this.relaysNamePrefix ? `${this.info.deviceName} ${friendlyName}` : friendlyName;
96
+ this.lightServices?.[i]
97
+ ?.setCharacteristic(Characteristic.ConfiguredName, serviceName)
98
+ .updateCharacteristic(Characteristic.On, power);
103
99
 
104
100
  //log info
105
- if (!this.disableLogInfo) {
106
- this.emit('info', `${friendlyName}, state: ${power ? 'ON' : 'OFF'}`);
107
- }
101
+ if (!this.disableLogInfo) this.emit('info', `${friendlyName}, state: ${power ? 'ON' : 'OFF'}`);
108
102
  }
109
103
  }
110
104