Skip to content

Commit

Permalink
0.2.0 improve volkswagen app
Browse files Browse the repository at this point in the history
  • Loading branch information
TA2k committed Oct 29, 2023
1 parent f8445da commit 315ef56
Show file tree
Hide file tree
Showing 5 changed files with 374 additions and 148 deletions.
2 changes: 1 addition & 1 deletion admin/index_m.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<select id="type" class="value">
<option value="vwv2">VWv2 neue Baujahr >= 2020</option>
<option value="vw">VW alte Baujahr vor 2020</option>
<option value="id">VW ID Reihe</option>
<option value="id">VW ID / Volkswagen App</option>
<option value="skoda">ŠKODA</option>
<option value="skodae">ŠKODA Enyaq</option>
<option value="audi">Audi</option>
Expand Down
6 changes: 5 additions & 1 deletion io-package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"common": {
"name": "vw-connect",
"version": "0.1.9",
"version": "0.2.0",
"news": {
"0.2.0": {
"en": "Improve Volkswagen App support (aux heating, lock and trips)",
"de": "Verbesserung der Volkswagen App Unterstützung (Standheizung, Verriegelung und Trips)"
},
"0.1.9": {
"en": "fix skoda parking position",
"de": "Fix für skoda parking position"
Expand Down
264 changes: 227 additions & 37 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1928,6 +1928,26 @@ class VwWeconnect extends utils.Adapter {
},
native: {},
});
this.setObjectNotExists(vin + ".remote.access", {
type: "state",
common: {
name: "Lock or Unlock Car",
type: "boolean",
role: "boolean",
write: true,
},
native: {},
});
this.setObjectNotExists(vin + ".remote.auxiliaryheating", {
type: "state",
common: {
name: "Standheizung Aux Heating",
type: "boolean",
role: "boolean",
write: true,
},
native: {},
});
});
resolve();
return;
Expand Down Expand Up @@ -2482,6 +2502,67 @@ class VwWeconnect extends utils.Adapter {
}
getIdStatus(vin) {
return new Promise(async (resolve, reject) => {
await axios({
method: "get",
url: "https://emea.bff.cariad.digital/vehicle/v1/vehicles/" + vin + "/selectivestatus?jobs=all",
headers: {
"content-type": "application/json",
accept: "*/*",
authorization: "Bearer " + this.config.atoken,
"accept-language": "de-DE,de;q=0.9",
"user-agent": this.userAgent,
"content-version": "1",
},
})
.then(async (res) => {
this.log.debug(JSON.stringify(res.data));
const data = {};
for (const key in res.data) {
if (key === "userCapabilities") {
data[key] = res.data[key];
} else {
for (const subkey in res.data[key]) {
if (data[subkey]) {
data[key + "_" + subkey] = res.data[key][subkey].value || {};
} else {
data[subkey] = res.data[key][subkey].value || {};
}
}
}
}
if (data.odometerStatus && data.odometerStatus.error) {
this.log.warn("Odometer Error: " + data.odometerStatus.error);
this.log.info(
"Please activate die Standortdaten freigeben und die automatische Terminvereinbarung in der VW App to receive odometer data",
);
}
// this.extractKeys(this, vin + ".status", data);
this.json2iob.parse(vin + ".status", data, { forceIndex: false });
if (this.config.rawJson) {
await this.setObjectNotExistsAsync(vin + ".status" + "rawJson", {
type: "state",
common: {
name: vin + ".status" + "rawJson",
role: "state",
type: "json",
write: false,
read: true,
},
native: {},
});
this.setState(vin + ".status" + "rawJson", JSON.stringify(data), true);
}
resolve();
})
.catch((error) => {
if (error.response && error.response.status >= 500) {
this.log.info("Server not available:" + JSON.stringify(error.response.data));
return;
}
this.log.error(error);
error && error.response && this.log.error(JSON.stringify(error.response.data));
reject();
});
await axios({
method: "get",
url: "https://emea.bff.cariad.digital/vehicle/v1/vehicles/" + vin + "/parkingposition",
Expand Down Expand Up @@ -2531,9 +2612,71 @@ class VwWeconnect extends utils.Adapter {
// error.response && this.log.error(JSON.stringify(error.response.data));
});
}
if (this.config.tripShortTerm == true) {
await axios({
method: "get",
url: "https://emea.bff.cariad.digital/vehicle/v1/trips/" + vin + "/shortterm",
headers: {
"content-type": "application/json",
accept: "*/*",
authorization: "Bearer " + this.config.atoken,
"accept-language": "de-DE,de;q=0.9",
"user-agent": this.userAgent,
"content-version": "1",
},
})
.then(async (res) => {
this.log.debug(JSON.stringify(res.data));
if (res.data && res.data.data) {
this.json2iob.parse(vin + ".shortterm", res.data.data, {
forceIndex: true,
channelName: "shortterm trips",
});
}
})
.catch((error) => {
if (error.response && error.response.status >= 500) {
this.log.info("Server not available:" + JSON.stringify(error.response.data));
return;
}
this.log.error(error);
error && error.response && this.log.error(JSON.stringify(error.response.data));
});
}
if (this.config.tripLongTerm == true) {
await axios({
method: "get",
url: "https://emea.bff.cariad.digital/vehicle/v1/trips/" + vin + "/longterm",
headers: {
"content-type": "application/json",
accept: "*/*",
authorization: "Bearer " + this.config.atoken,
"accept-language": "de-DE,de;q=0.9",
"user-agent": this.userAgent,
"content-version": "1",
},
})
.then(async (res) => {
this.log.debug(JSON.stringify(res.data));
if (res.data && res.data.data) {
this.json2iob.parse(vin + ".longterm", res.data.data, {
forceIndex: true,
channelName: "logterm trips",
});
}
})
.catch((error) => {
if (error.response && error.response.status >= 500) {
this.log.info("Server not available:" + JSON.stringify(error.response.data));
return;
}
this.log.error(error);
error && error.response && this.log.error(JSON.stringify(error.response.data));
});
}
await axios({
method: "get",
url: "https://emea.bff.cariad.digital/vehicle/v1/vehicles/" + vin + "/selectivestatus?jobs=all",
url: "https://emea.bff.cariad.digital/vehicle/v1/trips/" + vin + "/shortterm/last",
headers: {
"content-type": "application/json",
accept: "*/*",
Expand All @@ -2545,43 +2688,41 @@ class VwWeconnect extends utils.Adapter {
})
.then(async (res) => {
this.log.debug(JSON.stringify(res.data));
const data = {};
for (const key in res.data) {
if (key === "userCapabilities") {
data[key] = res.data[key];
} else {
for (const subkey in res.data[key]) {
if (data[subkey]) {
data[key + "_" + subkey] = res.data[key][subkey].value || {};
} else {
data[subkey] = res.data[key][subkey].value || {};
}
}
}
if (res.data && res.data.data) {
this.json2iob.parse(vin + ".shorttermlast", res.data.data, {
forceIndex: false,
channelName: "last shortterm trip",
});
}
if (data.odometerStatus && data.odometerStatus.error) {
this.log.warn("Odometer Error: " + data.odometerStatus.error);
this.log.info(
"Please activate die Standortdaten freigeben und die automatische Terminvereinbarung in der VW App to receive odometer data",
);
})
.catch((error) => {
if (error.response && error.response.status >= 500) {
this.log.info("Server not available:" + JSON.stringify(error.response.data));
return;
}
// this.extractKeys(this, vin + ".status", data);
this.json2iob.parse(vin + ".status", data, { forceIndex: false });
if (this.config.rawJson) {
await this.setObjectNotExistsAsync(vin + ".status" + "rawJson", {
type: "state",
common: {
name: vin + ".status" + "rawJson",
role: "state",
type: "json",
write: false,
read: true,
},
native: {},
this.log.error(error);
error && error.response && this.log.error(JSON.stringify(error.response.data));
});
await axios({
method: "get",
url: "https://emea.bff.cariad.digital/vehicle/v1/trips/" + vin + "/longterm/last",
headers: {
"content-type": "application/json",
accept: "*/*",
authorization: "Bearer " + this.config.atoken,
"accept-language": "de-DE,de;q=0.9",
"user-agent": this.userAgent,
"content-version": "1",
},
})
.then(async (res) => {
this.log.debug(JSON.stringify(res.data));
if (res.data && res.data.data) {
this.json2iob.parse(vin + ".longtermlast", res.data.data, {
forceIndex: false,
channelName: "last longterm trip",
});
this.setState(vin + ".status" + "rawJson", JSON.stringify(data), true);
}
resolve();
})
.catch((error) => {
if (error.response && error.response.status >= 500) {
Expand All @@ -2590,7 +2731,6 @@ class VwWeconnect extends utils.Adapter {
}
this.log.error(error);
error && error.response && this.log.error(JSON.stringify(error.response.data));
reject();
});
});
}
Expand Down Expand Up @@ -3431,7 +3571,7 @@ class VwWeconnect extends utils.Adapter {
setIdRemote(vin, action, value, bodyContent) {
return new Promise(async (resolve, reject) => {
const pre = this.name + "." + this.instance;
let body = bodyContent || {};
let body = bodyContent || { spin: this.config.pin };
if (action === "climatisation" && value === "start") {
const climateStates = await this.getStatesAsync(pre + "." + vin + ".status.climatisationSettings.*");
body = {};
Expand Down Expand Up @@ -4977,6 +5117,48 @@ class VwWeconnect extends utils.Adapter {
return;
}
}
if (action === "auxiliaryheating") {
if (this.config.type === "id" || this.config.type === "audietron") {
const value = state.val ? "start" : "stop";
this.setIdRemote(vin, action, value).catch(() => {
this.log.error("failed set state " + action);
});
return;
} else if (this.config.type === "seatcupra") {
const value = state.val ? "start" : "stop";
this.setSeatCupraStatus(vin, action, value).catch(() => {
this.log.error("failed set state " + action);
});
return;
} else if (this.config.type === "skodae") {
const value = state.val ? "Start" : "Stop";
this.setSkodaESettings(vin, action, value).catch(() => {
this.log.error("failed set state " + action);
});
return;
}
}
if (action === "access") {
if (this.config.type === "id" || this.config.type === "audietron") {
const value = state.val ? "lock" : "unlock";
this.setIdRemote(vin, action, value).catch(() => {
this.log.error("failed set state " + action);
});
return;
} else if (this.config.type === "seatcupra") {
const value = state.val ? "lock" : "unlock";
this.setSeatCupraStatus(vin, action, value).catch(() => {
this.log.error("failed set state " + action);
});
return;
} else if (this.config.type === "skodae") {
const value = state.val ? "lock" : "unlock";
this.setSkodaESettings(vin, action, value).catch(() => {
this.log.error("failed set state " + action);
});
return;
}
}
if (action === "air-conditioning") {
if (this.config.type === "skodae") {
const value = state.val ? "Start" : "Stop";
Expand Down Expand Up @@ -5267,7 +5449,15 @@ class VwWeconnect extends utils.Adapter {
}

if (action === "honk") {
//
/*
{
"duration_s": 15,
"mode": "flash",
"userPosition": {
"latitude": 48.2312143,
"longitude": 11.232123
}
}*/
const idArray = id.split(".");
idArray.pop();
idArray.pop();
Expand Down
Loading

0 comments on commit 315ef56

Please sign in to comment.