iobroker.bmw 2.6.3 → 2.7.0

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 (3) hide show
  1. package/io-package.json +5 -1
  2. package/main.js +37 -11
  3. package/package.json +13 -13
package/io-package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "common": {
3
3
  "name": "bmw",
4
- "version": "2.6.3",
4
+ "version": "2.7.0",
5
5
  "news": {
6
+ "2.7.0": {
7
+ "en": "Improve rate limit handling",
8
+ "de": "Rate Limit Handling verbessert"
9
+ },
6
10
  "2.6.3": {
7
11
  "en": "Add start and stop charging remotes",
8
12
  "de": "Start und Stop Charging Remotes hinzugefügt"
package/main.js CHANGED
@@ -37,6 +37,7 @@ class Bmw extends utils.Adapter {
37
37
  this.statusBlock = {};
38
38
  this.nonChargingHistory = {};
39
39
  this.json2iob = new Json2iob(this);
40
+ this.lastChargingSessionUpdate = 0;
40
41
  this.description = {
41
42
  allTrips: "alle Fahrten des Autos",
42
43
  avgCombinedConsumption: "Durchschnittlicher kombinierter Verbrauch",
@@ -194,11 +195,13 @@ class Bmw extends utils.Adapter {
194
195
  await this.cleanObjects();
195
196
  await this.updateDevices();
196
197
  this.updateInterval = setInterval(async () => {
198
+ await this.sleep(2000);
197
199
  await this.updateDevices();
198
200
  }, this.config.interval * 60 * 1000);
199
- this.refreshTokenInterval = setInterval(() => {
200
- this.refreshToken();
201
- }, this.session.expires_in * 1000);
201
+ this.refreshTokenInterval = setInterval(async () => {
202
+ await this.refreshToken();
203
+ await this.sleep(5000);
204
+ }, (this.session.expires_in - 123) * 1000);
202
205
  }
203
206
  }
204
207
  async login() {
@@ -334,7 +337,7 @@ class Bmw extends utils.Adapter {
334
337
  Accept: "*/*",
335
338
  Authorization: "Bearer " + this.session.access_token,
336
339
  };
337
-
340
+ this.log.debug("getVehicles");
338
341
  await this.requestClient({
339
342
  method: "get",
340
343
  url: "https://b2vapi.bmwgroup.com/webapi/v1/user/vehicles",
@@ -386,7 +389,7 @@ class Bmw extends utils.Adapter {
386
389
  host: "cocoapi.bmwgroup.com",
387
390
  "24-hour-format": "true",
388
391
  };
389
-
392
+ this.log.debug("getVehiclesv2");
390
393
  await this.requestClient({
391
394
  method: "get",
392
395
  url: "https://cocoapi.bmwgroup.com/eadrax-vcs/v4/vehicles?apptimezone=120&appDateTime=" + Date.now() + "&tireGuardMode=ENABLED",
@@ -455,8 +458,7 @@ class Bmw extends utils.Adapter {
455
458
  descriptions: this.description,
456
459
  });
457
460
 
458
- await this.sleep(5000);
459
- this.updateChargingSessionv2(vehicle.vin);
461
+ await this.updateChargingSessionv2(vehicle.vin);
460
462
  }
461
463
  })
462
464
  .catch((error) => {
@@ -489,11 +491,26 @@ class Bmw extends utils.Adapter {
489
491
  this.log.debug(JSON.stringify(res.data));
490
492
  this.json2iob.parse(vin, res.data, { forceIndex: true, descriptions: this.description });
491
493
  })
492
- .catch((error) => {
493
- this.log.error("update failed");
494
+ .catch(async (error) => {
495
+ if (error.response && error.response.status === 429) {
496
+ this.log.info(error.response.data.message + " Retry in 5 seconds");
497
+ await this.sleep(5000);
498
+ await this.updateDevices();
499
+ return;
500
+ }
501
+ if (error.response && error.response.status === 403) {
502
+ this.log.warn(error.response.data.message);
503
+ return;
504
+ }
505
+ if (error.response && error.response.status >= 500) {
506
+ this.log.error("BMW Server is not available");
507
+ }
508
+ this.log.error("update failed");
494
509
  this.log.error(error);
495
510
  error.response && this.log.error(JSON.stringify(error.response.data));
496
511
  });
512
+ await this.updateChargingSessionv2(vin);
513
+ await this.sleep(10000);
497
514
  }
498
515
  }
499
516
  sleep(ms) {
@@ -503,6 +520,12 @@ class Bmw extends utils.Adapter {
503
520
  if (this.nonChargingHistory[vin]) {
504
521
  return;
505
522
  }
523
+ if (Date.now() - this.lastChargingSessionUpdate < 1000 * 60 * 60 * 6) {
524
+ this.log.debug("updateChargingSessionv2 to early " + vin);
525
+ return;
526
+ }
527
+ await this.sleep(10000);
528
+ this.lastChargingSessionUpdate = Date.now();
506
529
  const headers = {
507
530
  "user-agent": this.userAgentDart,
508
531
  "x-user-agent": this.xuserAgent.replace(";brand;", `;${this.config.brand};`),
@@ -536,6 +559,8 @@ class Bmw extends utils.Adapter {
536
559
  name: "charging statistics",
537
560
  });
538
561
  for (const element of urlArray) {
562
+ await this.sleep(10000);
563
+ this.log.debug("update " + vin + element.path);
539
564
  await this.requestClient({
540
565
  method: "get",
541
566
  url: element.url,
@@ -582,7 +607,7 @@ class Bmw extends utils.Adapter {
582
607
  })
583
608
  .catch((error) => {
584
609
  if (error.response) {
585
- this.log.info("No charging session available. Ignore " + vin + "until restart");
610
+ this.log.info("No charging session available. Ignore " + vin + " until restart");
586
611
  this.nonChargingHistory[vin] = true;
587
612
  return;
588
613
  }
@@ -634,6 +659,7 @@ class Bmw extends utils.Adapter {
634
659
  }
635
660
 
636
661
  async refreshToken() {
662
+ this.log.debug("refresh token");
637
663
  await this.requestClient({
638
664
  method: "post",
639
665
  url: "https://customer.bmwgroup.com/gcdm/oauth/token",
@@ -716,7 +742,7 @@ class Bmw extends utils.Adapter {
716
742
  if (action) {
717
743
  url += "?action=" + action;
718
744
  }
719
-
745
+ this.log.debug("Send remote command " + command + " to " + vin);
720
746
  await this.requestClient({
721
747
  method: "post",
722
748
  url: url,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iobroker.bmw",
3
- "version": "2.6.3",
3
+ "version": "2.7.0",
4
4
  "description": "Adapter for BMW",
5
5
  "author": {
6
6
  "name": "TA2k",
@@ -17,30 +17,30 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@iobroker/adapter-core": "^3.0.4",
20
- "axios": "^1.5.1",
20
+ "axios": "^1.6.2",
21
21
  "http-cookie-agent": "^5.0.4",
22
22
  "json-bigint": "^1.0.0",
23
- "json2iob": "^2.4.8",
23
+ "json2iob": "^2.4.11",
24
24
  "qs": "^6.11.2",
25
25
  "tough-cookie": "^4.1.3"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@iobroker/testing": "^4.1.0",
29
- "@types/chai": "^4.3.9",
30
- "@types/chai-as-promised": "^7.1.7",
31
- "@types/mocha": "^10.0.3",
32
- "@types/node": "^20.8.7",
33
- "@types/proxyquire": "^1.3.30",
34
- "@types/sinon": "^10.0.20",
35
- "@types/sinon-chai": "^3.2.11",
29
+ "@types/chai": "^4.3.11",
30
+ "@types/chai-as-promised": "^7.1.8",
31
+ "@types/mocha": "^10.0.6",
32
+ "@types/node": "^20.10.3",
33
+ "@types/proxyquire": "^1.3.31",
34
+ "@types/sinon": "^17.0.2",
35
+ "@types/sinon-chai": "^3.2.12",
36
36
  "chai": "^4.3.10",
37
37
  "chai-as-promised": "^7.1.1",
38
- "eslint": "^8.52.0",
38
+ "eslint": "^8.55.0",
39
39
  "mocha": "^10.2.0",
40
40
  "proxyquire": "^2.1.3",
41
- "sinon": "^17.0.0",
41
+ "sinon": "^17.0.1",
42
42
  "sinon-chai": "^3.7.0",
43
- "typescript": "^5.2.2"
43
+ "typescript": "^5.3.2"
44
44
  },
45
45
  "main": "main.js",
46
46
  "scripts": {