homebridge-tasmota-control 0.7.2-beta.1 → 0.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": "0.7.2-beta.1",
4
+ "version": "0.7.2",
5
5
  "description": "Homebridge plugin to control Tasmota flashed devices.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
package/src/constans.json CHANGED
@@ -40,6 +40,8 @@
40
40
  "Humidity",
41
41
  "DewPoint",
42
42
  "Pressure",
43
- "Gas"
43
+ "Gas",
44
+ "CarbonDioxyde",
45
+ "Ambient"
44
46
  ]
45
47
  }
@@ -44,8 +44,6 @@ class TasmotaDevice {
44
44
  this.sensorsDewPointCount = 0;
45
45
  this.sensorsPressureCount = 0;
46
46
  this.sensorsGasCount = 0;
47
- this.sensorsCarbonDioxydeCount = 0;
48
- this.sensorsAmbientLightCount = 0;
49
47
 
50
48
  //variable
51
49
  this.startPrepareAccessory = true;
@@ -126,22 +124,23 @@ class TasmotaDevice {
126
124
  const addressMac = deviceInfo.StatusNET.Mac;
127
125
 
128
126
  //status sns
129
- const sensorTypes = CONSTANS.StatusSNS;
130
- const sensor = Object.entries(deviceInfo.StatusSNS)
131
- .filter(([key]) => sensorTypes.includes(key))
132
- .reduce((obj, [key, value]) => {
133
- obj[key] = value;
134
- return obj;
135
- }, {});
136
-
137
- const debug3 = this.enableDebugMode ? this.log(`Device: ${this.host} ${this.name}, debug sensors: ${JSON.stringify(sensor, null, 2)}`) : false;
138
- for (const [key, value] of Object.entries(sensor)) {
139
- const debug = this.enableDebugMode ? this.log(`Device: ${this.host} ${this.name}, debug key: ${key} value: ${JSON.stringify(value, null, 2)}`) : false;
140
- const obj = {
141
- 'name': key,
142
- 'data': value
127
+ const statusSNSSupported = deviceInfoKeys.includes('StatusSNS') ?? false;
128
+ if (statusSNSSupported) {
129
+ const sensorTypes = CONSTANS.StatusSNS;
130
+ const sensor = Object.entries(deviceInfo.StatusSNS)
131
+ .filter(([key]) => sensorTypes.some(type => key.includes(type)))
132
+ .reduce((obj, [key, value]) => {
133
+ obj[key] = value;
134
+ return obj;
135
+ }, {});
136
+
137
+ for (const [key, value] of Object.entries(sensor)) {
138
+ const obj = {
139
+ 'name': key,
140
+ 'data': value
141
+ }
142
+ this.sensors.push(obj);
143
143
  }
144
- this.sensors.push(obj);
145
144
  }
146
145
  const sensorsCount = this.sensors.length;
147
146
 
@@ -206,8 +205,6 @@ class TasmotaDevice {
206
205
  this.sensorsDewPoint = [];
207
206
  this.sensorsPressure = [];
208
207
  this.sensorsGas = [];
209
- this.sensorsCarbonDioxyde = [];
210
- this.sensorsAmbientLight = [];
211
208
 
212
209
  const sensorsStatusData = await this.axiosInstance(CONSTANS.ApiCommands.Status);
213
210
  const sensorsStatus = sensorsStatusData.data.StatusSNS;
@@ -230,8 +227,6 @@ class TasmotaDevice {
230
227
  const push3 = dewPoint !== false && dewPoint !== undefined && dewPoint !== null ? this.sensorsDewPoint.push(dewPoint) : false;
231
228
  const push4 = pressure !== false && pressure !== undefined && pressure !== null ? this.sensorsPressure.push(pressure) : false;
232
229
  const push5 = gas !== false && gas !== undefined && gas !== null ? this.sensorsGas.push(gas) : false;
233
- const push6 = carbonDioxyde !== false && carbonDioxyde !== undefined && carbonDioxyde !== null ? this.sensorsCarbonDioxyde.push(carbonDioxyde) : false;
234
- const push7 = ambientLight !== false && ambientLight !== undefined && ambientLight !== null ? this.sensorsAmbientLight.push(ambientLight) : false;
235
230
  };
236
231
 
237
232
  this.sensorsTemperatureCount = this.sensorsTemperature.length;
@@ -239,8 +234,6 @@ class TasmotaDevice {
239
234
  this.sensorsDewPointCount = this.sensorsDewPoint.length;
240
235
  this.sensorsPressureCount = this.sensorsPressure.length;
241
236
  this.sensorsGasCount = this.sensorsGas.length;
242
- this.sensorsCarbonDioxydeCount = this.sensorsCarbonDioxyde.length;
243
- this.sensorsAmbientLightCount = this.sensorsAmbientLight.length;
244
237
  this.tempUnit = sensorsStatus.TempUnit ?? 'C';
245
238
  this.pressureUnit = sensorsStatus.PressureUnit ?? 'hPa';
246
239
 
@@ -269,25 +262,6 @@ class TasmotaDevice {
269
262
  .updateCharacteristic(Characteristic.CurrentTemperature, dewPoint);
270
263
  };
271
264
  };
272
-
273
- if (this.sensorCarbonDioxydeServices && this.sensorsCarbonDioxydeCount > 0) {
274
- for (let i = 0; i < this.sensorsCarbonDioxydeCount; i++) {
275
- const carbonDioxydeDetected = this.sensorsCarbonDioxyde[i] > 1000;
276
- const carbonDioxydeLevel = this.sensorsCarbonDioxyde[i];
277
- this.sensorCarbonDioxydeServices[i]
278
- .updateCharacteristic(Characteristic.CarbonDioxideDetected, carbonDioxydeDetected)
279
- .updateCharacteristic(Characteristic.CarbonDioxideLevel, carbonDioxydeLevel)
280
- .updateCharacteristic(Characteristic.CarbonDioxidePeakLevel, carbonDioxydeLevel);
281
- };
282
- };
283
-
284
- if (this.sensorAmbientLightServices && this.sensorsAmbientLightCount > 0) {
285
- for (let i = 0; i < this.sensorsAmbientLightCount; i++) {
286
- const ambientLight = this.sensorsAmbientLight[i];
287
- this.sensorAmbientLightServices[i]
288
- .updateCharacteristic(Characteristic.CurrentAmbientLightLevel, ambientLight);
289
- };
290
- };
291
265
  };
292
266
 
293
267
  resolve();
@@ -416,7 +390,7 @@ class TasmotaDevice {
416
390
  sensorDewPointService.getCharacteristic(Characteristic.CurrentTemperature)
417
391
  .onGet(async () => {
418
392
  const value = this.sensorsDewPoint[i];
419
- const logInfo = this.disableLogInfo ? false : this.log(`Device: ${this.host}, ${accessoryName}, sensor:${sensorName} dew point: ${value} °${this.tempUnit}`);
393
+ const logInfo = this.disableLogInfo ? false : this.log(`Device: ${this.host}, ${accessoryName}, sensor: ${sensorName} dew point: ${value} °${this.tempUnit}`);
420
394
  return value;
421
395
  });
422
396
  this.sensorDewPointServices.push(sensorDewPointService);
@@ -429,61 +403,8 @@ class TasmotaDevice {
429
403
  //gas
430
404
 
431
405
  //carbon dioxyde
432
- const sensorsCarbonDioxydeCount = this.sensorsCarbonDioxydeCount;
433
- if (sensorsCarbonDioxydeCount > 0) {
434
- const debug = this.enableDebugMode ? this.log('Prepare Carbon Dioxyde Sensor Services') : false;
435
- this.sensorCarbonDioxydeServices = [];
436
- for (let i = 0; i < sensorsCarbonDioxydeCount; i++) {
437
- const sensorName = this.sensorsName[i];
438
- const serviceName = `${accessoryName} ${sensorName} Carbon Dioxyde`;
439
- const sensorCarbonDioxydeService = new Service.CarbonDioxideSensor(serviceName, `Carbon Dioxyde Sensor${i}`);
440
- sensorCarbonDioxydeService.addOptionalCharacteristic(Characteristic.ConfiguredName);
441
- sensorCarbonDioxydeService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
442
- sensorCarbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxideDetected)
443
- .onGet(async () => {
444
- const state = this.sensorsCarbonDioxyde[i] > 1000;
445
- const logInfo = this.disableLogInfo ? false : this.log(`Device: ${this.host}, ${accessoryName}, sensor:${sensorName} carbon dioxyde detected: ${state ? 'Yes' : 'No'}`);
446
- return state;
447
- });
448
- sensorCarbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxideLevel)
449
- .onGet(async () => {
450
- const value = this.sensorsCarbonDioxyde[i];
451
- const logInfo = this.disableLogInfo ? false : this.log(`Device: ${this.host}, ${accessoryName}, sensor:${sensorName} carbon dioxyde level: ${value} ppm`);
452
- return value;
453
- });
454
- sensorCarbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxidePeakLevel)
455
- .onGet(async () => {
456
- const value = this.sensorsCarbonDioxyde[i];
457
- const logInfo = this.disableLogInfo ? false : this.log(`Device: ${this.host}, ${accessoryName}, sensor:${sensorName} carbon dioxyde peak level: ${value} ppm`);
458
- return value;
459
- });
460
- this.sensorCarbonDioxydeServices.push(sensorCarbonDioxydeService);
461
- accessory.addService(sensorCarbonDioxydeService);
462
- };
463
- }
464
- };
465
406
 
466
- //ambient light
467
- const sensorsAmbientLightCount = this.sensorsAmbientLightCount;
468
- if (sensorsAmbientLightCount > 0) {
469
- const debug = this.enableDebugMode ? this.log('Prepare Ambient Light Sensor Services') : false;
470
- this.sensorAmbientLightServices = [];
471
- for (let i = 0; i < sensorsAmbientLightCount; i++) {
472
- const sensorName = this.sensorsName[i];
473
- const serviceName = `${accessoryName} ${sensorName} Ambient Light`;
474
- const sensorAmbientLightService = new Service.LightSensor(serviceName, `Ambient Light Sensor${i}`);
475
- sensorAmbientLightService.addOptionalCharacteristic(Characteristic.ConfiguredName);
476
- sensorAmbientLightService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
477
- sensorAmbientLightService.getCharacteristic(Characteristic.CurrentAmbientLightLevel)
478
- .onGet(async () => {
479
- const value = this.sensorsAmbientLight[i];
480
- const logInfo = this.disableLogInfo ? false : this.log(`Device: ${this.host}, ${accessoryName}, sensor:${sensorName} ambient light: ${value} lx`);
481
- return value;
482
- });
483
- this.sensorAmbientLightServices.push(sensorAmbientLightService);
484
- accessory.addService(sensorAmbientLightService);
485
- };
486
- }
407
+ };
487
408
 
488
409
  resolve(accessory);
489
410
  } catch (error) {