homebridge-openwrt-control 0.0.2-beta.51 → 0.0.2-beta.53

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
@@ -61,13 +61,12 @@ class OpenWrtPlatform {
61
61
  }
62
62
 
63
63
  try {
64
-
65
64
  // create impulse generator for every device
66
65
  const impulseGenerator = new ImpulseGenerator()
67
66
  .on('start', async () => {
68
67
  try {
69
68
 
70
- let openWrt = new OpenWrt(deviceConfig)
69
+ const openWrt = new OpenWrt(deviceConfig)
71
70
  .on('success', msg => logLevel.success && log.success(`Device: ${host}, ${msg}`))
72
71
  .on('info', msg => log.info(`Device: ${host} ${name}, ${msg}`))
73
72
  .on('debug', msg => log.info(`Device: ${host} ${name}, debug: ${msg}`))
@@ -126,7 +125,6 @@ class OpenWrtPlatform {
126
125
 
127
126
  // start accessory impulse generator
128
127
  await impulseGenerator.state(true, [{ name: 'start', sampling: 120000 }]);
129
-
130
128
  } catch (error) {
131
129
  if (logLevel.error) log.error(`Device: ${host} ${name}, Did finish launching error: ${error.message ?? error}`);
132
130
  }
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.51",
4
+ "version": "0.0.2-beta.53",
5
5
  "description": "Homebridge plugin to control OpenWrt flashed devices.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -1,4 +1,5 @@
1
1
  import EventEmitter from 'events';
2
+ import DeviceUpdate from './deviceupdate.js';
2
3
  let Accessory, Characteristic, Service, Categories, AccessoryUUID;
3
4
 
4
5
  class AccessPoint extends EventEmitter {
@@ -12,6 +13,7 @@ class AccessPoint extends EventEmitter {
12
13
  AccessoryUUID = api.hap.uuid;
13
14
 
14
15
  //config
16
+ this.config = config;
15
17
  this.host = config.host;
16
18
  this.name = config.accessPoint?.name || openWrtInfo.systemInfo.hostname;
17
19
  this.namePrefix = config.accessPoint?.namePrefix || false;
@@ -31,46 +33,39 @@ class AccessPoint extends EventEmitter {
31
33
  this.ssids = openWrtInfo.ssids;
32
34
 
33
35
  //openwrt client
34
- openWrt.on('systemInfo', (info) => {
35
- this.informationService?.updateCharacteristic(Characteristic.FirmwareRevision, info.release?.version);
36
- })
37
- .on('networkInfo', async (info) => {
38
- })
39
- .on('wirelessStatus', async (status) => {
40
- })
41
- .on('wirelessRadios', async (radios) => {
42
- })
43
- .on('ssids', async (ssids) => {
44
- this.ssids = ssids;
45
-
46
- // sensors
47
- for (let i = 0; i < ssids.length; i++) {
48
- const ssid = ssids[i];
49
- const name = ssid.name;
50
- const state = ssid.state;
51
- const serviceName = this.namePrefix ? `${this.name} ${name}` : name;
52
- this.services?.[i]
53
- ?.setCharacteristic(Characteristic.ConfiguredName, serviceName)
54
- .updateCharacteristic(Characteristic.On, state);
55
-
56
- this.sensorServices?.[i]
57
- ?.setCharacteristic(Characteristic.ConfiguredName, serviceName)
58
- .updateCharacteristic(Characteristic.ContactSensorState, !state);
59
-
60
- if (this.logInfo) {
61
- this.emit('info', `Name: ${ssid.name}`);
62
- this.emit('info', `State: ${ssid.state}`);
63
- this.emit('info', `Mode: ${ssid.mode}`);
64
- }
65
- }
66
- })
67
- .on('restFul', (path, data) => {
68
- if (this.restFulConnected) this.restFul1.update(path, data);
69
- })
70
- .on('mqtt', (topic, message) => {
71
- if (this.mqttConnected) this.mqtt1.emit('publish', topic, message);
72
- });
73
36
 
37
+ openWrt.on('openWrtInfo', (openWrtInfo) => {
38
+ this.informationService?.updateCharacteristic(Characteristic.FirmwareRevision, openWrtInfo.systemInfo.release?.version);
39
+ const ssids = openWrtInfo.ssids;
40
+ this.ssids = ssids;
41
+
42
+ // sensors
43
+ for (let i = 0; i < ssids.length; i++) {
44
+ const ssid = ssids[i];
45
+ const name = ssid.name;
46
+ const state = ssid.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: ${ssid.name}`);
58
+ this.emit('info', `State: ${ssid.state}`);
59
+ this.emit('info', `Mode: ${ssid.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
+ });
74
69
  };
75
70
 
76
71
  async externalIntegrations() {
@@ -242,6 +237,8 @@ class AccessPoint extends EventEmitter {
242
237
  this.emit('devInfo', `SSIDs: ${this.ssids.length}`);
243
238
  this.emit('devInfo', `----------------------------------`);
244
239
 
240
+
241
+
245
242
  //prepare accessory
246
243
  const accessory = await this.prepareAccessory();
247
244
  return accessory;
@@ -0,0 +1,34 @@
1
+ import EventEmitter from 'events';
2
+
3
+ class AccessPoint extends EventEmitter {
4
+ constructor(config, openWrt) {
5
+ super();
6
+
7
+ //config
8
+ this.logInfo = config.log?.info || false;
9
+ this.logDebug = config.log?.debug || false;
10
+
11
+ //external integration
12
+ this.restFul = config.restFul || {};
13
+ this.mqtt = config.mqtt || {};
14
+
15
+ //openwrt client
16
+ //openwrt
17
+ this.client = openWrt;
18
+ openWrt.on('openWrtInfo', async (openWrtInfo) => {
19
+ await this.updateState(openWrtInfo);
20
+ });
21
+ };
22
+
23
+ async updateState(openWrtInfo) {
24
+ try {
25
+ const ssids = openWrtInfo.ssids;
26
+ this.emit('ssids', ssids);
27
+
28
+ return true;
29
+ } catch (error) {
30
+ throw new Error(`Chaeck state error: ${error.message}`);
31
+ };
32
+ }
33
+ };
34
+ export default AccessPoint;
package/src/openwrt.js CHANGED
@@ -141,11 +141,7 @@ class OpenWrt extends EventEmitter {
141
141
  }
142
142
 
143
143
  // emit data
144
- this.emit('systemInfo', systemInfo);
145
- //this.emit('networkInfo', networkInfo);
146
- this.emit('wirelessStatus', wirelessStatus);
147
- //this.emit('wirelessRadios', wirelessRadios);
148
- this.emit('ssids', ssids);
144
+ this.emit('openWrtInfo', openWrtInfo);
149
145
 
150
146
  return openWrtInfo;
151
147
  } catch (error) {
package/src/switch.js CHANGED
@@ -26,12 +26,12 @@ class Switch extends EventEmitter {
26
26
  this.mqttConnected = false;
27
27
 
28
28
  //openwrt
29
- this.openWrt = openWrt;
29
+ this.client = openWrt;
30
30
  this.openWrtInfo = openWrtInfo;
31
31
  this.ssids = openWrtInfo.ssids;
32
32
 
33
33
  //openwrt client
34
- this.openWrt.on('systemInfo', (info) => {
34
+ openWrt.on('systemInfo', (info) => {
35
35
  this.informationService?.updateCharacteristic(Characteristic.FirmwareRevision, info.release?.version);
36
36
  })
37
37
  .on('networkInfo', async (info) => {
@@ -142,7 +142,7 @@ class Switch extends EventEmitter {
142
142
  switch (key) {
143
143
  case 'Power':
144
144
  const powerState = value ? 'ON' : 'OFF';
145
- set = await this.openWrt.send('Power', powerState);
145
+ set = await this.client.send('Power', powerState);
146
146
  break;
147
147
  default:
148
148
  this.emit('warn', `${integration}, received key: ${key}, value: ${value}`);