Skip to content

Commit 10995a3

Browse files
Revert "Dynamic endpoints and token to use official Tesla API (self-hosted or from third party provider) (#3866)"
This reverts commit 263f207.
1 parent 70ee93a commit 10995a3

File tree

27 files changed

+257
-423
lines changed

27 files changed

+257
-423
lines changed

lib/tesla_api/auth.ex

+4-19
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ defmodule TeslaApi.Auth do
1818
adapter Tesla.Adapter.Finch, name: TeslaMate.HTTP, receive_timeout: 60_000
1919

2020
plug TeslaApi.Middleware.FollowRedirects, except: [@redirect_uri]
21-
plug Tesla.Middleware.BaseUrl, System.get_env("TESLA_AUTH_HOST", "https://auth.tesla.com")
21+
plug Tesla.Middleware.BaseUrl, "https://auth.tesla.com"
2222
plug Tesla.Middleware.Headers, @default_headers
2323
plug Tesla.Middleware.JSON
2424
plug Tesla.Middleware.Logger, debug: true, log_level: &log_level/1
@@ -56,24 +56,9 @@ defmodule TeslaApi.Auth do
5656
end
5757
end
5858

59-
defp derive_issuer_url_from_oat("qts-" <> _),
60-
do:
61-
{:ok,
62-
System.get_env("TESLA_AUTH_HOST", "https://auth.tesla.com") <>
63-
System.get_env("TESLA_AUTH_PATH", "/oauth2/v3")}
64-
65-
defp derive_issuer_url_from_oat("eu-" <> _),
66-
do:
67-
{:ok,
68-
System.get_env("TESLA_AUTH_HOST", "https://auth.tesla.com") <>
69-
System.get_env("TESLA_AUTH_PATH", "/oauth2/v3")}
70-
71-
defp derive_issuer_url_from_oat("cn-" <> _),
72-
do:
73-
{:ok,
74-
System.get_env("TESLA_AUTH_HOST", "https://auth.tesla.com") <>
75-
System.get_env("TESLA_AUTH_PATH", "/oauth2/v3")}
76-
59+
defp derive_issuer_url_from_oat("qts-" <> _), do: {:ok, "https://auth.tesla.com/oauth2/v3"}
60+
defp derive_issuer_url_from_oat("eu-" <> _), do: {:ok, "https://auth.tesla.com/oauth2/v3"}
61+
defp derive_issuer_url_from_oat("cn-" <> _), do: {:ok, "https://auth.tesla.cn/oauth2/v3"}
7762
defp derive_issuer_url_from_oat(_), do: :error
7863

7964
defp decode_jwt_payload(jwt) do

lib/tesla_api/auth/refresh.ex

+2-9
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ defmodule TeslaApi.Auth.Refresh do
66
@web_client_id TeslaApi.Auth.web_client_id()
77

88
def refresh(%Auth{} = auth) do
9-
issuer_url = System.get_env("TESLA_AUTH_HOST", "") <> System.get_env("TESLA_AUTH_PATH", "")
10-
11-
if issuer_url == "" do
12-
^issuer_url = Auth.issuer_url(auth)
13-
end
9+
issuer_url = Auth.issuer_url(auth)
1410

1511
data = %{
1612
grant_type: "refresh_token",
@@ -19,10 +15,7 @@ defmodule TeslaApi.Auth.Refresh do
1915
refresh_token: auth.refresh_token
2016
}
2117

