homebridge-openwrt-control 0.0.2-beta.49 → 0.0.2-beta.50
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 +1 -1
- package/package.json +1 -1
- package/src/accesspoint.js +6 -5
- package/src/switch.js +41 -44
package/index.js
CHANGED
|
@@ -67,7 +67,7 @@ class OpenWrtPlatform {
|
|
|
67
67
|
.on('start', async () => {
|
|
68
68
|
try {
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
let openWrt = new OpenWrt(deviceConfig)
|
|
71
71
|
.on('success', msg => logLevel.success && log.success(`Device: ${host}, ${msg}`))
|
|
72
72
|
.on('info', msg => log.info(`Device: ${host} ${name}, ${msg}`))
|
|
73
73
|
.on('debug', msg => log.info(`Device: ${host} ${name}, debug: ${msg}`))
|
package/package.json
CHANGED
package/src/accesspoint.js
CHANGED
|
@@ -13,8 +13,9 @@ class AccessPoint extends EventEmitter {
|
|
|
13
13
|
|
|
14
14
|
//config
|
|
15
15
|
this.host = config.host;
|
|
16
|
-
this.name = config.accessPoint
|
|
17
|
-
this.
|
|
16
|
+
this.name = config.accessPoint?.name || openWrtInfo.systemInfo.hostname;
|
|
17
|
+
this.namePrefix = config.accessPoint?.namePrefix || false;
|
|
18
|
+
this.sensorsEnabled = config.accessPoint?.sensor || false
|
|
18
19
|
this.logInfo = config.log?.info || false;
|
|
19
20
|
this.logDebug = config.log?.debug || false;
|
|
20
21
|
|
|
@@ -47,7 +48,7 @@ class AccessPoint extends EventEmitter {
|
|
|
47
48
|
const ssid = ssids[i];
|
|
48
49
|
const name = ssid.name;
|
|
49
50
|
const state = ssid.state;
|
|
50
|
-
const serviceName = this.
|
|
51
|
+
const serviceName = this.namePrefix ? `${this.name} ${name}` : name;
|
|
51
52
|
this.services?.[i]
|
|
52
53
|
?.setCharacteristic(Characteristic.ConfiguredName, serviceName)
|
|
53
54
|
.updateCharacteristic(Characteristic.On, state);
|
|
@@ -185,7 +186,7 @@ class AccessPoint extends EventEmitter {
|
|
|
185
186
|
const name = ssid.name;
|
|
186
187
|
if (this.logDebug) this.emit('debug', `prepare ssid: ${name} service`);
|
|
187
188
|
|
|
188
|
-
const serviceName = this.
|
|
189
|
+
const serviceName = this.namePrefix ? `${accessoryName} ${name}` : name;
|
|
189
190
|
const service = accessory.addService(Service.Switch, serviceName, `service${name}`);
|
|
190
191
|
service.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
191
192
|
service.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
@@ -206,7 +207,7 @@ class AccessPoint extends EventEmitter {
|
|
|
206
207
|
});
|
|
207
208
|
this.services.push(service);
|
|
208
209
|
|
|
209
|
-
if (this.
|
|
210
|
+
if (this.sensorsEnabled) {
|
|
210
211
|
if (this.logDebug) this.emit('debug', `prepare ssid: ${name} sensor service`);
|
|
211
212
|
const sensorService = accessory.addService(Service.ContactSensor, serviceName, `sensorService${name}`);
|
|
212
213
|
sensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
package/src/switch.js
CHANGED
|
@@ -14,7 +14,8 @@ class Switch extends EventEmitter {
|
|
|
14
14
|
//config
|
|
15
15
|
this.host = config.host;
|
|
16
16
|
this.name = config.accessPoint.name || openWrtInfo.systemInfo.hostname;
|
|
17
|
-
this.
|
|
17
|
+
this.namePrefix = config.accessPoint?.namePrefix || false;
|
|
18
|
+
this.sensorsEnabled = config.accessPoint?.sensor || false
|
|
18
19
|
this.logInfo = config.log?.info || false;
|
|
19
20
|
this.logDebug = config.log?.debug || false;
|
|
20
21
|
|
|
@@ -28,6 +29,43 @@ class Switch extends EventEmitter {
|
|
|
28
29
|
this.openWrt = openWrt;
|
|
29
30
|
this.openWrtInfo = openWrtInfo;
|
|
30
31
|
this.ssids = openWrtInfo.ssids;
|
|
32
|
+
|
|
33
|
+
//openwrt client
|
|
34
|
+
this.openWrt.on('systemInfo', (info) => {
|
|
35
|
+
this.informationService?.updateCharacteristic(Characteristic.FirmwareRevision, info.release?.version);
|
|
36
|
+
})
|
|
37
|
+
.on('networkInfo', async (info) => {
|
|
38
|
+
})
|
|
39
|
+
.on('ports', async (ports) => {
|
|
40
|
+
this.ports = ports;
|
|
41
|
+
|
|
42
|
+
// sensors
|
|
43
|
+
for (let i = 0; i < ports.length; i++) {
|
|
44
|
+
const port = ports[i];
|
|
45
|
+
const name = port.name;
|
|
46
|
+
const state = port.state;
|
|
47
|
+
const serviceName = this.namePrefix ? `${this.name} ${name}` : name;
|
|
48
|
+
this.services?.[i]
|
|
49
|
+
?.setCharacteristic(Characteristic.ConfiguredName, serviceName)
|
|
50
|
+
.updateCharacteristic(Characteristic.On, state);
|
|
51
|
+
|
|
52
|
+
this.sensorServices?.[i]
|
|
53
|
+
?.setCharacteristic(Characteristic.ConfiguredName, serviceName)
|
|
54
|
+
.updateCharacteristic(Characteristic.ContactSensorState, !state);
|
|
55
|
+
|
|
56
|
+
if (this.logInfo) {
|
|
57
|
+
this.emit('info', `Name: ${ports.name}`);
|
|
58
|
+
this.emit('info', `State: ${ports.state}`);
|
|
59
|
+
this.emit('info', `Mode: ${ports.mode}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
.on('restFul', (path, data) => {
|
|
64
|
+
if (this.restFulConnected) this.restFul1.update(path, data);
|
|
65
|
+
})
|
|
66
|
+
.on('mqtt', (topic, message) => {
|
|
67
|
+
if (this.mqttConnected) this.mqtt1.emit('publish', topic, message);
|
|
68
|
+
});
|
|
31
69
|
};
|
|
32
70
|
|
|
33
71
|
async externalIntegrations() {
|
|
@@ -144,7 +182,7 @@ class Switch extends EventEmitter {
|
|
|
144
182
|
const name = port.name;
|
|
145
183
|
if (this.logDebug) this.emit('debug', `prepare port: ${name} service`);
|
|
146
184
|
|
|
147
|
-
const serviceName = this.
|
|
185
|
+
const serviceName = this.namePrefix ? `${accessoryName} ${name}` : name;
|
|
148
186
|
const service = accessory.addService(Service.Switch, serviceName, `service${name}`);
|
|
149
187
|
service.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
150
188
|
service.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
@@ -165,7 +203,7 @@ class Switch extends EventEmitter {
|
|
|
165
203
|
});
|
|
166
204
|
this.services.push(service);
|
|
167
205
|
|
|
168
|
-
if (this.
|
|
206
|
+
if (this.sensorsEnabled) {
|
|
169
207
|
if (this.logDebug) this.emit('debug', `prepare port: ${name} sensor service`);
|
|
170
208
|
|
|
171
209
|
const sensorService = accessory.addService(Service.ContactSensor, serviceName, `sensorService${name}`);
|
|
@@ -201,47 +239,6 @@ class Switch extends EventEmitter {
|
|
|
201
239
|
this.emit('devInfo', `Ports: ${this.ports.length}`);
|
|
202
240
|
this.emit('devInfo', `----------------------------------`);
|
|
203
241
|
|
|
204
|
-
//openwrt client
|
|
205
|
-
this.openWrt.on('systemInfo', (info) => {
|
|
206
|
-
this.informationService?.updateCharacteristic(Characteristic.FirmwareRevision, info.release?.version);
|
|
207
|
-
})
|
|
208
|
-
.on('networkInfo', async (info) => {
|
|
209
|
-
})
|
|
210
|
-
.on('wirelessStatus', async (status) => {
|
|
211
|
-
})
|
|
212
|
-
.on('wirelessRadios', async (radios) => {
|
|
213
|
-
})
|
|
214
|
-
.on('ports', async (ports) => {
|
|
215
|
-
this.ports = ports;
|
|
216
|
-
|
|
217
|
-
// sensors
|
|
218
|
-
for (let i = 0; i < ports.length; i++) {
|
|
219
|
-
const port = ports[i];
|
|
220
|
-
const name = port.name;
|
|
221
|
-
const state = port.state;
|
|
222
|
-
const serviceName = this.accessPoint.namePrefix ? `${this.name} ${name}` : name;
|
|
223
|
-
this.services?.[i]
|
|
224
|
-
?.setCharacteristic(Characteristic.ConfiguredName, serviceName)
|
|
225
|
-
.updateCharacteristic(Characteristic.On, state);
|
|
226
|
-
|
|
227
|
-
this.sensorServices?.[i]
|
|
228
|
-
?.setCharacteristic(Characteristic.ConfiguredName, serviceName)
|
|
229
|
-
.updateCharacteristic(Characteristic.ContactSensorState, !state);
|
|
230
|
-
|
|
231
|
-
if (this.logInfo) {
|
|
232
|
-
this.emit('info', `Name: ${ports.name}`);
|
|
233
|
-
this.emit('info', `State: ${ports.state}`);
|
|
234
|
-
this.emit('info', `Mode: ${ports.mode}`);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
})
|
|
238
|
-
.on('restFul', (path, data) => {
|
|
239
|
-
if (this.restFulConnected) this.restFul1.update(path, data);
|
|
240
|
-
})
|
|
241
|
-
.on('mqtt', (topic, message) => {
|
|
242
|
-
if (this.mqttConnected) this.mqtt1.emit('publish', topic, message);
|
|
243
|
-
});
|
|
244
|
-
|
|
245
242
|
//prepare accessory
|
|
246
243
|
const accessory = await this.prepareAccessory();
|
|
247
244
|
return accessory;
|