homebridge-tasmota-control 1.4.0-beta.33 → 1.4.0-beta.35
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 +48 -46
- package/package.json +1 -1
- package/src/deviceinfo.js +1 -1
- package/src/fans.js +3 -2
- package/src/lights.js +3 -2
- package/src/mielhvac.js +3 -2
- package/src/switches.js +3 -2
package/index.js
CHANGED
|
@@ -27,7 +27,7 @@ class tasmotaPlatform {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
api.on('didFinishLaunching', async () => {
|
|
30
|
-
for (const
|
|
30
|
+
for (const device of config.devices) {
|
|
31
31
|
|
|
32
32
|
//check accessory is enabled
|
|
33
33
|
const disableAccessory = deviceConfig.disableAccessory || false;
|
|
@@ -35,56 +35,34 @@ class tasmotaPlatform {
|
|
|
35
35
|
continue;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
const deviceName =
|
|
39
|
-
const host =
|
|
38
|
+
const deviceName = device.name;
|
|
39
|
+
const host = device.host;
|
|
40
40
|
if (!deviceName || !host) {
|
|
41
41
|
log.warn(`Device Name: ${deviceName ? 'OK' : deviceName}, host: ${host ? 'OK' : host}, in config wrong or missing.`);
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
//log config
|
|
46
|
-
const loadNameFromDevice = deviceConfig.loadNameFromDevice || false;
|
|
47
|
-
const auth = deviceConfig.auth || false;
|
|
48
46
|
const url = `http://${host}/cm?cmnd=`;
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
const
|
|
47
|
+
const auth = device.auth || false;
|
|
48
|
+
const user = device.user || '';
|
|
49
|
+
const passwd = device.passwd || '';
|
|
50
|
+
const loadNameFromDevice = device.loadNameFromDevice || false;
|
|
51
|
+
const refreshInterval = device.refreshInterval * 1000 || 5000;
|
|
52
|
+
const enableDebugMode = device.enableDebugMode || false;
|
|
53
|
+
const disableLogDeviceInfo = device.disableLogDeviceInfo || false;
|
|
54
|
+
const disableLogInfo = device.disableLogInfo || false;
|
|
55
|
+
const disableLogSuccess = device.disableLogSuccess || false;
|
|
56
|
+
const disableLogWarn = device.disableLogWarn || false;
|
|
57
|
+
const disableLogError = device.disableLogError || false;
|
|
58
58
|
const debug = enableDebugMode ? log.info(`Device: ${host} ${deviceName}, debug: Did finish launching.`) : false;
|
|
59
59
|
const newConfig = {
|
|
60
|
-
...
|
|
60
|
+
...device,
|
|
61
61
|
user: 'removed',
|
|
62
62
|
passwd: 'removed'
|
|
63
63
|
};
|
|
64
64
|
const debug1 = !enableDebugMode ? false : log.info(`Device: ${host} ${deviceName}, Config: ${JSON.stringify(newConfig, null, 2)}.`);
|
|
65
65
|
|
|
66
|
-
//check files exists, if not then create it
|
|
67
|
-
const postFix = deviceConfig.host.split('.').join('');
|
|
68
|
-
const defaultHeatingSetTemperatureFile = `${prefDir}/defaultHeatingSetTemperature_${postFix}`;
|
|
69
|
-
const defaultCoolingSetTemperatureFile = `${prefDir}/defaultCoolingSetTemperature_${postFix}`;
|
|
70
|
-
|
|
71
|
-
try {
|
|
72
|
-
const files = [
|
|
73
|
-
defaultHeatingSetTemperatureFile,
|
|
74
|
-
defaultCoolingSetTemperatureFile
|
|
75
|
-
];
|
|
76
|
-
|
|
77
|
-
files.forEach((file, index) => {
|
|
78
|
-
if (!existsSync(file)) {
|
|
79
|
-
const data = ['20', '23'][index]
|
|
80
|
-
writeFileSync(file, data);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
} catch (error) {
|
|
84
|
-
log.error(`Device: ${host} ${deviceName}, Prepare files error: ${error}`);
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
66
|
try {
|
|
89
67
|
//get device info
|
|
90
68
|
const deviceInfo = new deviceinfo(url, auth, user, passwd, deviceName, loadNameFromDevice, enableDebugMode, refreshInterval);
|
|
@@ -104,24 +82,48 @@ class tasmotaPlatform {
|
|
|
104
82
|
return;
|
|
105
83
|
}
|
|
106
84
|
|
|
107
|
-
|
|
108
|
-
let device;
|
|
85
|
+
let deviceType;
|
|
109
86
|
switch (info.deviceType) {
|
|
110
87
|
case 0://mielhvac
|
|
111
|
-
|
|
88
|
+
//check files exists, if not then create it
|
|
89
|
+
const postFix = deviceConfig.host.split('.').join('');
|
|
90
|
+
const defaultHeatingSetTemperatureFile = `${prefDir}/defaultHeatingSetTemperature_${postFix}`;
|
|
91
|
+
const defaultCoolingSetTemperatureFile = `${prefDir}/defaultCoolingSetTemperature_${postFix}`;
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
const files = [
|
|
95
|
+
defaultHeatingSetTemperatureFile,
|
|
96
|
+
defaultCoolingSetTemperatureFile
|
|
97
|
+
];
|
|
98
|
+
|
|
99
|
+
files.forEach((file, index) => {
|
|
100
|
+
if (!existsSync(file)) {
|
|
101
|
+
const data = ['20', '23'][index]
|
|
102
|
+
writeFileSync(file, data);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
} catch (error) {
|
|
106
|
+
log.error(`Device: ${host} ${deviceName}, Prepare files error: ${error}`);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
deviceType = new mielhvac(api, device, info, refreshInterval, defaultHeatingSetTemperatureFile, defaultCoolingSetTemperatureFile);
|
|
112
111
|
break;
|
|
113
112
|
case 1://switches
|
|
114
|
-
|
|
113
|
+
deviceType = new switches(api, device, info, refreshInterval);
|
|
115
114
|
break;
|
|
116
115
|
case 2://lights
|
|
117
|
-
|
|
116
|
+
deviceType = new lights(api, device, info, refreshInterval);
|
|
118
117
|
break;
|
|
119
118
|
case 3://fans
|
|
120
|
-
|
|
119
|
+
deviceType = new fans(api, device, info, refreshInterval);
|
|
121
120
|
break;
|
|
121
|
+
default:
|
|
122
|
+
const emitLog = disableLogWarn ? false : log.warn(`Device: ${host} ${deviceName}, unknown device: ${info.deviceType}.`);
|
|
123
|
+
return;
|
|
122
124
|
}
|
|
123
125
|
|
|
124
|
-
|
|
126
|
+
deviceType.on('publishAccessory', (accessory) => {
|
|
125
127
|
api.publishExternalAccessories(PluginName, [accessory]);
|
|
126
128
|
const emitLog = disableLogSuccess ? false : log.success(`Device: ${host} ${deviceName}, Published as external accessory.`);
|
|
127
129
|
})
|
|
@@ -148,11 +150,11 @@ class tasmotaPlatform {
|
|
|
148
150
|
const impulseGenerator = new ImpulseGenerator();
|
|
149
151
|
impulseGenerator.on('start', async () => {
|
|
150
152
|
try {
|
|
151
|
-
const startDone = await
|
|
153
|
+
const startDone = await deviceType.start();
|
|
152
154
|
const stopImpulseGenerator = startDone ? await impulseGenerator.stop() : false;
|
|
153
155
|
|
|
154
156
|
//start impulse generator
|
|
155
|
-
const startImpulseGenerator = stopImpulseGenerator ? await
|
|
157
|
+
const startImpulseGenerator = stopImpulseGenerator ? await deviceType.startImpulseGenerator() : false
|
|
156
158
|
} catch (error) {
|
|
157
159
|
const emitLog = disableLogError ? false : log.error(`Device: ${host} ${deviceName}, ${error}, trying again.`);
|
|
158
160
|
}
|
package/package.json
CHANGED
package/src/deviceinfo.js
CHANGED
package/src/fans.js
CHANGED
|
@@ -343,7 +343,7 @@ class Fans extends EventEmitter {
|
|
|
343
343
|
}
|
|
344
344
|
}
|
|
345
345
|
|
|
346
|
-
deviceInfo() {
|
|
346
|
+
async deviceInfo() {
|
|
347
347
|
this.emit('devInfo', `----- ${this.info.deviceName} -----`);
|
|
348
348
|
this.emit('devInfo', `Manufacturer: Tasmota`);
|
|
349
349
|
this.emit('devInfo', `Hardware: ${this.info.modelName}`);
|
|
@@ -352,6 +352,7 @@ class Fans extends EventEmitter {
|
|
|
352
352
|
this.emit('devInfo', `Relays: ${this.info.relaysCount}`);
|
|
353
353
|
this.emit('devInfo', `Sensors: ${this.sensorsCount}`);
|
|
354
354
|
this.emit('devInfo', `----------------------------------`);
|
|
355
|
+
return;
|
|
355
356
|
}
|
|
356
357
|
|
|
357
358
|
//prepare accessory
|
|
@@ -695,7 +696,7 @@ class Fans extends EventEmitter {
|
|
|
695
696
|
this.emit('success', `Connect Success`)
|
|
696
697
|
|
|
697
698
|
//check device info
|
|
698
|
-
const devInfo = !this.disableLogDeviceInfo ? this.deviceInfo() : false;
|
|
699
|
+
const devInfo = !this.disableLogDeviceInfo ? await this.deviceInfo() : false;
|
|
699
700
|
|
|
700
701
|
//start prepare accessory
|
|
701
702
|
if (this.startPrepareAccessory) {
|
package/src/lights.js
CHANGED
|
@@ -359,7 +359,7 @@ class Lights extends EventEmitter {
|
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
361
|
|
|
362
|
-
deviceInfo() {
|
|
362
|
+
async deviceInfo() {
|
|
363
363
|
this.emit('devInfo', `----- ${this.info.deviceName} -----`);
|
|
364
364
|
this.emit('devInfo', `Manufacturer: Tasmota`);
|
|
365
365
|
this.emit('devInfo', `Hardware: ${this.info.modelName}`);
|
|
@@ -368,6 +368,7 @@ class Lights extends EventEmitter {
|
|
|
368
368
|
this.emit('devInfo', `Relays: ${this.info.relaysCount}`);
|
|
369
369
|
this.emit('devInfo', `Sensors: ${this.sensorsCount}`);
|
|
370
370
|
this.emit('devInfo', `----------------------------------`);
|
|
371
|
+
return;
|
|
371
372
|
}
|
|
372
373
|
|
|
373
374
|
//prepare accessory
|
|
@@ -716,7 +717,7 @@ class Lights extends EventEmitter {
|
|
|
716
717
|
this.emit('success', `Connect Success`)
|
|
717
718
|
|
|
718
719
|
//check device info
|
|
719
|
-
const devInfo = !this.disableLogDeviceInfo ? this.deviceInfo() : false;
|
|
720
|
+
const devInfo = !this.disableLogDeviceInfo ? await this.deviceInfo() : false;
|
|
720
721
|
|
|
721
722
|
//start prepare accessory
|
|
722
723
|
if (this.startPrepareAccessory) {
|
package/src/mielhvac.js
CHANGED
|
@@ -811,7 +811,7 @@ class MiElHvac extends EventEmitter {
|
|
|
811
811
|
}
|
|
812
812
|
}
|
|
813
813
|
|
|
814
|
-
deviceInfo() {
|
|
814
|
+
async deviceInfo() {
|
|
815
815
|
this.emit('devInfo', `----- ${this.info.deviceName} -----`);
|
|
816
816
|
this.emit('devInfo', `Manufacturer: Tasmota`);
|
|
817
817
|
this.emit('devInfo', `Hardware: ${this.info.modelName}`);
|
|
@@ -819,6 +819,7 @@ class MiElHvac extends EventEmitter {
|
|
|
819
819
|
this.emit('devInfo', `Firmware: ${this.info.firmwareRevision}`);
|
|
820
820
|
this.emit('devInfo', `Sensor: MiELHVAC`);
|
|
821
821
|
this.emit('devInfo', `----------------------------------`);
|
|
822
|
+
return;
|
|
822
823
|
}
|
|
823
824
|
|
|
824
825
|
//prepare accessory
|
|
@@ -1380,7 +1381,7 @@ class MiElHvac extends EventEmitter {
|
|
|
1380
1381
|
this.emit('success', `Connect Success`)
|
|
1381
1382
|
|
|
1382
1383
|
//check device info
|
|
1383
|
-
const devInfo = !this.disableLogDeviceInfo ? this.deviceInfo() : false;
|
|
1384
|
+
const devInfo = !this.disableLogDeviceInfo ? await this.deviceInfo() : false;
|
|
1384
1385
|
|
|
1385
1386
|
//start prepare accessory
|
|
1386
1387
|
if (this.startPrepareAccessory) {
|
package/src/switches.js
CHANGED
|
@@ -312,7 +312,7 @@ class Switches extends EventEmitter {
|
|
|
312
312
|
}
|
|
313
313
|
}
|
|
314
314
|
|
|
315
|
-
deviceInfo() {
|
|
315
|
+
async deviceInfo() {
|
|
316
316
|
this.emit('devInfo', `----- ${this.info.deviceName} -----`);
|
|
317
317
|
this.emit('devInfo', `Manufacturer: Tasmota`);
|
|
318
318
|
this.emit('devInfo', `Hardware: ${this.info.modelName}`);
|
|
@@ -321,6 +321,7 @@ class Switches extends EventEmitter {
|
|
|
321
321
|
this.emit('devInfo', `Relays: ${this.info.relaysCount}`);
|
|
322
322
|
this.emit('devInfo', `Sensors: ${this.sensorsCount}`);
|
|
323
323
|
this.emit('devInfo', `----------------------------------`);
|
|
324
|
+
return;
|
|
324
325
|
}
|
|
325
326
|
|
|
326
327
|
//prepare accessory
|
|
@@ -605,7 +606,7 @@ class Switches extends EventEmitter {
|
|
|
605
606
|
this.emit('success', `Connect Success`)
|
|
606
607
|
|
|
607
608
|
//check device info
|
|
608
|
-
const devInfo = !this.disableLogDeviceInfo ? this.deviceInfo() : false;
|
|
609
|
+
const devInfo = !this.disableLogDeviceInfo ? await this.deviceInfo() : false;
|
|
609
610
|
|
|
610
611
|
//start prepare accessory
|
|
611
612
|
if (this.startPrepareAccessory) {
|