homebridge-openwrt-control 0.0.2-beta.0 → 0.0.2-beta.1
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/package.json +1 -1
- package/src/apdevice.js +1 -1
- package/src/openwrt.js +41 -33
- package/src/swdevice.js +3 -3
package/package.json
CHANGED
package/src/apdevice.js
CHANGED
|
@@ -198,7 +198,7 @@ class AccessPointDevice extends EventEmitter {
|
|
|
198
198
|
this.emit('devInfo', `Firmware: ${this.openWrtInfo.systemInfo.release?.description}`);
|
|
199
199
|
this.emit('devInfo', `----------------------------------`);
|
|
200
200
|
|
|
201
|
-
//
|
|
201
|
+
//openwrt client
|
|
202
202
|
this.openWrt.on('systemInfo', (info) => {
|
|
203
203
|
this.informationService?.updateCharacteristic(Characteristic.FirmwareRevision, info.release?.description);
|
|
204
204
|
})
|
package/src/openwrt.js
CHANGED
|
@@ -11,7 +11,8 @@ class OpenWrt extends EventEmitter {
|
|
|
11
11
|
this.host = config.host;
|
|
12
12
|
this.user = config.user;
|
|
13
13
|
this.passwd = config.passwd;
|
|
14
|
-
this.
|
|
14
|
+
this.logError = config.log?.error;
|
|
15
|
+
this.logDebug = config.log?.debug;
|
|
15
16
|
|
|
16
17
|
//external integration
|
|
17
18
|
this.restFulEnabled = config.restFul?.enable || false;
|
|
@@ -98,40 +99,47 @@ class OpenWrt extends EventEmitter {
|
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
async connect() {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
name:
|
|
111
|
-
state:
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
102
|
+
try {
|
|
103
|
+
const openWrtInfo = { state: false, systemInfo: {}, wirelessStatus: {}, wirelessRadios: [], ssids: [] }
|
|
104
|
+
const systemInfo = await this.ubusCall("system", "board");
|
|
105
|
+
if (this.logDebug) this.emit("debug", `System info data: ${JSON.stringify(systemInfo, null, 2)}`);
|
|
106
|
+
|
|
107
|
+
const wirelessStatus = await this.ubusCall("network.wireless", "status");
|
|
108
|
+
if (this.logDebug) this.emit("debug", `Wireless status data: ${JSON.stringify(wirelessStatus, null, 2)}`);
|
|
109
|
+
|
|
110
|
+
const wirelessRadios = Object.values(status.radios).map(radio => ({
|
|
111
|
+
name: radio.name,
|
|
112
|
+
state: radio.up === true,
|
|
113
|
+
interfaces: Object.values(radio.interfaces).map(i => ({
|
|
114
|
+
name: i.ssid,
|
|
115
|
+
state: i.up === true,
|
|
116
|
+
mode: i.mode
|
|
117
|
+
}))
|
|
118
|
+
}));
|
|
119
|
+
|
|
120
|
+
const ssids = wirelessRadios.flatMap(radio => radio.interfaces);
|
|
121
|
+
this.emit("systemInfo", systemInfo);
|
|
122
|
+
this.emit("wirelessStatus", wirelessStatus);
|
|
123
|
+
this.emit("wirelessRadios", wirelessRadios);
|
|
124
|
+
this.emit("ssids", ssids);
|
|
125
|
+
|
|
126
|
+
if (this.firstRun) {
|
|
127
|
+
this.emit("success", `Connect success`);
|
|
128
|
+
this.firstRun = false;
|
|
129
|
+
}
|
|
115
130
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
131
|
+
openWrtInfo.state = true;
|
|
132
|
+
openWrtInfo.systemInfo = systemInfo;
|
|
133
|
+
openWrtInfo.wirelessStatus = wirelessStatus;
|
|
134
|
+
openWrtInfo.wirelessRadios = wirelessRadios;
|
|
135
|
+
openWrtInfo.ssids = ssids;
|
|
121
136
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
137
|
+
if (this.logDebug) this.emit("debug", `OpenWrt Data: ${JSON.stringify(openWrtInfo, null, 2)}`);
|
|
138
|
+
return openWrtInfo;
|
|
139
|
+
} catch (error) {
|
|
140
|
+
if (this.logError) this.emit("error", `Connect error: ${error.message}`);
|
|
141
|
+
return null;
|
|
125
142
|
}
|
|
126
|
-
|
|
127
|
-
openWrtInfo.state = true;
|
|
128
|
-
openWrtInfo.systemInfo = systemInfo;
|
|
129
|
-
openWrtInfo.wirelessStatus = wirelessStatus;
|
|
130
|
-
openWrtInfo.wirelessRadios = wirelessRadios;
|
|
131
|
-
openWrtInfo.ssids = ssids;
|
|
132
|
-
|
|
133
|
-
if (this.logDebug) this.emit("debug", `OpenWrt Data: ${JSON.stringify(openWrtInfo, null, 2)}`);
|
|
134
|
-
return openWrtInfo;
|
|
135
143
|
}
|
|
136
144
|
|
|
137
145
|
async send(type, ssidName, state) {
|
|
@@ -160,7 +168,7 @@ class OpenWrt extends EventEmitter {
|
|
|
160
168
|
await this.ubusCall("uci", "commit", { config: "wireless" });
|
|
161
169
|
await this.ubusCall("network.wireless", "reload", {});
|
|
162
170
|
|
|
163
|
-
this.emit("
|
|
171
|
+
if (this.logDebug) this.emit("debug", `Send SSID ${ssidName} ${state ? "enabled" : "disabled"}`);
|
|
164
172
|
});
|
|
165
173
|
break;
|
|
166
174
|
case 'switch':
|
package/src/swdevice.js
CHANGED
|
@@ -195,12 +195,12 @@ class SwitchDevice extends EventEmitter {
|
|
|
195
195
|
this.emit('devInfo', `Name: ${this.openWrtInfo.systemInfo.hostname}`);
|
|
196
196
|
this.emit('devInfo', `Model: ${this.openWrtInfo.systemInfo.model}`);
|
|
197
197
|
this.emit('devInfo', `System: ${this.openWrtInfo.systemInfo.system}`);
|
|
198
|
-
this.emit('devInfo', `
|
|
198
|
+
this.emit('devInfo', `Firmware: ${this.openWrtInfo.systemInfo.release?.description}`);
|
|
199
199
|
this.emit('devInfo', `----------------------------------`);
|
|
200
200
|
|
|
201
|
-
//
|
|
201
|
+
//openwrt client
|
|
202
202
|
this.openWrt.on('systemInfo', (info) => {
|
|
203
|
-
this.informationService?.updateCharacteristic(Characteristic.FirmwareRevision, info.release?.
|
|
203
|
+
this.informationService?.updateCharacteristic(Characteristic.FirmwareRevision, info.release?.description);
|
|
204
204
|
})
|
|
205
205
|
.on('switchStatus', async (status) => {
|
|
206
206
|
})
|