homebridge-tasmota-control 1.6.1-beta.21 → 1.6.1-beta.23
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 +1 -1
- package/src/sensors.js +35 -34
package/package.json
CHANGED
package/src/sensors.js
CHANGED
|
@@ -94,6 +94,7 @@ class Sensors extends EventEmitter {
|
|
|
94
94
|
return obj;
|
|
95
95
|
}, {});
|
|
96
96
|
|
|
97
|
+
let i = 0;
|
|
97
98
|
for (const [key, value] of Object.entries(sensorData)) {
|
|
98
99
|
const sensorData = value;
|
|
99
100
|
|
|
@@ -119,8 +120,22 @@ class Sensors extends EventEmitter {
|
|
|
119
120
|
obj.tempUnit = '°C';
|
|
120
121
|
}
|
|
121
122
|
|
|
123
|
+
//update characteristics
|
|
124
|
+
this.sensorTemperatureServices?.[i]?.Characteristic?.CurrentTemperature?.updateCharacteristic(Characteristic.CurrentTemperature, obj.temperature);
|
|
125
|
+
this.sensorReferenceTemperatureServices?.[i]?.Characteristic?.CurrentTemperature?.updateCharacteristic(Characteristic.CurrentTemperature, obj.referenceTemperature);
|
|
126
|
+
this.sensorObjTemperatureServices?.[i]?.Characteristic?.CurrentTemperature?.updateCharacteristic(Characteristic.CurrentTemperature, obj.objTemperature);
|
|
127
|
+
this.sensorAmbTemperatureServices?.[i]?.Characteristic?.CurrentTemperature?.updateCharacteristic(Characteristic.CurrentTemperature, obj.ambTemperature);
|
|
128
|
+
this.sensorDewPointTemperatureServices?.[i]?.Characteristic?.CurrentTemperature?.updateCharacteristic(Characteristic.CurrentTemperature, obj.dewPointTemperature);
|
|
129
|
+
this.sensorHumidityServices?.[i]?.Characteristic?.CurrentRelativeHumidity?.updateCharacteristic(Characteristic.CurrentRelativeHumidity, obj.humidity);
|
|
130
|
+
this.sensorCarbonDioxydeServices?.[i]?.Characteristic?.CarbonDioxideDetected?.updateCharacteristic(Characteristic.CarbonDioxideDetected, obj.carbonDioxyde > 1000);
|
|
131
|
+
this.sensorCarbonDioxydeServices?.[i]?.Characteristic?.CarbonDioxideLevel?.updateCharacteristic(Characteristic.CarbonDioxideLevel, obj.carbonDioxyde);
|
|
132
|
+
this.sensorCarbonDioxydeServices?.[i]?.Characteristic?.CarbonDioxidePeakLevel?.updateCharacteristic(Characteristic.CarbonDioxidePeakLevel, obj.carbonDioxyde);
|
|
133
|
+
this.sensorAmbientLightServices?.[i]?.Characteristic?.CurrentAmbientLightLevel?.updateCharacteristic(Characteristic.CurrentAmbientLightLevel, obj.ambientLight);
|
|
134
|
+
this.sensorMotionServices?.[i]?.Characteristic?.MotionDetected?.updateCharacteristic(Characteristic.MotionDetected, obj.motion);
|
|
135
|
+
|
|
122
136
|
//energy
|
|
123
|
-
const
|
|
137
|
+
const isEnergy = key === 'ENERGY';
|
|
138
|
+
const energy = {
|
|
124
139
|
power: sensorData.Power,
|
|
125
140
|
apparentPower: sensorData.ApparentPower,
|
|
126
141
|
reactivePower: sensorData.ReactivePower,
|
|
@@ -135,44 +150,30 @@ class Sensors extends EventEmitter {
|
|
|
135
150
|
frequency: sensorData.Frequency,
|
|
136
151
|
load: sensorData.Load,
|
|
137
152
|
}
|
|
138
|
-
|
|
153
|
+
|
|
154
|
+
if (isEnergy) {
|
|
155
|
+
//update characteristics
|
|
156
|
+
this.sensorEnergyServices?.[i]?.Characteristic?.Power?.updateCharacteristic(Characteristic.Power, energy.power);
|
|
157
|
+
this.sensorEnergyServices?.[i]?.Characteristic?.ApparentPower?.updateCharacteristic(Characteristic.ApparentPower, energy.apparentPower);
|
|
158
|
+
this.sensorEnergyServices?.[i]?.Characteristic?.ReactivePower?.updateCharacteristic(Characteristic.ReactivePower, energy.reactivePower);
|
|
159
|
+
this.sensorEnergyServices?.[i]?.Characteristic?.EnergyToday?.updateCharacteristic(Characteristic.EnergyToday, energy.energyToday);
|
|
160
|
+
this.sensorEnergyServices?.[i]?.Characteristic?.EnergyLastDay?.updateCharacteristic(Characteristic.EnergyLastDay, energy.energyLastDay);
|
|
161
|
+
this.sensorEnergyServices?.[i]?.Characteristic?.EnergyLifetime?.updateCharacteristic(Characteristic.EnergyLifetime, energy.energyLifetime);
|
|
162
|
+
this.sensorEnergyServices?.[i]?.Characteristic?.Current?.updateCharacteristic(Characteristic.Current, energy.current);
|
|
163
|
+
this.sensorEnergyServices?.[i]?.Characteristic?.Voltage?.updateCharacteristic(Characteristic.Voltage, energy.voltage);
|
|
164
|
+
this.sensorEnergyServices?.[i]?.Characteristic?.Factor?.updateCharacteristic(Characteristic.Factor, energy.factor);
|
|
165
|
+
this.sensorEnergyServices?.[i]?.Characteristic?.Frequency?.updateCharacteristic(Characteristic.Frequency, energy.frequency);
|
|
166
|
+
this.sensorEnergyServices?.[i]?.Characteristic?.ReadingTime?.updateCharacteristic(Characteristic.ReadingTime, energy.time);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const sensor = isEnergy ? { ...obj, ...energy } : obj;
|
|
139
170
|
const debug1 = this.enableDebugMode ? this.emit('debug', `Sensor: ${JSON.stringify(sensor, null, 2)}`) : false;
|
|
140
171
|
|
|
141
172
|
//push to array
|
|
142
173
|
this.sensors.push(sensor);
|
|
174
|
+
i++;
|
|
143
175
|
}
|
|
144
176
|
this.sensorsCount = this.sensors.length;
|
|
145
|
-
|
|
146
|
-
//update characteristics
|
|
147
|
-
if (this.sensorsCount > 0) {
|
|
148
|
-
for (let i = 0; i < this.sensorsCount; i++) {
|
|
149
|
-
const sensor = this.sensors[i];
|
|
150
|
-
this.sensorTemperatureServices?.[i]?.Characteristic?.CurrentTemperature?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.temperature);
|
|
151
|
-
this.sensorReferenceTemperatureServices?.[i]?.Characteristic?.CurrentTemperature?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.referenceTemperature);
|
|
152
|
-
this.sensorObjTemperatureServices?.[i]?.Characteristic?.CurrentTemperature?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.objTemperature);
|
|
153
|
-
this.sensorAmbTemperatureServices?.[i]?.Characteristic?.CurrentTemperature?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.ambTemperature);
|
|
154
|
-
this.sensorDewPointTemperatureServices?.[i]?.Characteristic?.CurrentTemperature?.updateCharacteristic(Characteristic.CurrentTemperature, sensor.dewPointTemperature);
|
|
155
|
-
this.sensorHumidityServices?.[i]?.Characteristic?.CurrentRelativeHumidity?.updateCharacteristic(Characteristic.CurrentRelativeHumidity, sensor.humidity);
|
|
156
|
-
this.sensorCarbonDioxydeServices?.[i]?.Characteristic?.CarbonDioxideDetected?.updateCharacteristic(Characteristic.CarbonDioxideDetected, sensor.carbonDioxyde > 1000);
|
|
157
|
-
this.sensorCarbonDioxydeServices?.[i]?.Characteristic?.CarbonDioxideLevel?.updateCharacteristic(Characteristic.CarbonDioxideLevel, sensor.carbonDioxyde);
|
|
158
|
-
this.sensorCarbonDioxydeServices?.[i]?.Characteristic?.CarbonDioxidePeakLevel?.updateCharacteristic(Characteristic.CarbonDioxidePeakLevel, sensor.carbonDioxyde);
|
|
159
|
-
this.sensorAmbientLightServices?.[i]?.Characteristic?.CurrentAmbientLightLevel?.updateCharacteristic(Characteristic.CurrentAmbientLightLevel, sensor.ambientLight);
|
|
160
|
-
this.sensorMotionServices?.[i]?.Characteristic?.MotionDetected?.updateCharacteristic(Characteristic.MotionDetected, sensor.motion);
|
|
161
|
-
|
|
162
|
-
//energy
|
|
163
|
-
this.sensorEnergyServices?.[i]?.Characteristic?.Power?.updateCharacteristic(Characteristic.Power, sensor.power);
|
|
164
|
-
this.sensorEnergyServices?.[i]?.Characteristic?.ApparentPower?.updateCharacteristic(Characteristic.ApparentPower, sensor.apparentPower);
|
|
165
|
-
this.sensorEnergyServices?.[i]?.Characteristic?.ReactivePower?.updateCharacteristic(Characteristic.ReactivePower, sensor.reactivePower);
|
|
166
|
-
this.sensorEnergyServices?.[i]?.Characteristic?.EnergyToday?.updateCharacteristic(Characteristic.EnergyToday, sensor.energyToday);
|
|
167
|
-
this.sensorEnergyServices?.[i]?.Characteristic?.EnergyLastDay?.updateCharacteristic(Characteristic.EnergyLastDay, sensor.energyLastDay);
|
|
168
|
-
this.sensorEnergyServices?.[i]?.Characteristic?.EnergyLifetime?.updateCharacteristic(Characteristic.EnergyLifetime, sensor.energyLifetime);
|
|
169
|
-
this.sensorEnergyServices?.[i]?.Characteristic?.Current?.updateCharacteristic(Characteristic.Current, sensor.current);
|
|
170
|
-
this.sensorEnergyServices?.[i]?.Characteristic?.Voltage?.updateCharacteristic(Characteristic.Voltage, sensor.voltage);
|
|
171
|
-
this.sensorEnergyServices?.[i]?.Characteristic?.Factor?.updateCharacteristic(Characteristic.Factor, sensor.factor);
|
|
172
|
-
this.sensorEnergyServices?.[i]?.Characteristic?.Frequency?.updateCharacteristic(Characteristic.Frequency, sensor.frequency);
|
|
173
|
-
this.sensorEnergyServices?.[i]?.Characteristic?.ReadingTime?.updateCharacteristic(Characteristic.ReadingTime, sensor.time);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
177
|
}
|
|
177
178
|
|
|
178
179
|
return true;
|
|
@@ -261,7 +262,7 @@ class Sensors extends EventEmitter {
|
|
|
261
262
|
let i = 0;
|
|
262
263
|
for (const sensor of this.sensors) {
|
|
263
264
|
const sensorName = sensor.name;
|
|
264
|
-
if (sensor.temperature
|
|
265
|
+
if (sensor.temperature) {
|
|
265
266
|
const debug = this.enableDebugMode ? this.emit('debug', `Prepare Temperature Sensor Services`) : false;
|
|
266
267
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Temperature` : `${sensorName} Temperature`;
|
|
267
268
|
const sensorTemperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Temperature Sensor ${i}`);
|