Coder Social home page Coder Social logo

tesla's Introduction

tesla's People

Contributors

andig avatar barnybug avatar bogosj avatar codelingobot avatar dbrouwer-sbp avatar dependabot[bot] avatar dewski avatar evenmun avatar flarno11 avatar grimmimeloni avatar jnoxon avatar jsgoecke avatar machship-mm avatar mgb avatar michaelharo avatar think-free avatar uhthomas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

tesla's Issues

Support swap-in api replacement based on vehicle-command proxy like Tessi

Hi, as the unofficial Tesla API commands are being deprecated, is there any chance to create a code based on Tessie API. They as a company are allowed to use the official Tesla API and provide for their costumers an API of their one, which is quite good as it doesn’t wake up the car to check status and uses the last one known. It only wakes for commands. Please check https://developer.tessie.com

thanks!

Refs evcc-io/evcc#11846

Create v1.0 tag

I'd like to consider a v1.0 tag for the library after #8 is closed, preferable after #15 is merged.

Output OAuth2 token JSON to file

cmd/login dumps the OAuth2 token to stdout at current. It would be nice to have the option to support writing directly to a file as redirection won't work.

Switch to Tesla vehicle-commands

In evcc-io/evcc#10802 I've done some prototyping with vehicle-commands library. Basically, same requests as with this module are executed against fleet-api endpoints. Option 1 would be to switch this module to use the new endpoints.

What does not work is sending commands- these must now be signed. This can be achieved by using the new API or by running a Tesla-provided proxy that converts REST API to signed commands.

That said I will experiment some with which changes would need to be made to connect to arbitrary endpoint urls for simple requests or commands. Especially the response definitions are not part of the vehicle-commands library and still super helpful.

Support /api/products

evcc-io/evcc#5826 (reply in thread) has an interesting discussion on how to remote control a powerwall. Access is via Tesla api credentials that we have. It would be nice to provide read-only and potentially write access to the broader Tesla api beyond vehicles.

Update client.go to handle new OAuth

Currently I use the library by creating a http.Client outside of the library and manually creating a struct: https://github.com/bogosj/go-tesla-go/blob/0734ca75a1aaca030779f96ebdee98c1483b03e0/setup.go#L100-L108

This is done by using https://github.com/uhthomas/tesla/blob/master/cmd/login/main.go, saving the resulting JSON dictionary to disk and reading those files back.

This was done in bogosj/go-tesla-go@0734ca7

It seems sub-optimal to rely on another binary to bootstrap usage. We could bring uthomas' code into this project and create a method to persist the result of a login to a single token file, but there are likely other options worth considering.

@michaelharo

Login methods other than captcha

Are other login methods other that captcha supported? I was looking at the Ruby gem and it doesn't appear to be a hard auth requirement.

func (Vehicle) OpenTrunk Not Working

Whenever calling the v.OpenTrunk("front") or v.OpenTrunk("rear") functions, I get an error 400 Bad Request. Was the API moved or were the names changed?

switch trunk {
	case "rear":
	case "front":
		err := v.OpenTrunk(strings.ToLower(trunk))
		if err != nil {
			handleError(err, m, "There was an error opening your trunk. Contact @rudi9719 for more information with code %+v")
			return
		}
	default:
		k.SendMessageByConvID(m.ConvID, "You must supply front or rear.")
		return
	}

Commands returning 403 forbidden

Hey,

I can succesfully login and retrieve vehicle information, but as soon as I want to send a command like start charging or lock doors, I get "403 Forbidden".

I created the access_token and refresh_token via the iOS App "Auth for Tesla".

Do I need something else?

Example Code:

c, err := tesla.NewClient(ctx, tesla.WithTokenFile(tokenPath))
if err != nil {
return err
}

vehicles, err := c.Vehicles()
if err != nil {
	return err
}

