Giter VIP home page Giter VIP logo

node-tesla-api's Issues

Doest it still work?

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?

document api (restrict to only Vehicle API endpoints for now)

Validate differing endpoints

There are several unofficial Tesla API documents, as well as the more generic SmartCar API, and they contradict each other slightly.

API Function timdorr teslaapi.io smartcar node sdk
oauth/revoke post-oauth-token-grant_type-refresh_token revoke-access-token smartcar-connect-sdks
oauth/token post-oauth-token-grant_type-password get-access-token smartcar-connect-sdks
logs/getEntitlements n/a entitlements n/a
logs/setEntitlements n/a send n/a
logs/getLogs n/a logs n/a
vehicles/actuateTrunk post-api-1-vehicles-id-command-actuate_trunk n/a n/a
vehicles/autoConditioningStart post-api-1-vehicles-id-command-auto_conditioning_start start-hvac-system n/a
vehicles/autoConditioningStop post-api-1-vehicles-id-command-auto_conditioning_stop stop-hvac-system n/a
vehicles/chargeMaxRange post-api-1-vehicles-id-command-charge_max_range set-max-range-charge-limit n/a
vehicles/chargePortDoorClose post-api-1-vehicles-id-command-charge_port_door_close close-charge-port n/a
vehicles/chargePortDoorOpen post-api-1-vehicles-id-command-charge_port_door_open open-charge-port n/a
vehicles/chargeStandard post-api-1-vehicles-id-command-charge_standard set-standard-charge-limit n/a
vehicles/chargeStart post-api-1-vehicles-id-command-charge_start start-charging post-ev-startstop-charge*
vehicles/chargeState chargestate charge-state get-ev-charging-status and get-ev-battery-level
vehicles/chargeStop post-api-1-vehicles-id-command-charge_stop stop-charging post-ev-startstop-charge*
vehicles/climateState climatestate climate-state n/a
vehicles/doorLock post-api-1-vehicles-id-command-door_lock lock-doors n/a
vehicles/doorUnlock post-api-1-vehicles-id-command-door_unlock unlock-doors n/a
vehicles/driveState drivestate drive-state get-location
vehicles/flashLights post-api-1-vehicles-id-command-flash_lights flash-lights n/a
vehicles/guiSettings guisettings gui-settings n/a
vehicles/honkHorn post-api-1-vehicles-id-command-honk_horn honk-horn n/a
vehicles/list get-api-1-vehicles vehicles get-all-vehicles
vehicles/mediaTogglePlayback post-api-1-vehicles-id-command-media_toggle_playback n/a n/a
vehicles/mediaNextFav post-api-1-vehicles-id-command-media_next_fav n/a n/a
vehicles/mediaNextTrack post-api-1-vehicles-id-command-media_next_track n/a n/a
vehicles/mediaPrevFav post-api-1-vehicles-id-command-media_prev_fav n/a n/a
vehicles/mediaPrevTrack post-api-1-vehicles-id-command-media_prev_track n/a n/a
vehicles/mediaVolumeDown post-api-1-vehicles-id-command-media_volume_down n/a n/a
vehicles/mediaVolumeUp post-api-1-vehicles-id-command-media_volume_up n/a n/a
vehicles/mobileEnabled mobileenabled mobile-enabled n/a
vehicles/nearbyChargingSites nearbychargingsites n/a n/a
vehicles/remoteStartDrive remotestart remote-start-drive n/a
vehicles/resetValetPin post-api-1-vehicles-id-command-reset_valet_pin reset-valet-pin n/a
vehicles/scheduleSoftwareUpdate post-api-1-vehicles-id-command-schedule_software_update n/a n/a
vehicles/cancelSoftwareUpdate post-api-1-vehicles-id-command-cancel_software_update n/a n/a
vehicles/serviceData n/a vehicle-service-data n/a
vehicles/setChargeLimit post-api-1-vehicles-id-command-set_charge_limit set-charge-limit n/a
vehicles/setPreconditioningMax post-api-1-vehicles-id-command-set_preconditioning_max n/a n/a
vehicles/setSeatHeater post-api-1-vehicles-id-command-remote_seat_heater_request n/a n/a
vehicles/setSentryMode post-api-1-vehicles-id-command-set_sentry_mode n/a n/a
vehicles/setSteeringWheelHeater post-api-1-vehicles-id-command-remote_steering_wheel_heater_request n/a n/a
vehicles/setTemps post-api-1-vehicles-id-command-set_temps set-temperature n/a
vehicles/setValetMode post-api-1-vehicles-id-command-set_valet_mode set-valet-mode n/a
vehicles/share post-api-1-vehicles-id-command-share n/a n/a
vehicles/speedLimitActivate post-api-1-vehicles-id-command-speed_limit_activate speed-limit-activate n/a
vehicles/speedLimitClearPin post-api-1-vehicles-id-command-speed_limit_clear_pin speed-limit-clear-pin n/a
vehicles/speedLimitDeactivate post-api-1-vehicles-id-command-speed_limit_deactivate speed-limit-deactivate n/a
vehicles/speedLimitSetLimit post-api-1-vehicles-id-command-speed_limit_set_limit) speed-limit-set-limit n/a
vehicles/sunRoofControl post-api-1-vehicles-id-command-sun_roof_control n/a
vehicles/triggerHomelink homelink n/a n/a
vehicles/upcomingCalendarEntries calendarโ€  upcoming-calendar-entries n/a
vehicles/vehicle get-api-1-vehicles-id vehicles get-vehicle-attributes
vehicles/vehicleConfig get-api-1-vehicles-id-data_request-vehicle_config n/a n/a
vehicles/vehicleData data vehicle-data get-vehicle-attributes
vehicles/vehicleState vehiclestate n/a n/a
vehicles/wakeUp wake wake-up n/a
vehicles/windowControl post-api-1-vehicles-id-command-window_control n/a n/a

Compose a high level API

The low level API is problematic to say the least.

  1. potentially unstable due to being based on unofficial documentation, and trial and error,

  2. 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.

  3. the API does not prevent you from issuing commands to the car before it's been woken up

  4. 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()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.