homebridge-openwrt-control 0.0.2-beta.25 → 0.0.2-beta.27
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 +4 -4
- package/package.json +1 -1
- package/src/apdevice.js +20 -16
- package/src/openwrt.js +27 -17
- package/src/swdevice.js +31 -25
package/index.js
CHANGED
|
@@ -69,10 +69,10 @@ class OpenWrtPlatform {
|
|
|
69
69
|
|
|
70
70
|
const openWrt = new OpenWrt(deviceConfig)
|
|
71
71
|
.on('success', msg => logLevel.success && log.success(`Device: ${host}, ${msg}`))
|
|
72
|
-
.on('info', msg => log.info(`Device: ${host}, ${msg}`))
|
|
73
|
-
.on('debug', msg => log.info(`Device: ${host}, debug: ${msg}`))
|
|
74
|
-
.on('warn', msg => log.warn(`Device: ${host}, ${msg}`))
|
|
75
|
-
.on('error', msg => log.error(`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
76
|
|
|
77
77
|
const openWrtInfo = await openWrt.connect();
|
|
78
78
|
if (!openWrtInfo.state) {
|
package/package.json
CHANGED
package/src/apdevice.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import EventEmitter from 'events';
|
|
2
2
|
let Accessory, Characteristic, Service, Categories, AccessoryUUID;
|
|
3
3
|
|
|
4
|
-
class
|
|
4
|
+
class AccessPoint extends EventEmitter {
|
|
5
5
|
constructor(api, config, openWrt, openWrtInfo) {
|
|
6
6
|
super();
|
|
7
7
|
|
|
@@ -12,6 +12,7 @@ class AccessPointDevice extends EventEmitter {
|
|
|
12
12
|
AccessoryUUID = api.hap.uuid;
|
|
13
13
|
|
|
14
14
|
//config
|
|
15
|
+
this.host = config.host;
|
|
15
16
|
this.name = config.accessPoint.name || openWrtInfo.systemInfo.hostname;
|
|
16
17
|
this.accessPoint = config.accessPoint;
|
|
17
18
|
this.logInfo = config.log?.info || false;
|
|
@@ -121,22 +122,22 @@ class AccessPointDevice extends EventEmitter {
|
|
|
121
122
|
//prepare accessory
|
|
122
123
|
if (this.logDebug) this.emit('debug', `prepare accessory`);
|
|
123
124
|
const accessoryName = this.name;
|
|
124
|
-
const accessoryUUID = AccessoryUUID.generate(this.openWrtInfo.systemInfo.hostname);
|
|
125
|
+
const accessoryUUID = AccessoryUUID.generate(`${this.host}${this.openWrtInfo.systemInfo.hostname}`);
|
|
125
126
|
const accessoryCategory = Categories.AIRPORT;
|
|
126
127
|
const accessory = new Accessory(accessoryName, accessoryUUID, accessoryCategory);
|
|
127
128
|
|
|
128
129
|
//prepare information service
|
|
129
130
|
if (this.logDebug) this.emit('debug', `prepare information service`);
|
|
130
131
|
accessory.getService(Service.AccessoryInformation)
|
|
131
|
-
.setCharacteristic(Characteristic.Manufacturer, 'OpenWrt')
|
|
132
|
+
.setCharacteristic(Characteristic.Manufacturer, this.openWrtInfo.systemInfo.release.distribution || 'OpenWrt')
|
|
132
133
|
.setCharacteristic(Characteristic.Model, this.openWrtInfo.systemInfo.model)
|
|
133
134
|
.setCharacteristic(Characteristic.SerialNumber, this.openWrtInfo.systemInfo.system)
|
|
134
|
-
.setCharacteristic(Characteristic.FirmwareRevision, this.openWrtInfo.systemInfo.release?.
|
|
135
|
+
.setCharacteristic(Characteristic.FirmwareRevision, this.openWrtInfo.systemInfo.release?.version)
|
|
135
136
|
.setCharacteristic(Characteristic.ConfiguredName, accessoryName);
|
|
136
137
|
|
|
137
138
|
if (this.logDebug) this.emit('debug', `prepare service`);
|
|
138
139
|
|
|
139
|
-
//
|
|
140
|
+
//services
|
|
140
141
|
this.services = [];
|
|
141
142
|
for (const ssid of this.ssids) {
|
|
142
143
|
const name = ssid.name;
|
|
@@ -192,39 +193,42 @@ class AccessPointDevice extends EventEmitter {
|
|
|
192
193
|
if (this.restFul.enable || this.mqtt.enable) await this.externalIntegrations();
|
|
193
194
|
|
|
194
195
|
this.emit('devInfo', `-------- Access Point ${this.name} --------`);
|
|
195
|
-
this.emit('devInfo', `
|
|
196
|
-
this.emit('devInfo', `Model: ${this.openWrtInfo.systemInfo.model}`);
|
|
196
|
+
this.emit('devInfo', `Model: ${this.openWrtInfo.systemInfo.model || this.openWrtInfo.systemInfo.board_name}`);
|
|
197
197
|
this.emit('devInfo', `System: ${this.openWrtInfo.systemInfo.system}`);
|
|
198
|
+
this.emit('devInfo', `Kernel: ${this.openWrtInfo.systemInfo.kernel}`);
|
|
198
199
|
this.emit('devInfo', `Firmware: ${this.openWrtInfo.systemInfo.release?.description}`);
|
|
200
|
+
this.emit('devInfo', `Target: ${this.openWrtInfo.systemInfo.release?.target}`);
|
|
201
|
+
this.emit('devInfo', `SSIDs: ${this.ssids.length}`);
|
|
199
202
|
this.emit('devInfo', `----------------------------------`);
|
|
200
203
|
|
|
201
204
|
//openwrt client
|
|
202
205
|
this.openWrt.on('systemInfo', (info) => {
|
|
203
|
-
this.informationService?.updateCharacteristic(Characteristic.FirmwareRevision, info.release?.
|
|
206
|
+
this.informationService?.updateCharacteristic(Characteristic.FirmwareRevision, info.release?.version);
|
|
204
207
|
})
|
|
205
208
|
.on('wirelessStatus', async (status) => {
|
|
206
209
|
})
|
|
207
210
|
.on('wirelessRadios', async (radios) => {
|
|
208
211
|
})
|
|
209
212
|
.on('ssids', async (ssids) => {
|
|
213
|
+
this.ssids = ssids;
|
|
214
|
+
|
|
210
215
|
// sensors
|
|
211
216
|
for (let i = 0; i < ssids.length; i++) {
|
|
212
217
|
const ssid = ssids[i];
|
|
213
|
-
|
|
214
|
-
const
|
|
215
|
-
const state = ssid[i].state;
|
|
218
|
+
const name = ssid.name;
|
|
219
|
+
const state = ssid.state;
|
|
216
220
|
const serviceName = this.accessPoint.namePrefix ? `${this.name} ${name}` : name;
|
|
217
221
|
this.services?.[i]
|
|
218
222
|
?.setCharacteristic(Characteristic.ConfiguredName, serviceName)
|
|
219
223
|
.updateCharacteristic(Characteristic.On, state);
|
|
220
224
|
|
|
221
225
|
this.sensorServices?.[i]
|
|
222
|
-
?.setCharacteristic(Characteristic.ConfiguredName,
|
|
223
|
-
.updateCharacteristic(Characteristic.ContactSensorState, state
|
|
226
|
+
?.setCharacteristic(Characteristic.ConfiguredName, serviceName)
|
|
227
|
+
.updateCharacteristic(Characteristic.ContactSensorState, !state);
|
|
224
228
|
|
|
225
229
|
if (this.logInfo) {
|
|
226
|
-
this.emit('info', `
|
|
227
|
-
this.emit('info', `
|
|
230
|
+
this.emit('info', `Name: ${ssid.name}`);
|
|
231
|
+
this.emit('info', `State: ${ssid.state}`);
|
|
228
232
|
this.emit('info', `Mode: ${ssid.mode}`);
|
|
229
233
|
}
|
|
230
234
|
}
|
|
@@ -244,4 +248,4 @@ class AccessPointDevice extends EventEmitter {
|
|
|
244
248
|
}
|
|
245
249
|
}
|
|
246
250
|
};
|
|
247
|
-
export default
|
|
251
|
+
export default AccessPoint;
|
package/src/openwrt.js
CHANGED
|
@@ -102,23 +102,35 @@ class OpenWrt extends EventEmitter {
|
|
|
102
102
|
const systemInfo = await this.ubusCall('system', 'board');
|
|
103
103
|
if (this.logDebug) this.emit('debug', `System info data: ${JSON.stringify(systemInfo, null, 2)}`);
|
|
104
104
|
|
|
105
|
-
const wirelessStatus = await this.ubusCall('network.wireless', 'status');
|
|
105
|
+
//const wirelessStatus = await this.ubusCall('network.wireless', 'status');
|
|
106
|
+
const wirelessStatus = await this.ubusCall('uci', 'get', { config: 'wireless' });
|
|
106
107
|
if (this.logDebug) this.emit('debug', `Wireless status data: ${JSON.stringify(wirelessStatus, null, 2)}`);
|
|
107
108
|
|
|
108
|
-
const wirelessRadios = Object.values(wirelessStatus.radios).map(radio => ({
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}));
|
|
117
|
-
|
|
118
|
-
const ssids = wirelessRadios.flatMap(radio => radio.interfaces);
|
|
109
|
+
//const wirelessRadios = Object.values(wirelessStatus.radios).map(radio => ({
|
|
110
|
+
//name: radio.name,
|
|
111
|
+
//state: radio.up === true,
|
|
112
|
+
//interfaces: Object.values(radio.interfaces).map(i => ({
|
|
113
|
+
//name: i.ssid,
|
|
114
|
+
//state: i.up === true,
|
|
115
|
+
//mode: i.mode
|
|
116
|
+
//}))
|
|
117
|
+
//}));
|
|
118
|
+
|
|
119
|
+
//const ssids = wirelessRadios.flatMap(radio => radio.interfaces);
|
|
120
|
+
const ssids = Object.entries(wirelessStatus.values || {}).flatMap(([key, data]) => {
|
|
121
|
+
if (!key.startsWith('wifinet')) return []; // pomijamy wszystko inne
|
|
122
|
+
return [{
|
|
123
|
+
ifname: data['.name'] || key,
|
|
124
|
+
name: data.ssid || null,
|
|
125
|
+
device: data.device || null,
|
|
126
|
+
mode: data.mode || null,
|
|
127
|
+
hidden: data.hidden === '1' || data.hidden === true,
|
|
128
|
+
state: true
|
|
129
|
+
}];
|
|
130
|
+
});
|
|
119
131
|
this.emit('systemInfo', systemInfo);
|
|
120
132
|
this.emit('wirelessStatus', wirelessStatus);
|
|
121
|
-
this.emit('wirelessRadios', wirelessRadios);
|
|
133
|
+
//this.emit('wirelessRadios', wirelessRadios);
|
|
122
134
|
this.emit('ssids', ssids);
|
|
123
135
|
|
|
124
136
|
if (this.firstRun) {
|
|
@@ -129,10 +141,9 @@ class OpenWrt extends EventEmitter {
|
|
|
129
141
|
openWrtInfo.state = true;
|
|
130
142
|
openWrtInfo.systemInfo = systemInfo;
|
|
131
143
|
openWrtInfo.wirelessStatus = wirelessStatus;
|
|
132
|
-
openWrtInfo.wirelessRadios = wirelessRadios;
|
|
144
|
+
//openWrtInfo.wirelessRadios = wirelessRadios;
|
|
133
145
|
openWrtInfo.ssids = ssids;
|
|
134
146
|
|
|
135
|
-
if (this.logDebug) this.emit('debug', `OpenWrt Data: ${JSON.stringify(openWrtInfo, null, 2)}`);
|
|
136
147
|
return openWrtInfo;
|
|
137
148
|
} catch (error) {
|
|
138
149
|
if (this.logError) this.emit('error', `Connect error: ${error.message}`);
|
|
@@ -175,5 +186,4 @@ class OpenWrt extends EventEmitter {
|
|
|
175
186
|
}
|
|
176
187
|
}
|
|
177
188
|
|
|
178
|
-
export default OpenWrt;
|
|
179
|
-
|
|
189
|
+
export default OpenWrt;
|
package/src/swdevice.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import EventEmitter from 'events';
|
|
2
2
|
let Accessory, Characteristic, Service, Categories, AccessoryUUID;
|
|
3
3
|
|
|
4
|
-
class
|
|
4
|
+
class Switch extends EventEmitter {
|
|
5
5
|
constructor(api, config, openWrt, openWrtInfo) {
|
|
6
6
|
super();
|
|
7
7
|
|
|
@@ -12,8 +12,9 @@ class SwitchDevice extends EventEmitter {
|
|
|
12
12
|
AccessoryUUID = api.hap.uuid;
|
|
13
13
|
|
|
14
14
|
//config
|
|
15
|
-
this.
|
|
16
|
-
this.
|
|
15
|
+
this.host = config.host;
|
|
16
|
+
this.name = config.accessPoint.name || openWrtInfo.systemInfo.hostname;
|
|
17
|
+
this.accessPoint = config.accessPoint;
|
|
17
18
|
this.logInfo = config.log?.info || false;
|
|
18
19
|
this.logDebug = config.log?.debug || false;
|
|
19
20
|
|
|
@@ -121,29 +122,29 @@ class SwitchDevice extends EventEmitter {
|
|
|
121
122
|
//prepare accessory
|
|
122
123
|
if (this.logDebug) this.emit('debug', `prepare accessory`);
|
|
123
124
|
const accessoryName = this.name;
|
|
124
|
-
const accessoryUUID = AccessoryUUID.generate(this.openWrtInfo.systemInfo.hostname);
|
|
125
|
-
const accessoryCategory = Categories.
|
|
125
|
+
const accessoryUUID = AccessoryUUID.generate(`${this.host}${this.openWrtInfo.systemInfo.hostname}`);
|
|
126
|
+
const accessoryCategory = Categories.AIRPORT;
|
|
126
127
|
const accessory = new Accessory(accessoryName, accessoryUUID, accessoryCategory);
|
|
127
128
|
|
|
128
129
|
//prepare information service
|
|
129
130
|
if (this.logDebug) this.emit('debug', `prepare information service`);
|
|
130
131
|
accessory.getService(Service.AccessoryInformation)
|
|
131
|
-
.setCharacteristic(Characteristic.Manufacturer, 'OpenWrt')
|
|
132
|
+
.setCharacteristic(Characteristic.Manufacturer, this.openWrtInfo.systemInfo.release.distribution || 'OpenWrt')
|
|
132
133
|
.setCharacteristic(Characteristic.Model, this.openWrtInfo.systemInfo.model)
|
|
133
134
|
.setCharacteristic(Characteristic.SerialNumber, this.openWrtInfo.systemInfo.system)
|
|
134
|
-
.setCharacteristic(Characteristic.FirmwareRevision, this.openWrtInfo.systemInfo.release?.
|
|
135
|
+
.setCharacteristic(Characteristic.FirmwareRevision, this.openWrtInfo.systemInfo.release?.version)
|
|
135
136
|
.setCharacteristic(Characteristic.ConfiguredName, accessoryName);
|
|
136
137
|
|
|
137
138
|
if (this.logDebug) this.emit('debug', `prepare service`);
|
|
138
139
|
|
|
139
|
-
//
|
|
140
|
+
//services
|
|
140
141
|
this.services = [];
|
|
141
142
|
for (const port of this.ports) {
|
|
142
143
|
const name = port.name;
|
|
143
144
|
if (this.logDebug) this.emit('debug', `prepare port: ${name} service`);
|
|
144
145
|
|
|
145
|
-
const serviceName = this.accessPoint.namePrefix ? `${accessoryName} ${
|
|
146
|
-
const service = accessory.addService(Service.Switch, serviceName, `service${
|
|
146
|
+
const serviceName = this.accessPoint.namePrefix ? `${accessoryName} ${name}` : name;
|
|
147
|
+
const service = accessory.addService(Service.Switch, serviceName, `service${name}`);
|
|
147
148
|
service.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
148
149
|
service.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
149
150
|
service.getCharacteristic(Characteristic.On)
|
|
@@ -191,39 +192,44 @@ class SwitchDevice extends EventEmitter {
|
|
|
191
192
|
//start external integrations
|
|
192
193
|
if (this.restFul.enable || this.mqtt.enable) await this.externalIntegrations();
|
|
193
194
|
|
|
194
|
-
this.emit('devInfo', `--------
|
|
195
|
-
this.emit('devInfo', `
|
|
196
|
-
this.emit('devInfo', `Model: ${this.openWrtInfo.systemInfo.model}`);
|
|
195
|
+
this.emit('devInfo', `-------- Access Point ${this.name} --------`);
|
|
196
|
+
this.emit('devInfo', `Model: ${this.openWrtInfo.systemInfo.model || this.openWrtInfo.systemInfo.board_name}`);
|
|
197
197
|
this.emit('devInfo', `System: ${this.openWrtInfo.systemInfo.system}`);
|
|
198
|
+
this.emit('devInfo', `Kernel: ${this.openWrtInfo.systemInfo.kernel}`);
|
|
198
199
|
this.emit('devInfo', `Firmware: ${this.openWrtInfo.systemInfo.release?.description}`);
|
|
200
|
+
this.emit('devInfo', `Target: ${this.openWrtInfo.systemInfo.release?.target}`);
|
|
201
|
+
this.emit('devInfo', `Ports: ${this.ports.length}`);
|
|
199
202
|
this.emit('devInfo', `----------------------------------`);
|
|
200
203
|
|
|
201
204
|
//openwrt client
|
|
202
205
|
this.openWrt.on('systemInfo', (info) => {
|
|
203
|
-
this.informationService?.updateCharacteristic(Characteristic.FirmwareRevision, info.release?.
|
|
206
|
+
this.informationService?.updateCharacteristic(Characteristic.FirmwareRevision, info.release?.version);
|
|
204
207
|
})
|
|
205
|
-
.on('
|
|
208
|
+
.on('wirelessStatus', async (status) => {
|
|
206
209
|
})
|
|
207
|
-
.on('
|
|
210
|
+
.on('wirelessRadios', async (radios) => {
|
|
211
|
+
})
|
|
212
|
+
.on('ports', async (ports) => {
|
|
213
|
+
this.ports = ports;
|
|
214
|
+
|
|
208
215
|
// sensors
|
|
209
216
|
for (let i = 0; i < ports.length; i++) {
|
|
210
217
|
const port = ports[i];
|
|
211
|
-
|
|
212
|
-
const
|
|
213
|
-
const state = port[i].state;
|
|
218
|
+
const name = port.name;
|
|
219
|
+
const state = port.state;
|
|
214
220
|
const serviceName = this.accessPoint.namePrefix ? `${this.name} ${name}` : name;
|
|
215
221
|
this.services?.[i]
|
|
216
222
|
?.setCharacteristic(Characteristic.ConfiguredName, serviceName)
|
|
217
223
|
.updateCharacteristic(Characteristic.On, state);
|
|
218
224
|
|
|
219
225
|
this.sensorServices?.[i]
|
|
220
|
-
?.setCharacteristic(Characteristic.ConfiguredName,
|
|
221
|
-
.updateCharacteristic(Characteristic.ContactSensorState, state
|
|
226
|
+
?.setCharacteristic(Characteristic.ConfiguredName, serviceName)
|
|
227
|
+
.updateCharacteristic(Characteristic.ContactSensorState, !state);
|
|
222
228
|
|
|
223
229
|
if (this.logInfo) {
|
|
224
|
-
this.emit('info', `
|
|
225
|
-
this.emit('info', `
|
|
226
|
-
this.emit('info', `Mode: ${
|
|
230
|
+
this.emit('info', `Name: ${ports.name}`);
|
|
231
|
+
this.emit('info', `State: ${ports.state}`);
|
|
232
|
+
this.emit('info', `Mode: ${ports.mode}`);
|
|
227
233
|
}
|
|
228
234
|
}
|
|
229
235
|
})
|
|
@@ -242,4 +248,4 @@ class SwitchDevice extends EventEmitter {
|
|
|
242
248
|
}
|
|
243
249
|
}
|
|
244
250
|
};
|
|
245
|
-
export default
|
|
251
|
+
export default Switch;
|