iobroker.bmw 2.6.2 → 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 +9 -1
  2. package/main.js +39 -11
  3. package/package.json +15 -15
package/io-package.json CHANGED
@@ -1,8 +1,16 @@
1
1
  {
2
2
  "common": {
3
3
  "name": "bmw",
4
- "version": "2.6.2",
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
+ },
10
+ "2.6.3": {
11
+ "en": "Add start and stop charging remotes",
12
+ "de": "Start und Stop Charging Remotes hinzugefügt"
13
+ },
6
14
  "2.6.2": {
7
15
  "en": "Fix Charging response parsing",
8
16
  "de": "Fix Charging Antwort Verarbeitung"
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",
@@ -433,6 +436,8 @@ class Bmw extends utils.Adapter {
433
436
  { command: "vehicle-finder" },
434
437
  { command: "climate-now_START" },
435
438
  { command: "climate-now_STOP" },
439
+ { command: "start-charging" },
440
+ { command: "stop-charging" },
436
441
  { command: "force-refresh", name: "Force Refresh" },
437
442
  ];
438
443
  remoteArray.forEach((remote) => {
@@ -453,8 +458,7 @@ class Bmw extends utils.Adapter {
453
458
  descriptions: this.description,
454
459
  });
455
460
 
456
- await this.sleep(5000);
457
- this.updateChargingSessionv2(vehicle.vin);
461
+ await this.updateChargingSessionv2(vehicle.vin);
458
462
  }
459
463
  })
460
464
  .catch((error) => {
@@ -487,11 +491,26 @@ class Bmw extends utils.Adapter {
487
491
  this.log.debug(JSON.stringify(res.data));
488
492
  this.json2iob.parse(vin, res.data, { forceIndex: true, descriptions: this.description });
489
493
  })
490
- .catch((error) => {
491
- 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");
492
509
  this.log.error(error);
493
510
  error.response && this.log.error(JSON.stringify(error.response.data));
494
511
  });
512
+ await this.updateChargingSessionv2(vin);
513
+ await this.sleep(10000);
495
514
  }
496
515
  }
497
516
  sleep(ms) {
@@ -501,6 +520,12 @@ class Bmw extends utils.Adapter {
501
520
  if (this.nonChargingHistory[vin]) {
502
521
  return;
503
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();
504
529
  const headers = {
505
530
  "user-agent": this.userAgentDart,
506
531
  "x-user-agent": this.xuserAgent.replace(";brand;", `;${this.config.brand};`),
@@ -534,6 +559,8 @@ class Bmw extends utils.Adapter {
534
559
  name: "charging statistics",
535
560
  });
536
561
  for (const element of urlArray) {
562
+ await this.sleep(10000);
563
+ this.log.debug("update " + vin + element.path);
537
564
  await this.requestClient({
538
565
  method: "get",
539
566
  url: element.url,
@@ -580,7 +607,7 @@ class Bmw extends utils.Adapter {
580
607
  })
581
608
  .catch((error) => {
582
609
  if (error.response) {
583
- this.log.info("No charging session available. Ignore " + vin + "until restart");
610
+ this.log.info("No charging session available. Ignore " + vin + " until restart");
584
611
  this.nonChargingHistory[vin] = true;
585
612
  return;
586
613
  }
@@ -632,6 +659,7 @@ class Bmw extends utils.Adapter {
632
659
  }
633
660
 
634
661
  async refreshToken() {
662
+ this.log.debug("refresh token");
635
663
  await this.requestClient({
636
664
  method: "post",
637
665
  url: "https://customer.bmwgroup.com/gcdm/oauth/token",
@@ -714,7 +742,7 @@ class Bmw extends utils.Adapter {
714
742
  if (action) {
715
743
  url += "?action=" + action;
716
744
  }
717
-
745
+ this.log.debug("Send remote command " + command + " to " + vin);
718
746
  await this.requestClient({
719
747
  method: "post",
720
748
  url: url,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iobroker.bmw",
3
- "version": "2.6.2",
3
+ "version": "2.7.0",
4
4
  "description": "Adapter for BMW",
5
5
  "author": {
6
6
  "name": "TA2k",
@@ -16,31 +16,31 @@
16
16
  "url": "https://github.com/TA2k/ioBroker.bmw"
17
17
  },
18
18
  "dependencies": {
19
- "@iobroker/adapter-core": "^2.6.8",
20
- "axios": "^1.4.0",
19
+ "@iobroker/adapter-core": "^3.0.4",
20
+ "axios": "^1.6.2",
21
21
  "http-cookie-agent": "^5.0.4",
22
22
  "json-bigint": "^1.0.0",
23
- "json2iob": "^2.4.5",
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.5",
30
- "@types/chai-as-promised": "^7.1.5",
31
- "@types/mocha": "^10.0.1",
32
- "@types/node": "^18.17.3",
33
- "@types/proxyquire": "^1.3.28",
34
- "@types/sinon": "^10.0.16",
35
- "@types/sinon-chai": "^3.2.9",
36
- "chai": "^4.3.7",
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
+ "chai": "^4.3.10",
37
37
  "chai-as-promised": "^7.1.1",
38
- "eslint": "^8.46.0",
38
+ "eslint": "^8.55.0",
39
39
  "mocha": "^10.2.0",
40
40
  "proxyquire": "^2.1.3",
41
- "sinon": "^15.2.0",
41
+ "sinon": "^17.0.1",
42
42
  "sinon-chai": "^3.7.0",
43
- "typescript": "^5.1.6"
43
+ "typescript": "^5.3.2"
44
44
  },
45
45
  "main": "main.js",
46
46
  "scripts": {