homebridge-tasmota-control 1.6.2-beta.0 → 1.6.2-beta.10
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 +49 -42
package/package.json
CHANGED
package/src/sensors.js
CHANGED
|
@@ -114,29 +114,7 @@ class Sensors extends EventEmitter {
|
|
|
114
114
|
gas: sensorData.Gas,
|
|
115
115
|
carbonDioxyde: sensorData.CarbonDioxyde,
|
|
116
116
|
ambientLight: sensorData.Ambient,
|
|
117
|
-
motion: sensorData.Motion
|
|
118
|
-
}
|
|
119
|
-
if (obj.tempUnit === 'C') {
|
|
120
|
-
obj.tempUnit = '°C';
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
this.emit('warn', `Sensors status: ${JSON.stringify(obj, null, 2)}`)
|
|
124
|
-
//update characteristics
|
|
125
|
-
this.sensorTemperatureServices?.[i]?.Characteristic?.CurrentTemperature?.updateCharacteristic(Characteristic.CurrentTemperature, obj.temperature);
|
|
126
|
-
this.sensorReferenceTemperatureServices?.[i]?.Characteristic?.CurrentTemperature?.updateCharacteristic(Characteristic.CurrentTemperature, obj.referenceTemperature);
|
|
127
|
-
this.sensorObjTemperatureServices?.[i]?.Characteristic?.CurrentTemperature?.updateCharacteristic(Characteristic.CurrentTemperature, obj.objTemperature);
|
|
128
|
-
this.sensorAmbTemperatureServices?.[i]?.Characteristic?.CurrentTemperature?.updateCharacteristic(Characteristic.CurrentTemperature, obj.ambTemperature);
|
|
129
|
-
this.sensorDewPointTemperatureServices?.[i]?.Characteristic?.CurrentTemperature?.updateCharacteristic(Characteristic.CurrentTemperature, obj.dewPointTemperature);
|
|
130
|
-
this.sensorHumidityServices?.[i]?.Characteristic?.CurrentRelativeHumidity?.updateCharacteristic(Characteristic.CurrentRelativeHumidity, obj.humidity);
|
|
131
|
-
this.sensorCarbonDioxydeServices?.[i]?.Characteristic?.CarbonDioxideDetected?.updateCharacteristic(Characteristic.CarbonDioxideDetected, obj.carbonDioxyde > 1000);
|
|
132
|
-
this.sensorCarbonDioxydeServices?.[i]?.Characteristic?.CarbonDioxideLevel?.updateCharacteristic(Characteristic.CarbonDioxideLevel, obj.carbonDioxyde);
|
|
133
|
-
this.sensorCarbonDioxydeServices?.[i]?.Characteristic?.CarbonDioxidePeakLevel?.updateCharacteristic(Characteristic.CarbonDioxidePeakLevel, obj.carbonDioxyde);
|
|
134
|
-
this.sensorAmbientLightServices?.[i]?.Characteristic?.CurrentAmbientLightLevel?.updateCharacteristic(Characteristic.CurrentAmbientLightLevel, obj.ambientLight);
|
|
135
|
-
this.sensorMotionServices?.[i]?.Characteristic?.MotionDetected?.updateCharacteristic(Characteristic.MotionDetected, obj.motion);
|
|
136
|
-
|
|
137
|
-
//energy
|
|
138
|
-
const isEnergy = key === 'ENERGY';
|
|
139
|
-
const energy = {
|
|
117
|
+
motion: sensorData.Motion,
|
|
140
118
|
power: sensorData.Power,
|
|
141
119
|
apparentPower: sensorData.ApparentPower,
|
|
142
120
|
reactivePower: sensorData.ReactivePower,
|
|
@@ -149,29 +127,58 @@ class Sensors extends EventEmitter {
|
|
|
149
127
|
voltage: sensorData.Voltage,
|
|
150
128
|
factor: sensorData.Factor,
|
|
151
129
|
frequency: sensorData.Frequency,
|
|
152
|
-
load: sensorData.Load
|
|
130
|
+
load: sensorData.Load
|
|
153
131
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
//update characteristics
|
|
157
|
-
this.sensorEnergyServices?.[i]?.Characteristic?.Power?.updateCharacteristic(Characteristic.Power, energy.power);
|
|
158
|
-
this.sensorEnergyServices?.[i]?.Characteristic?.ApparentPower?.updateCharacteristic(Characteristic.ApparentPower, energy.apparentPower);
|
|
159
|
-
this.sensorEnergyServices?.[i]?.Characteristic?.ReactivePower?.updateCharacteristic(Characteristic.ReactivePower, energy.reactivePower);
|
|
160
|
-
this.sensorEnergyServices?.[i]?.Characteristic?.EnergyToday?.updateCharacteristic(Characteristic.EnergyToday, energy.energyToday);
|
|
161
|
-
this.sensorEnergyServices?.[i]?.Characteristic?.EnergyLastDay?.updateCharacteristic(Characteristic.EnergyLastDay, energy.energyLastDay);
|
|
162
|
-
this.sensorEnergyServices?.[i]?.Characteristic?.EnergyLifetime?.updateCharacteristic(Characteristic.EnergyLifetime, energy.energyLifetime);
|
|
163
|
-
this.sensorEnergyServices?.[i]?.Characteristic?.Current?.updateCharacteristic(Characteristic.Current, energy.current);
|
|
164
|
-
this.sensorEnergyServices?.[i]?.Characteristic?.Voltage?.updateCharacteristic(Characteristic.Voltage, energy.voltage);
|
|
165
|
-
this.sensorEnergyServices?.[i]?.Characteristic?.Factor?.updateCharacteristic(Characteristic.Factor, energy.factor);
|
|
166
|
-
this.sensorEnergyServices?.[i]?.Characteristic?.Frequency?.updateCharacteristic(Characteristic.Frequency, energy.frequency);
|
|
167
|
-
this.sensorEnergyServices?.[i]?.Characteristic?.ReadingTime?.updateCharacteristic(Characteristic.ReadingTime, energy.time);
|
|
132
|
+
if (obj.tempUnit === 'C') {
|
|
133
|
+
obj.tempUnit = '°C';
|
|
168
134
|
}
|
|
169
135
|
|
|
170
|
-
const sensor = isEnergy ? { ...obj, ...energy } : obj;
|
|
171
|
-
const debug1 = this.enableDebugMode ? this.emit('debug', `Sensor: ${JSON.stringify(sensor, null, 2)}`) : false;
|
|
172
|
-
|
|
173
136
|
//push to array
|
|
174
|
-
this.sensors.push(
|
|
137
|
+
this.sensors.push(obj);
|
|
138
|
+
|
|
139
|
+
//update characteristics
|
|
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
|
+
}
|
|
157
|
+
|
|
158
|
+
//energy
|
|
159
|
+
const isEnergy = key === 'ENERGY';
|
|
160
|
+
if (isEnergy) {
|
|
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
|
+
const emitw = energyService?.Characteristic?.[charType] ? this.emit('warn', `Power: ${JSON.stringify(obj, null, 2)}`) : false
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const debug1 = this.enableDebugMode ? this.emit('debug', `Sensor: ${JSON.stringify(obj, null, 2)}`) : false;
|
|
175
182
|
i++;
|
|
176
183
|
}
|
|
177
184
|
this.sensorsCount = this.sensors.length;
|