22-
case post(
23-
"#{issuer_url}/token" <> System.get_env("TOKEN", ""),
24-
data
25-
) do
18+
case post("#{issuer_url}/token", data) do
2619
{:ok, %Tesla.Env{status: 200, body: body}} ->
2720
auth = %Auth{
2821
token: body["access_token"],

lib/tesla_api/stream.ex

+3-10
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,16 @@ defmodule TeslaApi.Stream do
3232

3333
endpoint_url =
3434
case Auth.region(state.auth) do
35-
:chinese ->
36-
System.get_env("TESLA_WSS_HOST", "wss://streaming.vn.cloud.tesla.cn") <>
37-
"/streaming/" <>
38-
System.get_env("TOKEN", "")
39-
40-
_global ->
41-
System.get_env("TESLA_WSS_HOST", "wss://streaming.vn.teslamotors.com") <>
42-
"/streaming/" <>
43-
System.get_env("TOKEN", "")
35+
:chinese -> "wss://streaming.vn.cloud.tesla.cn/streaming/"
36+
_global -> "wss://streaming.vn.teslamotors.com/streaming/"
4437
end
4538

4639
WebSockex.start_link(endpoint_url, __MODULE__, state,
4740
socket_connect_timeout: :timer.seconds(15),
4841
socket_recv_timeout: :timer.seconds(30),
4942
name: :"stream_#{state.vehicle_id}",
5043
cacerts: @cacerts,
51-
insecure: System.get_env("TESLA_WSS_TLS_ACCEPT_INVALID_CERTS", "") == "true",
44+
insecure: false,
5245
async: true
5346
)
5447
end

lib/tesla_api/vehicle.ex

+9-14
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,33 @@ defmodule TeslaApi.Vehicle do
2525
def list(%Auth{} = auth) do
2626
endpoint_url =
2727
case Auth.region(auth) do
28-
:chinese -> System.get_env("TESLA_API_HOST", "https://owner-api.vn.cloud.tesla.cn")
29-
_global -> System.get_env("TESLA_API_HOST", "https://owner-api.teslamotors.com")
28+
:chinese -> "https://owner-api.vn.cloud.tesla.cn"
29+
_global -> "https://owner-api.teslamotors.com"
3030
end
3131

32-
TeslaApi.get(endpoint_url <> "/api/1/products" <> System.get_env("TOKEN", ""),
33-
opts: [access_token: auth.token]
34-
)
32+
TeslaApi.get(endpoint_url <> "/api/1/products", opts: [access_token: auth.token])
3533
|> handle_response(transform: &list_result/1)
3634
end
3735

3836
def get(%Auth{} = auth, id) do
3937
endpoint_url =
4038
case Auth.region(auth) do
41-
:chinese -> System.get_env("TESLA_API_HOST", "https://owner-api.vn.cloud.tesla.cn")
42-
_global -> System.get_env("TESLA_API_HOST", "https://owner-api.teslamotors.com")
39+
:chinese -> "https://owner-api.vn.cloud.tesla.cn"
40+
_global -> "https://owner-api.teslamotors.com"
4341
end
4442

45-
TeslaApi.get(endpoint_url <> "/api/1/vehicles/#{id}" <> System.get_env("TOKEN", ""),
46-
opts: [access_token: auth.token]
47-
)
43+
TeslaApi.get(endpoint_url <> "/api/1/vehicles/#{id}", opts: [access_token: auth.token])
4844
|> handle_response(transform: &result/1)
4945
end
5046

5147
def get_with_state(%Auth{} = auth, id) do
5248
endpoint_url =
5349
case Auth.region(auth) do
54-
:chinese -> System.get_env("TESLA_API_HOST", "https://owner-api.vn.cloud.tesla.cn")
55-
_global -> System.get_env("TESLA_API_HOST", "https://owner-api.teslamotors.com")
50+
:chinese -> "https://owner-api.vn.cloud.tesla.cn"
51+
_global -> "https://owner-api.teslamotors.com"
5652
end
5753

58-
TeslaApi.get(
59-
endpoint_url <> "/api/1/vehicles/#{id}/vehicle_data" <> System.get_env("TOKEN", ""),
54+
TeslaApi.get(endpoint_url <> "/api/1/vehicles/#{id}/vehicle_data",
6055
query: [
6156
endpoints:
6257
"charge_state;climate_state;closures_state;drive_state;gui_settings;location_data;vehicle_config;vehicle_state;vehicle_data_combo"

lib/teslamate/http.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
defmodule TeslaMate.HTTP do
22
@pools %{
3-
System.get_env("TESLA_API_HOST", "https://owner-api.teslamotors.com") => [size: 10],
3+
"https://owner-api.teslamotors.com" => [size: 10],
44
"https://nominatim.openstreetmap.org" => [size: 3],
55
"https://api.github.com" => [size: 1],
66
:default => [size: 5]

lib/teslamate/vehicles/vehicle.ex

+1-8
Original file line numberDiff line numberDiff line change
@@ -1587,15 +1587,8 @@ defmodule TeslaMate.Vehicles.Vehicle do
15871587

15881588
me = self()
15891589

1590-
id =
1591-
if System.get_env("TESLA_WSS_USE_VIN") do
1592-
data.car.vin
1593-
else
1594-
data.car.vid
1595-
end
1596-
15971590
call(data.deps.api, :stream, [
1598-
id,
1591+
data.car.vid,
15991592
fn stream_data -> send(me, {:stream, stream_data}) end
16001593
])
16011594
end

lib/teslamate_web/live/signin_live/index.ex

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ defmodule TeslaMateWeb.SignInLive.Index do
1313
page_title: gettext("Sign in"),
1414
error: nil,
1515
task: nil,
16-
changeset: Auth.change_tokens(),
17-
token: System.get_env("TOKEN", ""),
18-
provider: System.get_env("TESLA_AUTH_HOST", "https://auth.tesla.com")
16+
changeset: Auth.change_tokens()
1917
}
2018

2119
{:ok, assign(socket, assigns)}

lib/teslamate_web/live/signin_live/index.html.heex

+43-69
Original file line numberDiff line numberDiff line change
@@ -14,56 +14,37 @@
1414
</div>
1515
<% end %>
1616

17-
<%= if @token == "" do %>
18-
<div class="field">
19-
<%= label(f, :access, gettext("Access Token"), class: "label") %>
20-
<div class="control has-icons-left">
21-
<%= text_input(f, :access,
22-
class: "input is-rounded",
23-
autocorrect: "off",
24-
autocapitalize: "none",
25-
spellcheck: "false",
26-
disabled: !!@task
27-
) %>
28-
<span class="icon is-small is-left">
29-
<i class="mdi mdi-api"></i>
30-
</span>
31-
</div>
32-
</div>
33-
34-
<div class="field">
35-
<%= label(f, :refresh, gettext("Refresh Token"), class: "label") %>
36-
<div class="control has-icons-left">
37-
<%= text_input(f, :refresh,
38-
class: "input is-rounded",
39-
autocorrect: "off",
40-
autocapitalize: "none",
41-
spellcheck: "false",
42-
disabled: !!@task
43-
) %>
44-
<span class="icon is-small is-left">
45-
<i class="mdi mdi-cloud-refresh"></i>
46-
</span>
47-
</div>
17+
<div class="field">
18+
<%= label(f, :access, gettext("Access Token"), class: "label") %>
19+
<div class="control has-icons-left">
20+
<%= text_input(f, :access,
21+
class: "input is-rounded",
22+
autocorrect: "off",
23+
autocapitalize: "none",
24+
spellcheck: "false",
25+
disabled: !!@task
26+
) %>
27+
<span class="icon is-small is-left">
28+
<i class="mdi mdi-api"></i>
29+
</span>
4830
</div>
49-
<% else %>
50-
<p class="is-size-7 has-text-centered is-italic has-text-weight-light">
51-
<% provider_link =
52-
link(@provider,
53-
to: @provider,
54-
target: "_blank",
55-
rel: "noopener noreferrer"
56-
) %>
31+
</div>
5732

58-
<%= raw(
59-
gettext(
60-
"You are using the API key (%{token}) provided by %{url}. It will allow your TeslaMate to access the official Tesla Fleet API and Tesla Telemetry streaming.",
61-
token: @token,
62-
url: safe_to_string(provider_link)
63-
)
33+
<div class="field">
34+
<%= label(f, :refresh, gettext("Refresh Token"), class: "label") %>
35+
<div class="control has-icons-left">
36+
<%= text_input(f, :refresh,
37+
class: "input is-rounded",
38+
autocorrect: "off",
39+
autocapitalize: "none",
40+
spellcheck: "false",
41+
disabled: !!@task
6442
) %>
65-
</p>
66-
<% end %>
43+
<span class="icon is-small is-left">
44+
<i class="mdi mdi-cloud-refresh"></i>
45+
</span>
46+
</div>
47+
</div>
6748

6849
<div class="field mt-5">
6950
<div class="control">
@@ -75,34 +56,27 @@
7556
"is-link",
7657
if(!!@task, do: "is-loading")
7758
],
78-
disabled:
79-
if @token == "" do
80-
!@changeset.valid?
81-
else
82-
false
83-
end,
59+
disabled: !@changeset.valid?,
8460
phx_disable_with: gettext("Saving...")
8561
) %>
8662
</div>
8763
</div>
8864

89-
<%= if @token == "" do %>
90-
<p class="is-size-7 has-text-centered is-italic has-text-weight-light">
91-
<% here_link =
92-
link(gettext("here"),
93-
to: "https://docs.teslamate.org/docs/faq#how-to-generate-your-own-tokens",
94-
target: "_blank",
95-
rel: "noopener noreferrer"
96-
) %>
97-
98-
<%= raw(
99-
gettext(
100-
"Obtaining tokens through the Tesla API requires programming experience or a 3rd-party service. Information can be found %{here}.",
101-
here: safe_to_string(here_link)
102-
)
65+
<p class="is-size-7 has-text-centered is-italic has-text-weight-light">
66+
<% here_link =
67+
link(gettext("here"),
68+
to: "https://docs.teslamate.org/docs/faq#how-to-generate-your-own-tokens",
69+
target: "_blank",
70+
rel: "noopener noreferrer"
10371
) %>
104-
</p>
105-
<% end %>
72+
73+
<%= raw(
74+
gettext(
75+
"Obtaining tokens through the Tesla API requires programming experience or a 3rd-party service. Information can be found %{here}.",
76+
here: safe_to_string(here_link)
77+
)
78+
) %>
79+
</p>
10680
</.form>
10781
</div>
10882
</div>

priv/gettext/da/LC_MESSAGES/default.po

+9-14
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ msgstr "Gem"
178178

179179
#: lib/teslamate_web/live/charge_live/cost.html.heex:169
180180
#: lib/teslamate_web/live/geofence_live/form.html.heex:130
181-
#: lib/teslamate_web/live/signin_live/index.html.heex:84
181+
#: lib/teslamate_web/live/signin_live/index.html.heex:60
182182
#, elixir-autogen, elixir-format
183183
msgid "Saving..."
184184
msgstr "Gemmer..."
@@ -194,7 +194,7 @@ msgstr "Tid indtil forsøg på at sove"
194194
msgid "min"
195195
msgstr "min"
196196

197-
#: lib/teslamate_web/live/signin_live/index.ex:83
197+
#: lib/teslamate_web/live/signin_live/index.ex:81
198198
#, elixir-autogen, elixir-format
199199
msgid "Signed in successfully"
200200
msgstr "Logget ind"
@@ -460,7 +460,7 @@ msgid "Time zone"
460460
msgstr "Tidszone"
461461

462462
#: lib/teslamate_web/live/signin_live/index.ex:13
463-
#: lib/teslamate_web/live/signin_live/index.html.heex:70
463+
#: lib/teslamate_web/live/signin_live/index.html.heex:51
464464
#, elixir-autogen, elixir-format
465465
msgid "Sign in"
466466
msgstr "Log ind"
@@ -575,32 +575,32 @@ msgstr "Softwareopdatering tilgængelig (%{version})"
575575
msgid "Sign out"
576576
msgstr "Log Ud"
577577

578-
#: lib/teslamate_web/live/signin_live/index.html.heex:19
578+
#: lib/teslamate_web/live/signin_live/index.html.heex:18
579579
#, elixir-autogen, elixir-format
580580
msgid "Access Token"
581581
msgstr ""
582582

583-
#: lib/teslamate_web/live/signin_live/index.html.heex:35
583+
#: lib/teslamate_web/live/signin_live/index.html.heex:34
584584
#, elixir-autogen, elixir-format
585585
msgid "Refresh Token"
586586
msgstr ""
587587

588-
#: lib/teslamate_web/live/signin_live/index.ex:58
588+
#: lib/teslamate_web/live/signin_live/index.ex:56
589589
#, elixir-autogen, elixir-format
590590
msgid "Tokens are invalid"
591591
msgstr ""
592592

593-
#: lib/teslamate_web/live/signin_live/index.html.heex:99
593+
#: lib/teslamate_web/live/signin_live/index.html.heex:74
594594
#, elixir-autogen, elixir-format
595595
msgid "Obtaining tokens through the Tesla API requires programming experience or a 3rd-party service. Information can be found %{here}."
596596
msgstr ""
597597

598-
#: lib/teslamate_web/live/signin_live/index.html.heex:92
598+
#: lib/teslamate_web/live/signin_live/index.html.heex:67
599599
#, elixir-autogen, elixir-format
600600
msgid "here"
601601
msgstr ""
602602

603-
#: lib/teslamate_web/live/signin_live/index.ex:61
603+
#: lib/teslamate_web/live/signin_live/index.ex:59
604604
#, elixir-autogen, elixir-format
605605
msgid "Your Tesla account is locked due to too many failed sign in attempts. To unlock your account, reset your password"
606606
msgstr ""
@@ -654,8 +654,3 @@ msgstr ""
654654
#, elixir-autogen, elixir-format
655655
msgid "Expected Finish Time"
656656
msgstr ""
657-
658-
#: lib/teslamate_web/live/signin_live/index.html.heex:59
659-
#, elixir-autogen, elixir-format, fuzzy
660-
msgid "You are using the API key (%{token}) provided by %{url}. It will allow your TeslaMate to access the official Tesla Fleet API and Tesla Telemetry streaming."
661-
msgstr ""

0 commit comments

Comments
 (0)