homebridge-tasmota-control 1.7.3 → 1.7.4
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 +110 -109
- package/package.json +1 -1
- package/src/deviceinfo.js +1 -1
package/index.js
CHANGED
|
@@ -35,111 +35,111 @@ class tasmotaPlatform {
|
|
|
35
35
|
const disableAccessory = device.disableAccessory || false;
|
|
36
36
|
if (disableAccessory) continue;
|
|
37
37
|
|
|
38
|
-
const deviceName = device.name;
|
|
39
|
-
const host = device.host;
|
|
40
|
-
if (!deviceName || !host) {
|
|
41
|
-
log.warn(`Device Name: ${deviceName ? 'OK' : deviceName}, host: ${host ? 'OK' : host}, in config wrong or missing.`);
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
//log config
|
|
46
|
-
const url = `http://${host}/cm?cmnd=`;
|
|
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 = Number.isInteger(device.refreshInterval) && device.refreshInterval > 0 ? device.refreshInterval * 1000 : 5000;
|
|
52
|
-
const enableDebugMode = device.enableDebugMode || false;
|
|
53
|
-
const logLevel = {
|
|
54
|
-
debug: device.enableDebugMode,
|
|
55
|
-
info: !device.disableLogInfo,
|
|
56
|
-
success: !device.disableLogSuccess,
|
|
57
|
-
warn: !device.disableLogWarn,
|
|
58
|
-
error: !device.disableLogError,
|
|
59
|
-
devInfo: !device.disableLogDeviceInfo,
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
if (logLevel.debug) log.info(`Device: ${host} ${deviceName}, debug: Did finish launching.`);
|
|
63
|
-
const newConfig = {
|
|
64
|
-
...device,
|
|
65
|
-
user: 'removed',
|
|
66
|
-
passwd: 'removed'
|
|
67
|
-
};
|
|
68
|
-
if (logLevel.debug) log.info(`Device: ${host} ${deviceName}, Config: ${JSON.stringify(newConfig, null, 2)}.`);
|
|
69
|
-
|
|
70
38
|
try {
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
.on('error', (msg) => logLevel.error && log.error(`Device: ${host} ${deviceName}, ${msg}`));
|
|
76
|
-
|
|
77
|
-
const info = await deviceInfo.getInfo();
|
|
78
|
-
if (!info.serialNumber) {
|
|
79
|
-
log.warn(`Device: ${host} ${deviceName}, serial not found.`);
|
|
39
|
+
const deviceName = device.name;
|
|
40
|
+
const host = device.host;
|
|
41
|
+
if (!deviceName || !host) {
|
|
42
|
+
log.warn(`Device Name: ${deviceName ? 'OK' : deviceName}, host: ${host ? 'OK' : host}, in config wrong or missing.`);
|
|
80
43
|
continue;
|
|
81
44
|
}
|
|
82
45
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
46
|
+
//log config
|
|
47
|
+
const url = `http://${host}/cm?cmnd=`;
|
|
48
|
+
const auth = device.auth || false;
|
|
49
|
+
const user = device.user || '';
|
|
50
|
+
const passwd = device.passwd || '';
|
|
51
|
+
const loadNameFromDevice = device.loadNameFromDevice || false;
|
|
52
|
+
const refreshInterval = (device.refreshInterval ?? 5000) * 1000;
|
|
53
|
+
const enableDebugMode = device.enableDebugMode || false;
|
|
54
|
+
const logLevel = {
|
|
55
|
+
debug: device.enableDebugMode,
|
|
56
|
+
info: !device.disableLogInfo,
|
|
57
|
+
success: !device.disableLogSuccess,
|
|
58
|
+
warn: !device.disableLogWarn,
|
|
59
|
+
error: !device.disableLogError,
|
|
60
|
+
devInfo: !device.disableLogDeviceInfo,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
if (logLevel.debug) log.info(`Device: ${host} ${deviceName}, debug: Did finish launching.`);
|
|
64
|
+
const newConfig = {
|
|
65
|
+
...device,
|
|
66
|
+
user: 'removed',
|
|
67
|
+
passwd: 'removed'
|
|
68
|
+
};
|
|
69
|
+
if (logLevel.debug) log.info(`Device: ${host} ${deviceName}, Config: ${JSON.stringify(newConfig, null, 2)}.`);
|
|
70
|
+
|
|
71
|
+
//create impulse generator
|
|
72
|
+
const impulseGenerator = new ImpulseGenerator()
|
|
73
|
+
.on('start', async () => {
|
|
89
74
|
try {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
75
|
+
//get device info
|
|
76
|
+
const deviceInfo = new DeviceInfo(url, auth, user, passwd, deviceName, loadNameFromDevice, enableDebugMode)
|
|
77
|
+
.on('debug', (msg) => logLevel.debug && log.info(`Device: ${host} ${deviceName}, debug: ${msg}`))
|
|
78
|
+
.on('warn', (msg) => logLevel.warn && log.warn(`Device: ${host} ${deviceName}, ${msg}`))
|
|
79
|
+
.on('error', (msg) => logLevel.error && log.error(`Device: ${host} ${deviceName}, ${msg}`));
|
|
80
|
+
|
|
81
|
+
const info = await deviceInfo.getInfo();
|
|
82
|
+
if (!info.serialNumber) {
|
|
83
|
+
log.warn(`Device: ${host} ${deviceName}, serial not found.`);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
let i = 0;
|
|
88
|
+
for (const type of info.deviceTypes) {
|
|
89
|
+
const serialNumber = i === 0 ? info.serialNumber : `${info.serialNumber}${i}`;
|
|
90
|
+
|
|
91
|
+
//check files exists, if not then create it
|
|
92
|
+
if (type === 0) {
|
|
93
|
+
try {
|
|
94
|
+
const postFix = device.host.split('.').join('');
|
|
95
|
+
info.defaultHeatingSetTemperatureFile = `${prefDir}/defaultHeatingSetTemperature_${postFix}`;
|
|
96
|
+
info.defaultCoolingSetTemperatureFile = `${prefDir}/defaultCoolingSetTemperature_${postFix}`;
|
|
97
|
+
const files = [
|
|
98
|
+
info.defaultHeatingSetTemperatureFile,
|
|
99
|
+
info.defaultCoolingSetTemperatureFile
|
|
100
|
+
];
|
|
101
|
+
|
|
102
|
+
files.forEach((file, index) => {
|
|
103
|
+
if (!existsSync(file)) {
|
|
104
|
+
const data = ['20', '23'][index];
|
|
105
|
+
writeFileSync(file, data);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
} catch (error) {
|
|
109
|
+
if (logLevel.error) log.error(`Device: ${host} ${deviceName}, Prepare files error: ${error}`);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
102
112
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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}`));
|
|
138
|
-
|
|
139
|
-
//create impulse generator
|
|
140
|
-
const impulseGenerator = new ImpulseGenerator()
|
|
141
|
-
.on('start', async () => {
|
|
142
|
-
try {
|
|
113
|
+
|
|
114
|
+
let deviceType;
|
|
115
|
+
switch (type) {
|
|
116
|
+
case 0: //mielhvac
|
|
117
|
+
deviceType = new MiElHvac(api, device, info, serialNumber, refreshInterval);
|
|
118
|
+
break;
|
|
119
|
+
case 1: //switches
|
|
120
|
+
deviceType = new Switches(api, device, info, serialNumber, refreshInterval);
|
|
121
|
+
break;
|
|
122
|
+
case 2: //lights
|
|
123
|
+
deviceType = new Lights(api, device, info, serialNumber, refreshInterval);
|
|
124
|
+
break;
|
|
125
|
+
case 3: //fans
|
|
126
|
+
deviceType = new Fans(api, device, info, serialNumber, refreshInterval);
|
|
127
|
+
break;
|
|
128
|
+
case 4: //sensors
|
|
129
|
+
deviceType = new Sensors(api, device, info, serialNumber, refreshInterval);
|
|
130
|
+
break;
|
|
131
|
+
default:
|
|
132
|
+
if (logLevel.warn) log.warn(`Device: ${host} ${deviceName}, unknown device: ${info.deviceTypes}.`);
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
deviceType.on('devInfo', (msg) => logLevel.devInfo && log.info(msg))
|
|
137
|
+
.on('success', (msg) => logLevel.success && log.success(`Device: ${host} ${deviceName}, ${msg}`))
|
|
138
|
+
.on('info', (msg) => logLevel.info && log.info(`Device: ${host} ${deviceName}, ${msg}`))
|
|
139
|
+
.on('debug', (msg) => logLevel.debug && log.info(`Device: ${host} ${deviceName}, debug: ${msg}`))
|
|
140
|
+
.on('warn', (msg) => logLevel.warn && log.warn(`Device: ${host} ${deviceName}, ${msg}`))
|
|
141
|
+
.on('error', (msg) => logLevel.error && log.error(`Device: ${host} ${deviceName}, ${msg}`));
|
|
142
|
+
|
|
143
143
|
const accessory = await deviceType.start();
|
|
144
144
|
if (accessory) {
|
|
145
145
|
api.publishExternalAccessories(PluginName, [accessory]);
|
|
@@ -148,19 +148,20 @@ class tasmotaPlatform {
|
|
|
148
148
|
await impulseGenerator.stop();
|
|
149
149
|
await deviceType.startImpulseGenerator();
|
|
150
150
|
}
|
|
151
|
-
|
|
152
|
-
|
|
151
|
+
|
|
152
|
+
i++;
|
|
153
153
|
}
|
|
154
|
-
}
|
|
155
|
-
if (logLevel.
|
|
156
|
-
}
|
|
154
|
+
} catch (error) {
|
|
155
|
+
if (logLevel.error) log.error(`Device: ${host} ${deviceName}, ${error}, trying again.`);
|
|
156
|
+
}
|
|
157
|
+
}).on('state', (state) => {
|
|
158
|
+
if (logLevel.debug) log.info(`Device: ${host} ${deviceName}, Start impulse generator ${state ? 'started' : 'stopped'}.`);
|
|
159
|
+
});
|
|
157
160
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
i++;
|
|
161
|
-
}
|
|
161
|
+
//start impulse generator
|
|
162
|
+
await impulseGenerator.start([{ name: 'start', sampling: 60000 }]);
|
|
162
163
|
} catch (error) {
|
|
163
|
-
if (logLevel.error)
|
|
164
|
+
if (logLevel.error) log.error(`Device: ${host} ${deviceName}, Did finish launching error: ${error}.`);
|
|
164
165
|
}
|
|
165
166
|
}
|
|
166
167
|
});
|
package/package.json
CHANGED