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.
- package/package.json +1 -1
- package/src/openwrt.js +10 -23
package/package.json
CHANGED
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
|
-
|
|
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
|
|
66
|
-
'
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
|
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');
|