homebridge-tasmota-control 1.7.3 → 1.7.4-beta.0
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 +84 -82
- package/package.json +1 -1
- package/src/deviceinfo.js +1 -1
package/index.js
CHANGED
|
@@ -48,7 +48,7 @@ class tasmotaPlatform {
|
|
|
48
48
|
const user = device.user || '';
|
|
49
49
|
const passwd = device.passwd || '';
|
|
50
50
|
const loadNameFromDevice = device.loadNameFromDevice || false;
|
|
51
|
-
const refreshInterval =
|
|
51
|
+
const refreshInterval = (device.refreshInterval ?? 5000) * 1000;
|
|
52
52
|
const enableDebugMode = device.enableDebugMode || false;
|
|
53
53
|
const logLevel = {
|
|
54
54
|
debug: device.enableDebugMode,
|
|
@@ -68,78 +68,78 @@ class tasmotaPlatform {
|
|
|
68
68
|
if (logLevel.debug) log.info(`Device: ${host} ${deviceName}, Config: ${JSON.stringify(newConfig, null, 2)}.`);
|
|
69
69
|
|
|
70
70
|
try {
|
|
71
|
-
//
|
|
72
|
-
const
|
|
73
|
-
.on('
|
|
74
|
-
.on('warn', (msg) => logLevel.warn && log.warn(`Device: ${host} ${deviceName}, ${msg}`))
|
|
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.`);
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
let i = 0;
|
|
84
|
-
for (const type of info.deviceTypes) {
|
|
85
|
-
const serialNumber = i === 0 ? info.serialNumber : `${info.serialNumber}${i}`;
|
|
86
|
-
|
|
87
|
-
//check files exists, if not then create it
|
|
88
|
-
if (type === 0) {
|
|
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,21 @@ 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
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
+
});
|
|
160
|
+
|
|
161
|
+
//start impulse generator
|
|
162
|
+
await impulseGenerator.start([{ name: 'start', sampling: 60000 }]);
|
|
163
|
+
|
|
162
164
|
} catch (error) {
|
|
163
|
-
if (logLevel.error)
|
|
165
|
+
if (logLevel.error) log.error(`Device: ${host} ${deviceName}, Did finish launching error: ${error}.`);
|
|
164
166
|
}
|
|
165
167
|
}
|
|
166
168
|
});
|
package/package.json
CHANGED