homebridge-openwrt-control 0.3.5 → 0.3.6-beta.0

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.3.5",
4
+ "version": "0.3.6-beta.0",
5
5
  "description": "Homebridge plugin to control OpenWrt flashed devices.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -30,12 +30,12 @@
30
30
  "LICENSE"
31
31
  ],
32
32
  "engines": {
33
- "homebridge": "^1.8.0 || ^2.0.0 || ^2.0.0-beta.80 || ^2.0.0-alpha.63",
34
- "node": "^20 || ^22 || ^24 || ^25"
33
+ "homebridge": "^1.8.0 || ^2.0.0",
34
+ "node": "^20 || ^22 || ^24 || ^25 || ^26"
35
35
  },
36
36
  "dependencies": {
37
37
  "mqtt": "^5.15.1",
38
- "axios": "^1.15.0",
38
+ "axios": "^1.16.0",
39
39
  "express": "^5.2.1"
40
40
  },
41
41
  "keywords": [
package/src/openwrt.js CHANGED
@@ -1,14 +1,13 @@
1
1
  import EventEmitter from 'events';
2
2
  import axios from 'axios';
3
- import Functions from './functions.js';
4
3
  import ImpulseGenerator from './impulsegenerator.js';
5
- import { AclPath, AclData } from './constants.js';
6
4
 
7
5
  class OpenWrt extends EventEmitter {
8
6
  constructor(config) {
9
7
  super();
10
8
  this.user = config.auth?.user || 'root';
11
9
  this.passwd = config.auth?.passwd;
10
+ this.logWarn = config.log?.warn;
12
11
  this.logError = config.log?.error;
13
12
  this.logDebug = config.log?.debug;
14
13
 
@@ -16,8 +15,6 @@ class OpenWrt extends EventEmitter {
16
15
  this.sessionId = null;
17
16
  this.sessionExpiresAt = 0;
18
17
 
19
- this.functions = new Functions();
20
-
21
18
  const baseUrl = `http://${config.host}/ubus`;
22
19
  this.axiosInstance = axios.create({
23
20
  baseURL: baseUrl,
package/src/restful.js CHANGED
@@ -72,7 +72,7 @@ class RestFul extends EventEmitter {
72
72
  }
73
73
 
74
74
  update(path, data) {
75
- if (this.restFulData.hasOwnProperty(path)) {
75
+ if (Object.hasOwn(this.restFulData, path)) {
76
76
  this.restFulData[path] = data;
77
77
  } else {
78
78
  if (this.logWarn) this.emit('warn', `Unknown RESTFul update path: ${path}, data: ${JSON.stringify(data)}`);
package/src/router.js CHANGED
@@ -27,6 +27,7 @@ class Router extends EventEmitter {
27
27
  this.buttons = (config.buttons ?? []).filter(b => (b.displayType ?? 0) > 0);
28
28
  this.logDeviceInfo = config.log?.deviceInfo || false;
29
29
  this.logInfo = config.log?.info || false;
30
+ this.logWarn = config.log?.warn || false;
30
31
  this.logDebug = config.log?.debug || false;
31
32
 
32
33
  // external integrations
@@ -184,6 +185,7 @@ class Router extends EventEmitter {
184
185
  if (this.restFul.enable) {
185
186
  this.restFul1 = new RestFul({
186
187
  port: this.restFul.port || 3000,
188
+ logWarn: this.logWarn,
187
189
  logDebug: this.logDebug
188
190
  })
189
191
  .on('connected', msg => {
@@ -206,6 +208,7 @@ class Router extends EventEmitter {
206
208
  prefix: this.mqtt.prefix ? `${this.openWrtInfo.systemInfo.model}/${this.mqtt.prefix}/${this.name}` : `${this.openWrtInfo.systemInfo.model}/${this.name}`,
207
209
  user: this.mqtt.auth?.user,
208
210
  passwd: this.mqtt.auth?.passwd,
211
+ logWarn: this.logWarn,
209
212
  logDebug: this.logDebug
210
213
  })
211
214
  .on('connected', msg => {
@@ -228,11 +231,11 @@ class Router extends EventEmitter {
228
231
 
229
232
  switch (key) {
230
233
  case 'SystemReboot':
231
- return this.openWrt.send('externalIntegration', null, null, null, 0);
234
+ return this.openWrt.send('externalIntegration', null, null, null, null, 0);
232
235
  case 'NetworkReload':
233
- return this.openWrt.send('externalIntegration', null, null, null, 1);
236
+ return this.openWrt.send('externalIntegration', null, null, null, null, 1);
234
237
  case 'WirelessReload':
235
- return this.openWrt.send('externalIntegration', null, null, null, 2);
238
+ return this.openWrt.send('externalIntegration', null, null, null, null, 2);
236
239
  default:
237
240
  this.emit('warn', `${integration} unknown key ${key}`);
238
241
  return false;
@@ -245,7 +248,7 @@ class Router extends EventEmitter {
245
248
  const radioId = `radio:${name}:${band}`;
246
249
  const convertedBand = band === '2g' ? '2.4GHz' : band === '5g' ? '5GHz' : '';
247
250
 
248
- const getCurrent = () => this.openWrtInfo.wirelessSsids.find(r => r.name === name && r.band === band);
251
+ const getCurrent = () => this.openWrtInfo.wirelessRadios.find(r => r.name === name && r.band === band);
249
252
 
250
253
  // control
251
254
  if (this.wirelessRadioControl.displayType > 0) {
@@ -301,11 +304,11 @@ class Router extends EventEmitter {
301
304
  service.getCharacteristic(Characteristic.ConfiguredName)
302
305
  .onGet(async () => {
303
306
  const current = getCurrent();
304
- return current.name;
307
+ return current?.name ?? name;
305
308
  })
306
309
  .onSet(async (value) => {
307
310
  const current = getCurrent();
308
- if (current.name === value) return;
311
+ if (!current || current.name === value) return;
309
312
 
310
313
  await this.openWrt.send('ssid', radio, name, value, !current.disabled, null, false); //{type, radioName, ssidName, newSsidName, state, command, restart}
311
314
  });
@@ -394,7 +397,7 @@ class Router extends EventEmitter {
394
397
  if (!state) return;
395
398
 
396
399
  button.state = true;
397
- await this.openWrt.send('button', null, null, null, button.command, false); //{type, radioName, ssidName, newSsidName, state, command, restart}
400
+ await this.openWrt.send('button', null, null, null, null, button.command, false); //{type, radioName, ssidName, newSsidName, state, command, restart}
398
401
  setTimeout(() => {
399
402
  button.state = false;
400
403
  buttonService.updateCharacteristic(Characteristic.On, false);