Skip to content

Commit

Permalink
Fix "vehicle" API
Browse files Browse the repository at this point in the history
- vehicleID is not updated
- carIndex can be given thanks to args.carIndex (msg.commandArgs.carIndex with node-red-contrib-tesla)
  • Loading branch information
GaPhi committed Nov 21, 2023
1 parent 5384712 commit 51d2024
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
],
"_from": "@gaphi/[email protected]",
"_inBundle": false,
"_integrity": "sha512-vj44fBwrAZiac4wbEP7rRES5hCjEOdzpsUb3oEzITD+fu0I/o/558CvB5vjlu3aH94xzC0TvCeYjl14g0eEaKQ==",
"_integrity": "sha512-b2bQYNNO1qkj4L27UBvSsLnc2FJK5XaHPtAmTrb0kz/brhKqVHslJwumZ5nbUalfmJoxMfEllDTJWjJQEFechA==",
"_location": "/@gaphi/teslajs",
"_phantomChildren": {},
"_requested": {
"type": "range",
"type": "version",
"registry": true,
"raw": "@gaphi/[email protected]",
"name": "@gaphi/teslajs",
Expand Down Expand Up @@ -82,5 +82,5 @@
"prepublishOnly": "uglifyjs teslajs.js -c -m --comments -o teslajs.min.js",
"test": "jshint teslajs.js samples && ./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js --verbose"
},
"version": "4.11.0-7"
"version": "4.11.0-8"
}
8 changes: 3 additions & 5 deletions teslajs.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,13 +606,11 @@ exports.postAsync = Promise.denodeify(exports.post);
*/
exports.vehicle = function vehicle(options, args, callback) {
callback = callback ?? function (err, vehicle) { /* do nothing! */ }
exports.get(options, '/api/1/vehicles', null, function (err, body) {
exports.vehicles(options, args, function (err, vehicles) {
if (err) { return callback(err, null); }
try {
body = body.response[options.carIndex ?? 0];
body.id = body.id_s;
options.vehicleID = body.id; // This API updates options object
callback(null, body);
let vehicle = vehicles[args?.carIndex ?? 0];
callback(null, vehicle);
} catch (e) {
log(API_ERR_LEVEL, 'Error parsing vehicles response');
callback(e, null);
Expand Down
Loading

0 comments on commit 51d2024

Please sign in to comment.