homebridge-openwrt-control 0.0.2-beta.16 → 0.0.2-beta.18

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/openwrt.js +12 -27
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.16",
4
+ "version": "0.0.2-beta.18",
5
5
  "description": "Homebridge plugin to control OpenWrt flashed devices.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
package/src/openwrt.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import EventEmitter from 'events';
2
2
  import axios from 'axios';
3
- import http from 'http';
4
3
  import Functions from './functions.js';
5
4
  import ImpulseGenerator from './impulsegenerator.js';
6
5
 
@@ -25,9 +24,9 @@ class OpenWrt extends EventEmitter {
25
24
 
26
25
  this.functions = new Functions();
27
26
  this.axiosInstance = axios.create({
28
- baseURL: `http://${config.host}/ubus`,
27
+ method: 'POST',
28
+ baseURL: `http://${config.host}`,
29
29
  timeout: 5000,
30
- httpAgent: new http.Agent({ keepAlive: false }),
31
30
  headers: {
32
31
  "Content-Type": "application/json"
33
32
  }
@@ -49,8 +48,7 @@ class OpenWrt extends EventEmitter {
49
48
  try {
50
49
  await fn();
51
50
  } catch (error) {
52
- this.emit('error', `Impulse generator error: ${error.message}`
53
- );
51
+ this.emit('error', `Impulse generator error: ${error.message}`);
54
52
  } finally {
55
53
  this.lock = false;
56
54
  }
@@ -62,26 +60,13 @@ class OpenWrt extends EventEmitter {
62
60
  return this.sessionId;
63
61
  }
64
62
 
65
- const response = await axios.post(
66
- 'http://192.168.1.5/ubus',
67
- JSON.stringify({
68
- jsonrpc: '2.0',
69
- id: 1,
70
- method: 'call',
71
- params: [
72
- '00000000000000000000000000000000',
73
- 'session',
74
- 'login',
75
- { username: 'root', password: this.passwd }
76
- ]
77
- }),
78
- {
79
- headers: {
80
- 'Content-Type': 'application/json',
81
- 'Accept': 'application/json'
82
- }
83
- }
84
- );
63
+ this.emit('debug', `Login: ${this.usere} ${this.passwd}`)
64
+ const response = await this.axiosInstance('/ubus', {
65
+ jsonrpc: '2.0',
66
+ id: 1,
67
+ method: 'call',
68
+ params: ['00000000000000000000000000000000', 'session', 'login', { username: this.user, password: this.passwd }]
69
+ });
85
70
 
86
71
  const result = response.data?.result?.[1];
87
72
  if (!result?.ubus_rpc_session) {
@@ -98,12 +83,12 @@ class OpenWrt extends EventEmitter {
98
83
  async ubusCall(service, method, params = {}) {
99
84
  const session = await this.login();
100
85
 
101
- const response = await this.axiosInstance.post('', JSON.stringify({
86
+ const response = await this.axiosInstance('/ubus', {
102
87
  jsonrpc: '2.0',
103
88
  id: 2,
104
89
  method: 'call',
105
90
  params: [session, service, method, params]
106
- }));
91
+ });
107
92
 
108
93
  if (response.data?.error) {
109
94
  throw new Error(response.data.error.message || 'ubus call error');