Skip to content

Commit

Permalink
add location update
Browse files Browse the repository at this point in the history
  • Loading branch information
TA2k committed Jul 9, 2024
1 parent 970be17 commit ce98d1b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 36 deletions.
6 changes: 6 additions & 0 deletions admin/index_m.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ <h6 class="translate">
<label for="interval" class="translate">Update interval in minutes</label>
</div>
</div>
<div class="row">
<div class="col s2 input-field">
<input type="checkbox" class="value" id="locationUpdate" />
<label for="locationUpdate" class="translate">Fahrzeugort abfragen. Deaktivieren um geringeren Updateinterval zu erlauben.</label>
</div>
</div>
<div class="row">
<div class="col s2 input-field">
<input type="checkbox" class="value" id="forceUpdate" />
Expand Down
22 changes: 6 additions & 16 deletions io-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,8 @@
"pl": "Adapter do FordPass",
"zh-cn": "FordPass 适配器"
},
"authors": [
"TA2k <[email protected]>"
],
"keywords": [
"ford",
"FordPass"
],
"authors": ["TA2k <[email protected]>"],
"keywords": ["ford", "FordPass"],
"license": "MIT",
"platform": "Javascript/Node.js",
"main": "main.js",
Expand Down Expand Up @@ -130,14 +125,8 @@
}
]
},
"encryptedNative": [
"password",
"secret"
],
"protectedNative": [
"password",
"secret"
],
"encryptedNative": ["password", "secret"],
"protectedNative": ["password", "secret"],
"native": {
"username": "",
"password": "",
Expand All @@ -147,7 +136,8 @@
"codeUrl": "",
"interval": 5,
"forceUpdate": true,
"skip12VCheck": false
"skip12VCheck": false,
"locationUpdate": true
},
"objects": [],
"instanceObjects": [
Expand Down
42 changes: 22 additions & 20 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,27 +596,29 @@ class Ford extends utils.Adapter {
this.log.error(JSON.stringify(error.response.data));
}
});
await this.requestClient({
method: 'get',
url: `https://api.mps.ford.com/api/fordconnect/v3/vehicles/${vin}/location`,
headers: {
Accept: '*/*',
'Content-Type': 'application/json',
'Application-Id': 'AFDC085B-377A-4351-B23E-5E1D35FB3700',
Authorization: 'Bearer ' + this.session.access_token,
},
})
.then((res) => {
this.log.debug(JSON.stringify(res.data));
this.json2iob.parse(vin + '.location', res.data);
if (this.config.locationUpdate) {
await this.requestClient({
method: 'get',
url: `https://api.mps.ford.com/api/fordconnect/v3/vehicles/${vin}/location`,
headers: {
Accept: '*/*',
'Content-Type': 'application/json',
'Application-Id': 'AFDC085B-377A-4351-B23E-5E1D35FB3700',
Authorization: 'Bearer ' + this.session.access_token,
},
})
.catch((error) => {
this.log.error('Failed to update vehicle location');
this.log.error(error);
if (error.response) {
this.log.error(JSON.stringify(error.response.data));
}
});
.then((res) => {
this.log.debug(JSON.stringify(res.data));
this.json2iob.parse(vin + '.location', res.data);
})
.catch((error) => {
this.log.error('Failed to update vehicle location');
this.log.error(error);
if (error.response) {
this.log.error(JSON.stringify(error.response.data));
}
});
}
}
}
async getVehicles() {
Expand Down

0 comments on commit ce98d1b

Please sign in to comment.