Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic endpoints and token to use official Tesla API (self-hosted or from third party provider) #3866

Merged
merged 27 commits into from May 20, 2024

Conversation

jlestel
Copy link
Contributor

@jlestel jlestel commented Apr 24, 2024

I introduced dynamic endpoints and a token to maxime compatibility for future Tesla API/streaming change:

  • dynamic endpoints based on ENV vars allows us to connect self-hosted Tesla Fleet API or homemade streaming/testing API
  • an optional token param to use official Tesla API and Telemetry via by a third party:
    • It is because the access_token and refresh_token are refreshed by these third parties that this token parameter is mandatory. Thus TeslaMate does not lose access and the API keys are managed on the third party's site.
    • Here are the 2 actors who operate according to this principle: MyTeslamate (free) and Teslemetry (24$/year)
    • When a token is provided, no inputs are needed when the user sign up

A compatible streaming server is also provided by a third party, the stream only sends events with the minimum interval of 1 minute. The streaming interval is the main regression in this operation with official Tesla Telemetry.

However, the new API also contains new data that can make it possible to create interesting new features.

Copy link

netlify bot commented Apr 24, 2024

Deploy Preview for teslamate ready!

Name Link
🔨 Latest commit 653ef7b
🔍 Latest deploy log https://app.netlify.com/sites/teslamate/deploys/66342e7b0a13d400086eabd5
😎 Deploy Preview https://deploy-preview-3866--teslamate.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@brianmay
Copy link
Collaborator

I have been thinking about doing this myself :-)

I note you have some TESLA_CN_* variables. Wondering if maybe these should be just TESLA_*.

I think it is unlikely that people will need a mixture of China vs non-China variables, and this makes it more complicated trying to figure out which variables need to be set.

@jlestel
Copy link
Contributor Author

jlestel commented Apr 26, 2024

I have been thinking about doing this myself :-)

I note you have some TESLA_CN_* variables. Wondering if maybe these should be just TESLA_*.

I think it is unlikely that people will need a mixture of China vs non-China variables, and this makes it more complicated trying to figure out which variables need to be set.

I made the same observation. But since we only know a user's region after login, the same settings will work for all users. This is why I did not factor in a single environment variable in a first time.

Now, I removed all the TESLA_CN_* to make the variables more understandable for the majority of users.

@JakobLichterfeld JakobLichterfeld added the area:teslamate Related to TeslaMate core label Apr 27, 2024
@jlestel jlestel changed the title WIP: dynamic endpoints Dynamic endpoints and token to use official Tesla API from third API provider Apr 30, 2024
@jlestel jlestel changed the title Dynamic endpoints and token to use official Tesla API from third API provider Dynamic endpoints and token to use official Tesla API (self-hosted or from third party provider) Apr 30, 2024
Copy link
Collaborator

@JakobLichterfeld JakobLichterfeld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty, lgtm

@JakobLichterfeld JakobLichterfeld merged commit 263f207 into teslamate-org:master May 20, 2024
12 checks passed
@JakobLichterfeld
Copy link
Collaborator

JakobLichterfeld commented May 20, 2024

@jlestel

Not working on my end without any env variables. Will revert as it breaks backwards compatibility

teslamate | 2024-05-20 14:03:49.632 [notice] Application teslamate exited: TeslaMate.Application.start(:normal, []) returned an error: shutdown: failed to start child: TeslaMate.Api
teslamate | ** (EXIT) an exception was raised:
teslamate | ** (MatchError) no match of right hand side value: "https://auth.tesla.com/oauth2/v3"
teslamate | (teslamate 1.29.0) lib/tesla_api/auth/refresh.ex:12: TeslaApi.Auth.Refresh.refresh/1
teslamate | (teslamate 1.29.0) lib/teslamate/api.ex:220: TeslaMate.Api.refresh_tokens/1
teslamate | (teslamate 1.29.0) lib/teslamate/api.ex:116: TeslaMate.Api.init/1
teslamate | (stdlib 5.2) gen_server.erl:980: :gen_server.init_it/2
teslamate | (stdlib 5.2) gen_server.erl:935: :gen_server.init_it/6
teslamate | (stdlib 5.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3

@JakobLichterfeld
Copy link
Collaborator

JakobLichterfeld commented May 20, 2024

same in #3897

JakobLichterfeld added a commit that referenced this pull request May 20, 2024
…osted or from third party provider) (#3866)"

This reverts commit 263f207.
@jlestel
Copy link
Contributor Author

jlestel commented May 21, 2024

@jlestel

Not working on my end without any env variables. Will revert as it breaks backwards compatibility

teslamate | 2024-05-20 14:03:49.632 [notice] Application teslamate exited: TeslaMate.Application.start(:normal, []) returned an error: shutdown: failed to start child: TeslaMate.Api
teslamate | ** (EXIT) an exception was raised:
teslamate | ** (MatchError) no match of right hand side value: "https://auth.tesla.com/oauth2/v3"
teslamate | (teslamate 1.29.0) lib/tesla_api/auth/refresh.ex:12: TeslaApi.Auth.Refresh.refresh/1
teslamate | (teslamate 1.29.0) lib/teslamate/api.ex:220: TeslaMate.Api.refresh_tokens/1
teslamate | (teslamate 1.29.0) lib/teslamate/api.ex:116: TeslaMate.Api.init/1
teslamate | (stdlib 5.2) gen_server.erl:980: :gen_server.init_it/2
teslamate | (stdlib 5.2) gen_server.erl:935: :gen_server.init_it/6
teslamate | (stdlib 5.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3

Sorry I thought I checked it. I fix it ASAP to submit a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:teslamate Related to TeslaMate core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants