homebridge-openwrt-control 0.0.2-beta.48 → 0.0.2-beta.49

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 CHANGED
@@ -99,7 +99,7 @@ class OpenWrtPlatform {
99
99
  continue;
100
100
  }
101
101
 
102
- const type = new DeviceClass(api, deviceConfig)
102
+ const type = new DeviceClass(api, deviceConfig, openWrt, openWrtInfo)
103
103
  .on('devInfo', msg => logLevel.devInfo && log.info(msg))
104
104
  .on('success', msg => logLevel.success && log.success(`Device: ${host} ${name}, ${msg}`))
105
105
  .on('info', msg => log.info(`Device: ${host} ${name}, ${msg}`))
@@ -107,7 +107,7 @@ class OpenWrtPlatform {
107
107
  .on('warn', msg => log.warn(`Device: ${host} ${name}, ${msg}`))
108
108
  .on('error', msg => log.error(`Device: ${host} ${name}, ${msg}`));
109
109
 
110
- const accessory = await type.start(openWrt, openWrtInfo);
110
+ const accessory = await type.start();
111
111
  if (accessory) {
112
112
  api.publishExternalAccessories(PluginName, [accessory]);
113
113
  if (logLevel.success) log.success(`Device: ${host} ${name}, Published as external accessory.`);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "OpenWrt Control",
3
3
  "name": "homebridge-openwrt-control",
4
- "version": "0.0.2-beta.48",
4
+ "version": "0.0.2-beta.49",
5
5
  "description": "Homebridge plugin to control OpenWrt flashed devices.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -25,6 +25,50 @@ class AccessPoint extends EventEmitter {
25
25
  this.mqttConnected = false;
26
26
 
27
27
  //openwrt
28
+ this.openWrt = openWrt;
29
+ this.openWrtInfo = openWrtInfo;
30
+ this.ssids = openWrtInfo.ssids;
31
+
32
+ //openwrt client
33
+ this.openWrt.on('systemInfo', (info) => {
34
+ this.informationService?.updateCharacteristic(Characteristic.FirmwareRevision, info.release?.version);
35
+ })
36
+ .on('networkInfo', async (info) => {
37
+ })
38
+ .on('wirelessStatus', async (status) => {
39
+ })
40
+ .on('wirelessRadios', async (radios) => {
41
+ })
42
+ .on('ssids', async (ssids) => {
43
+ this.ssids = ssids;
44
+
45
+ // sensors
46
+ for (let i = 0; i < ssids.length; i++) {
47
+ const ssid = ssids[i];
48
+ const name = ssid.name;
49
+ const state = ssid.state;
50
+ const serviceName = this.accessPoint.namePrefix ? `${this.name} ${name}` : name;
51
+ this.services?.[i]
52
+ ?.setCharacteristic(Characteristic.ConfiguredName, serviceName)
53
+ .updateCharacteristic(Characteristic.On, state);
54
+
55
+ this.sensorServices?.[i]
56
+ ?.setCharacteristic(Characteristic.ConfiguredName, serviceName)
57
+ .updateCharacteristic(Characteristic.ContactSensorState, !state);
58
+
59
+ if (this.logInfo) {
60
+ this.emit('info', `Name: ${ssid.name}`);
61
+ this.emit('info', `State: ${ssid.state}`);
62
+ this.emit('info', `Mode: ${ssid.mode}`);
63
+ }
64
+ }
65
+ })
66
+ .on('restFul', (path, data) => {
67
+ if (this.restFulConnected) this.restFul1.update(path, data);
68
+ })
69
+ .on('mqtt', (topic, message) => {
70
+ if (this.mqttConnected) this.mqtt1.emit('publish', topic, message);
71
+ });
28
72
 
29
73
  };
30
74
 
@@ -183,11 +227,7 @@ class AccessPoint extends EventEmitter {
183
227
  };
184
228
 
185
229
  //start
186
- async start(openWrt, openWrtInfo) {
187
- this.openWrt = openWrt;
188
- this.openWrtInfo = openWrtInfo;
189
- this.ssids = openWrtInfo.ssids;
190
-
230
+ async start() {
191
231
  try {
192
232
  //start external integrations
193
233
  if (this.restFul.enable || this.mqtt.enable) await this.externalIntegrations();
@@ -201,47 +241,6 @@ class AccessPoint extends EventEmitter {
201
241
  this.emit('devInfo', `SSIDs: ${this.ssids.length}`);
202
242
  this.emit('devInfo', `----------------------------------`);
203
243
 
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('ssids', async (ssids) => {
215
- this.ssids = ssids;
216
-
217
- // sensors
218
- for (let i = 0; i < ssids.length; i++) {
219
- const ssid = ssids[i];
220
- const name = ssid.name;
221
- const state = ssid.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: ${ssid.name}`);
233
- this.emit('info', `State: ${ssid.state}`);
234
- this.emit('info', `Mode: ${ssid.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
244
  //prepare accessory
246
245
  const accessory = await this.prepareAccessory();
247
246
  return accessory;