iobroker.renault 0.0.14 → 0.0.16

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 +7 -1
  2. package/main.js +48 -14
  3. package/package.json +14 -15
package/io-package.json CHANGED
@@ -1,8 +1,14 @@
1
1
  {
2
2
  "common": {
3
3
  "name": "renault",
4
- "version": "0.0.14",
4
+ "version": "0.0.16",
5
5
  "news": {
6
+ "0.0.16": {
7
+ "en": "update apikey"
8
+ },
9
+ "0.0.15": {
10
+ "en": "fix charge start and reduce error logs"
11
+ },
6
12
  "0.0.14": {
7
13
  "en": "add charging stop"
8
14
  },
package/main.js CHANGED
@@ -7,10 +7,9 @@
7
7
  // The adapter-core module gives you access to the core ioBroker functions
8
8
  // you need to create an adapter
9
9
  const utils = require("@iobroker/adapter-core");
10
- const axios = require("axios");
10
+ const axios = require("axios").default;
11
11
  const qs = require("qs");
12
12
  const Json2iob = require("./lib/json2iob");
13
- const descriptions = require("./lib/descriptions");
14
13
 
15
14
  class Renault extends utils.Adapter {
16
15
  /**
@@ -28,6 +27,7 @@ class Renault extends utils.Adapter {
28
27
  this.json2iob = new Json2iob(this);
29
28
  this.ignoreState = {};
30
29
  this.firstUpdate = true;
30
+ this.requestClient = axios.create();
31
31
  }
32
32
 
33
33
  /**
@@ -40,7 +40,6 @@ class Renault extends utils.Adapter {
40
40
  this.log.info("Set interval to minimum 0.5");
41
41
  this.config.interval = 0.5;
42
42
  }
43
- this.requestClient = axios.create();
44
43
  this.updateInterval = null;
45
44
  this.reLoginTimeout = null;
46
45
  this.refreshTokenTimeout = null;
@@ -48,7 +47,25 @@ class Renault extends utils.Adapter {
48
47
  this.session = {};
49
48
  //DE API Key
50
49
  this.apiKey = "3_7PLksOyBRkHv126x5WhHb-5pqC1qFR8pQjxSeLB6nhAnPERTUlwnYoznHSxwX668";
51
- this.apiKeyUpdate = "VAX7XYKGfa92yMvXculCkEFyfZbuM7Ss";
50
+ this.apiKeyUpdate = "YjkKtHmGfaceeuExUDKGxrLZGGvtVS0J";
51
+ await this.requestClient({
52
+ method: "get",
53
+ url: "https://raw.githubusercontent.com/db-EV/ZoePHP/main/src/api-keys.php",
54
+ })
55
+
56
+ .then((res) => {
57
+ this.log.debug(JSON.stringify(res.data));
58
+ const data = res.data;
59
+ //find kamereon_api via regex
60
+ const regex = /\$kamereon_api\s*=\s*['"]([^'"]+)['"]/;
61
+ const match = data.match(regex);
62
+ if (match && match[1]) {
63
+ this.apiKeyUpdate = match[1];
64
+ }
65
+ })
66
+ .catch((error) => {
67
+ this.log.debug(error);
68
+ });
52
69
  if (this.config.apiKeyUpdate) {
53
70
  this.apiKeyUpdate = this.config.apiKeyUpdate;
54
71
  }
@@ -157,6 +174,7 @@ class Renault extends utils.Adapter {
157
174
  this.log.error("Filtered accounts: " + filteredAccounts);
158
175
  return;
159
176
  }
177
+
160
178
  this.account = filteredAccounts[0];
161
179
  })
162
180
  .catch((error) => {
@@ -235,7 +253,7 @@ class Renault extends utils.Adapter {
235
253
  common: {
236
254
  name: remote.name || "",
237
255
  type: remote.type || "boolean",
238
- role: remote.role || "boolean",
256
+ role: remote.role || "button",
239
257
  write: true,
240
258
  read: true,
241
259
  },
@@ -253,6 +271,10 @@ class Renault extends utils.Adapter {
253
271
  }
254
272
 
255
273
  async updateDevices() {
274
+ if (!this.account.accountId) {
275
+ this.log.error("No accountId found");
276
+ return;
277
+ }
256
278
  const curDate = new Date().toISOString().split("T")[0];
257
279
 
258
280
  const statusArray = [
@@ -423,7 +445,7 @@ class Renault extends utils.Adapter {
423
445
  if (error.response.status === 401) {
424
446
  error.response && this.log.debug(JSON.stringify(error.response.data));
425
447
  this.log.info(element.path + " receive 401 error. Refresh Token in 60 seconds");
426
- clearTimeout(this.refreshTokenTimeout);
448
+ this.refreshTokenTimeout && clearTimeout(this.refreshTokenTimeout);
427
449
  this.refreshTokenTimeout = setTimeout(() => {
428
450
  this.refreshToken();
429
451
  }, 1000 * 60);
@@ -439,6 +461,9 @@ class Renault extends utils.Adapter {
439
461
  error.response.status === 502 ||
440
462
  error.response.status === 400
441
463
  ) {
464
+ if (!this.ignoreState[vin]) {
465
+ this.ignoreState[vin] = [];
466
+ }
442
467
  this.ignoreState[vin].push(element.path);
443
468
  this.log.info("Feature not found for " + vin + ". Ignore " + element.path + " for updates.");
444
469
  this.log.debug(error);
@@ -447,6 +472,10 @@ class Renault extends utils.Adapter {
447
472
  }
448
473
  }
449
474
  }
475
+ if (error.response && error.response.status >= 500) {
476
+ this.log.warn(`Renault Server error: ${error.response.status} `);
477
+ return;
478
+ }
450
479
  this.log.error(url);
451
480
  this.log.error(error);
452
481
  error.response && this.log.error(JSON.stringify(error.response.data));
@@ -502,6 +531,8 @@ class Renault extends utils.Adapter {
502
531
  if (!string) {
503
532
  return;
504
533
  }
534
+ string = string.replace("actions/", "");
535
+ string = string.replace("/", "-");
505
536
  const camelC = string.replace(/-([a-z])/g, function (g) {
506
537
  return g[1].toUpperCase();
507
538
  });
@@ -515,9 +546,9 @@ class Renault extends utils.Adapter {
515
546
  try {
516
547
  this.setState("info.connection", false, true);
517
548
  clearTimeout(this.refreshTimeout);
518
- clearTimeout(this.reLoginTimeout);
519
- clearTimeout(this.refreshTokenTimeout);
520
- clearInterval(this.updateInterval);
549
+ this.reLoginTimeout && clearTimeout(this.reLoginTimeout);
550
+ this.refreshTokenTimeout && clearTimeout(this.refreshTokenTimeout);
551
+ this.updateInterval && clearInterval(this.updateInterval);
521
552
  clearInterval(this.refreshTokenInterval);
522
553
  callback();
523
554
  } catch (e) {
@@ -549,10 +580,12 @@ class Renault extends utils.Adapter {
549
580
  }
550
581
  const command = path.split("/")[1];
551
582
  let action = state.val ? "start" : "cancel";
552
- if (path === "charging-start") {
553
- action = state.val ? "start" : "stop";
583
+ let midPart = "kca/car-adapter/v1/cars/";
584
+ if (path === "charge/pause-resume") {
585
+ action = state.val ? "resume" : "pause";
586
+ midPart = "kcm/v1/vehicles/";
554
587
  }
555
- const data = { data: { type: this.toCamelCase(command), attributes: { action: action } } };
588
+ const data = { data: { type: this.toCamelCase(path), attributes: { action: action } } };
556
589
  if (command === "hvac-start") {
557
590
  const temperatureState = await this.getStateAsync(deviceId + ".remote.hvac-temperature");
558
591
  if (temperatureState) {
@@ -564,7 +597,8 @@ class Renault extends utils.Adapter {
564
597
  const url =
565
598
  "https://api-wired-prod-1-euw1.wrd-aws.com/commerce/v1/accounts/" +
566
599
  this.account.accountId +
567
- "/kamereon/kca/car-adapter/v1/cars/" +
600
+ "/kamereon/" +
601
+ midPart +
568
602
  deviceId +
569
603
  "/" +
570
604
  path +
@@ -586,7 +620,7 @@ class Renault extends utils.Adapter {
586
620
  data: data,
587
621
  })
588
622
  .then((res) => {
589
- this.log.debug(JSON.stringify(res.data));
623
+ this.log.info(JSON.stringify(res.data));
590
624
  return res.data;
591
625
  })
592
626
  .catch((error) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iobroker.renault",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "description": "Adapter for Renault and Renault",
5
5
  "author": {
6
6
  "name": "TA2k",
@@ -24,29 +24,28 @@
24
24
  "url": "https://github.com/TA2k/ioBroker.renault"
25
25
  },
26
26
  "dependencies": {
27
- "@iobroker/adapter-core": "^2.6.2",
28
- "axios": "^0.27.2",
27
+ "@iobroker/adapter-core": "^2.6.8",
28
+ "axios": "^1.3.6",
29
29
  "json-bigint": "^1.0.0",
30
- "qs": "^6.11.0"
30
+ "qs": "^6.11.1"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@iobroker/testing": "^4.1.0",
34
- "@types/chai": "^4.3.3",
34
+ "@types/chai": "^4.3.4",
35
35
  "@types/chai-as-promised": "^7.1.5",
36
- "@types/gulp": "^4.0.9",
37
- "@types/mocha": "^9.1.1",
38
- "@types/node": "^18.7.16",
36
+ "@types/mocha": "^10.0.1",
37
+ "@types/node": "^18.15.12",
39
38
  "@types/proxyquire": "^1.3.28",
40
- "@types/sinon": "^10.0.13",
41
- "@types/sinon-chai": "^3.2.8",
42
- "chai": "^4.3.6",
39
+ "@types/sinon": "^10.0.14",
40
+ "@types/sinon-chai": "^3.2.9",
41
+ "chai": "^4.3.7",
43
42
  "chai-as-promised": "^7.1.1",
44
- "eslint": "^8.23.0",
45
- "mocha": "^10.0.0",
43
+ "eslint": "^8.38.0",
44
+ "mocha": "^10.2.0",
46
45
  "proxyquire": "^2.1.3",
47
- "sinon": "^14.0.0",
46
+ "sinon": "^15.0.3",
48
47
  "sinon-chai": "^3.7.0",
49
- "typescript": "^4.8.3"
48
+ "typescript": "^5.0.4"
50
49
  },
51
50
  "main": "main.js",
52
51
  "files": [