homebridge-tasmota-control 1.6.2-beta.7 → 1.6.2-beta.8

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/sensors.js +35 -23
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.2-beta.7",
4
+ "version": "1.6.2-beta.8",
5
5
  "description": "Homebridge plugin to control Tasmota flashed devices.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
package/src/sensors.js CHANGED
@@ -137,33 +137,45 @@ class Sensors extends EventEmitter {
137
137
  this.sensors.push(obj);
138
138
 
139
139
  //update characteristics
140
- this.sensorTemperatureServices?.[i]?.Characteristic?.CurrentTemperature?.updateCharacteristic(Characteristic.CurrentTemperature, obj.temperature);
141
- this.sensorReferenceTemperatureServices?.[i]?.Characteristic?.CurrentTemperature?.updateCharacteristic(Characteristic.CurrentTemperature, obj.referenceTemperature);
142
- this.sensorObjTemperatureServices?.[i]?.Characteristic?.CurrentTemperature?.updateCharacteristic(Characteristic.CurrentTemperature, obj.objTemperature);
143
- this.sensorAmbTemperatureServices?.[i]?.Characteristic?.CurrentTemperature?.updateCharacteristic(Characteristic.CurrentTemperature, obj.ambTemperature);
144
- this.sensorDewPointTemperatureServices?.[i].Characteristic?.CurrentTemperature?.updateCharacteristic(Characteristic.CurrentTemperature, obj.dewPointTemperature);
145
- this.sensorHumidityServices?.[i]?.Characteristic?.CurrentRelativeHumidity?.updateCharacteristic(Characteristic.CurrentRelativeHumidity, obj.humidity);
146
- this.sensorCarbonDioxydeServices?.[i]?.Characteristic?.CarbonDioxideDetected?.updateCharacteristic(Characteristic.CarbonDioxideDetected, obj.carbonDioxyde > 1000);
147
- this.sensorCarbonDioxydeServices?.[i]?.Characteristic?.CarbonDioxideLevel?.updateCharacteristic(Characteristic.CarbonDioxideLevel, obj.carbonDioxyde);
148
- this.sensorCarbonDioxydeServices?.[i]?.Characteristic?.CarbonDioxidePeakLevel?.updateCharacteristic(Characteristic.CarbonDioxidePeakLevel, obj.carbonDioxyde);
149
- this.sensorAmbientLightServices?.[i]?.Characteristic?.CurrentAmbientLightLevel?.updateCharacteristic(Characteristic.CurrentAmbientLightLevel, obj.ambientLight);
150
- this.sensorMotionServices?.[i]?.Characteristic?.MotionDetected?.updateCharacteristic(Characteristic.MotionDetected, obj.motion);
140
+ const charMap = [
141
+ [this.sensorTemperatureServices?.[i], Characteristic.CurrentTemperature, obj.temperature],
142
+ [this.sensorReferenceTemperatureServices?.[i], Characteristic.CurrentTemperature, obj.referenceTemperature],
143
+ [this.sensorObjTemperatureServices?.[i], Characteristic.CurrentTemperature, obj.objTemperature],
144
+ [this.sensorAmbTemperatureServices?.[i], Characteristic.CurrentTemperature, obj.ambTemperature],
145
+ [this.sensorDewPointTemperatureServices?.[i], Characteristic.CurrentTemperature, obj.dewPointTemperature],
146
+ [this.sensorHumidityServices?.[i], Characteristic.CurrentRelativeHumidity, obj.humidity],
147
+ [this.sensorCarbonDioxydeServices?.[i], Characteristic.CarbonDioxideDetected, obj.carbonDioxyde > 1000],
148
+ [this.sensorCarbonDioxydeServices?.[i], Characteristic.CarbonDioxideLevel, obj.carbonDioxyde],
149
+ [this.sensorCarbonDioxydeServices?.[i], Characteristic.CarbonDioxidePeakLevel, obj.carbonDioxyde],
150
+ [this.sensorAmbientLightServices?.[i], Characteristic.CurrentAmbientLightLevel, obj.ambientLight],
151
+ [this.sensorMotionServices?.[i], Characteristic.MotionDetected, obj.motion],
152
+ ];
153
+
154
+ for (const [service, charType, value] of charMap) {
155
+ service?.Characteristic?.[charType]?.updateCharacteristic?.(charType, value);
156
+ }
151
157
 
152
158
  //energy
153
159
  const isEnergy = key === 'ENERGY';
154
160
  if (isEnergy) {
155
- //update characteristics
156
- this.sensorEnergyServices?.[i]?.Characteristic?.Power?.updateCharacteristic(Characteristic.Power, obj.power);
157
- this.sensorEnergyServices?.[i]?.Characteristic?.ApparentPower?.updateCharacteristic(Characteristic.ApparentPower, obj.apparentPower);
158
- this.sensorEnergyServices?.[i]?.Characteristic?.ReactivePower?.updateCharacteristic(Characteristic.ReactivePower, obj.reactivePower);
159
- this.sensorEnergyServices?.[i]?.Characteristic?.EnergyToday?.updateCharacteristic(Characteristic.EnergyToday, obj.energyToday);
160
- this.sensorEnergyServices?.[i]?.Characteristic?.EnergyLastDay?.updateCharacteristic(Characteristic.EnergyLastDay, obj.energyLastDay);
161
- this.sensorEnergyServices?.[i]?.Characteristic?.EnergyLifetime?.updateCharacteristic(Characteristic.EnergyLifetime, obj.energyLifetime);
162
- this.sensorEnergyServices?.[i]?.Characteristic?.Current?.updateCharacteristic(Characteristic.Current, obj.current);
163
- this.sensorEnergyServices?.[i]?.Characteristic?.Voltage?.updateCharacteristic(Characteristic.Voltage, obj.voltage);
164
- this.sensorEnergyServices?.[i]?.Characteristic?.Factor?.updateCharacteristic(Characteristic.Factor, obj.factor);
165
- this.sensorEnergyServices?.[i]?.Characteristic?.Frequency?.updateCharacteristic(Characteristic.Frequency, obj.frequency);
166
- this.sensorEnergyServices?.[i]?.Characteristic?.ReadingTime?.updateCharacteristic(Characteristic.ReadingTime, obj.time);
161
+ const energyMap = [
162
+ [Characteristic.Power, obj.power],
163
+ [Characteristic.ApparentPower, obj.apparentPower],
164
+ [Characteristic.ReactivePower, obj.reactivePower],
165
+ [Characteristic.EnergyToday, obj.energyToday],
166
+ [Characteristic.EnergyLastDay, obj.energyLastDay],
167
+ [Characteristic.EnergyLifetime, obj.energyLifetime],
168
+ [Characteristic.Current, obj.current],
169
+ [Characteristic.Voltage, obj.voltage],
170
+ [Characteristic.Factor, obj.factor],
171
+ [Characteristic.Frequency, obj.frequency],
172
+ [Characteristic.ReadingTime, obj.time],
173
+ ];
174
+
175
+ const energyService = this.sensorEnergyServices?.[i];
176
+ for (const [charType, value] of energyMap) {
177
+ energyService?.Characteristic?.[charType]?.updateCharacteristic?.(charType, value);
178
+ }
167
179
  }
168
180
 
169
181
  const emit = this.sensorEnergyServices?.[i]?.Characteristic?.Power ? this.emit('warn', `Power: ${JSON.stringify(obj, null, 2)}`) : false;