iobroker.bmw 2.5.0 → 2.5.3
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/io-package.json +11 -1
- package/lib/extractKeys.js +1 -1
- package/main.js +37 -11
- package/package.json +59 -59
package/io-package.json
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"common": {
|
|
3
3
|
"name": "bmw",
|
|
4
|
-
"version": "2.5.
|
|
4
|
+
"version": "2.5.3",
|
|
5
5
|
"news": {
|
|
6
|
+
"2.5.3": {
|
|
7
|
+
"en": "Fix login"
|
|
8
|
+
},
|
|
9
|
+
"2.5.2": {
|
|
10
|
+
"en": "Bugfixes"
|
|
11
|
+
},
|
|
12
|
+
"2.5.1": {
|
|
13
|
+
"en": "Add login error message",
|
|
14
|
+
"de": "Loginproblem Nachricht hinzugefügt"
|
|
15
|
+
},
|
|
6
16
|
"2.5.0": {
|
|
7
17
|
"en": "Fix Login",
|
|
8
18
|
"de": "Loginproblem behoben"
|
package/lib/extractKeys.js
CHANGED
|
@@ -324,7 +324,7 @@ const description = {
|
|
|
324
324
|
cbsType: "Service Art",
|
|
325
325
|
VEHICLE_CHECK: "Fahrzeug Überprüfung",
|
|
326
326
|
position: "Position",
|
|
327
|
-
heading: "
|
|
327
|
+
heading: "Richtung",
|
|
328
328
|
lat: "Latitude",
|
|
329
329
|
lon: "Longitude",
|
|
330
330
|
DCS_CCH_Activation: "DCS CCH Aktivierung",
|
package/main.js
CHANGED
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
const utils = require("@iobroker/adapter-core");
|
|
10
10
|
const axios = require("axios");
|
|
11
11
|
|
|
12
|
+
const { HttpsCookieAgent } = require("http-cookie-agent");
|
|
12
13
|
const crypto = require("crypto");
|
|
13
14
|
const qs = require("qs");
|
|
14
15
|
const { extractKeys } = require("./lib/extractKeys");
|
|
15
|
-
const axiosCookieJarSupport = require("axios-cookiejar-support").default;
|
|
16
16
|
const tough = require("tough-cookie");
|
|
17
17
|
class Bmw extends utils.Adapter {
|
|
18
18
|
/**
|
|
@@ -38,9 +38,15 @@ class Bmw extends utils.Adapter {
|
|
|
38
38
|
this.log.info("Set interval to minimum 0.5");
|
|
39
39
|
this.config.interval = 0.5;
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
this.requestClient = axios.create(
|
|
41
|
+
this.cookieJar = new tough.CookieJar(null, { ignoreError: true });
|
|
42
|
+
|
|
43
|
+
this.requestClient = axios.create({
|
|
44
|
+
jar: this.cookieJar,
|
|
45
|
+
withCredentials: true,
|
|
46
|
+
httpsAgent: new HttpsCookieAgent({
|
|
47
|
+
jar: this.cookieJar,
|
|
48
|
+
}),
|
|
49
|
+
});
|
|
44
50
|
this.updateInterval = null;
|
|
45
51
|
this.reLoginTimeout = null;
|
|
46
52
|
this.refreshTokenTimeout = null;
|
|
@@ -50,10 +56,13 @@ class Bmw extends utils.Adapter {
|
|
|
50
56
|
this.statusBlock = {};
|
|
51
57
|
this.nonChargingHistory = {};
|
|
52
58
|
this.subscribeStates("*");
|
|
53
|
-
|
|
59
|
+
if (!this.config.username || !this.config.password) {
|
|
60
|
+
this.log.error("Please set username and password");
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
54
63
|
await this.login();
|
|
55
64
|
if (this.session.access_token) {
|
|
56
|
-
await this.getVehicles();
|
|
65
|
+
// await this.getVehicles(); //old depracted api
|
|
57
66
|
await this.cleanObjects();
|
|
58
67
|
await this.getVehiclesv2();
|
|
59
68
|
this.updateInterval = setInterval(async () => {
|
|
@@ -85,6 +94,7 @@ class Bmw extends utils.Adapter {
|
|
|
85
94
|
password: this.config.password,
|
|
86
95
|
grant_type: "authorization_code",
|
|
87
96
|
};
|
|
97
|
+
|
|
88
98
|
const authUrl = await this.requestClient({
|
|
89
99
|
method: "post",
|
|
90
100
|
url: "https://customer.bmwgroup.com/gcdm/oauth/authenticate",
|
|
@@ -98,12 +108,19 @@ class Bmw extends utils.Adapter {
|
|
|
98
108
|
return res.data;
|
|
99
109
|
})
|
|
100
110
|
.catch((error) => {
|
|
111
|
+
this.log.error("Login failed");
|
|
101
112
|
this.log.error(error);
|
|
102
113
|
if (error.response) {
|
|
103
114
|
this.log.error(JSON.stringify(error.response.data));
|
|
104
115
|
}
|
|
105
116
|
if (error.response && error.response.status === 401) {
|
|
106
|
-
this.log.error("Please check username and password");
|
|
117
|
+
this.log.error("Please check username and password or too many logins in 5 minutes");
|
|
118
|
+
|
|
119
|
+
this.log.error("Start relogin in 5min");
|
|
120
|
+
this.reLoginTimeout && clearTimeout(this.reLoginTimeout);
|
|
121
|
+
this.reLoginTimeout = setTimeout(() => {
|
|
122
|
+
this.login();
|
|
123
|
+
}, 5000 * 60 * 1);
|
|
107
124
|
}
|
|
108
125
|
if (error.response && error.response.status === 400) {
|
|
109
126
|
this.log.error("Please check username and password");
|
|
@@ -125,6 +142,7 @@ class Bmw extends utils.Adapter {
|
|
|
125
142
|
data: qs.stringify(data),
|
|
126
143
|
jar: this.cookieJar,
|
|
127
144
|
withCredentials: true,
|
|
145
|
+
maxRedirects: 0,
|
|
128
146
|
})
|
|
129
147
|
.then((res) => {
|
|
130
148
|
this.log.debug(JSON.stringify(res.data));
|
|
@@ -132,16 +150,18 @@ class Bmw extends utils.Adapter {
|
|
|
132
150
|
})
|
|
133
151
|
.catch((error) => {
|
|
134
152
|
let code = "";
|
|
135
|
-
if (error.response && error.response.status
|
|
153
|
+
if (error.response && error.response.status >= 400) {
|
|
136
154
|
this.log.error(JSON.stringify(error.response.data));
|
|
137
155
|
return;
|
|
138
156
|
}
|
|
139
|
-
if (error.
|
|
140
|
-
this.log.debug(JSON.stringify(error.
|
|
141
|
-
code = qs.parse(error.
|
|
157
|
+
if (error.response.status === 302) {
|
|
158
|
+
this.log.debug(JSON.stringify(error.response.headers.location));
|
|
159
|
+
code = qs.parse(error.response.headers.location.split("?")[1]).code;
|
|
142
160
|
this.log.debug(code);
|
|
143
161
|
return code;
|
|
144
162
|
}
|
|
163
|
+
this.log.error(error);
|
|
164
|
+
return;
|
|
145
165
|
});
|
|
146
166
|
await this.requestClient({
|
|
147
167
|
method: "post",
|
|
@@ -165,6 +185,7 @@ class Bmw extends utils.Adapter {
|
|
|
165
185
|
return res.data;
|
|
166
186
|
})
|
|
167
187
|
.catch((error) => {
|
|
188
|
+
this.log.error("Login step 3 failed");
|
|
168
189
|
this.log.error(error);
|
|
169
190
|
if (error.response) {
|
|
170
191
|
this.log.error(JSON.stringify(error.response.data));
|
|
@@ -224,6 +245,7 @@ class Bmw extends utils.Adapter {
|
|
|
224
245
|
}
|
|
225
246
|
})
|
|
226
247
|
.catch((error) => {
|
|
248
|
+
this.log.error("getVehicles failed");
|
|
227
249
|
this.log.error(error);
|
|
228
250
|
error.response && this.log.error(JSON.stringify(error.response.data));
|
|
229
251
|
});
|
|
@@ -300,6 +322,7 @@ class Bmw extends utils.Adapter {
|
|
|
300
322
|
}
|
|
301
323
|
})
|
|
302
324
|
.catch((error) => {
|
|
325
|
+
this.log.error("getvehicles v2 failed");
|
|
303
326
|
this.log.error(error);
|
|
304
327
|
});
|
|
305
328
|
}
|
|
@@ -360,6 +383,7 @@ class Bmw extends utils.Adapter {
|
|
|
360
383
|
this.nonChargingHistory[vin] = true;
|
|
361
384
|
return;
|
|
362
385
|
}
|
|
386
|
+
this.log.error("updateChargingSessionv2 failed");
|
|
363
387
|
this.log.error(element.url);
|
|
364
388
|
this.log.error(error);
|
|
365
389
|
error.response && this.log.error(JSON.stringify(error.response.data));
|
|
@@ -428,6 +452,7 @@ class Bmw extends utils.Adapter {
|
|
|
428
452
|
this.log.error(error);
|
|
429
453
|
error.response && this.log.error(JSON.stringify(error.response.data));
|
|
430
454
|
this.log.error("Start relogin in 1min");
|
|
455
|
+
this.reLoginTimeout && clearTimeout(this.reLoginTimeout);
|
|
431
456
|
this.reLoginTimeout = setTimeout(() => {
|
|
432
457
|
this.login();
|
|
433
458
|
}, 1000 * 60 * 1);
|
|
@@ -499,6 +524,7 @@ class Bmw extends utils.Adapter {
|
|
|
499
524
|
return res.data;
|
|
500
525
|
})
|
|
501
526
|
.catch((error) => {
|
|
527
|
+
this.log.error("Remote command failed");
|
|
502
528
|
this.log.error(error);
|
|
503
529
|
if (error.response) {
|
|
504
530
|
this.log.error(JSON.stringify(error.response.data));
|
package/package.json
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
2
|
+
"name": "iobroker.bmw",
|
|
3
|
+
"version": "2.5.3",
|
|
4
|
+
"description": "Adapter for BMW",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "TA2k",
|
|
7
|
+
"email": "tombox2020@gmail.com"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://github.com/TA2k/ioBroker.bmw",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"keywords": [
|
|
12
|
+
"BMW"
|
|
13
|
+
],
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/TA2k/ioBroker.bmw"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@iobroker/adapter-core": "^2.6.0",
|
|
20
|
+
"axios": "^0.26.1",
|
|
21
|
+
"http-cookie-agent": "^1.0.5",
|
|
22
|
+
"json-bigint": "^1.0.0",
|
|
23
|
+
"qs": "^6.10.3",
|
|
24
|
+
"tough-cookie": "^4.0.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@alcalzone/release-script": "^2.2.2",
|
|
28
|
+
"@iobroker/adapter-dev": "^1.0.0",
|
|
29
|
+
"@iobroker/testing": "^2.5.4",
|
|
30
|
+
"@types/chai": "^4.3.0",
|
|
31
|
+
"@types/chai-as-promised": "^7.1.5",
|
|
32
|
+
"@types/mocha": "^9.1.0",
|
|
33
|
+
"@types/node": "^14.18.12",
|
|
34
|
+
"@types/proxyquire": "^1.3.28",
|
|
35
|
+
"@types/sinon": "^10.0.11",
|
|
36
|
+
"@types/sinon-chai": "^3.2.8",
|
|
37
|
+
"chai": "^4.3.6",
|
|
38
|
+
"chai-as-promised": "^7.1.1",
|
|
39
|
+
"eslint": "^8.10.0",
|
|
40
|
+
"mocha": "^9.2.1",
|
|
41
|
+
"proxyquire": "^2.1.3",
|
|
42
|
+
"sinon": "^13.0.1",
|
|
43
|
+
"sinon-chai": "^3.7.0",
|
|
44
|
+
"typescript": "~4.5.5"
|
|
45
|
+
},
|
|
46
|
+
"main": "main.js",
|
|
47
|
+
"scripts": {
|
|
48
|
+
"test:js": "mocha --config test/mocharc.custom.json \"{!(node_modules|test)/**/*.test.js,*.test.js,test/**/test!(PackageFiles|Startup).js}\"",
|
|
49
|
+
"test:package": "mocha test/package --exit",
|
|
50
|
+
"test:unit": "mocha test/unit --exit",
|
|
51
|
+
"test:integration": "mocha test/integration --exit",
|
|
52
|
+
"test": "npm run test:js && npm run test:package",
|
|
53
|
+
"check": "tsc --noEmit -p tsconfig.check.json",
|
|
54
|
+
"lint": "eslint"
|
|
55
|
+
},
|
|
56
|
+
"bugs": {
|
|
57
|
+
"url": "https://github.com/TA2k/ioBroker.bmw/issues"
|
|
58
|
+
},
|
|
59
|
+
"readmeFilename": "README.md"
|
|
60
|
+
}
|