homebridge-openwrt-control 0.0.2-beta.45 → 0.0.2-beta.46
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 -35
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -60,35 +60,36 @@ class OpenWrtPlatform {
|
|
|
60
60
|
log.info(`Device: ${host} ${name}, Config: ${JSON.stringify(safeConfig, null, 2)}`);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
const configuredDevices = [];
|
|
64
|
-
const refreshInterval = (deviceConfig.refreshInterval ?? 5) * 1000;
|
|
65
|
-
if (deviceConfig.accessPoint?.enable) configuredDevices.push('accessPoint');
|
|
66
|
-
if (deviceConfig.switch?.enable) configuredDevices.push('switch');
|
|
67
|
-
if (configuredDevices.length === 0) continue;
|
|
68
|
-
|
|
69
63
|
try {
|
|
70
|
-
const openWrt = new OpenWrt(deviceConfig)
|
|
71
|
-
.on('success', msg => logLevel.success && log.success(`Device: ${host}, ${msg}`))
|
|
72
|
-
.on('info', msg => log.info(`Device: ${host} ${name}, ${msg}`))
|
|
73
|
-
.on('debug', msg => log.info(`Device: ${host} ${name}, debug: ${msg}`))
|
|
74
|
-
.on('warn', msg => log.warn(`Device: ${host} ${name}, ${msg}`))
|
|
75
|
-
.on('error', msg => log.error(`Device: ${host} ${name}, ${msg}`))
|
|
76
|
-
|
|
77
|
-
const openWrtInfo = await openWrt.connect();
|
|
78
|
-
if (!openWrtInfo.state) {
|
|
79
|
-
if (logLevel.warn) log.warn(`Device: ${host} ${name}, no data received`);
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// start openwrt impulse generator
|
|
84
|
-
await openWrt.impulseGenerator.state(true, [{ name: 'connect', sampling: refreshInterval }], false);
|
|
85
64
|
|
|
86
65
|
// create impulse generator for every device
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
66
|
+
const impulseGenerator = new ImpulseGenerator()
|
|
67
|
+
.on('start', async () => {
|
|
68
|
+
try {
|
|
69
|
+
|
|
70
|
+
const openWrt = new OpenWrt(deviceConfig)
|
|
71
|
+
.on('success', msg => logLevel.success && log.success(`Device: ${host}, ${msg}`))
|
|
72
|
+
.on('info', msg => log.info(`Device: ${host} ${name}, ${msg}`))
|
|
73
|
+
.on('debug', msg => log.info(`Device: ${host} ${name}, debug: ${msg}`))
|
|
74
|
+
.on('warn', msg => log.warn(`Device: ${host} ${name}, ${msg}`))
|
|
75
|
+
.on('error', msg => log.error(`Device: ${host} ${name}, ${msg}`))
|
|
76
|
+
|
|
77
|
+
const openWrtInfo = await openWrt.connect();
|
|
78
|
+
if (!openWrtInfo.state) {
|
|
79
|
+
if (logLevel.warn) log.warn(`Device: ${host} ${name}, no data received`);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// start openwrt impulse generator
|
|
84
|
+
await openWrt.impulseGenerator.state(true, [{ name: 'connect', sampling: refreshInterval }], false);
|
|
85
|
+
|
|
86
|
+
const configuredDevices = [];
|
|
87
|
+
const refreshInterval = (deviceConfig.refreshInterval ?? 5) * 1000;
|
|
88
|
+
if (deviceConfig.accessPoint?.enable) configuredDevices.push('accessPoint');
|
|
89
|
+
if (deviceConfig.switch?.enable) configuredDevices.push('switch');
|
|
90
|
+
if (configuredDevices.length === 0) return;
|
|
91
91
|
|
|
92
|
+
for (const device of configuredDevices) {
|
|
92
93
|
// create device clases
|
|
93
94
|
const DeviceClasses = { accessPoint: AccessPoint, switch: Switch };
|
|
94
95
|
const DeviceClass = DeviceClasses[device];
|
|
@@ -114,17 +115,18 @@ class OpenWrtPlatform {
|
|
|
114
115
|
|
|
115
116
|
// stop accessory impulse generator
|
|
116
117
|
await impulseGenerator.state(false);
|
|
117
|
-
} catch (error) {
|
|
118
|
-
if (logLevel.error) log.error(`Device: ${host} ${name}, Start impulse generator error: ${error.message ?? error}, trying again.`);
|
|
119
118
|
}
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
119
|
+
} catch (error) {
|
|
120
|
+
if (logLevel.error) log.error(`Device: ${host} ${name}, Start impulse generator error: ${error.message ?? error}, trying again.`);
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
.on('state', (state) => {
|
|
124
|
+
if (logLevel.debug) log.info(`Device: ${host} ${name}, Start impulse generator ${state ? 'started' : 'stopped'}.`);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// start accessory impulse generator
|
|
128
|
+
await impulseGenerator.state(true, [{ name: 'start', sampling: 120000 }]);
|
|
129
|
+
|
|
128
130
|
} catch (error) {
|
|
129
131
|
if (logLevel.error) log.error(`Device: ${host} ${name}, Did finish launching error: ${error.message ?? error}`);
|
|
130
132
|
}
|
package/package.json
CHANGED