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