homebridge-tasmota-control 1.7.5 → 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 CHANGED
@@ -42,14 +42,15 @@ class tasmotaPlatform {
42
42
  continue;
43
43
  }
44
44
 
45
- //log config
45
+ //config
46
46
  const url = `http://${host}/cm?cmnd=`;
47
47
  const auth = device.auth || false;
48
48
  const user = device.user || '';
49
49
  const passwd = device.passwd || '';
50
50
  const loadNameFromDevice = device.loadNameFromDevice || false;
51
51
  const refreshInterval = (device.refreshInterval ?? 5000) * 1000;
52
- const enableDebugMode = device.enableDebugMode || false;
52
+
53
+ //log
53
54
  const logLevel = {
54
55
  debug: device.enableDebugMode,
55
56
  info: !device.disableLogInfo,
@@ -73,7 +74,7 @@ class tasmotaPlatform {
73
74
  .on('start', async () => {
74
75
  try {
75
76
  //get device info
76
- const deviceInfo = new DeviceInfo(url, auth, user, passwd, deviceName, loadNameFromDevice, enableDebugMode)
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
  }
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.5",
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.12.2"
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
- throw new Error(`Read data error: ${error}`);
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