iobroker.renault 0.0.4 → 0.0.8

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/README.md CHANGED
@@ -12,13 +12,12 @@
12
12
 
13
13
  **Tests:** ![Test and Release](https://github.com/TA2k/ioBroker.renault/workflows/Test%20and%20Release/badge.svg)
14
14
 
15
- ## renault adapter for ioBroker
16
-
17
- Adapter for Renault and Renault
15
+ ## renault/dacia adapter for ioBroker
18
16
 
17
+ Adapter for Renault and Dacia
19
18
  ## Loginablauf
20
19
 
21
- Die myRenault Mail und Passwort eingeben.
20
+ Die myRenault/myDacia Mail und Passwort eingeben.
22
21
 
23
22
  ## Steuern
24
23
 
@@ -29,7 +28,7 @@ renault.0.vin.remote auf true setzen steuert den jeweiligen Befehl
29
28
 
30
29
  ## Changelog
31
30
 
32
- ### 0.0.4
31
+ ### 0.0.7
33
32
 
34
33
  * (TA2k) initial release
35
34
 
package/io-package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "common": {
3
3
  "name": "renault",
4
- "version": "0.0.4",
4
+ "version": "0.0.8",
5
5
  "news": {
6
- "0.0.4": {
6
+ "0.0.8": {
7
7
  "en": "initial release",
8
8
  "de": "Erstveröffentlichung",
9
9
  "ru": "Начальная версия",
@@ -69,7 +69,7 @@
69
69
  },
70
70
  "dependencies": [
71
71
  {
72
- "js-controller": ">=3.0.0"
72
+ "js-controller": ">=3.2.0"
73
73
  }
74
74
  ],
75
75
  "globalDependencies": [
package/lib/json2iob.js CHANGED
@@ -1,4 +1,4 @@
1
- //v1.1
1
+ //v1.1 custom renault
2
2
  /*
3
3
  options:
4
4
  write
@@ -99,13 +99,17 @@ module.exports = class Json2iob {
99
99
  if (options.descriptions && options.descriptions[key]) {
100
100
  objectName = options.descriptions[key];
101
101
  }
102
+ let type = element[key] !== null ? typeof element[key] : "mixed";
103
+ if (key === "gpsLatitude" || key === "gpsLongitude") {
104
+ type = "mixed";
105
+ }
102
106
  await this.adapter
103
107
  .setObjectNotExistsAsync(path + "." + key, {
104
108
  type: "state",
105
109
  common: {
106
110
  name: objectName,
107
111
  role: this.getRole(element[key], options.write),
108
- type: element[key] !== null ? typeof element[key] : "mixed",
112
+ type: type,
109
113
  write: options.write,
110
114
  read: true,
111
115
  },
package/main.js CHANGED
@@ -27,6 +27,7 @@ class Renault extends utils.Adapter {
27
27
  this.deviceArray = [];
28
28
  this.json2iob = new Json2iob(this);
29
29
  this.ignoreState = [];
30
+ this.firstUpdate = true;
30
31
  }
31
32
 
32
33
  /**
@@ -51,7 +52,7 @@ class Renault extends utils.Adapter {
51
52
 
52
53
  await this.login();
53
54
 
54
- if (this.session.id_token) {
55
+ if (this.session.id_token && this.session_data && this.account) {
55
56
  await this.getDeviceList();
56
57
  await this.updateDevices();
57
58
  this.updateInterval = setInterval(async () => {
@@ -59,7 +60,7 @@ class Renault extends utils.Adapter {
59
60
  }, this.config.interval * 60 * 1000);
60
61
  this.refreshTokenInterval = setInterval(() => {
61
62
  this.refreshToken();
62
- }, 3500 * 1000); //7days
63
+ }, 3500 * 1000);
63
64
  }
64
65
  }
65
66
  async login() {
@@ -142,9 +143,14 @@ class Renault extends utils.Adapter {
142
143
  .then((res) => {
143
144
  this.log.debug(JSON.stringify(res.data));
144
145
  const filteredAccounts = res.data.currentUser.accounts.filter(function (el) {
145
- return el.accountType === "MYRENAULT" && el.accountStatus === "ACTIVE";
146
+ return (el.accountType === "MYRENAULT" || el.accountType === "MYDACIA") && el.accountStatus === "ACTIVE";
146
147
  });
147
-
148
+ if (filteredAccounts.length === 0) {
149
+ this.log.error("No Account found");
150
+ this.log.error("All accounts: " + res.data.currentUser.accounts);
151
+ this.log.error("Filtered accounts: " + filteredAccounts);
152
+ return;
153
+ }
148
154
  this.account = filteredAccounts[0];
149
155
  })
150
156
  .catch((error) => {
@@ -322,8 +328,8 @@ class Renault extends utils.Adapter {
322
328
  "accept-language": "de-de",
323
329
  "x-gigya-id_token": this.session.id_token,
324
330
  };
325
- this.deviceArray.forEach(async (vin) => {
326
- statusArray.forEach(async (element) => {
331
+ for (const vin of this.deviceArray) {
332
+ for (const element of statusArray) {
327
333
  if (this.ignoreState.includes(element.path)) {
328
334
  return;
329
335
  }
@@ -361,29 +367,37 @@ class Renault extends utils.Adapter {
361
367
 
362
368
  return;
363
369
  }
364
- if (
365
- error.response.status === 403 ||
366
- error.response.status === 404 ||
367
- error.response.status === 500 ||
368
- error.response.status === 501 ||
369
- error.response.status === 502 ||
370
- error.response.status === 400
371
- ) {
372
- this.ignoreState.push(element.path);
373
- this.log.info("Feature not found. Ignore " + element.path + " for updates.");
374
- this.log.info(error);
375
- error.response && this.log.info(JSON.stringify(error.response.data));
376
- return;
370
+ if (this.firstUpdate) {
371
+ if (
372
+ error.response.status === 403 ||
373
+ error.response.status === 404 ||
374
+ error.response.status === 500 ||
375
+ error.response.status === 501 ||
376
+ error.response.status === 502 ||
377
+ error.response.status === 400
378
+ ) {
379
+ this.ignoreState.push(element.path);
380
+ this.log.info("Feature not found. Ignore " + element.path + " for updates.");
381
+ this.log.info(error);
382
+ error.response && this.log.info(JSON.stringify(error.response.data));
383
+ return;
384
+ }
377
385
  }
378
386
  }
379
387
  this.log.error(url);
380
388
  this.log.error(error);
381
389
  error.response && this.log.error(JSON.stringify(error.response.data));
382
390
  });
383
- });
384
- });
391
+ }
392
+ }
393
+ this.firstUpdate = false;
385
394
  }
386
395
  async refreshToken() {
396
+ if (!this.session_data) {
397
+ this.log.error("No session found relogin");
398
+ await this.login();
399
+ return;
400
+ }
387
401
  await this.requestClient({
388
402
  method: "post",
389
403
  url: "https://accounts.eu1.gigya.com/accounts.getJWT",
@@ -422,6 +436,9 @@ class Renault extends utils.Adapter {
422
436
  return new Promise((resolve) => setTimeout(resolve, ms));
423
437
  }
424
438
  toCamelCase(string) {
439
+ if (!string) {
440
+ return;
441
+ }
425
442
  const camelC = string.replace(/-([a-z])/g, function (g) {
426
443
  return g[1].toUpperCase();
427
444
  });
@@ -455,6 +472,13 @@ class Renault extends utils.Adapter {
455
472
  if (!state.ack) {
456
473
  const deviceId = id.split(".")[2];
457
474
  const path = id.split(".")[4];
475
+ if (path === "hvac-temperature") {
476
+ return;
477
+ }
478
+ if (!this.account) {
479
+ this.log.error("No account found");
480
+ return;
481
+ }
458
482
  const command = path.split("/")[1];
459
483
  const data = { data: { type: this.toCamelCase(command), attributes: { action: state.val ? "start" : "cancel" } } };
460
484
  if (command === "hvac-start") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iobroker.renault",
3
- "version": "0.0.4",
3
+ "version": "0.0.8",
4
4
  "description": "Adapter for Renault and Renault",
5
5
  "author": {
6
6
  "name": "TA2k",
@@ -15,7 +15,9 @@
15
15
  "license": "MIT",
16
16
  "keywords": [
17
17
  "renault",
18
- "Renault"
18
+ "Renault",
19
+ "dacia",
20
+ "Dacia"
19
21
  ],
20
22
  "repository": {
21
23
  "type": "git",
@@ -23,7 +25,7 @@
23
25
  },
24
26
  "dependencies": {
25
27
  "@iobroker/adapter-core": "^2.5.1",
26
- "axios": "^0.21.4",
28
+ "axios": "^0.24.0",
27
29
  "json-bigint": "^1.0.0",
28
30
  "qs": "^6.10.1"
29
31
  },