iobroker.renault 0.0.3 → 0.0.7
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 +1 -1
- package/io-package.json +2 -2
- package/lib/json2iob.js +6 -2
- package/main.js +61 -34
- package/package.json +2 -2
package/README.md
CHANGED
package/io-package.json
CHANGED
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:
|
|
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);
|
|
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) => {
|
|
@@ -172,10 +178,14 @@ class Renault extends utils.Adapter {
|
|
|
172
178
|
|
|
173
179
|
for (const device of res.data.vehicleLinks) {
|
|
174
180
|
this.deviceArray.push(device.vin);
|
|
181
|
+
let name = device.vehicleDetails.modelSCR;
|
|
182
|
+
if (device.vehicleDetails.model && device.vehicleDetails.model.label) {
|
|
183
|
+
name += device.vehicleDetails.model.label;
|
|
184
|
+
}
|
|
175
185
|
await this.setObjectNotExistsAsync(device.vin, {
|
|
176
186
|
type: "device",
|
|
177
187
|
common: {
|
|
178
|
-
name:
|
|
188
|
+
name: name,
|
|
179
189
|
},
|
|
180
190
|
native: {},
|
|
181
191
|
});
|
|
@@ -318,8 +328,8 @@ class Renault extends utils.Adapter {
|
|
|
318
328
|
"accept-language": "de-de",
|
|
319
329
|
"x-gigya-id_token": this.session.id_token,
|
|
320
330
|
};
|
|
321
|
-
this.deviceArray
|
|
322
|
-
|
|
331
|
+
for (const vin of this.deviceArray) {
|
|
332
|
+
for (const element of statusArray) {
|
|
323
333
|
if (this.ignoreState.includes(element.path)) {
|
|
324
334
|
return;
|
|
325
335
|
}
|
|
@@ -357,29 +367,37 @@ class Renault extends utils.Adapter {
|
|
|
357
367
|
|
|
358
368
|
return;
|
|
359
369
|
}
|
|
360
|
-
if (
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
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
|
+
}
|
|
373
385
|
}
|
|
374
386
|
}
|
|
375
387
|
this.log.error(url);
|
|
376
388
|
this.log.error(error);
|
|
377
389
|
error.response && this.log.error(JSON.stringify(error.response.data));
|
|
378
390
|
});
|
|
379
|
-
}
|
|
380
|
-
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
this.firstUpdate = false;
|
|
381
394
|
}
|
|
382
395
|
async refreshToken() {
|
|
396
|
+
if (!this.session_data) {
|
|
397
|
+
this.log.error("No session found relogin");
|
|
398
|
+
await this.login();
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
383
401
|
await this.requestClient({
|
|
384
402
|
method: "post",
|
|
385
403
|
url: "https://accounts.eu1.gigya.com/accounts.getJWT",
|
|
@@ -418,6 +436,9 @@ class Renault extends utils.Adapter {
|
|
|
418
436
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
419
437
|
}
|
|
420
438
|
toCamelCase(string) {
|
|
439
|
+
if (!string) {
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
421
442
|
const camelC = string.replace(/-([a-z])/g, function (g) {
|
|
422
443
|
return g[1].toUpperCase();
|
|
423
444
|
});
|
|
@@ -451,30 +472,36 @@ class Renault extends utils.Adapter {
|
|
|
451
472
|
if (!state.ack) {
|
|
452
473
|
const deviceId = id.split(".")[2];
|
|
453
474
|
const path = id.split(".")[4];
|
|
475
|
+
if (path === "hvac-temperature") {
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
454
478
|
const command = path.split("/")[1];
|
|
455
479
|
const data = { data: { type: this.toCamelCase(command), attributes: { action: state.val ? "start" : "cancel" } } };
|
|
456
480
|
if (command === "hvac-start") {
|
|
457
481
|
const temperatureState = await this.getStateAsync(deviceId + ".remote.hvac-temperature");
|
|
458
482
|
if (temperatureState) {
|
|
459
|
-
data.data.attributes.targetTemperature = temperatureState.val ? temperatureState.val :
|
|
483
|
+
data.data.attributes.targetTemperature = temperatureState.val ? temperatureState.val : 21;
|
|
484
|
+
} else {
|
|
485
|
+
data.data.attributes.targetTemperature = 21;
|
|
460
486
|
}
|
|
461
487
|
}
|
|
462
|
-
|
|
488
|
+
const url =
|
|
489
|
+
"https://api-wired-prod-1-euw1.wrd-aws.com/commerce/v1/accounts/" +
|
|
490
|
+
this.account.accountId +
|
|
491
|
+
"/kamereon/kca/car-adapter/v1/cars/" +
|
|
492
|
+
deviceId +
|
|
493
|
+
"/" +
|
|
494
|
+
path +
|
|
495
|
+
"?country=" +
|
|
496
|
+
this.country;
|
|
463
497
|
this.log.debug(JSON.stringify(data));
|
|
498
|
+
this.log.debug(url);
|
|
464
499
|
await this.requestClient({
|
|
465
500
|
method: "post",
|
|
466
|
-
url:
|
|
467
|
-
"https://api-wired-prod-1-euw1.wrd-aws.com/commerce/v1/accounts/" +
|
|
468
|
-
this.account.accountId +
|
|
469
|
-
"/kamereon/kca/car-adapter/v2/cars/" +
|
|
470
|
-
deviceId +
|
|
471
|
-
"/" +
|
|
472
|
-
path +
|
|
473
|
-
"?country=" +
|
|
474
|
-
this.country,
|
|
501
|
+
url: url,
|
|
475
502
|
headers: {
|
|
476
503
|
apikey: "Ae9FDWugRxZQAGm3Sxgk7uJn6Q4CGEA2",
|
|
477
|
-
"content-type": "application/json",
|
|
504
|
+
"content-type": "application/vnd.api+json",
|
|
478
505
|
accept: "*/*",
|
|
479
506
|
"user-agent": "MYRenault/39 CFNetwork/1312 Darwin/21.0.0",
|
|
480
507
|
"accept-language": "de-de",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iobroker.renault",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Adapter for Renault and Renault",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "TA2k",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@iobroker/adapter-core": "^2.5.1",
|
|
26
|
-
"axios": "^0.
|
|
26
|
+
"axios": "^0.24.0",
|
|
27
27
|
"json-bigint": "^1.0.0",
|
|
28
28
|
"qs": "^6.10.1"
|
|
29
29
|
},
|