homebridge-tasmota-control 1.8.0-beta.1 → 1.8.0-beta.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/CHANGELOG.md +13 -0
- package/README.md +11 -6
- package/config.schema.json +47 -41
- package/index.js +13 -13
- package/package.json +1 -1
- package/src/fans.js +37 -37
- package/src/lights.js +17 -17
- package/src/mielhvac.js +28 -28
- package/src/sensors.js +42 -42
- package/src/switches.js +12 -12
package/src/sensors.js
CHANGED
|
@@ -20,9 +20,9 @@ class Sensors extends EventEmitter {
|
|
|
20
20
|
|
|
21
21
|
//other config
|
|
22
22
|
this.sensorsNamePrefix = config.sensorsNamePrefix || false;
|
|
23
|
-
this.
|
|
24
|
-
this.
|
|
25
|
-
this.
|
|
23
|
+
this.logDeviceInfo = device.log?.deviceInfo || false;
|
|
24
|
+
this.logInfo = device.log?.info || false;
|
|
25
|
+
this.logDebug = device.log?.debug || false;
|
|
26
26
|
this.functions = new Functions();
|
|
27
27
|
|
|
28
28
|
//sensors
|
|
@@ -56,12 +56,12 @@ class Sensors extends EventEmitter {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
async checkState() {
|
|
59
|
-
if (this.
|
|
59
|
+
if (this.logDebug) this.emit('debug', `Requesting status`);
|
|
60
60
|
try {
|
|
61
61
|
//sensor status
|
|
62
62
|
const sensorStatusData = await this.client.get(ApiCommands.Status);
|
|
63
63
|
const sensorStatus = sensorStatusData.data ?? {};
|
|
64
|
-
if (this.
|
|
64
|
+
if (this.logDebug) this.emit('debug', `Sensors status: ${JSON.stringify(sensorStatus, null, 2)}`);
|
|
65
65
|
|
|
66
66
|
//sensor status keys
|
|
67
67
|
const sensorStatusKeys = Object.keys(sensorStatus);
|
|
@@ -168,7 +168,7 @@ class Sensors extends EventEmitter {
|
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
if (this.
|
|
171
|
+
if (this.logDebug) this.emit('debug', `Sensor: ${JSON.stringify(sensor, null, 2)}`);
|
|
172
172
|
i++;
|
|
173
173
|
}
|
|
174
174
|
|
|
@@ -194,7 +194,7 @@ class Sensors extends EventEmitter {
|
|
|
194
194
|
|
|
195
195
|
//prepare accessory
|
|
196
196
|
async prepareAccessory() {
|
|
197
|
-
if (this.
|
|
197
|
+
if (this.logDebug) this.emit('debug', `Prepare Accessory`);
|
|
198
198
|
|
|
199
199
|
try {
|
|
200
200
|
//accessory
|
|
@@ -204,7 +204,7 @@ class Sensors extends EventEmitter {
|
|
|
204
204
|
const accessory = new Accessory(accessoryName, accessoryUUID, accessoryCategory);
|
|
205
205
|
|
|
206
206
|
//Prepare information service
|
|
207
|
-
if (this.
|
|
207
|
+
if (this.logDebug) this.emit('debug', `Prepare Information Service`);
|
|
208
208
|
accessory.getService(Service.AccessoryInformation)
|
|
209
209
|
.setCharacteristic(Characteristic.Manufacturer, 'Tasmota')
|
|
210
210
|
.setCharacteristic(Characteristic.Model, this.info.modelName ?? 'Model Name')
|
|
@@ -214,7 +214,7 @@ class Sensors extends EventEmitter {
|
|
|
214
214
|
|
|
215
215
|
//Prepare services
|
|
216
216
|
if (this.sensorsCount > 0) {
|
|
217
|
-
if (this.
|
|
217
|
+
if (this.logDebug) this.emit('debug', `Prepare Sensor Services`);
|
|
218
218
|
this.temperatureServices = [];
|
|
219
219
|
this.temperatureReferenceServices = [];
|
|
220
220
|
this.temperatureObjServices = [];
|
|
@@ -231,7 +231,7 @@ class Sensors extends EventEmitter {
|
|
|
231
231
|
for (const sensor of this.sensors) {
|
|
232
232
|
const sensorName = sensor.name;
|
|
233
233
|
if (sensor.temperature) {
|
|
234
|
-
if (this.
|
|
234
|
+
if (this.logDebug) this.emit('debug', `Prepare Temperature Sensor Services`);
|
|
235
235
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Temperature` : `${sensorName} Temperature`;
|
|
236
236
|
const temperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Temperature Sensor ${i}`);
|
|
237
237
|
temperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
@@ -239,7 +239,7 @@ class Sensors extends EventEmitter {
|
|
|
239
239
|
temperatureService.getCharacteristic(Characteristic.CurrentTemperature)
|
|
240
240
|
.onGet(async () => {
|
|
241
241
|
const value = sensor.temperature;
|
|
242
|
-
if (
|
|
242
|
+
if (this.logInfo) this.emit('info', `sensor: ${sensorName} temperature: ${value} °${sensor.tempUnit}`);
|
|
243
243
|
return value;
|
|
244
244
|
});
|
|
245
245
|
this.temperatureServices.push(temperatureService);
|
|
@@ -247,7 +247,7 @@ class Sensors extends EventEmitter {
|
|
|
247
247
|
|
|
248
248
|
//reference temperature
|
|
249
249
|
if (sensor.referenceTemperature) {
|
|
250
|
-
if (this.
|
|
250
|
+
if (this.logDebug) this.emit('debug', `Prepare Reference Temperature Sensor Services`);
|
|
251
251
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Reference Temperature` : `${sensorName} Reference Temperature`;
|
|
252
252
|
const temperatureReferenceService = accessory.addService(Service.TemperatureSensor, serviceName, `Reference Temperature Sensor ${i}`);
|
|
253
253
|
temperatureReferenceService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
@@ -255,7 +255,7 @@ class Sensors extends EventEmitter {
|
|
|
255
255
|
temperatureReferenceService.getCharacteristic(Characteristic.CurrentTemperature)
|
|
256
256
|
.onGet(async () => {
|
|
257
257
|
const value = sensor.referenceTemperature;
|
|
258
|
-
if (
|
|
258
|
+
if (this.logInfo) this.emit('info', `sensor: ${sensorName} reference temperature: ${value} °${sensor.tempUnit}`);
|
|
259
259
|
return value;
|
|
260
260
|
});
|
|
261
261
|
this.temperatureReferenceServices.push(temperatureReferenceService);
|
|
@@ -263,7 +263,7 @@ class Sensors extends EventEmitter {
|
|
|
263
263
|
|
|
264
264
|
//object temperature
|
|
265
265
|
if (sensor.objTemperature) {
|
|
266
|
-
if (this.
|
|
266
|
+
if (this.logDebug) this.emit('debug', `Prepare Obj Temperature Sensor Services`);
|
|
267
267
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Obj Temperature` : `${sensorName} Obj Temperature`;
|
|
268
268
|
const temperatureObjService = accessory.addService(Service.TemperatureSensor, serviceName, `Obj Temperature Sensor ${i}`);
|
|
269
269
|
temperatureObjService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
@@ -271,7 +271,7 @@ class Sensors extends EventEmitter {
|
|
|
271
271
|
temperatureObjService.getCharacteristic(Characteristic.CurrentTemperature)
|
|
272
272
|
.onGet(async () => {
|
|
273
273
|
const value = sensor.objTemperature;
|
|
274
|
-
if (
|
|
274
|
+
if (this.logInfo) this.emit('info', `sensor: ${sensorName} obj temperature: ${value} °${sensor.tempUnit}`);
|
|
275
275
|
return value;
|
|
276
276
|
});
|
|
277
277
|
this.temperatureObjServices.push(temperatureObjService);
|
|
@@ -279,7 +279,7 @@ class Sensors extends EventEmitter {
|
|
|
279
279
|
|
|
280
280
|
//ambient temperature
|
|
281
281
|
if (sensor.ambTemperature) {
|
|
282
|
-
if (this.
|
|
282
|
+
if (this.logDebug) this.emit('debug', `Prepare Amb Temperature Sensor Services`);
|
|
283
283
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Amb Temperature` : `${sensorName} Amb Temperature`;
|
|
284
284
|
const temperatureAmbService = accessory.addService(Service.TemperatureSensor, serviceName, `Amb Temperature Sensor ${i}`);
|
|
285
285
|
temperatureAmbService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
@@ -287,7 +287,7 @@ class Sensors extends EventEmitter {
|
|
|
287
287
|
temperatureAmbService.getCharacteristic(Characteristic.CurrentTemperature)
|
|
288
288
|
.onGet(async () => {
|
|
289
289
|
const value = sensor.ambTemperature;
|
|
290
|
-
if (
|
|
290
|
+
if (this.logInfo) this.emit('info', `sensor: ${sensorName} amb temperature: ${value} °${sensor.tempUnit}`);
|
|
291
291
|
return value;
|
|
292
292
|
});
|
|
293
293
|
this.temperatureAmbServices.push(temperatureAmbService);
|
|
@@ -295,7 +295,7 @@ class Sensors extends EventEmitter {
|
|
|
295
295
|
|
|
296
296
|
//dew point temperature
|
|
297
297
|
if (sensor.dewPointTemperature) {
|
|
298
|
-
if (this.
|
|
298
|
+
if (this.logDebug) this.emit('debug', `Prepare Dew Point Temperature Sensor Services`);
|
|
299
299
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Dew Point` : `${sensorName} Dew Point`;
|
|
300
300
|
const temperatureDewPointService = accessory.addService(Service.TemperatureSensor, serviceName, `Dew Point Temperature Sensor ${i}`);
|
|
301
301
|
temperatureDewPointService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
@@ -303,7 +303,7 @@ class Sensors extends EventEmitter {
|
|
|
303
303
|
temperatureDewPointService.getCharacteristic(Characteristic.CurrentTemperature)
|
|
304
304
|
.onGet(async () => {
|
|
305
305
|
const value = sensor.dewPointTemperature;
|
|
306
|
-
if (
|
|
306
|
+
if (this.logInfo) this.emit('info', `sensor: ${sensorName} dew point: ${value} °${sensor.tempUnit}`);
|
|
307
307
|
return value;
|
|
308
308
|
});
|
|
309
309
|
this.temperatureDewPointServices.push(temperatureDewPointService);
|
|
@@ -311,7 +311,7 @@ class Sensors extends EventEmitter {
|
|
|
311
311
|
|
|
312
312
|
//humidity
|
|
313
313
|
if (sensor.humidity) {
|
|
314
|
-
if (this.
|
|
314
|
+
if (this.logDebug) this.emit('debug', `Prepare Humidity Sensor Services`);
|
|
315
315
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Humidity` : `${sensorName} Humidity`;
|
|
316
316
|
const humidityService = accessory.addService(Service.HumiditySensor, serviceName, `Humidity Sensor ${i}`);
|
|
317
317
|
humidityService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
@@ -319,7 +319,7 @@ class Sensors extends EventEmitter {
|
|
|
319
319
|
humidityService.getCharacteristic(Characteristic.CurrentRelativeHumidity)
|
|
320
320
|
.onGet(async () => {
|
|
321
321
|
const value = sensor.humidity;
|
|
322
|
-
if (
|
|
322
|
+
if (this.logInfo) this.emit('info', `sensor: ${sensorName} humidity: ${value} %`);
|
|
323
323
|
return value;
|
|
324
324
|
});
|
|
325
325
|
this.humidityServices.push(humidityService);
|
|
@@ -331,7 +331,7 @@ class Sensors extends EventEmitter {
|
|
|
331
331
|
|
|
332
332
|
//carbon dioxyde
|
|
333
333
|
if (sensor.carbonDioxyde) {
|
|
334
|
-
if (this.
|
|
334
|
+
if (this.logDebug) this.emit('debug', `Prepare Carbon Dioxyde Sensor Services`);
|
|
335
335
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Carbon Dioxyde` : `${sensorName} Carbon Dioxyde`;
|
|
336
336
|
const carbonDioxydeService = accessory.addService(Service.CarbonDioxideSensor, serviceName, `Carbon Dioxyde Sensor ${i}`);
|
|
337
337
|
carbonDioxydeService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
@@ -339,19 +339,19 @@ class Sensors extends EventEmitter {
|
|
|
339
339
|
carbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxideDetected)
|
|
340
340
|
.onGet(async () => {
|
|
341
341
|
const state = sensor.carbonDioxyde > 1000;
|
|
342
|
-
if (
|
|
342
|
+
if (this.logInfo) this.emit('info', `sensor: ${sensorName} carbon dioxyde detected: ${state ? 'Yes' : 'No'}`);
|
|
343
343
|
return state;
|
|
344
344
|
});
|
|
345
345
|
carbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxideLevel)
|
|
346
346
|
.onGet(async () => {
|
|
347
347
|
const value = sensor.carbonDioxyde;
|
|
348
|
-
if (
|
|
348
|
+
if (this.logInfo) this.emit('info', `sensor: ${sensorName} carbon dioxyde level: ${value} ppm`);
|
|
349
349
|
return value;
|
|
350
350
|
});
|
|
351
351
|
carbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxidePeakLevel)
|
|
352
352
|
.onGet(async () => {
|
|
353
353
|
const value = sensor.carbonDioxyde;
|
|
354
|
-
if (
|
|
354
|
+
if (this.logInfo) this.emit('info', `sensor: ${sensorName} carbon dioxyde peak level: ${value} ppm`);
|
|
355
355
|
return value;
|
|
356
356
|
});
|
|
357
357
|
this.carbonDioxydeServices.push(carbonDioxydeService);
|
|
@@ -359,7 +359,7 @@ class Sensors extends EventEmitter {
|
|
|
359
359
|
|
|
360
360
|
//ambient light
|
|
361
361
|
if (sensor.ambientLight) {
|
|
362
|
-
if (this.
|
|
362
|
+
if (this.logDebug) this.emit('debug', `Prepare Ambient Light Sensor Services`);
|
|
363
363
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Ambient Light` : `${sensorName} Ambient Light`;
|
|
364
364
|
const ambientLightService = accessory.addService(Service.LightSensor, serviceName, `Ambient Light Sensor ${i}`);
|
|
365
365
|
ambientLightService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
@@ -367,7 +367,7 @@ class Sensors extends EventEmitter {
|
|
|
367
367
|
ambientLightService.getCharacteristic(Characteristic.CurrentAmbientLightLevel)
|
|
368
368
|
.onGet(async () => {
|
|
369
369
|
const value = sensor.ambientLight;
|
|
370
|
-
if (
|
|
370
|
+
if (this.logInfo) this.emit('info', `sensor: ${sensorName} ambient light: ${value} lx`);
|
|
371
371
|
return value;
|
|
372
372
|
});
|
|
373
373
|
this.ambientLightServices.push(ambientLightService);
|
|
@@ -375,7 +375,7 @@ class Sensors extends EventEmitter {
|
|
|
375
375
|
|
|
376
376
|
//motion
|
|
377
377
|
if (sensor.motion) {
|
|
378
|
-
if (this.
|
|
378
|
+
if (this.logDebug) this.emit('debug', `Prepare Motion Sensor Services`);
|
|
379
379
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Motion` : `${sensorName} Motion`;
|
|
380
380
|
const motionService = accessory.addService(Service.MotionSensor, serviceName, `Motion Sensor ${i}`);
|
|
381
381
|
motionService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
@@ -383,7 +383,7 @@ class Sensors extends EventEmitter {
|
|
|
383
383
|
motionService.getCharacteristic(Characteristic.MotionDetected)
|
|
384
384
|
.onGet(async () => {
|
|
385
385
|
const state = sensor.motion;
|
|
386
|
-
if (
|
|
386
|
+
if (this.logInfo) this.emit('info', `sensor: ${sensorName} motion: ${state ? 'ON' : 'OFF'}`);
|
|
387
387
|
return state;
|
|
388
388
|
});
|
|
389
389
|
this.motionServices.push(motionService);
|
|
@@ -391,7 +391,7 @@ class Sensors extends EventEmitter {
|
|
|
391
391
|
|
|
392
392
|
//energy
|
|
393
393
|
if (sensor.name === 'ENERGY') {
|
|
394
|
-
const debug4 = this.
|
|
394
|
+
const debug4 = this.logDebug ? this.emit('debug', `Prepare Power And Energy Service`) : false;
|
|
395
395
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName}` : `${sensorName}`;
|
|
396
396
|
const powerAndEnergyService = accessory.addService(Service.PowerAndEnergy, serviceName, `Energy Sensor ${i}`);
|
|
397
397
|
powerAndEnergyService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
@@ -399,7 +399,7 @@ class Sensors extends EventEmitter {
|
|
|
399
399
|
powerAndEnergyService.getCharacteristic(Characteristic.Power)
|
|
400
400
|
.onGet(async () => {
|
|
401
401
|
const value = sensor.power;
|
|
402
|
-
if (
|
|
402
|
+
if (this.logInfo) this.emit('info', `sensor: ${sensorName} power: ${value} W`);
|
|
403
403
|
return value;
|
|
404
404
|
});
|
|
405
405
|
}
|
|
@@ -407,7 +407,7 @@ class Sensors extends EventEmitter {
|
|
|
407
407
|
powerAndEnergyService.getCharacteristic(Characteristic.ApparentPower)
|
|
408
408
|
.onGet(async () => {
|
|
409
409
|
const value = sensor.apparentPower;
|
|
410
|
-
if (
|
|
410
|
+
if (this.logInfo) this.emit('info', `sensor: ${sensorName} apparent power: ${value} VA`);
|
|
411
411
|
return value;
|
|
412
412
|
});
|
|
413
413
|
}
|
|
@@ -415,7 +415,7 @@ class Sensors extends EventEmitter {
|
|
|
415
415
|
powerAndEnergyService.getCharacteristic(Characteristic.ReactivePower)
|
|
416
416
|
.onGet(async () => {
|
|
417
417
|
const value = sensor.reactivePower;
|
|
418
|
-
if (
|
|
418
|
+
if (this.logInfo) this.emit('info', `sensor: ${sensorName} reactive power: ${value} VAr`);
|
|
419
419
|
return value;
|
|
420
420
|
});
|
|
421
421
|
}
|
|
@@ -423,7 +423,7 @@ class Sensors extends EventEmitter {
|
|
|
423
423
|
powerAndEnergyService.getCharacteristic(Characteristic.EnergyToday)
|
|
424
424
|
.onGet(async () => {
|
|
425
425
|
const value = sensor.energyToday;
|
|
426
|
-
if (
|
|
426
|
+
if (this.logInfo) this.emit('info', `sensor: ${sensorName} energy today: ${value} kWh`);
|
|
427
427
|
return value;
|
|
428
428
|
});
|
|
429
429
|
}
|
|
@@ -431,7 +431,7 @@ class Sensors extends EventEmitter {
|
|
|
431
431
|
powerAndEnergyService.getCharacteristic(Characteristic.EnergyLastDay)
|
|
432
432
|
.onGet(async () => {
|
|
433
433
|
const value = sensor.energyLastDay;
|
|
434
|
-
if (
|
|
434
|
+
if (this.logInfo) this.emit('info', `sensor: ${sensorName} energy last day: ${value} kWh`);
|
|
435
435
|
return value;
|
|
436
436
|
});
|
|
437
437
|
}
|
|
@@ -439,7 +439,7 @@ class Sensors extends EventEmitter {
|
|
|
439
439
|
powerAndEnergyService.getCharacteristic(Characteristic.EnergyLifetime)
|
|
440
440
|
.onGet(async () => {
|
|
441
441
|
const value = sensor.energyLifetime;
|
|
442
|
-
if (
|
|
442
|
+
if (this.logInfo) this.emit('info', `sensor: ${sensorName} energy lifetime: ${value} kWh`);
|
|
443
443
|
return value;
|
|
444
444
|
});
|
|
445
445
|
}
|
|
@@ -447,7 +447,7 @@ class Sensors extends EventEmitter {
|
|
|
447
447
|
powerAndEnergyService.getCharacteristic(Characteristic.Current)
|
|
448
448
|
.onGet(async () => {
|
|
449
449
|
const value = sensor.current;
|
|
450
|
-
if (
|
|
450
|
+
if (this.logInfo) this.emit('info', `sensor: ${sensorName} current: ${value} A`);
|
|
451
451
|
return value;
|
|
452
452
|
});
|
|
453
453
|
}
|
|
@@ -455,7 +455,7 @@ class Sensors extends EventEmitter {
|
|
|
455
455
|
powerAndEnergyService.getCharacteristic(Characteristic.Voltage)
|
|
456
456
|
.onGet(async () => {
|
|
457
457
|
const value = sensor.voltage;
|
|
458
|
-
if (
|
|
458
|
+
if (this.logInfo) this.emit('info', `sensor: ${sensorName} voltage: ${value} V`);
|
|
459
459
|
return value;
|
|
460
460
|
});
|
|
461
461
|
}
|
|
@@ -463,7 +463,7 @@ class Sensors extends EventEmitter {
|
|
|
463
463
|
powerAndEnergyService.getCharacteristic(Characteristic.Factor)
|
|
464
464
|
.onGet(async () => {
|
|
465
465
|
const value = sensor.factor;
|
|
466
|
-
if (
|
|
466
|
+
if (this.logInfo) this.emit('info', `sensor: ${sensorName} power factor: ${value} cos φ`);
|
|
467
467
|
return value;
|
|
468
468
|
});
|
|
469
469
|
}
|
|
@@ -471,7 +471,7 @@ class Sensors extends EventEmitter {
|
|
|
471
471
|
powerAndEnergyService.getCharacteristic(Characteristic.Freqency)
|
|
472
472
|
.onGet(async () => {
|
|
473
473
|
const value = sensor.frequency;
|
|
474
|
-
if (
|
|
474
|
+
if (this.logInfo) this.emit('info', `sensor: ${sensorName} frequency: ${value} Hz`);
|
|
475
475
|
return value;
|
|
476
476
|
});
|
|
477
477
|
}
|
|
@@ -479,7 +479,7 @@ class Sensors extends EventEmitter {
|
|
|
479
479
|
powerAndEnergyService.getCharacteristic(Characteristic.ReadingTime)
|
|
480
480
|
.onGet(async () => {
|
|
481
481
|
const value = sensor.time;
|
|
482
|
-
if (
|
|
482
|
+
if (this.logInfo) this.emit('info', `sensor: ${sensorName} last report: ${value}`);
|
|
483
483
|
return value;
|
|
484
484
|
});
|
|
485
485
|
}
|
|
@@ -505,7 +505,7 @@ class Sensors extends EventEmitter {
|
|
|
505
505
|
this.emit('success', `Connect Success`)
|
|
506
506
|
|
|
507
507
|
//check device info
|
|
508
|
-
if (!this.
|
|
508
|
+
if (!this.logDeviceInfo) await this.deviceInfo();
|
|
509
509
|
|
|
510
510
|
//start prepare accessory
|
|
511
511
|
const accessory = await this.prepareAccessory();
|
package/src/switches.js
CHANGED
|
@@ -22,9 +22,9 @@ class Switches extends EventEmitter {
|
|
|
22
22
|
//other config
|
|
23
23
|
this.relaysDisplayType = config.relaysDisplayType || 0;
|
|
24
24
|
this.relaysNamePrefix = config.relaysNamePrefix || false;
|
|
25
|
-
this.
|
|
26
|
-
this.
|
|
27
|
-
this.
|
|
25
|
+
this.logDeviceInfo = device.log?.deviceInfo || false;
|
|
26
|
+
this.logInfo = device.log?.info || false;
|
|
27
|
+
this.logDebug = device.log?.debug || false;
|
|
28
28
|
this.functions = new Functions();
|
|
29
29
|
|
|
30
30
|
//axios instance
|
|
@@ -55,12 +55,12 @@ class Switches extends EventEmitter {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
async checkState() {
|
|
58
|
-
if (this.
|
|
58
|
+
if (this.logDebug) this.emit('debug', `Requesting status`);
|
|
59
59
|
try {
|
|
60
60
|
//power status
|
|
61
61
|
const powerStatusData = await this.client.get(ApiCommands.PowerStatus);
|
|
62
62
|
const powerStatus = powerStatusData.data ?? {};
|
|
63
|
-
if (this.
|
|
63
|
+
if (this.logDebug) this.emit('debug', `Power status: ${JSON.stringify(powerStatus, null, 2)}`);
|
|
64
64
|
|
|
65
65
|
//relays
|
|
66
66
|
const relaysCount = this.relaysCount;
|
|
@@ -87,7 +87,7 @@ class Switches extends EventEmitter {
|
|
|
87
87
|
.updateCharacteristic(Characteristic.On, power);
|
|
88
88
|
|
|
89
89
|
//log info
|
|
90
|
-
if (
|
|
90
|
+
if (this.logInfo) this.emit('info', `${friendlyName}, state: ${power ? 'ON' : 'OFF'}`);
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
|
|
@@ -110,7 +110,7 @@ class Switches extends EventEmitter {
|
|
|
110
110
|
|
|
111
111
|
//prepare accessory
|
|
112
112
|
async prepareAccessory() {
|
|
113
|
-
if (this.
|
|
113
|
+
if (this.logDebug) this.emit('debug', `Prepare Accessory`);
|
|
114
114
|
|
|
115
115
|
try {
|
|
116
116
|
//accessory
|
|
@@ -120,7 +120,7 @@ class Switches extends EventEmitter {
|
|
|
120
120
|
const accessory = new Accessory(accessoryName, accessoryUUID, accessoryCategory);
|
|
121
121
|
|
|
122
122
|
//Prepare information service
|
|
123
|
-
if (this.
|
|
123
|
+
if (this.logDebug) this.emit('debug', `Prepare Information Service`);
|
|
124
124
|
accessory.getService(Service.AccessoryInformation)
|
|
125
125
|
.setCharacteristic(Characteristic.Manufacturer, 'Tasmota')
|
|
126
126
|
.setCharacteristic(Characteristic.Model, this.info.modelName ?? 'Model Name')
|
|
@@ -129,9 +129,9 @@ class Switches extends EventEmitter {
|
|
|
129
129
|
.setCharacteristic(Characteristic.ConfiguredName, accessoryName);
|
|
130
130
|
|
|
131
131
|
//Prepare services
|
|
132
|
-
if (this.
|
|
132
|
+
if (this.logDebug) this.emit('debug', `Prepare Services`);
|
|
133
133
|
if (this.switchesOutlets.length > 0) {
|
|
134
|
-
if (this.
|
|
134
|
+
if (this.logDebug) this.emit('debug', `Prepare Switch/Outlet Services`);
|
|
135
135
|
this.switchOutletServices = [];
|
|
136
136
|
|
|
137
137
|
for (let i = 0; i < this.switchesOutlets.length; i++) {
|
|
@@ -155,7 +155,7 @@ class Switches extends EventEmitter {
|
|
|
155
155
|
state = state ? powerOn : powerOff;
|
|
156
156
|
|
|
157
157
|
await this.client.get(state);
|
|
158
|
-
if (
|
|
158
|
+
if (this.logInfo) this.emit('info', `${friendlyName}, set state: ${state ? 'ON' : 'OFF'}`);
|
|
159
159
|
} catch (error) {
|
|
160
160
|
this.emit('warn', `${friendlyName}, set state error: ${error}`);
|
|
161
161
|
}
|
|
@@ -180,7 +180,7 @@ class Switches extends EventEmitter {
|
|
|
180
180
|
this.emit('success', `Connect Success`)
|
|
181
181
|
|
|
182
182
|
//check device info
|
|
183
|
-
if (!this.
|
|
183
|
+
if (!this.logDeviceInfo) await this.deviceInfo();
|
|
184
184
|
|
|
185
185
|
//start prepare accessory
|
|
186
186
|
const accessory = await this.prepareAccessory();
|