davesag / node-tesla-api Goto Github PK
View Code? Open in Web Editor NEWA modern nodeJS implementation of the (unofficial) Tesla API
License: MIT License
A modern nodeJS implementation of the (unofficial) Tesla API
License: MIT License
Add validators for
Hi,
When I try to connect I get:
ResponseError: Endpoint deprecated: Please update your App
details: { method: 'post', url: '/oauth/token' },
status: 400
Any clue?
There are two (possibly competing) API Doc sets available.
There are several unofficial Tesla API documents, as well as the more generic SmartCar API, and they contradict each other slightly.
There's an older version of the api documented in swagger.
see also: teslajs.js
The low level API is problematic to say the least.
potentially unstable due to being based on unofficial documentation, and trial and error,
there's many endpoints that return overlapping or irrelevant, or even inaccurate data.
For example
the car's id
is a number that's longer than javascript's number object allows.
The API itself recognises this and returns an idS
field which is a string
version of the `id.
It uses metric for temperature and imperial for distance (presumably because my GUI is set to Metric) but it would be nicer if distance was also reported in metric if the user's GUI settings are metric.
the API does not prevent you from issuing commands to the car before it's been woken up
the API does not prevent you from doing things like trying to open a sunroof on a car without a sunroof.
A better solution would be to spec out a preferred high-level API, say called 'simple-node-tesla' that uses this.
const Tesla = async (username, password) => {
const token = password
? await api.oauth.({ username, password, clientId, clientSecret })
: username
return {
loggedIn: Boolean(token),
vehicles: () => {
const { response: cars } = await api.vehicles.vehicles({ token })
return cars.map(car => ({
...car,
siblings: cars.filter(({ idS }) => idS !== car.idS),
// then a handy set of functions
// wrapped up with logic preventing commands when car is not awake,
// and that manages things like refreshing tokens, and throttling api limits.
// and which manages a cache of the state of the car
wake: async () => api.vehicles.wake({ id: car.idS, token }),
beep: async () => api.vehicles.beepHorn({ id: car.idS, token }),
flash: async () => api.vehicles.flashLights({ id: car.idS, token }),
serviceHistory: async () => api.vehicles. serviceHistory({ id: car.idS, token }),
// etc
}))
}
}
}
Then used like
const Tesla = require('simple-node-tesla')
const client = Tesla(username, password) // or token if you already have an access token
const[myCar] = await client.vehicles()
await myCar.wake()
const location = await myCar.location()
const serviceHistory = await myCar.serviceHistory()
await myCar.beep()
await myCar.flash()
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.