homebridge-tasmota-control 1.6.15-beta.23 → 1.6.15-beta.25
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/index.js +32 -50
- package/package.json +1 -1
- package/src/deviceinfo.js +2 -2
- package/src/fans.js +36 -44
- package/src/lights.js +16 -24
- package/src/mielhvac.js +21 -23
- package/src/sensors.js +30 -38
- package/src/switches.js +11 -19
package/index.js
CHANGED
|
@@ -52,34 +52,29 @@ class tasmotaPlatform {
|
|
|
52
52
|
const loadNameFromDevice = device.loadNameFromDevice || false;
|
|
53
53
|
const refreshInterval = device.refreshInterval * 1000 || 5000;
|
|
54
54
|
const enableDebugMode = device.enableDebugMode || false;
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
const logLevel = {
|
|
56
|
+
debug: enableDebugMode,
|
|
57
|
+
info: !device.disableLogInfo,
|
|
58
|
+
success: !device.disableLogSuccess,
|
|
59
|
+
warn: !device.disableLogWarn,
|
|
60
|
+
error: !device.disableLogError,
|
|
61
|
+
devInfo: !device.disableLogDeviceInfo,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
if (logLevel.debug) log.info(`Device: ${host} ${deviceName}, debug: Did finish launching.`);
|
|
61
65
|
const newConfig = {
|
|
62
66
|
...device,
|
|
63
67
|
user: 'removed',
|
|
64
68
|
passwd: 'removed'
|
|
65
69
|
};
|
|
66
|
-
|
|
70
|
+
if (logLevel.debug) log.info(`Device: ${host} ${deviceName}, Config: ${JSON.stringify(newConfig, null, 2)}.`);
|
|
67
71
|
|
|
68
72
|
try {
|
|
69
73
|
//get device info
|
|
70
74
|
const deviceInfo = new DeviceInfo(url, auth, user, passwd, deviceName, loadNameFromDevice, enableDebugMode, refreshInterval)
|
|
71
|
-
.on('debug', (
|
|
72
|
-
|
|
73
|
-
})
|
|
74
|
-
.on('debug', (debug) => {
|
|
75
|
-
const emitLog = !enableDebugMode ? false : log.info(`Device: ${host} ${deviceName}, debug: ${debug}.`);
|
|
76
|
-
})
|
|
77
|
-
.on('warn', (warn) => {
|
|
78
|
-
const emitLog = disableLogWarn ? false : log.warn(`Device: ${host} ${deviceName}, ${warn}.`);
|
|
79
|
-
})
|
|
80
|
-
.on('error', (error) => {
|
|
81
|
-
const emitLog = disableLogError ? false : log.error(`Device: ${host} ${deviceName}, ${error}.`);
|
|
82
|
-
});
|
|
75
|
+
.on('debug', (msg) => logLevel.debug && log.info(`Device: ${host} ${deviceName}, debug: ${msg}`))
|
|
76
|
+
.on('warn', (msg) => logLevel.warn && log.warn(`Device: ${host} ${deviceName}, ${msg}`))
|
|
77
|
+
.on('error', (msg) => logLevel.error && log.error(`Device: ${host} ${deviceName}, ${msg}`));
|
|
83
78
|
|
|
84
79
|
const info = await deviceInfo.getInfo();
|
|
85
80
|
if (!info.serialNumber) {
|
|
@@ -130,47 +125,34 @@ class tasmotaPlatform {
|
|
|
130
125
|
deviceType = new Sensors(api, device, info, serialNumber, refreshInterval);
|
|
131
126
|
break;
|
|
132
127
|
default:
|
|
133
|
-
|
|
128
|
+
if (logLevel.warn) log.warn(`Device: ${host} ${deviceName}, unknown device: ${info.deviceTypes}.`);
|
|
134
129
|
return;
|
|
135
130
|
}
|
|
136
131
|
|
|
137
|
-
deviceType.on('
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
.on('
|
|
142
|
-
|
|
143
|
-
})
|
|
144
|
-
.on('success', (success) => {
|
|
145
|
-
const emitLog = disableLogSuccess ? false : log.success(`Device: ${host} ${deviceName}, ${success}.`);
|
|
146
|
-
})
|
|
147
|
-
.on('info', (info) => {
|
|
148
|
-
const emitLog = disableLogInfo ? false : log.info(`Device: ${host} ${deviceName}, ${info}.`);
|
|
149
|
-
})
|
|
150
|
-
.on('debug', (debug) => {
|
|
151
|
-
const emitLog = !enableDebugMode ? false : log.info(`Device: ${host} ${deviceName}, debug: ${debug}.`);
|
|
152
|
-
})
|
|
153
|
-
.on('warn', (warn) => {
|
|
154
|
-
const emitLog = disableLogWarn ? false : log.warn(`Device: ${host} ${deviceName}, ${warn}.`);
|
|
155
|
-
})
|
|
156
|
-
.on('error', (error) => {
|
|
157
|
-
const emitLog = disableLogError ? false : log.error(`Device: ${host} ${deviceName}, ${error}.`);
|
|
158
|
-
});
|
|
132
|
+
deviceType.on('devInfo', (msg) => logLevel.devInfo && log.info(msg))
|
|
133
|
+
.on('success', (msg) => logLevel.success && log.success(`Device: ${host} ${deviceName}, ${msg}`))
|
|
134
|
+
.on('info', (msg) => logLevel.info && log.info(`Device: ${host} ${deviceName}, ${msg}`))
|
|
135
|
+
.on('debug', (msg) => logLevel.debug && log.info(`Device: ${host} ${deviceName}, debug: ${msg}`))
|
|
136
|
+
.on('warn', (msg) => logLevel.warn && log.warn(`Device: ${host} ${deviceName}, ${msg}`))
|
|
137
|
+
.on('error', (msg) => logLevel.error && log.error(`Device: ${host} ${deviceName}, ${msg}`));
|
|
159
138
|
|
|
160
139
|
//create impulse generator
|
|
161
140
|
const impulseGenerator = new ImpulseGenerator()
|
|
162
141
|
.on('start', async () => {
|
|
163
142
|
try {
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
143
|
+
const accessory = await deviceType.start()
|
|
144
|
+
if (accessory) {
|
|
145
|
+
api.publishExternalAccessories(PluginName, [accessory]);
|
|
146
|
+
if (logLevel.success) log.success(`Device: ${host} ${deviceName}, Published as external accessory.`);
|
|
147
|
+
|
|
148
|
+
await impulseGenerator.stop();
|
|
149
|
+
await zone.startImpulseGenerator();
|
|
150
|
+
}
|
|
169
151
|
} catch (error) {
|
|
170
|
-
|
|
152
|
+
if (logLevel.error) log.error(`Device: ${host} ${deviceName}, ${error}, trying again.`);
|
|
171
153
|
}
|
|
172
154
|
}).on('state', (state) => {
|
|
173
|
-
|
|
155
|
+
if (logLevel.debug) log.info(`Device: ${host} ${deviceName}, Start impulse generator ${state ? 'started' : 'stopped'}.`);
|
|
174
156
|
});
|
|
175
157
|
|
|
176
158
|
//start impulse generator
|
|
@@ -178,7 +160,7 @@ class tasmotaPlatform {
|
|
|
178
160
|
i++;
|
|
179
161
|
}
|
|
180
162
|
} catch (error) {
|
|
181
|
-
|
|
163
|
+
if (logLevel.error) log.error(`Device: ${host} ${deviceName}, Did finish launching error: ${error}.`);
|
|
182
164
|
}
|
|
183
165
|
}
|
|
184
166
|
});
|
package/package.json
CHANGED
package/src/deviceinfo.js
CHANGED
|
@@ -24,11 +24,11 @@ class DeviceInfo extends EventEmitter {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
async getInfo() {
|
|
27
|
-
|
|
27
|
+
if (this.enableDebugMode) this.emit('debug', `Requesting info`);
|
|
28
28
|
try {
|
|
29
29
|
const deviceInfoData = await this.axiosInstance(ApiCommands.Status);
|
|
30
30
|
const deviceInfo = deviceInfoData.data ?? {};
|
|
31
|
-
|
|
31
|
+
if (this.enableDebugMode) this.emit('debug', `Info: ${JSON.stringify(deviceInfo, null, 2)}`);
|
|
32
32
|
await new Promise(resolve => setTimeout(resolve, 250));
|
|
33
33
|
|
|
34
34
|
//status
|
package/src/fans.js
CHANGED
|
@@ -28,9 +28,6 @@ class Fans extends EventEmitter {
|
|
|
28
28
|
this.disableLogDeviceInfo = config.disableLogDeviceInfo || false;
|
|
29
29
|
this.refreshInterval = refreshInterval;
|
|
30
30
|
|
|
31
|
-
//variable
|
|
32
|
-
this.startPrepareAccessory = true;
|
|
33
|
-
|
|
34
31
|
//axios instance
|
|
35
32
|
const url = `http://${config.host}/cm?cmnd=`;
|
|
36
33
|
this.axiosInstance = axios.create({
|
|
@@ -64,18 +61,18 @@ class Fans extends EventEmitter {
|
|
|
64
61
|
}
|
|
65
62
|
|
|
66
63
|
async checkDeviceState() {
|
|
67
|
-
|
|
64
|
+
if (this.enableDebugMode) this.emit('debug', `Requesting status`);
|
|
68
65
|
try {
|
|
69
66
|
//power status
|
|
70
67
|
const powerStatusData = await this.axiosInstance(ApiCommands.PowerStatus);
|
|
71
68
|
const powerStatus = powerStatusData.data ?? {};
|
|
72
69
|
const powerStatusKeys = Object.keys(powerStatus);
|
|
73
|
-
|
|
70
|
+
if (this.enableDebugMode) this.emit('debug', `Power status: ${JSON.stringify(powerStatus, null, 2)}`);
|
|
74
71
|
|
|
75
72
|
//sensor status
|
|
76
73
|
const sensorStatusData = await this.axiosInstance(ApiCommands.Status);
|
|
77
74
|
const sensorStatus = sensorStatusData.data ?? {};
|
|
78
|
-
|
|
75
|
+
if (this.enableDebugMode) this.emit('debug', `Sensors status: ${JSON.stringify(sensorStatus, null, 2)}`);
|
|
79
76
|
|
|
80
77
|
//sensor status keys
|
|
81
78
|
const sensorStatusKeys = Object.keys(sensorStatus);
|
|
@@ -158,7 +155,7 @@ class Fans extends EventEmitter {
|
|
|
158
155
|
try {
|
|
159
156
|
data = JSON.stringify(data, null, 2);
|
|
160
157
|
await fsPromises.writeFile(path, data);
|
|
161
|
-
|
|
158
|
+
if (this.enableDebugMode) this.emit('debug', `Saved data: ${data}`);
|
|
162
159
|
return true;
|
|
163
160
|
} catch (error) {
|
|
164
161
|
throw new Error(`Save data error: ${error}`);
|
|
@@ -198,7 +195,7 @@ class Fans extends EventEmitter {
|
|
|
198
195
|
|
|
199
196
|
//prepare accessory
|
|
200
197
|
async prepareAccessory() {
|
|
201
|
-
|
|
198
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Accessory`);
|
|
202
199
|
|
|
203
200
|
try {
|
|
204
201
|
//accessory
|
|
@@ -208,7 +205,7 @@ class Fans extends EventEmitter {
|
|
|
208
205
|
const accessory = new Accessory(accessoryName, accessoryUUID, accessoryCategory);
|
|
209
206
|
|
|
210
207
|
//Prepare information service
|
|
211
|
-
|
|
208
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Information Service`);
|
|
212
209
|
accessory.getService(Service.AccessoryInformation)
|
|
213
210
|
.setCharacteristic(Characteristic.Manufacturer, 'Tasmota')
|
|
214
211
|
.setCharacteristic(Characteristic.Model, this.info.modelName ?? 'Model Name')
|
|
@@ -217,9 +214,9 @@ class Fans extends EventEmitter {
|
|
|
217
214
|
.setCharacteristic(Characteristic.ConfiguredName, accessoryName);
|
|
218
215
|
|
|
219
216
|
//Prepare services
|
|
220
|
-
|
|
217
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Services`);
|
|
221
218
|
if (this.fans.length > 0) {
|
|
222
|
-
|
|
219
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Fan Services`);
|
|
223
220
|
this.fanServices = [];
|
|
224
221
|
|
|
225
222
|
for (let i = 0; i < this.fans.length; i++) {
|
|
@@ -239,7 +236,7 @@ class Fans extends EventEmitter {
|
|
|
239
236
|
state = state ? 1 : 0;
|
|
240
237
|
const speed = `${ApiCommands.FanSpeed}${state}`;
|
|
241
238
|
await this.axiosInstance(speed);
|
|
242
|
-
|
|
239
|
+
if (!this.disableLogInfo) this.emit('info', `${friendlyName}, set state: ${state ? 'ON' : 'OFF'}`);
|
|
243
240
|
} catch (error) {
|
|
244
241
|
this.emit('warn', `${friendlyName}, set state error: ${error}`);
|
|
245
242
|
}
|
|
@@ -253,7 +250,7 @@ class Fans extends EventEmitter {
|
|
|
253
250
|
// try {
|
|
254
251
|
// const direction = `${ApiCommands.FanDirection}${value}`;
|
|
255
252
|
// await this.axiosInstance(direction);
|
|
256
|
-
//
|
|
253
|
+
// if (!this.disableLogInfo) this.emit('info', `${friendlyName}, set direction: ${value}`);
|
|
257
254
|
// } catch (error) {
|
|
258
255
|
// this.emit('warn', `${friendlyName}, set direction error: ${error}`);
|
|
259
256
|
// }
|
|
@@ -272,7 +269,7 @@ class Fans extends EventEmitter {
|
|
|
272
269
|
try {
|
|
273
270
|
const speed = `${ApiCommands.FanSpeed}${value}`;
|
|
274
271
|
await this.axiosInstance(speed);
|
|
275
|
-
|
|
272
|
+
if (!this.disableLogInfo) this.emit('info', `${friendlyName}, set speed: ${value}`);
|
|
276
273
|
} catch (error) {
|
|
277
274
|
this.emit('warn', `${friendlyName}, set rotation speed error: ${error}`);
|
|
278
275
|
}
|
|
@@ -302,7 +299,7 @@ class Fans extends EventEmitter {
|
|
|
302
299
|
const powerOff = this.lights.length === 1 ? (this.lights[i].power1 ? `${ApiCommands.Power}${relayNr}${ApiCommands.Off}` : ApiCommands.PowerOff) : `${ApiCommands.Power}${relayNr}${ApiCommands.Off}`;
|
|
303
300
|
state = state ? powerOn : powerOff;
|
|
304
301
|
await this.axiosInstance(state);
|
|
305
|
-
|
|
302
|
+
if (!this.disableLogInfo) this.emit('info', `${friendlyName}, set state: ${state ? 'ON' : 'OFF'}`);
|
|
306
303
|
} catch (error) {
|
|
307
304
|
this.emit('warn', `${friendlyName}, set state error: ${error}`);
|
|
308
305
|
}
|
|
@@ -313,12 +310,12 @@ class Fans extends EventEmitter {
|
|
|
313
310
|
|
|
314
311
|
//sensors
|
|
315
312
|
if (this.sensorsCount > 0) {
|
|
316
|
-
|
|
313
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Sensor Services`);
|
|
317
314
|
|
|
318
315
|
//temperature
|
|
319
316
|
const sensorsTemperatureCount = this.sensorsTemperatureCount;
|
|
320
317
|
if (sensorsTemperatureCount > 0) {
|
|
321
|
-
|
|
318
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Temperature Sensor Services`);
|
|
322
319
|
this.sensorTemperatureServices = [];
|
|
323
320
|
for (let i = 0; i < sensorsTemperatureCount; i++) {
|
|
324
321
|
const sensorName = this.sensorsName[i];
|
|
@@ -329,7 +326,7 @@ class Fans extends EventEmitter {
|
|
|
329
326
|
sensorTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
|
|
330
327
|
.onGet(async () => {
|
|
331
328
|
const value = this.sensorsTemperature[i];
|
|
332
|
-
|
|
329
|
+
if (!this.disableLogInfo) this.emit('info', `sensor: ${sensorName} temperature: ${value} °${this.tempUnit}`);
|
|
333
330
|
return value;
|
|
334
331
|
});
|
|
335
332
|
this.sensorTemperatureServices.push(sensorTemperatureService);
|
|
@@ -339,7 +336,7 @@ class Fans extends EventEmitter {
|
|
|
339
336
|
//reference temperature
|
|
340
337
|
const sensorsReferenceTemperatureCount = this.sensorsReferenceTemperatureCount;
|
|
341
338
|
if (sensorsReferenceTemperatureCount > 0) {
|
|
342
|
-
|
|
339
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Reference Temperature Sensor Services`);
|
|
343
340
|
this.sensorReferenceTemperatureServices = [];
|
|
344
341
|
for (let i = 0; i < sensorsReferenceTemperatureCount; i++) {
|
|
345
342
|
const sensorName = this.sensorsName[i];
|
|
@@ -350,7 +347,7 @@ class Fans extends EventEmitter {
|
|
|
350
347
|
sensorReferenceTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
|
|
351
348
|
.onGet(async () => {
|
|
352
349
|
const value = this.sensorsReferenceTemperature[i];
|
|
353
|
-
|
|
350
|
+
if (!this.disableLogInfo) this.emit('info', `sensor: ${sensorName} reference temperature: ${value} °${this.tempUnit}`);
|
|
354
351
|
return value;
|
|
355
352
|
});
|
|
356
353
|
this.sensorReferenceTemperatureServices.push(sensorReferenceTemperatureService);
|
|
@@ -360,7 +357,7 @@ class Fans extends EventEmitter {
|
|
|
360
357
|
//object temperature
|
|
361
358
|
const sensorsObjTemperatureCount = this.sensorsObjTemperatureCount;
|
|
362
359
|
if (sensorsObjTemperatureCount > 0) {
|
|
363
|
-
|
|
360
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Obj Temperature Sensor Services`);
|
|
364
361
|
this.sensorObjTemperatureServices = [];
|
|
365
362
|
for (let i = 0; i < sensorsObjTemperatureCount; i++) {
|
|
366
363
|
const sensorName = this.sensorsName[i];
|
|
@@ -371,7 +368,7 @@ class Fans extends EventEmitter {
|
|
|
371
368
|
sensorObjTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
|
|
372
369
|
.onGet(async () => {
|
|
373
370
|
const value = this.sensorsObjTemperature[i];
|
|
374
|
-
|
|
371
|
+
if (!this.disableLogInfo) this.emit('info', `sensor: ${sensorName} obj temperature: ${value} °${this.tempUnit}`);
|
|
375
372
|
return value;
|
|
376
373
|
});
|
|
377
374
|
this.sensorObjTemperatureServices.push(sensorObjTemperatureService);
|
|
@@ -381,7 +378,7 @@ class Fans extends EventEmitter {
|
|
|
381
378
|
//ambient temperature
|
|
382
379
|
const sensorsAmbTemperatureCount = this.sensorsAmbTemperatureCount;
|
|
383
380
|
if (sensorsAmbTemperatureCount > 0) {
|
|
384
|
-
|
|
381
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Amb Temperature Sensor Services`);
|
|
385
382
|
this.sensorAmbTemperatureServices = [];
|
|
386
383
|
for (let i = 0; i < sensorsAmbTemperatureCount; i++) {
|
|
387
384
|
const sensorName = this.sensorsName[i];
|
|
@@ -392,7 +389,7 @@ class Fans extends EventEmitter {
|
|
|
392
389
|
sensorAmbTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
|
|
393
390
|
.onGet(async () => {
|
|
394
391
|
const value = this.sensorsAmbTemperature[i];
|
|
395
|
-
|
|
392
|
+
if (!this.disableLogInfo) this.emit('info', `sensor: ${sensorName} amb temperature: ${value} °${this.tempUnit}`);
|
|
396
393
|
return value;
|
|
397
394
|
});
|
|
398
395
|
this.sensorAmbTemperatureServices.push(sensorAmbTemperatureService);
|
|
@@ -402,7 +399,7 @@ class Fans extends EventEmitter {
|
|
|
402
399
|
//dew point temperature
|
|
403
400
|
const sensorsDewPointTemperatureCount = this.sensorsDewPointTemperatureCount;
|
|
404
401
|
if (sensorsDewPointTemperatureCount > 0) {
|
|
405
|
-
|
|
402
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Dew Point Temperature Sensor Services`);
|
|
406
403
|
this.sensorDewPointTemperatureServices = [];
|
|
407
404
|
for (let i = 0; i < sensorsDewPointTemperatureCount; i++) {
|
|
408
405
|
const sensorName = this.sensorsName[i];
|
|
@@ -413,7 +410,7 @@ class Fans extends EventEmitter {
|
|
|
413
410
|
sensorDewPointTemperatureService.getCharacteristic(Characteristic.CurrentTemperature)
|
|
414
411
|
.onGet(async () => {
|
|
415
412
|
const value = this.sensorsDewPointTemperature[i];
|
|
416
|
-
|
|
413
|
+
if (!this.disableLogInfo) this.emit('info', `sensor: ${sensorName} dew point: ${value} °${this.tempUnit}`);
|
|
417
414
|
return value;
|
|
418
415
|
});
|
|
419
416
|
this.sensorDewPointTemperatureServices.push(sensorDewPointTemperatureService);
|
|
@@ -423,7 +420,7 @@ class Fans extends EventEmitter {
|
|
|
423
420
|
//humidity
|
|
424
421
|
const sensorsHumidityCount = this.sensorsHumidityCount;
|
|
425
422
|
if (sensorsHumidityCount > 0) {
|
|
426
|
-
|
|
423
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Humidity Sensor Services`);
|
|
427
424
|
this.sensorHumidityServices = [];
|
|
428
425
|
for (let i = 0; i < sensorsHumidityCount; i++) {
|
|
429
426
|
const sensorName = this.sensorsName[i];
|
|
@@ -434,7 +431,7 @@ class Fans extends EventEmitter {
|
|
|
434
431
|
sensorHumidityService.getCharacteristic(Characteristic.CurrentRelativeHumidity)
|
|
435
432
|
.onGet(async () => {
|
|
436
433
|
const value = this.sensorsHumidity[i];
|
|
437
|
-
|
|
434
|
+
if (!this.disableLogInfo) this.emit('info', `sensor: ${sensorName} humidity: ${value} %`);
|
|
438
435
|
return value;
|
|
439
436
|
});
|
|
440
437
|
this.sensorHumidityServices.push(sensorHumidityService);
|
|
@@ -448,7 +445,7 @@ class Fans extends EventEmitter {
|
|
|
448
445
|
//carbon dioxyde
|
|
449
446
|
const sensorsCarbonDioxydeCount = this.sensorsCarbonDioxydeCount;
|
|
450
447
|
if (sensorsCarbonDioxydeCount > 0) {
|
|
451
|
-
|
|
448
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Carbon Dioxyde Sensor Services`);
|
|
452
449
|
this.sensorCarbonDioxydeServices = [];
|
|
453
450
|
for (let i = 0; i < sensorsCarbonDioxydeCount; i++) {
|
|
454
451
|
const sensorName = this.sensorsName[i];
|
|
@@ -459,19 +456,19 @@ class Fans extends EventEmitter {
|
|
|
459
456
|
sensorCarbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxideDetected)
|
|
460
457
|
.onGet(async () => {
|
|
461
458
|
const state = this.sensorsCarbonDioxyde[i] > 1000;
|
|
462
|
-
|
|
459
|
+
if (!this.disableLogInfo) this.emit('info', `sensor: ${sensorName} carbon dioxyde detected: ${state ? 'Yes' : 'No'}`);
|
|
463
460
|
return state;
|
|
464
461
|
});
|
|
465
462
|
sensorCarbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxideLevel)
|
|
466
463
|
.onGet(async () => {
|
|
467
464
|
const value = this.sensorsCarbonDioxyde[i];
|
|
468
|
-
|
|
465
|
+
if (!this.disableLogInfo) this.emit('info', `sensor: ${sensorName} carbon dioxyde level: ${value} ppm`);
|
|
469
466
|
return value;
|
|
470
467
|
});
|
|
471
468
|
sensorCarbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxidePeakLevel)
|
|
472
469
|
.onGet(async () => {
|
|
473
470
|
const value = this.sensorsCarbonDioxyde[i];
|
|
474
|
-
|
|
471
|
+
if (!this.disableLogInfo) this.emit('info', `sensor: ${sensorName} carbon dioxyde peak level: ${value} ppm`);
|
|
475
472
|
return value;
|
|
476
473
|
});
|
|
477
474
|
this.sensorCarbonDioxydeServices.push(sensorCarbonDioxydeService);
|
|
@@ -481,7 +478,7 @@ class Fans extends EventEmitter {
|
|
|
481
478
|
//ambient light
|
|
482
479
|
const sensorsAmbientLightCount = this.sensorsAmbientLightCount;
|
|
483
480
|
if (sensorsAmbientLightCount > 0) {
|
|
484
|
-
|
|
481
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Ambient Light Sensor Services`);
|
|
485
482
|
this.sensorAmbientLightServices = [];
|
|
486
483
|
for (let i = 0; i < sensorsAmbientLightCount; i++) {
|
|
487
484
|
const sensorName = this.sensorsName[i];
|
|
@@ -492,7 +489,7 @@ class Fans extends EventEmitter {
|
|
|
492
489
|
sensorAmbientLightService.getCharacteristic(Characteristic.CurrentAmbientLightLevel)
|
|
493
490
|
.onGet(async () => {
|
|
494
491
|
const value = this.sensorsAmbientLight[i];
|
|
495
|
-
|
|
492
|
+
if (!this.disableLogInfo) this.emit('info', `sensor: ${sensorName} ambient light: ${value} lx`);
|
|
496
493
|
return value;
|
|
497
494
|
});
|
|
498
495
|
this.sensorAmbientLightServices.push(sensorAmbientLightService);
|
|
@@ -502,7 +499,7 @@ class Fans extends EventEmitter {
|
|
|
502
499
|
//motion
|
|
503
500
|
const sensorsMotionCount = this.sensorsMotionCount;
|
|
504
501
|
if (sensorsMotionCount > 0) {
|
|
505
|
-
|
|
502
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Motion Sensor Services`);
|
|
506
503
|
this.sensorMotionServices = [];
|
|
507
504
|
for (let i = 0; i < sensorsMotionCount; i++) {
|
|
508
505
|
const sensorName = this.sensorsName[i];
|
|
@@ -513,7 +510,7 @@ class Fans extends EventEmitter {
|
|
|
513
510
|
sensorMotionService.getCharacteristic(Characteristic.MotionDetected)
|
|
514
511
|
.onGet(async () => {
|
|
515
512
|
const state = this.sensorsMotion[i];
|
|
516
|
-
|
|
513
|
+
if (!this.disableLogInfo) this.emit('info', `sensor: ${sensorName} motion: ${state ? 'ON' : 'OFF'}`);
|
|
517
514
|
return state;
|
|
518
515
|
});
|
|
519
516
|
this.sensorMotionServices.push(sensorMotionService);
|
|
@@ -537,16 +534,11 @@ class Fans extends EventEmitter {
|
|
|
537
534
|
this.emit('success', `Connect Success`)
|
|
538
535
|
|
|
539
536
|
//check device info
|
|
540
|
-
|
|
537
|
+
if (!this.disableLogDeviceInfo) await this.deviceInfo();
|
|
541
538
|
|
|
542
539
|
//start prepare accessory
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
const publishAccessory = this.emit('publishAccessory', accessory);
|
|
546
|
-
this.startPrepareAccessory = false;
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
return true;
|
|
540
|
+
const accessory = await this.prepareAccessory();
|
|
541
|
+
return accessory;
|
|
550
542
|
} catch (error) {
|
|
551
543
|
throw new Error(`Start error: ${error}`);
|
|
552
544
|
}
|
package/src/lights.js
CHANGED
|
@@ -27,9 +27,6 @@ class Lights extends EventEmitter {
|
|
|
27
27
|
this.disableLogDeviceInfo = config.disableLogDeviceInfo || false;
|
|
28
28
|
this.refreshInterval = refreshInterval;
|
|
29
29
|
|
|
30
|
-
//variable
|
|
31
|
-
this.startPrepareAccessory = true;
|
|
32
|
-
|
|
33
30
|
//axios instance
|
|
34
31
|
const url = `http://${config.host}/cm?cmnd=`;
|
|
35
32
|
this.axiosInstance = axios.create({
|
|
@@ -62,18 +59,18 @@ class Lights extends EventEmitter {
|
|
|
62
59
|
}
|
|
63
60
|
|
|
64
61
|
async checkDeviceState() {
|
|
65
|
-
|
|
62
|
+
if (this.enableDebugMode) this.emit('debug', `Requesting status`);
|
|
66
63
|
try {
|
|
67
64
|
//power status
|
|
68
65
|
const powerStatusData = await this.axiosInstance(ApiCommands.PowerStatus);
|
|
69
66
|
const powerStatus = powerStatusData.data ?? {};
|
|
70
67
|
const powerStatusKeys = Object.keys(powerStatus);
|
|
71
|
-
|
|
68
|
+
if (this.enableDebugMode) this.emit('debug', `Power status: ${JSON.stringify(powerStatus, null, 2)}`);
|
|
72
69
|
|
|
73
70
|
//sensor status
|
|
74
71
|
const sensorStatusData = await this.axiosInstance(ApiCommands.Status);
|
|
75
72
|
const sensorStatus = sensorStatusData.data ?? {};
|
|
76
|
-
|
|
73
|
+
if (this.enableDebugMode) this.emit('debug', `Sensors status: ${JSON.stringify(sensorStatus, null, 2)}`);
|
|
77
74
|
|
|
78
75
|
//sensor status keys
|
|
79
76
|
const sensorStatusKeys = Object.keys(sensorStatus);
|
|
@@ -170,7 +167,7 @@ class Lights extends EventEmitter {
|
|
|
170
167
|
try {
|
|
171
168
|
data = JSON.stringify(data, null, 2);
|
|
172
169
|
await fsPromises.writeFile(path, data);
|
|
173
|
-
|
|
170
|
+
if (this.enableDebugMode) this.emit('debug', `Saved data: ${data}`);
|
|
174
171
|
return true;
|
|
175
172
|
} catch (error) {
|
|
176
173
|
throw new Error(`Save data error: ${error}`);
|
|
@@ -210,7 +207,7 @@ class Lights extends EventEmitter {
|
|
|
210
207
|
|
|
211
208
|
//prepare accessory
|
|
212
209
|
async prepareAccessory() {
|
|
213
|
-
|
|
210
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Accessory`);
|
|
214
211
|
|
|
215
212
|
try {
|
|
216
213
|
//accessory
|
|
@@ -220,7 +217,7 @@ class Lights extends EventEmitter {
|
|
|
220
217
|
const accessory = new Accessory(accessoryName, accessoryUUID, accessoryCategory);
|
|
221
218
|
|
|
222
219
|
//Prepare information service
|
|
223
|
-
|
|
220
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Information Service`);
|
|
224
221
|
accessory.getService(Service.AccessoryInformation)
|
|
225
222
|
.setCharacteristic(Characteristic.Manufacturer, 'Tasmota')
|
|
226
223
|
.setCharacteristic(Characteristic.Model, this.info.modelName ?? 'Model Name')
|
|
@@ -229,9 +226,9 @@ class Lights extends EventEmitter {
|
|
|
229
226
|
.setCharacteristic(Characteristic.ConfiguredName, accessoryName);
|
|
230
227
|
|
|
231
228
|
//Prepare services
|
|
232
|
-
|
|
229
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Services`);
|
|
233
230
|
if (this.lights.length > 0) {
|
|
234
|
-
|
|
231
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Light Services`);
|
|
235
232
|
this.lightServices = [];
|
|
236
233
|
|
|
237
234
|
for (let i = 0; i < this.lights.length; i++) {
|
|
@@ -254,7 +251,7 @@ class Lights extends EventEmitter {
|
|
|
254
251
|
state = state ? powerOn : powerOff;
|
|
255
252
|
|
|
256
253
|
await this.axiosInstance(state);
|
|
257
|
-
|
|
254
|
+
if (!this.disableLogInfo) this.emit('info', `${friendlyName}, set state: ${state ? 'ON' : 'OFF'}`);
|
|
258
255
|
} catch (error) {
|
|
259
256
|
this.emit('warn', `${friendlyName}, set state error: ${error}`);
|
|
260
257
|
}
|
|
@@ -269,7 +266,7 @@ class Lights extends EventEmitter {
|
|
|
269
266
|
try {
|
|
270
267
|
const brightness = ['', `${ApiCommands.Dimmer}${value}`, `${ApiCommands.HSBBrightness}${value}`][this.lights[i].brightnessType]; //0..100
|
|
271
268
|
await this.axiosInstance(brightness);
|
|
272
|
-
|
|
269
|
+
if (!this.disableLogInfo) this.emit('info', `${friendlyName}, set brightness: ${value} %`);
|
|
273
270
|
} catch (error) {
|
|
274
271
|
this.emit('warn', `set brightness error: ${error}`);
|
|
275
272
|
}
|
|
@@ -286,7 +283,7 @@ class Lights extends EventEmitter {
|
|
|
286
283
|
value = await this.scaleValue(value, 140, 500, 153, 500);
|
|
287
284
|
const colorTemperature = `${ApiCommands.ColorTemperature}${value}`; //153..500
|
|
288
285
|
await this.axiosInstance(colorTemperature);
|
|
289
|
-
|
|
286
|
+
if (!this.disableLogInfo) this.emit('info', `${friendlyName}, set color temperatur: ${value}`);
|
|
290
287
|
} catch (error) {
|
|
291
288
|
this.emit('warn', `set color temperatur error: ${error}`);
|
|
292
289
|
}
|
|
@@ -302,7 +299,7 @@ class Lights extends EventEmitter {
|
|
|
302
299
|
try {
|
|
303
300
|
const hue = `${ApiCommands.HSBHue}${value}`; //0..360
|
|
304
301
|
await this.axiosInstance(hue);
|
|
305
|
-
|
|
302
|
+
if (!this.disableLogInfo) this.emit('info', `${friendlyName}, set hue: ${value}`);
|
|
306
303
|
} catch (error) {
|
|
307
304
|
this.emit('warn', `set hue error: ${error}`);
|
|
308
305
|
}
|
|
@@ -318,7 +315,7 @@ class Lights extends EventEmitter {
|
|
|
318
315
|
try {
|
|
319
316
|
const saturation = `${ApiCommands.HSBSaturation}${value}`; //0..100
|
|
320
317
|
await this.axiosInstance(saturation);
|
|
321
|
-
|
|
318
|
+
if (!this.disableLogInfo) this.emit('info', `set saturation: ${value}`);
|
|
322
319
|
} catch (error) {
|
|
323
320
|
this.emit('warn', `set saturation error: ${error}`);
|
|
324
321
|
}
|
|
@@ -344,16 +341,11 @@ class Lights extends EventEmitter {
|
|
|
344
341
|
this.emit('success', `Connect Success`)
|
|
345
342
|
|
|
346
343
|
//check device info
|
|
347
|
-
|
|
344
|
+
if (!this.disableLogDeviceInfo) await this.deviceInfo();
|
|
348
345
|
|
|
349
346
|
//start prepare accessory
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
const publishAccessory = this.emit('publishAccessory', accessory);
|
|
353
|
-
this.startPrepareAccessory = false;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
return true;
|
|
347
|
+
const accessory = await this.prepareAccessory();
|
|
348
|
+
return accessory;
|
|
357
349
|
} catch (error) {
|
|
358
350
|
throw new Error(`Start error: ${error}`);
|
|
359
351
|
}
|
package/src/mielhvac.js
CHANGED
|
@@ -114,9 +114,6 @@ class MiElHvac extends EventEmitter {
|
|
|
114
114
|
this.disableLogDeviceInfo = config.disableLogDeviceInfo || false;
|
|
115
115
|
this.refreshInterval = refreshInterval;
|
|
116
116
|
|
|
117
|
-
//variable
|
|
118
|
-
this.startPrepareAccessory = true;
|
|
119
|
-
|
|
120
117
|
//mielhvac
|
|
121
118
|
this.mielHvac = {};
|
|
122
119
|
this.previousStateSwingV = 'auto';
|
|
@@ -181,17 +178,17 @@ class MiElHvac extends EventEmitter {
|
|
|
181
178
|
}
|
|
182
179
|
|
|
183
180
|
async checkDeviceState() {
|
|
184
|
-
|
|
181
|
+
if (this.enableDebugMode) this.emit('debug', `Requesting status`);
|
|
185
182
|
try {
|
|
186
183
|
//power status
|
|
187
184
|
const powerStatusData = await this.axiosInstance(ApiCommands.PowerStatus);
|
|
188
185
|
const powerStatus = powerStatusData.data ?? {};
|
|
189
|
-
|
|
186
|
+
if (this.enableDebugMode) this.emit('debug', `Power status: ${JSON.stringify(powerStatus, null, 2)}`);
|
|
190
187
|
|
|
191
188
|
//sensor status
|
|
192
189
|
const sensorStatusData = await this.axiosInstance(ApiCommands.Status);
|
|
193
190
|
const sensorStatus = sensorStatusData.data ?? {};
|
|
194
|
-
|
|
191
|
+
if (this.enableDebugMode) this.emit('debug', `Sensors status: ${JSON.stringify(sensorStatus, null, 2)}`);
|
|
195
192
|
|
|
196
193
|
//sensor status keys
|
|
197
194
|
const sensorStatusKeys = Object.keys(sensorStatus);
|
|
@@ -226,6 +223,9 @@ class MiElHvac extends EventEmitter {
|
|
|
226
223
|
const vaneHorizontalDirection = miElHvac.SwingH ?? 'Unknown';
|
|
227
224
|
const prohibit = miElHvac.Prohibit ?? 'Unknown';
|
|
228
225
|
const purify = miElHvac.Purify ?? 'Unknown';
|
|
226
|
+
const econoCool = miElHvac.EonoCool ?? 'Unknown';
|
|
227
|
+
const powerFull = miElHvac.PowerFull ?? 'Unknown';
|
|
228
|
+
const nightMode = miElHvac.NightMode ?? 'Unknown';
|
|
229
229
|
const airDirection = miElHvac.AirDirection ?? 'Unknown';
|
|
230
230
|
const compressor = miElHvac.Compressor ?? 'Unknown';
|
|
231
231
|
const compressorFrequency = miElHvac.CompressorFrequency ?? 0;
|
|
@@ -266,6 +266,9 @@ class MiElHvac extends EventEmitter {
|
|
|
266
266
|
vaneHorizontalDirection: vaneHorizontalDirection,
|
|
267
267
|
prohibit: prohibit,
|
|
268
268
|
purify: purify,
|
|
269
|
+
econoCool: econoCool,
|
|
270
|
+
powerFull: powerFull,
|
|
271
|
+
nightMode: nightMode,
|
|
269
272
|
airDirection: airDirection,
|
|
270
273
|
swingMode: swingMode,
|
|
271
274
|
compressor: compressor,
|
|
@@ -707,7 +710,7 @@ class MiElHvac extends EventEmitter {
|
|
|
707
710
|
//get remote temp
|
|
708
711
|
const rmoteTempData = await this.axiosInstanceRemoteTemp();
|
|
709
712
|
const remoteTemp = rmoteTempData.data ?? false;
|
|
710
|
-
|
|
713
|
+
if (this.enableDebugMode) this.emit('debug', `Remote temp: ${JSON.stringify(remoteTemp, null, 2)}`);
|
|
711
714
|
|
|
712
715
|
//set remote temp
|
|
713
716
|
const temp = `${MiElHVAC.SetRemoteTemp}${remoteTemp}`
|
|
@@ -723,7 +726,7 @@ class MiElHvac extends EventEmitter {
|
|
|
723
726
|
try {
|
|
724
727
|
data = JSON.stringify(data, null, 2);
|
|
725
728
|
await fsPromises.writeFile(path, data);
|
|
726
|
-
|
|
729
|
+
if (this.enableDebugMode) this.emit('debug', `Saved data: ${data}`);
|
|
727
730
|
return true;
|
|
728
731
|
} catch (error) {
|
|
729
732
|
throw new Error(`Save data error: ${error}`);
|
|
@@ -764,7 +767,7 @@ class MiElHvac extends EventEmitter {
|
|
|
764
767
|
|
|
765
768
|
//prepare accessory
|
|
766
769
|
async prepareAccessory() {
|
|
767
|
-
|
|
770
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Accessory`);
|
|
768
771
|
|
|
769
772
|
try {
|
|
770
773
|
//accessory
|
|
@@ -774,7 +777,7 @@ class MiElHvac extends EventEmitter {
|
|
|
774
777
|
const accessory = new Accessory(accessoryName, accessoryUUID, accessoryCategory);
|
|
775
778
|
|
|
776
779
|
//Prepare information service
|
|
777
|
-
|
|
780
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Information Service`);
|
|
778
781
|
accessory.getService(Service.AccessoryInformation)
|
|
779
782
|
.setCharacteristic(Characteristic.Manufacturer, 'Tasmota')
|
|
780
783
|
.setCharacteristic(Characteristic.Model, this.info.modelName ?? 'Model Name')
|
|
@@ -783,8 +786,8 @@ class MiElHvac extends EventEmitter {
|
|
|
783
786
|
.setCharacteristic(Characteristic.ConfiguredName, accessoryName);
|
|
784
787
|
|
|
785
788
|
//Prepare services
|
|
786
|
-
|
|
787
|
-
|
|
789
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Services`);
|
|
790
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare mitsubishi hvac service`);
|
|
788
791
|
const autoDryFanMode = [MiElHVAC.SetMode.auto, MiElHVAC.SetMode.auto, MiElHVAC.SetMode.dry, MiElHVAC.SetMode.fan][this.autoDryFanMode]; //NONE, AUTO, DRY, FAN
|
|
789
792
|
const heatDryFanMode = [MiElHVAC.SetMode.heat, MiElHVAC.SetMode.heat, MiElHVAC.SetMode.dry, MiElHVAC.SetMode.fan][this.heatDryFanMode]; //NONE, HEAT, DRY, FAN
|
|
790
793
|
const coolDryFanMode = [MiElHVAC.SetMode.cool, MiElHVAC.SetMode.cool, MiElHVAC.SetMode.dry, MiElHVAC.SetMode.fan][this.coolDryFanMode]; //NONE, COOL, DRY, FAN
|
|
@@ -1178,7 +1181,7 @@ class MiElHvac extends EventEmitter {
|
|
|
1178
1181
|
|
|
1179
1182
|
//sensors services
|
|
1180
1183
|
if (this.sensorsConfiguredCount > 0) {
|
|
1181
|
-
|
|
1184
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare sensors services`);
|
|
1182
1185
|
this.sensorsServices = [];
|
|
1183
1186
|
|
|
1184
1187
|
this.sensorsConfigured.forEach((sensor, index) => {
|
|
@@ -1206,7 +1209,7 @@ class MiElHvac extends EventEmitter {
|
|
|
1206
1209
|
|
|
1207
1210
|
//room temperature sensor service
|
|
1208
1211
|
if (this.temperatureSensor && this.mielHvac.roomTemperature !== null) {
|
|
1209
|
-
|
|
1212
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare room temperature sensor service`);
|
|
1210
1213
|
this.roomTemperatureSensorService = new Service.TemperatureSensor(`${serviceName} Room`, `Room Temperature Sensor`);
|
|
1211
1214
|
this.roomTemperatureSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
1212
1215
|
this.roomTemperatureSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Room`);
|
|
@@ -1225,7 +1228,7 @@ class MiElHvac extends EventEmitter {
|
|
|
1225
1228
|
|
|
1226
1229
|
//outdoor temperature sensor service
|
|
1227
1230
|
if (this.temperatureSensorOutdoor && this.mielHvac.hasOutdoorTemperature && this.mielHvac.outdoorTemperature !== null) {
|
|
1228
|
-
|
|
1231
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare outdoor temperature sensor service`);
|
|
1229
1232
|
this.outdoorTemperatureSensorService = new Service.TemperatureSensor(`${serviceName} Outdoor`, `Outdoor Temperature Sensor`);
|
|
1230
1233
|
this.outdoorTemperatureSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
1231
1234
|
this.outdoorTemperatureSensorService.setCharacteristic(Characteristic.ConfiguredName, `${accessoryName} Outdoor`);
|
|
@@ -1259,16 +1262,11 @@ class MiElHvac extends EventEmitter {
|
|
|
1259
1262
|
this.emit('success', `Connect Success`)
|
|
1260
1263
|
|
|
1261
1264
|
//check device info
|
|
1262
|
-
|
|
1265
|
+
if (!this.disableLogDeviceInfo) await this.deviceInfo();
|
|
1263
1266
|
|
|
1264
1267
|
//start prepare accessory
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
const publishAccessory = this.emit('publishAccessory', accessory);
|
|
1268
|
-
this.startPrepareAccessory = false;
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
|
-
return true;
|
|
1268
|
+
const accessory = await this.prepareAccessory();
|
|
1269
|
+
return accessory;
|
|
1272
1270
|
} catch (error) {
|
|
1273
1271
|
throw new Error(`Start error: ${error}`);
|
|
1274
1272
|
}
|
package/src/sensors.js
CHANGED
|
@@ -29,9 +29,6 @@ class Sensors extends EventEmitter {
|
|
|
29
29
|
//sensors
|
|
30
30
|
this.sensorsCount = 0;
|
|
31
31
|
|
|
32
|
-
//variable
|
|
33
|
-
this.startPrepareAccessory = true;
|
|
34
|
-
|
|
35
32
|
//axios instance
|
|
36
33
|
const url = `http://${config.host}/cm?cmnd=`;
|
|
37
34
|
this.axiosInstance = axios.create({
|
|
@@ -65,12 +62,12 @@ class Sensors extends EventEmitter {
|
|
|
65
62
|
}
|
|
66
63
|
|
|
67
64
|
async checkDeviceState() {
|
|
68
|
-
|
|
65
|
+
if (this.enableDebugMode) this.emit('debug', `Requesting status`);
|
|
69
66
|
try {
|
|
70
67
|
//sensor status
|
|
71
68
|
const sensorStatusData = await this.axiosInstance(ApiCommands.Status);
|
|
72
69
|
const sensorStatus = sensorStatusData.data ?? {};
|
|
73
|
-
|
|
70
|
+
if (this.enableDebugMode) this.emit('debug', `Sensors status: ${JSON.stringify(sensorStatus, null, 2)}`);
|
|
74
71
|
|
|
75
72
|
//sensor status keys
|
|
76
73
|
const sensorStatusKeys = Object.keys(sensorStatus);
|
|
@@ -179,7 +176,7 @@ class Sensors extends EventEmitter {
|
|
|
179
176
|
}
|
|
180
177
|
}
|
|
181
178
|
|
|
182
|
-
|
|
179
|
+
if (this.enableDebugMode) this.emit('debug', `Sensor: ${JSON.stringify(sensor, null, 2)}`);
|
|
183
180
|
i++;
|
|
184
181
|
}
|
|
185
182
|
|
|
@@ -196,7 +193,7 @@ class Sensors extends EventEmitter {
|
|
|
196
193
|
try {
|
|
197
194
|
data = JSON.stringify(data, null, 2);
|
|
198
195
|
await fsPromises.writeFile(path, data);
|
|
199
|
-
|
|
196
|
+
if (this.enableDebugMode) this.emit('debug', `Saved data: ${data}`);
|
|
200
197
|
return true;
|
|
201
198
|
} catch (error) {
|
|
202
199
|
throw new Error(`Save data error: ${error}`);
|
|
@@ -236,7 +233,7 @@ class Sensors extends EventEmitter {
|
|
|
236
233
|
|
|
237
234
|
//prepare accessory
|
|
238
235
|
async prepareAccessory() {
|
|
239
|
-
|
|
236
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Accessory`);
|
|
240
237
|
|
|
241
238
|
try {
|
|
242
239
|
//accessory
|
|
@@ -246,7 +243,7 @@ class Sensors extends EventEmitter {
|
|
|
246
243
|
const accessory = new Accessory(accessoryName, accessoryUUID, accessoryCategory);
|
|
247
244
|
|
|
248
245
|
//Prepare information service
|
|
249
|
-
|
|
246
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Information Service`);
|
|
250
247
|
accessory.getService(Service.AccessoryInformation)
|
|
251
248
|
.setCharacteristic(Characteristic.Manufacturer, 'Tasmota')
|
|
252
249
|
.setCharacteristic(Characteristic.Model, this.info.modelName ?? 'Model Name')
|
|
@@ -256,7 +253,7 @@ class Sensors extends EventEmitter {
|
|
|
256
253
|
|
|
257
254
|
//Prepare services
|
|
258
255
|
if (this.sensorsCount > 0) {
|
|
259
|
-
|
|
256
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Sensor Services`);
|
|
260
257
|
this.temperatureServices = [];
|
|
261
258
|
this.temperatureReferenceServices = [];
|
|
262
259
|
this.temperatureObjServices = [];
|
|
@@ -273,7 +270,7 @@ class Sensors extends EventEmitter {
|
|
|
273
270
|
for (const sensor of this.sensors) {
|
|
274
271
|
const sensorName = sensor.name;
|
|
275
272
|
if (sensor.temperature) {
|
|
276
|
-
|
|
273
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Temperature Sensor Services`);
|
|
277
274
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Temperature` : `${sensorName} Temperature`;
|
|
278
275
|
const temperatureService = accessory.addService(Service.TemperatureSensor, serviceName, `Temperature Sensor ${i}`);
|
|
279
276
|
temperatureService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
@@ -281,7 +278,7 @@ class Sensors extends EventEmitter {
|
|
|
281
278
|
temperatureService.getCharacteristic(Characteristic.CurrentTemperature)
|
|
282
279
|
.onGet(async () => {
|
|
283
280
|
const value = sensor.temperature;
|
|
284
|
-
|
|
281
|
+
if (!this.disableLogInfo) this.emit('info', `sensor: ${sensorName} temperature: ${value} °${sensor.tempUnit}`);
|
|
285
282
|
return value;
|
|
286
283
|
});
|
|
287
284
|
this.temperatureServices.push(temperatureService);
|
|
@@ -289,7 +286,7 @@ class Sensors extends EventEmitter {
|
|
|
289
286
|
|
|
290
287
|
//reference temperature
|
|
291
288
|
if (sensor.referenceTemperature) {
|
|
292
|
-
|
|
289
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Reference Temperature Sensor Services`);
|
|
293
290
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Reference Temperature` : `${sensorName} Reference Temperature`;
|
|
294
291
|
const temperatureReferenceService = accessory.addService(Service.TemperatureSensor, serviceName, `Reference Temperature Sensor ${i}`);
|
|
295
292
|
temperatureReferenceService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
@@ -297,7 +294,7 @@ class Sensors extends EventEmitter {
|
|
|
297
294
|
temperatureReferenceService.getCharacteristic(Characteristic.CurrentTemperature)
|
|
298
295
|
.onGet(async () => {
|
|
299
296
|
const value = sensor.referenceTemperature;
|
|
300
|
-
|
|
297
|
+
if (!this.disableLogInfo) this.emit('info', `sensor: ${sensorName} reference temperature: ${value} °${sensor.tempUnit}`);
|
|
301
298
|
return value;
|
|
302
299
|
});
|
|
303
300
|
this.temperatureReferenceServices.push(temperatureReferenceService);
|
|
@@ -305,7 +302,7 @@ class Sensors extends EventEmitter {
|
|
|
305
302
|
|
|
306
303
|
//object temperature
|
|
307
304
|
if (sensor.objTemperature) {
|
|
308
|
-
|
|
305
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Obj Temperature Sensor Services`);
|
|
309
306
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Obj Temperature` : `${sensorName} Obj Temperature`;
|
|
310
307
|
const temperatureObjService = accessory.addService(Service.TemperatureSensor, serviceName, `Obj Temperature Sensor ${i}`);
|
|
311
308
|
temperatureObjService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
@@ -313,7 +310,7 @@ class Sensors extends EventEmitter {
|
|
|
313
310
|
temperatureObjService.getCharacteristic(Characteristic.CurrentTemperature)
|
|
314
311
|
.onGet(async () => {
|
|
315
312
|
const value = sensor.objTemperature;
|
|
316
|
-
|
|
313
|
+
if (!this.disableLogInfo) this.emit('info', `sensor: ${sensorName} obj temperature: ${value} °${sensor.tempUnit}`);
|
|
317
314
|
return value;
|
|
318
315
|
});
|
|
319
316
|
this.temperatureObjServices.push(temperatureObjService);
|
|
@@ -321,7 +318,7 @@ class Sensors extends EventEmitter {
|
|
|
321
318
|
|
|
322
319
|
//ambient temperature
|
|
323
320
|
if (sensor.ambTemperature) {
|
|
324
|
-
|
|
321
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Amb Temperature Sensor Services`);
|
|
325
322
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Amb Temperature` : `${sensorName} Amb Temperature`;
|
|
326
323
|
const temperatureAmbService = accessory.addService(Service.TemperatureSensor, serviceName, `Amb Temperature Sensor ${i}`);
|
|
327
324
|
temperatureAmbService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
@@ -329,7 +326,7 @@ class Sensors extends EventEmitter {
|
|
|
329
326
|
temperatureAmbService.getCharacteristic(Characteristic.CurrentTemperature)
|
|
330
327
|
.onGet(async () => {
|
|
331
328
|
const value = sensor.ambTemperature;
|
|
332
|
-
|
|
329
|
+
if (!this.disableLogInfo) this.emit('info', `sensor: ${sensorName} amb temperature: ${value} °${sensor.tempUnit}`);
|
|
333
330
|
return value;
|
|
334
331
|
});
|
|
335
332
|
this.temperatureAmbServices.push(temperatureAmbService);
|
|
@@ -337,7 +334,7 @@ class Sensors extends EventEmitter {
|
|
|
337
334
|
|
|
338
335
|
//dew point temperature
|
|
339
336
|
if (sensor.dewPointTemperature) {
|
|
340
|
-
|
|
337
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Dew Point Temperature Sensor Services`);
|
|
341
338
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Dew Point` : `${sensorName} Dew Point`;
|
|
342
339
|
const temperatureDewPointService = accessory.addService(Service.TemperatureSensor, serviceName, `Dew Point Temperature Sensor ${i}`);
|
|
343
340
|
temperatureDewPointService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
@@ -345,7 +342,7 @@ class Sensors extends EventEmitter {
|
|
|
345
342
|
temperatureDewPointService.getCharacteristic(Characteristic.CurrentTemperature)
|
|
346
343
|
.onGet(async () => {
|
|
347
344
|
const value = sensor.dewPointTemperature;
|
|
348
|
-
|
|
345
|
+
if (!this.disableLogInfo) this.emit('info', `sensor: ${sensorName} dew point: ${value} °${sensor.tempUnit}`);
|
|
349
346
|
return value;
|
|
350
347
|
});
|
|
351
348
|
this.temperatureDewPointServices.push(temperatureDewPointService);
|
|
@@ -353,7 +350,7 @@ class Sensors extends EventEmitter {
|
|
|
353
350
|
|
|
354
351
|
//humidity
|
|
355
352
|
if (sensor.humidity) {
|
|
356
|
-
|
|
353
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Humidity Sensor Services`);
|
|
357
354
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Humidity` : `${sensorName} Humidity`;
|
|
358
355
|
const humidityService = accessory.addService(Service.HumiditySensor, serviceName, `Humidity Sensor ${i}`);
|
|
359
356
|
humidityService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
@@ -361,7 +358,7 @@ class Sensors extends EventEmitter {
|
|
|
361
358
|
humidityService.getCharacteristic(Characteristic.CurrentRelativeHumidity)
|
|
362
359
|
.onGet(async () => {
|
|
363
360
|
const value = sensor.humidity;
|
|
364
|
-
|
|
361
|
+
if (!this.disableLogInfo) this.emit('info', `sensor: ${sensorName} humidity: ${value} %`);
|
|
365
362
|
return value;
|
|
366
363
|
});
|
|
367
364
|
this.humidityServices.push(humidityService);
|
|
@@ -373,7 +370,7 @@ class Sensors extends EventEmitter {
|
|
|
373
370
|
|
|
374
371
|
//carbon dioxyde
|
|
375
372
|
if (sensor.carbonDioxyde) {
|
|
376
|
-
|
|
373
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Carbon Dioxyde Sensor Services`);
|
|
377
374
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Carbon Dioxyde` : `${sensorName} Carbon Dioxyde`;
|
|
378
375
|
const carbonDioxydeService = accessory.addService(Service.CarbonDioxideSensor, serviceName, `Carbon Dioxyde Sensor ${i}`);
|
|
379
376
|
carbonDioxydeService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
@@ -381,19 +378,19 @@ class Sensors extends EventEmitter {
|
|
|
381
378
|
carbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxideDetected)
|
|
382
379
|
.onGet(async () => {
|
|
383
380
|
const state = sensor.carbonDioxyde > 1000;
|
|
384
|
-
|
|
381
|
+
if (!this.disableLogInfo) this.emit('info', `sensor: ${sensorName} carbon dioxyde detected: ${state ? 'Yes' : 'No'}`);
|
|
385
382
|
return state;
|
|
386
383
|
});
|
|
387
384
|
carbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxideLevel)
|
|
388
385
|
.onGet(async () => {
|
|
389
386
|
const value = sensor.carbonDioxyde;
|
|
390
|
-
|
|
387
|
+
if (!this.disableLogInfo) this.emit('info', `sensor: ${sensorName} carbon dioxyde level: ${value} ppm`);
|
|
391
388
|
return value;
|
|
392
389
|
});
|
|
393
390
|
carbonDioxydeService.getCharacteristic(Characteristic.CarbonDioxidePeakLevel)
|
|
394
391
|
.onGet(async () => {
|
|
395
392
|
const value = sensor.carbonDioxyde;
|
|
396
|
-
|
|
393
|
+
if (!this.disableLogInfo) this.emit('info', `sensor: ${sensorName} carbon dioxyde peak level: ${value} ppm`);
|
|
397
394
|
return value;
|
|
398
395
|
});
|
|
399
396
|
this.carbonDioxydeServices.push(carbonDioxydeService);
|
|
@@ -401,7 +398,7 @@ class Sensors extends EventEmitter {
|
|
|
401
398
|
|
|
402
399
|
//ambient light
|
|
403
400
|
if (sensor.ambientLight) {
|
|
404
|
-
|
|
401
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Ambient Light Sensor Services`);
|
|
405
402
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Ambient Light` : `${sensorName} Ambient Light`;
|
|
406
403
|
const ambientLightService = accessory.addService(Service.LightSensor, serviceName, `Ambient Light Sensor ${i}`);
|
|
407
404
|
ambientLightService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
@@ -409,7 +406,7 @@ class Sensors extends EventEmitter {
|
|
|
409
406
|
ambientLightService.getCharacteristic(Characteristic.CurrentAmbientLightLevel)
|
|
410
407
|
.onGet(async () => {
|
|
411
408
|
const value = sensor.ambientLight;
|
|
412
|
-
|
|
409
|
+
if (!this.disableLogInfo) this.emit('info', `sensor: ${sensorName} ambient light: ${value} lx`);
|
|
413
410
|
return value;
|
|
414
411
|
});
|
|
415
412
|
this.ambientLightServices.push(ambientLightService);
|
|
@@ -417,7 +414,7 @@ class Sensors extends EventEmitter {
|
|
|
417
414
|
|
|
418
415
|
//motion
|
|
419
416
|
if (sensor.motion) {
|
|
420
|
-
|
|
417
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Motion Sensor Services`);
|
|
421
418
|
const serviceName = this.sensorsNamePrefix ? `${accessoryName} ${sensorName} Motion` : `${sensorName} Motion`;
|
|
422
419
|
const motionService = accessory.addService(Service.MotionSensor, serviceName, `Motion Sensor ${i}`);
|
|
423
420
|
motionService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
@@ -425,7 +422,7 @@ class Sensors extends EventEmitter {
|
|
|
425
422
|
motionService.getCharacteristic(Characteristic.MotionDetected)
|
|
426
423
|
.onGet(async () => {
|
|
427
424
|
const state = sensor.motion;
|
|
428
|
-
|
|
425
|
+
if (!this.disableLogInfo) this.emit('info', `sensor: ${sensorName} motion: ${state ? 'ON' : 'OFF'}`);
|
|
429
426
|
return state;
|
|
430
427
|
});
|
|
431
428
|
this.motionServices.push(motionService);
|
|
@@ -547,16 +544,11 @@ class Sensors extends EventEmitter {
|
|
|
547
544
|
this.emit('success', `Connect Success`)
|
|
548
545
|
|
|
549
546
|
//check device info
|
|
550
|
-
|
|
547
|
+
if (!this.disableLogDeviceInfo) await this.deviceInfo();
|
|
551
548
|
|
|
552
549
|
//start prepare accessory
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
const publishAccessory = this.emit('publishAccessory', accessory);
|
|
556
|
-
this.startPrepareAccessory = false;
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
return true;
|
|
550
|
+
const accessory = await this.prepareAccessory();
|
|
551
|
+
return accessory;
|
|
560
552
|
} catch (error) {
|
|
561
553
|
throw new Error(`Start error: ${error}`);
|
|
562
554
|
}
|
package/src/switches.js
CHANGED
|
@@ -28,9 +28,6 @@ class Switches extends EventEmitter {
|
|
|
28
28
|
this.disableLogDeviceInfo = config.disableLogDeviceInfo || false;
|
|
29
29
|
this.refreshInterval = refreshInterval;
|
|
30
30
|
|
|
31
|
-
//variable
|
|
32
|
-
this.startPrepareAccessory = true;
|
|
33
|
-
|
|
34
31
|
//axios instance
|
|
35
32
|
const url = `http://${config.host}/cm?cmnd=`;
|
|
36
33
|
this.axiosInstance = axios.create({
|
|
@@ -64,12 +61,12 @@ class Switches extends EventEmitter {
|
|
|
64
61
|
}
|
|
65
62
|
|
|
66
63
|
async checkDeviceState() {
|
|
67
|
-
|
|
64
|
+
if (this.enableDebugMode) this.emit('debug', `Requesting status`);
|
|
68
65
|
try {
|
|
69
66
|
//power status
|
|
70
67
|
const powerStatusData = await this.axiosInstance(ApiCommands.PowerStatus);
|
|
71
68
|
const powerStatus = powerStatusData.data ?? {};
|
|
72
|
-
|
|
69
|
+
if (this.enableDebugMode) this.emit('debug', `Power status: ${JSON.stringify(powerStatus, null, 2)}`);
|
|
73
70
|
|
|
74
71
|
//relays
|
|
75
72
|
const relaysCount = this.relaysCount;
|
|
@@ -114,7 +111,7 @@ class Switches extends EventEmitter {
|
|
|
114
111
|
try {
|
|
115
112
|
data = JSON.stringify(data, null, 2);
|
|
116
113
|
await fsPromises.writeFile(path, data);
|
|
117
|
-
|
|
114
|
+
if (this.enableDebugMode) this.emit('debug', `Saved data: ${data}`);
|
|
118
115
|
return true;
|
|
119
116
|
} catch (error) {
|
|
120
117
|
throw new Error(`Save data error: ${error}`);
|
|
@@ -154,7 +151,7 @@ class Switches extends EventEmitter {
|
|
|
154
151
|
|
|
155
152
|
//prepare accessory
|
|
156
153
|
async prepareAccessory() {
|
|
157
|
-
|
|
154
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Accessory`);
|
|
158
155
|
|
|
159
156
|
try {
|
|
160
157
|
//accessory
|
|
@@ -164,7 +161,7 @@ class Switches extends EventEmitter {
|
|
|
164
161
|
const accessory = new Accessory(accessoryName, accessoryUUID, accessoryCategory);
|
|
165
162
|
|
|
166
163
|
//Prepare information service
|
|
167
|
-
|
|
164
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Information Service`);
|
|
168
165
|
accessory.getService(Service.AccessoryInformation)
|
|
169
166
|
.setCharacteristic(Characteristic.Manufacturer, 'Tasmota')
|
|
170
167
|
.setCharacteristic(Characteristic.Model, this.info.modelName ?? 'Model Name')
|
|
@@ -173,9 +170,9 @@ class Switches extends EventEmitter {
|
|
|
173
170
|
.setCharacteristic(Characteristic.ConfiguredName, accessoryName);
|
|
174
171
|
|
|
175
172
|
//Prepare services
|
|
176
|
-
|
|
173
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Services`);
|
|
177
174
|
if (this.switchesOutlets.length > 0) {
|
|
178
|
-
|
|
175
|
+
if (this.enableDebugMode) this.emit('debug', `Prepare Switch/Outlet Services`);
|
|
179
176
|
this.switchOutletServices = [];
|
|
180
177
|
|
|
181
178
|
for (let i = 0; i < this.switchesOutlets.length; i++) {
|
|
@@ -199,7 +196,7 @@ class Switches extends EventEmitter {
|
|
|
199
196
|
state = state ? powerOn : powerOff;
|
|
200
197
|
|
|
201
198
|
await this.axiosInstance(state);
|
|
202
|
-
|
|
199
|
+
if (!this.disableLogInfo) this.emit('info', `${friendlyName}, set state: ${state ? 'ON' : 'OFF'}`);
|
|
203
200
|
} catch (error) {
|
|
204
201
|
this.emit('warn', `${friendlyName}, set state error: ${error}`);
|
|
205
202
|
}
|
|
@@ -224,16 +221,11 @@ class Switches extends EventEmitter {
|
|
|
224
221
|
this.emit('success', `Connect Success`)
|
|
225
222
|
|
|
226
223
|
//check device info
|
|
227
|
-
|
|
224
|
+
if (!this.disableLogDeviceInfo) await this.deviceInfo();
|
|
228
225
|
|
|
229
226
|
//start prepare accessory
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
const publishAccessory = this.emit('publishAccessory', accessory);
|
|
233
|
-
this.startPrepareAccessory = false;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
return true;
|
|
227
|
+
const accessory = await this.prepareAccessory();
|
|
228
|
+
return accessory;
|
|
237
229
|
} catch (error) {
|
|
238
230
|
throw new Error(`Start error: ${error}`);
|
|
239
231
|
}
|