homebridge-tasmota-control 1.7.4 → 1.7.6
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 +37 -36
- package/package.json +2 -2
- package/src/functions.js +26 -5
package/index.js
CHANGED
|
@@ -35,45 +35,46 @@ class tasmotaPlatform {
|
|
|
35
35
|
const disableAccessory = device.disableAccessory || false;
|
|
36
36
|
if (disableAccessory) continue;
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
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)}.`);
|
|
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
|
+
}
|
|
70
44
|
|
|
45
|
+
//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 = (device.refreshInterval ?? 5000) * 1000;
|
|
52
|
+
|
|
53
|
+
//log
|
|
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
|
+
try {
|
|
71
72
|
//create impulse generator
|
|
72
73
|
const impulseGenerator = new ImpulseGenerator()
|
|
73
74
|
.on('start', async () => {
|
|
74
75
|
try {
|
|
75
76
|
//get device info
|
|
76
|
-
const deviceInfo = new DeviceInfo(url, auth, user, passwd, deviceName, loadNameFromDevice,
|
|
77
|
+
const deviceInfo = new DeviceInfo(url, auth, user, passwd, deviceName, loadNameFromDevice, logLevel.debug)
|
|
77
78
|
.on('debug', (msg) => logLevel.debug && log.info(`Device: ${host} ${deviceName}, debug: ${msg}`))
|
|
78
79
|
.on('warn', (msg) => logLevel.warn && log.warn(`Device: ${host} ${deviceName}, ${msg}`))
|
|
79
80
|
.on('error', (msg) => logLevel.error && log.error(`Device: ${host} ${deviceName}, ${msg}`));
|
|
@@ -106,7 +107,7 @@ class tasmotaPlatform {
|
|
|
106
107
|
}
|
|
107
108
|
});
|
|
108
109
|
} catch (error) {
|
|
109
|
-
if (logLevel.error) log.error(`Device: ${host} ${deviceName}, Prepare files error: ${error}`);
|
|
110
|
+
if (logLevel.error) log.error(`Device: ${host} ${deviceName}, Prepare files error: ${error.message ?? error}`);
|
|
110
111
|
continue;
|
|
111
112
|
}
|
|
112
113
|
}
|
|
@@ -152,7 +153,7 @@ class tasmotaPlatform {
|
|
|
152
153
|
i++;
|
|
153
154
|
}
|
|
154
155
|
} catch (error) {
|
|
155
|
-
if (logLevel.error) log.error(`Device: ${host} ${deviceName}, ${error}, trying again.`);
|
|
156
|
+
if (logLevel.error) log.error(`Device: ${host} ${deviceName}, Start impulse generator error: ${error.message ?? error}, trying again.`);
|
|
156
157
|
}
|
|
157
158
|
}).on('state', (state) => {
|
|
158
159
|
if (logLevel.debug) log.info(`Device: ${host} ${deviceName}, Start impulse generator ${state ? 'started' : 'stopped'}.`);
|
|
@@ -161,7 +162,7 @@ class tasmotaPlatform {
|
|
|
161
162
|
//start impulse generator
|
|
162
163
|
await impulseGenerator.start([{ name: 'start', sampling: 60000 }]);
|
|
163
164
|
} catch (error) {
|
|
164
|
-
if (logLevel.error) log.error(`Device: ${host} ${deviceName}, Did finish launching error: ${error}.`);
|
|
165
|
+
if (logLevel.error) log.error(`Device: ${host} ${deviceName}, Did finish launching error: ${error.message ?? error}.`);
|
|
165
166
|
}
|
|
166
167
|
}
|
|
167
168
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"displayName": "Tasmota Control",
|
|
3
3
|
"name": "homebridge-tasmota-control",
|
|
4
|
-
"version": "1.7.
|
|
4
|
+
"version": "1.7.6",
|
|
5
5
|
"description": "Homebridge plugin to control Tasmota flashed devices.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "grzegorz914",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"node": "^20 || ^22 || ^24"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"axios": "^1.
|
|
37
|
+
"axios": "^1.13.1"
|
|
38
38
|
},
|
|
39
39
|
"keywords": [
|
|
40
40
|
"homebridge",
|
package/src/functions.js
CHANGED
|
@@ -4,9 +4,9 @@ class Functions {
|
|
|
4
4
|
constructor(config) {
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
async saveData(path, data) {
|
|
7
|
+
async saveData(path, data, stringify = true) {
|
|
8
8
|
try {
|
|
9
|
-
data = JSON.stringify(data, null, 2);
|
|
9
|
+
data = stringify ? JSON.stringify(data, null, 2) : data;
|
|
10
10
|
await fsPromises.writeFile(path, data);
|
|
11
11
|
return true;
|
|
12
12
|
} catch (error) {
|
|
@@ -14,12 +14,33 @@ class Functions {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
async readData(path) {
|
|
17
|
+
async readData(path, parseJson = false) {
|
|
18
18
|
try {
|
|
19
|
-
const data = await fsPromises.readFile(path);
|
|
19
|
+
const data = await fsPromises.readFile(path, 'utf8');
|
|
20
|
+
|
|
21
|
+
if (parseJson) {
|
|
22
|
+
if (!data.trim()) {
|
|
23
|
+
// Empty file when expecting JSON
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(data);
|
|
28
|
+
} catch (jsonError) {
|
|
29
|
+
throw new Error(`JSON parse error in file "${path}": ${jsonError.message}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// For non-JSON, just return file content (can be empty string)
|
|
20
34
|
return data;
|
|
21
35
|
} catch (error) {
|
|
22
|
-
|
|
36
|
+
if (error.code === 'ENOENT') {
|
|
37
|
+
// File does not exist
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
// Preserve original error details
|
|
41
|
+
const wrappedError = new Error(`Read data error for "${path}": ${error.message}`);
|
|
42
|
+
wrappedError.original = error;
|
|
43
|
+
throw wrappedError;
|
|
23
44
|
}
|
|
24
45
|
}
|
|
25
46
|
|