homebridge-openwrt-control 0.0.2-beta.26 → 0.0.2-beta.28
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 +8 -8
- package/package.json +1 -1
- package/src/apdevice.js +6 -6
- package/src/openwrt.js +0 -1
- package/src/swdevice.js +31 -25
package/index.js
CHANGED
|
@@ -14,7 +14,6 @@ class OpenWrtPlatform {
|
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
16
16
|
this.accessories = [];
|
|
17
|
-
this.devices = [];
|
|
18
17
|
|
|
19
18
|
//check if prefs directory exist
|
|
20
19
|
const prefDir = join(api.user.storagePath(), 'openWrt');
|
|
@@ -61,18 +60,19 @@ class OpenWrtPlatform {
|
|
|
61
60
|
log.info(`Device: ${host} ${name}, Config: ${JSON.stringify(safeConfig, null, 2)}`);
|
|
62
61
|
}
|
|
63
62
|
|
|
63
|
+
const devices = [];
|
|
64
64
|
const refreshInterval = (deviceConfig.refreshInterval ?? 5) * 1000;
|
|
65
|
-
if (deviceConfig.accessPoint?.enable)
|
|
66
|
-
if (deviceConfig.switch?.enable)
|
|
65
|
+
if (deviceConfig.accessPoint?.enable) devices.push('accessPoint');
|
|
66
|
+
if (deviceConfig.switch?.enable) devices.push('switch');
|
|
67
67
|
|
|
68
68
|
if (this.devices.length === 0) return;
|
|
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) {
|
|
@@ -81,7 +81,7 @@ class OpenWrtPlatform {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
try {
|
|
84
|
-
for (const device of
|
|
84
|
+
for (const device of devices) {
|
|
85
85
|
// create impulse generator
|
|
86
86
|
const impulseGenerator = new ImpulseGenerator()
|
|
87
87
|
.on('start', async () => {
|
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
|
|
|
@@ -137,7 +137,7 @@ class AccessPointDevice extends EventEmitter {
|
|
|
137
137
|
|
|
138
138
|
if (this.logDebug) this.emit('debug', `prepare service`);
|
|
139
139
|
|
|
140
|
-
//
|
|
140
|
+
//services
|
|
141
141
|
this.services = [];
|
|
142
142
|
for (const ssid of this.ssids) {
|
|
143
143
|
const name = ssid.name;
|
|
@@ -198,6 +198,7 @@ class AccessPointDevice extends EventEmitter {
|
|
|
198
198
|
this.emit('devInfo', `Kernel: ${this.openWrtInfo.systemInfo.kernel}`);
|
|
199
199
|
this.emit('devInfo', `Firmware: ${this.openWrtInfo.systemInfo.release?.description}`);
|
|
200
200
|
this.emit('devInfo', `Target: ${this.openWrtInfo.systemInfo.release?.target}`);
|
|
201
|
+
this.emit('devInfo', `SSIDs: ${this.ssids.length}`);
|
|
201
202
|
this.emit('devInfo', `----------------------------------`);
|
|
202
203
|
|
|
203
204
|
//openwrt client
|
|
@@ -214,7 +215,6 @@ class AccessPointDevice extends EventEmitter {
|
|
|
214
215
|
// sensors
|
|
215
216
|
for (let i = 0; i < ssids.length; i++) {
|
|
216
217
|
const ssid = ssids[i];
|
|
217
|
-
|
|
218
218
|
const name = ssid.name;
|
|
219
219
|
const state = ssid.state;
|
|
220
220
|
const serviceName = this.accessPoint.namePrefix ? `${this.name} ${name}` : name;
|
|
@@ -227,8 +227,8 @@ class AccessPointDevice extends EventEmitter {
|
|
|
227
227
|
.updateCharacteristic(Characteristic.ContactSensorState, !state);
|
|
228
228
|
|
|
229
229
|
if (this.logInfo) {
|
|
230
|
-
this.emit('info', `
|
|
231
|
-
this.emit('info', `
|
|
230
|
+
this.emit('info', `Name: ${ssid.name}`);
|
|
231
|
+
this.emit('info', `State: ${ssid.state}`);
|
|
232
232
|
this.emit('info', `Mode: ${ssid.mode}`);
|
|
233
233
|
}
|
|
234
234
|
}
|
|
@@ -248,4 +248,4 @@ class AccessPointDevice extends EventEmitter {
|
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
250
|
};
|
|
251
|
-
export default
|
|
251
|
+
export default AccessPoint;
|
package/src/openwrt.js
CHANGED
|
@@ -144,7 +144,6 @@ class OpenWrt extends EventEmitter {
|
|
|
144
144
|
//openWrtInfo.wirelessRadios = wirelessRadios;
|
|
145
145
|
openWrtInfo.ssids = ssids;
|
|
146
146
|
|
|
147
|
-
if (this.logDebug) this.emit('debug', `OpenWrt Data: ${JSON.stringify(openWrtInfo, null, 2)}`);
|
|
148
147
|
return openWrtInfo;
|
|
149
148
|
} catch (error) {
|
|
150
149
|
if (this.logError) this.emit('error', `Connect error: ${error.message}`);
|
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;
|