Skip to content

Commit 8f391d4

Browse files
authored
Update main.js
added some changes to include also the location for electrican cars
1 parent 5b181b1 commit 8f391d4

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

main.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,16 @@ class Volvo extends utils.Adapter {
206206
native: {},
207207
});
208208

209+
//added for including location position
210+
await this.setObjectNotExistsAsync(id + ".location", {
211+
type: "channel",
212+
common: {
213+
name: "Location of the car via Connected Vehicle API",
214+
},
215+
native: {},
216+
});
217+
// end
218+
209219
let remoteArray = [{ command: "Refresh", name: "True = Refresh" }];
210220
await this.requestClient({
211221
method: "get",
@@ -305,7 +315,26 @@ class Volvo extends utils.Adapter {
305315
error.response && this.log.error(JSON.stringify(error.response.data));
306316
});
307317
}
318+
// added for including location position
319+
await this.requestClient({
320+
method: "get",
321+
url: "https://api.volvocars.com/location/v1/vehicles/" + vin + "/location",
322+
headers: {
323+
accept: "application/json",
324+
"vcc-api-key": this.config.vccapikey,
325+
Authorization: "Bearer " + this.session.access_token,
326+
},
327+
})
328+
.then(async (res) => {
329+
this.log.debug(JSON.stringify(res.data));
330+
this.json2iob.parse(vin + ".location", res.data.data, { forceIndex: true });
331+
})
332+
.catch((error) => {
333+
this.log.error(error);
334+
error.response && this.log.error(JSON.stringify(error.response.data));
335+
});
308336

337+
//added for including location position
309338
await this.requestClient({
310339
method: "get",
311340
url: "https://api.volvocars.com/energy/v1/vehicles/" + vin + "/recharge-status",

0 commit comments

Comments
 (0)