homebridge-openwrt-control 0.0.2-beta.24 → 0.0.2-beta.26

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/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.24",
4
+ "version": "0.0.2-beta.26",
5
5
  "description": "Homebridge plugin to control OpenWrt flashed devices.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
package/src/apdevice.js CHANGED
@@ -12,6 +12,7 @@ class AccessPointDevice extends EventEmitter {
12
12
  AccessoryUUID = api.hap.uuid;
13
13
 
14
14
  //config
15
+ this.host = config.host;
15
16
  this.name = config.accessPoint.name || openWrtInfo.systemInfo.hostname;
16
17
  this.accessPoint = config.accessPoint;
17
18
  this.logInfo = config.log?.info || false;
@@ -121,17 +122,17 @@ class AccessPointDevice 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 accessoryUUID = AccessoryUUID.generate(`${this.host}${this.openWrtInfo.systemInfo.hostname}`);
125
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?.description)
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`);
@@ -192,35 +193,38 @@ class AccessPointDevice extends EventEmitter {
192
193
  if (this.restFul.enable || this.mqtt.enable) await this.externalIntegrations();
193
194
 
194
195
  this.emit('devInfo', `-------- Access Point ${this.name} --------`);
195
- this.emit('devInfo', `Name: ${this.openWrtInfo.systemInfo.hostname}`);
196
- this.emit('devInfo', `Model: ${this.openWrtInfo.systemInfo.model}`);
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}`);
199
201
  this.emit('devInfo', `----------------------------------`);
200
202
 
201
203
  //openwrt client
202
204
  this.openWrt.on('systemInfo', (info) => {
203
- this.informationService?.updateCharacteristic(Characteristic.FirmwareRevision, info.release?.description);
205
+ this.informationService?.updateCharacteristic(Characteristic.FirmwareRevision, info.release?.version);
204
206
  })
205
207
  .on('wirelessStatus', async (status) => {
206
208
  })
207
209
  .on('wirelessRadios', async (radios) => {
208
210
  })
209
211
  .on('ssids', async (ssids) => {
212
+ this.ssids = ssids;
213
+
210
214
  // sensors
211
215
  for (let i = 0; i < ssids.length; i++) {
212
216
  const ssid = ssids[i];
213
217
 
214
- const name = ssid[i].name;
215
- const state = ssid[i].state;
218
+ const name = ssid.name;
219
+ const state = ssid.state;
216
220
  const serviceName = this.accessPoint.namePrefix ? `${this.name} ${name}` : name;
217
221
  this.services?.[i]
218
222
  ?.setCharacteristic(Characteristic.ConfiguredName, serviceName)
219
223
  .updateCharacteristic(Characteristic.On, state);
220
224
 
221
225
  this.sensorServices?.[i]
222
- ?.setCharacteristic(Characteristic.ConfiguredName, name)
223
- .updateCharacteristic(Characteristic.ContactSensorState, state ? 0 : 1);
226
+ ?.setCharacteristic(Characteristic.ConfiguredName, serviceName)
227
+ .updateCharacteristic(Characteristic.ContactSensorState, !state);
224
228
 
225
229
  if (this.logInfo) {
226
230
  this.emit('info', `SSID name: ${ssid.name}`);
package/src/openwrt.js CHANGED
@@ -99,26 +99,38 @@ class OpenWrt extends EventEmitter {
99
99
  const openWrtInfo = { state: false, systemInfo: {}, wirelessStatus: {}, wirelessRadios: [], ssids: [] }
100
100
 
101
101
  try {
102
- //const systemInfo = await this.ubusCall('system', 'board');
103
- //if (!this.logDebug) this.emit('debug', `System info data: ${JSON.stringify(systemInfo, null, 2)}`);
104
-
105
- const wirelessStatus = await this.ubusCall('network.wireless', 'status');
106
- if (!this.logDebug) this.emit('debug', `Wireless status data: ${JSON.stringify(wirelessStatus, null, 2)}`);
107
-
108
- const wirelessRadios = Object.values(wirelessStatus.radios).map(radio => ({
109
- name: radio.name,
110
- state: radio.up === true,
111
- interfaces: Object.values(radio.interfaces).map(i => ({
112
- name: i.ssid,
113
- state: i.up === true,
114
- mode: i.mode
115
- }))
116
- }));
117
-
118
- const ssids = wirelessRadios.flatMap(radio => radio.interfaces);
102
+ const systemInfo = await this.ubusCall('system', 'board');
103
+ if (this.logDebug) this.emit('debug', `System info data: ${JSON.stringify(systemInfo, null, 2)}`);
104
+
105
+ //const wirelessStatus = await this.ubusCall('network.wireless', 'status');
106
+ const wirelessStatus = await this.ubusCall('uci', 'get', { config: 'wireless' });
107
+ if (this.logDebug) this.emit('debug', `Wireless status data: ${JSON.stringify(wirelessStatus, null, 2)}`);
108
+
109
+ //const wirelessRadios = Object.values(wirelessStatus.radios).map(radio => ({
110
+ //name: radio.name,
111
+ //state: radio.up === true,
112
+ //interfaces: Object.values(radio.interfaces).map(i => ({
113
+ //name: i.ssid,
114
+ //state: i.up === true,
115
+ //mode: i.mode
116
+ //}))
117
+ //}));
118
+
119
+ //const ssids = wirelessRadios.flatMap(radio => radio.interfaces);
120
+ const ssids = Object.entries(wirelessStatus.values || {}).flatMap(([key, data]) => {
121
+ if (!key.startsWith('wifinet')) return []; // pomijamy wszystko inne
122
+ return [{
123
+ ifname: data['.name'] || key,
124
+ name: data.ssid || null,
125
+ device: data.device || null,
126
+ mode: data.mode || null,
127
+ hidden: data.hidden === '1' || data.hidden === true,
128
+ state: true
129
+ }];
130
+ });
119
131
  this.emit('systemInfo', systemInfo);
120
132
  this.emit('wirelessStatus', wirelessStatus);
121
- this.emit('wirelessRadios', wirelessRadios);
133
+ //this.emit('wirelessRadios', wirelessRadios);
122
134
  this.emit('ssids', ssids);
123
135
 
124
136
  if (this.firstRun) {
@@ -129,7 +141,7 @@ class OpenWrt extends EventEmitter {
129
141
  openWrtInfo.state = true;
130
142
  openWrtInfo.systemInfo = systemInfo;
131
143
  openWrtInfo.wirelessStatus = wirelessStatus;
132
- openWrtInfo.wirelessRadios = wirelessRadios;
144
+ //openWrtInfo.wirelessRadios = wirelessRadios;
133
145
  openWrtInfo.ssids = ssids;
134
146
 
135
147
  if (this.logDebug) this.emit('debug', `OpenWrt Data: ${JSON.stringify(openWrtInfo, null, 2)}`);
@@ -175,5 +187,4 @@ class OpenWrt extends EventEmitter {
175
187
  }
176
188
  }
177
189
 
178
- export default OpenWrt;
179
-
190
+ export default OpenWrt;