for i, v := range vehicles {
	if i > 0 {
		fmt.Println("----")
	}

	wakeup, err := v.Wakeup()
	if err != nil {
		fmt.Println("Wake up err")
		fmt.Println(err)
	}

	fmt.Println(wakeup)

	fmt.Printf("ID: %x\n", v.ID)
	fmt.Printf("Name %s\n", v.DisplayName)

	enabled, err := v.MobileEnabled()
	fmt.Println(enabled) <--- True
	if err != nil {
		fmt.Println("mobile enabled err")
		fmt.Println(err)
	}

	err = v.LockDoors() <--- 403 Forbidden
	if err != nil {
		return err
	}

Thanks for your help!

Add more automation

Code in client.go is lacking comments on exported members. Somehow we weren't yelled at about this. We should have been.

Token refresh issue

I've noticed this in my logfile today:

[tesla ] TRACE 2022/03/18 09:28:55 POST https://auth.tesla.com/oauth2/v3/token
[tesla ] TRACE 2022/03/18 09:28:55 grant_type=refresh_token&refresh_token=***
--
{"error":"unauthorized_client","error_description":"Unauthorized client","error_uri":"https://auth.tesla.com/error/reference/240b1ae2-..."}
[tesla ] TRACE 2022/03/18 09:28:55 POST https://auth.tesla.com/oauth2/v3/token
[tesla ] TRACE 2022/03/18 09:28:56 client_id=ownerapi&grant_type=refresh_token&refresh_token=***
--
{"access_token":"eyJhbGciO...","expires_in":28800,"token_type":"Bearer"}

it seems as if we're trying to refresh the token twice, first time with missing clientid=ownerapi though I couldn't immediately find it.

Any ideas?

Captcha

Hi guys, are we planning anything to address the new captcha madness? Guess we need an interface to let consumer allow to display the captcha or feed it to a solver service?

Unable to authenticate using cmd/login

Was writing a bot and accidentally logged out. Now I can't seem to log back in using my old code, or the cmd/login example.

╭─rudi@imogene ~/tesla/cmd/login  ‹main› 
╰─➤  go run . -o tesla.token
Username: [email protected]
Password: ************************************************************
2021/07/10 11:06:37 list devices: do: Get "https://auth.tesla.com/oauth2/v3/authorize/mfa/factors?transaction_id=[redacted]": net/http: timeout awaiting response headers
exit status 1

VC API changes to struct definition

Position seems to have changed:

"drive_state": {
    "active_route_latitude": 53,
    "active_route_longitude": 8,
    "active_route_traffic_minutes_delay": 0,
    "power": 3,
    "shift_state": null,
    "speed": null,
    "timestamp": 1700314839825
}

DriveState content change

Given the new data I get from my car, it looks like the DriveState field names has changed:

"drive_state":{
         "active_route_latitude":123.456,
         "active_route_longitude":123.456,
         "active_route_traffic_minutes_delay":0.0,
         "power":0,
         "shift_state":null,
         "speed":null,
         "timestamp":123456789
      }

May it be possible to update the API?

Timestamps changed?

Not sure if this is my mistake but it seems as if the tesla API might have changed its timestamp format:

{
	"response": {
		"battery_heater_on": false,
		"battery_level": 57,
		"battery_range": 186.49,
		"charge_current_request": 6,
		"charge_current_request_max": 6,
		"charge_enable_request": true,
		"charge_energy_added": 0.1,
		"charge_limit_soc": 90,
		"charge_limit_soc_max": 100,
		"charge_limit_soc_min": 50,
		"charge_limit_soc_std": 90,
		"charge_miles_added_ideal": 0.5,
		"charge_miles_added_rated": 0.5,
		"charge_port_cold_weather_mode": false,
		"charge_port_door_open": true,
		"charge_port_latch": "Engaged",
		"charge_rate": 4.8,
		"charge_to_max_range": false,
		"charger_actual_current": 6,
		"charger_phases": 1,
		"charger_pilot_current": 6,
		"charger_power": 1,
		"charger_voltage": 220,
		"charging_state": "Charging",
		"conn_charge_cable": "IEC",
		"est_battery_range": 135.85,
		"fast_charger_brand": "<invalid>",
		"fast_charger_present": false,
		"fast_charger_type": "<invalid>",
		"ideal_battery_range": 186.49,
		"managed_charging_active": false,
		"managed_charging_start_time": null,
		"managed_charging_user_canceled": false,
		"max_range_charge_counter": 1,
		"minutes_to_full_charge": 4080,
		"not_enough_power_to_heat": null,
		"scheduled_charging_pending": false,
		"scheduled_charging_start_time": null,
		"time_to_full_charge": 68.0,
		"timestamp": 1614069716042,
		"trip_charging": false,
		"usable_battery_level": 55,
		"user_charge_enable_request": null
	}
}
parsing time "1614069715531" as ""2006-01-02T15:04:05Z07:00"": cannot parse "1614069715531" as """

Looks like unix timestamp (millis?) instead of formatted time. Can anyone confirm?

cmd/login timeout error

I'm assuming this is due to some new change to the CAPCHA?

go run .
Username: <username>
Password: *****
2021/09/05 22:06:09 list devices: do: Get "https://auth.tesla.com/oauth2/v3/authorize/mfa/factors?transaction_id=Y2LsCGiQ": net/http: timeout awaiting response headers
exit status 1

Login gives HTTP 403

When I try to run the login command, I get a 403 error. Is this just me or is there an issue with the API itself?

Username: [email protected]
Password: ******************
2022/07/01 13:45:07 unexpected status code 403
exit status 1

Tesla WAF

Hi!

So, it looks like Tesla has updated their WAF again. After some experimenting, I've managed to get something working.

https://github.com/uhthomas/tesla/compare/f00d0e07a2b61907751647920f5b7c1f8197c07a..1caf33b692d9258ef27505b335ee3aa8869c1e8d

The changes are:

  • Include an Accept with */*
  • Include an Accept-Encoding with gzip, deflate, br
    This is paired with a custom round tripper which is capable of decoding gzip responses.
  • Randomize the User-Agent header every 6 hours
    The user agent can't always be random, as logging in is expected to keep the same user agent for the entire flow.

Unable to get Vehicle State

Receiving the following error when calling

	vehicleState, err := vehicle.VehicleState()
	if err != nil {
		fmt.Printf("Unable to get Vehicle State: %+v\n", err)
		return
	}

Unable to get Vehicle State: json: cannot unmarshal number 50.0 into Go struct field .response.speed_limit_mode.min_limit_mph of type int

No Current Location info anymore

Hi, I see the drive state changes have been applied (see #111 for context).
I do encounter some issues using these active_route parameters to determinate the car is Home or not:

  • If there is a software update, these values are empty ( I think so, might also been the wrong values, did not read data before driving after update)
  • If you don't plan a route while driving home, these will not reflect the actual location.
  • These values give you the destination location, not your actual location (for my purpose use, this is of no issue)

So giving the above, is there any way to get the Actual Location (used to work before) from the owner api that this library uses ?
The previous location values does not seem to get update anymore.

Error messages swallowed

Whenever we receive a non-200 response, the response JSON is ignored and any contained error swallowed:

HTTP/2.0 408 Request Timeout
Content-Length: 106
Cache-Control: no-cache, no-store, private, s-max-age=0
Content-Type: application/json; charset=utf-8
Date: Fri, 30 Dec 2022 15:46:15 GMT
Server: envoy
Strict-Transport-Security: max-age=31536000; includeSubDomains
Vary: Accept
X-Content-Type-Options: nosniff
X-Envoy-Upstream-Cluster: owner-api
X-Envoy-Upstream-Service-Time: 35
X-Frame-Options: DENY
X-Request-Id: 607ca386-1396-48f4-8846-26ae6d5cf866
X-Txid: 443ce41d67afee316399a80eefb2243d
X-Xss-Protection: 1; mode=block

{"response":null,"error":"vehicle unavailable: {:error=>\"vehicle unavailable:\"}","error_description":""}

Will only ever return the HTTP 408 although the code seems to suggest that we're actually decoding the error (which itself is json encoded as string...).

fetching products fails if non-energy products are present

The call against the products endpoint gives mixed responses if non-energy products like vehicles are present in the same account as e.g. a powerwall. The unmarshalling of the response fails on this response, as the product.id field varies between numeric (for vehicles) and string (for energy products).

Missing semver tag?

When I upgrade to latest version, I do not get an update:

❯ go get -v github.com/bogosj/tesla@latest

go.mod remains at:

github.com/bogosj/tesla v0.0.0-20210425155839-8493aa0dee71

I'm wondering if that's due to the tag being 1.0 instead of 1.0.0 which would be correct semver?

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.