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

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 +10 -23
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.17",
5
5
  "description": "Homebridge plugin to control OpenWrt flashed devices.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
package/src/openwrt.js CHANGED
@@ -25,7 +25,8 @@ class OpenWrt extends EventEmitter {
25
25
 
26
26
  this.functions = new Functions();
27
27
  this.axiosInstance = axios.create({
28
- baseURL: `http://${config.host}/ubus`,
28
+ method: 'POST',
29
+ baseURL: `http://${config.host}`,
29
30
  timeout: 5000,
30
31
  httpAgent: new http.Agent({ keepAlive: false }),
31
32
  headers: {
@@ -62,26 +63,12 @@ class OpenWrt extends EventEmitter {
62
63
  return this.sessionId;
63
64
  }
64
65
 
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
- );
66
+ const response = await this.axiosInstance('/ubus', {
67
+ jsonrpc: '2.0',
68
+ id: 1,
69
+ method: 'call',
70
+ params: ['00000000000000000000000000000000', 'session', 'login', { username: this.user, password: this.passwd }]
71
+ });
85
72
 
86
73
  const result = response.data?.result?.[1];
87
74
  if (!result?.ubus_rpc_session) {
@@ -98,12 +85,12 @@ class OpenWrt extends EventEmitter {
98
85
  async ubusCall(service, method, params = {}) {
99
86
  const session = await this.login();
100
87
 
101
- const response = await this.axiosInstance.post('', JSON.stringify({
88
+ const response = await this.axiosInstance('/ubus', {
102
89
  jsonrpc: '2.0',
103
90
  id: 2,
104
91
  method: 'call',
105
92
  params: [session, service, method, params]
106
- }));
93
+ });
107
94
 
108
95
  if (response.data?.error) {
109
96
  throw new Error(response.data.error.message || 'ubus call error');