homebridge-openwrt-control 0.0.2-beta.47 → 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
@@ -67,7 +67,6 @@ class OpenWrtPlatform {
67
67
  .on('start', async () => {
68
68
  try {
69
69
 
70
- const refreshInterval = (deviceConfig.refreshInterval ?? 5) * 1000;
71
70
  const openWrt = new OpenWrt(deviceConfig)
72
71
  .on('success', msg => logLevel.success && log.success(`Device: ${host}, ${msg}`))
73
72
  .on('info', msg => log.info(`Device: ${host} ${name}, ${msg}`))
@@ -82,6 +81,7 @@ class OpenWrtPlatform {
82
81
  }
83
82
 
84
83
  // start openwrt impulse generator
84
+ const refreshInterval = (deviceConfig.refreshInterval ?? 5) * 1000;
85
85
  await openWrt.impulseGenerator.state(true, [{ name: 'connect', sampling: refreshInterval }], false);
86
86
 
87
87
  const configuredDevices = [];
@@ -96,7 +96,7 @@ class OpenWrtPlatform {
96
96
 
97
97
  if (!DeviceClass) {
98
98
  if (logLevel.warn) log.warn(`Device: ${host} ${name}, class not found for: ${device}`);
99
- return;
99
+ continue;
100
100
  }
101
101
 
102
102
  const type = new DeviceClass(api, deviceConfig, openWrt, openWrtInfo)
@@ -112,10 +112,10 @@ class OpenWrtPlatform {
112
112
  api.publishExternalAccessories(PluginName, [accessory]);
113
113
  if (logLevel.success) log.success(`Device: ${host} ${name}, Published as external accessory.`);
114
114
  }
115
-
116
- // stop accessory impulse generator
117
- await impulseGenerator.state(false);
118
115
  }
116
+
117
+ // stop accessory impulse generator
118
+ await impulseGenerator.state(false);
119
119
  } catch (error) {
120
120
  if (logLevel.error) log.error(`Device: ${host} ${name}, Start impulse generator error: ${error.message ?? error}, trying again.`);
121
121
  }
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.47",
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",
@@ -28,6 +28,48 @@ class AccessPoint extends EventEmitter {
28
28
  this.openWrt = openWrt;
29
29
  this.openWrtInfo = openWrtInfo;
30
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
+ });
72
+
31
73
  };
32
74
 
33
75
  async externalIntegrations() {
@@ -199,47 +241,6 @@ class AccessPoint extends EventEmitter {
199
241
  this.emit('devInfo', `SSIDs: ${this.ssids.length}`);
200
242
  this.emit('devInfo', `----------------------------------`);
201
243
 
202
- //openwrt client
203
- this.openWrt.on('systemInfo', (info) => {
204
- this.informationService?.updateCharacteristic(Characteristic.FirmwareRevision, info.release?.version);
205
- })
206
- .on('networkInfo', async (info) => {
207
- })
208
- .on('wirelessStatus', async (status) => {
209
- })
210
- .on('wirelessRadios', async (radios) => {
211
- })
212
- .on('ssids', async (ssids) => {
213
- this.ssids = ssids;
214
-
215
- // sensors
216
- for (let i = 0; i < ssids.length; i++) {
217
- const ssid = ssids[i];
218
- const name = ssid.name;
219
- const state = ssid.state;
220
- const serviceName = this.accessPoint.namePrefix ? `${this.name} ${name}` : name;
221
- this.services?.[i]
222
- ?.setCharacteristic(Characteristic.ConfiguredName, serviceName)
223
- .updateCharacteristic(Characteristic.On, state);
224
-
225
- this.sensorServices?.[i]
226
- ?.setCharacteristic(Characteristic.ConfiguredName, serviceName)
227
- .updateCharacteristic(Characteristic.ContactSensorState, !state);
228
-
229
- if (this.logInfo) {
230
- this.emit('info', `Name: ${ssid.name}`);
231
- this.emit('info', `State: ${ssid.state}`);
232
- this.emit('info', `Mode: ${ssid.mode}`);
233
- }
234
- }
235
- })
236
- .on('restFul', (path, data) => {
237
- if (this.restFulConnected) this.restFul1.update(path, data);
238
- })
239
- .on('mqtt', (topic, message) => {
240
- if (this.mqttConnected) this.mqtt1.emit('publish', topic, message);
241
- });
242
-
243
244
  //prepare accessory
244
245
  const accessory = await this.prepareAccessory();
245
246
  return accessory;