Use new Chinese endpoints

Related to #2214
This commit is contained in:
Adrian Kumpf
2021-12-13 18:19:20 +01:00
parent e09c8c458e
commit 977f423014
5 changed files with 40 additions and 16 deletions
+7 -3
View File
@@ -15,8 +15,6 @@ defmodule TeslaApi.Stream do
disconnects: 0
end
@endpoint_url "wss://streaming.vn.teslamotors.com/streaming/"
@columns ~w(speed odometer soc elevation est_heading est_lat est_lng power shift_state range
est_range heading)a
@@ -32,7 +30,13 @@ defmodule TeslaApi.Stream do
auth: Keyword.fetch!(args, :auth)
}
WebSockex.start_link(@endpoint_url, __MODULE__, state,
endpoint_url =
case Auth.region(state.auth) do
:chinese -> "wss://streaming.vn.teslamotors.cn/streaming/"
_global -> "wss://streaming.vn.teslamotors.com/streaming/"
end
WebSockex.start_link(endpoint_url, __MODULE__, state,
socket_connect_timeout: :timer.seconds(15),
socket_recv_timeout: :timer.seconds(30),
name: :"stream_#{state.vehicle_id}",
+26 -6
View File
@@ -22,18 +22,38 @@ defmodule TeslaApi.Vehicle do
vehicle_config: nil,
vehicle_state: nil
def list(%Auth{token: token}) do
TeslaApi.get("/api/1/vehicles", opts: [access_token: token])
def list(%Auth{} = auth) do
endpoint_url =
case Auth.region(auth) do
:chinese -> "https://owner-api.teslamotors.cn"
_global -> "https://owner-api.teslamotors.com"
end
TeslaApi.get(endpoint_url <> "/api/1/vehicles", opts: [access_token: auth.token])
|> handle_response(transform: &result/1)
end
def get(%Auth{token: token}, id) do
TeslaApi.get("/api/1/vehicles/#{id}", opts: [access_token: token])
def get(%Auth{} = auth, id) do
endpoint_url =
case Auth.region(auth) do
:chinese -> "https://owner-api.teslamotors.cn"
_global -> "https://owner-api.teslamotors.com"
end
TeslaApi.get(endpoint_url <> "/api/1/vehicles/#{id}", opts: [access_token: auth.token])
|> handle_response(transform: &result/1)
end
def get_with_state(%Auth{token: token}, id) do
TeslaApi.get("/api/1/vehicles/#{id}/vehicle_data", opts: [access_token: token])
def get_with_state(%Auth{} = auth, id) do
endpoint_url =
case Auth.region(auth) do
:chinese -> "https://owner-api.teslamotors.cn"
_global -> "https://owner-api.teslamotors.com"
end
TeslaApi.get(endpoint_url <> "/api/1/vehicles/#{id}/vehicle_data",
opts: [access_token: auth.token]
)
|> handle_response(transform: &result/1)
end
@@ -38,9 +38,9 @@ defmodule TeslaMate.Vehicles.Vehicle.ChargingSyncTest do
refute_receive _
end) =~
"""
[warn] Invalid charge data: %{ideal_battery_range_km: [\"can't be blank\"]}
[warn] Invalid charge data: %{ideal_battery_range_km: [\"can't be blank\"]}
~r"""
\[warn.*\] Invalid charge data: %{ideal_battery_range_km: \[\"can't be blank\"\]}
\[warn.*\] Invalid charge data: %{ideal_battery_range_km: \[\"can't be blank\"\]}
"""
end
@@ -189,7 +189,7 @@ defmodule TeslaMate.Vehicles.Vehicle.ChargingTest do
assert capture_log(@log_opts, fn ->
assert_receive {:insert_charge, ^cproc, %{date: _, charge_energy_added: 0.3}}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :charging}}}
end) =~ "[warn] Discarded incomplete fetch result"
end) =~ "Discarded incomplete fetch result"
assert_receive {:insert_position, ^car, %{}}
assert_receive {:insert_charge, ^cproc, %{date: _, charge_energy_added: 0.3}}
@@ -234,7 +234,7 @@ defmodule TeslaMate.Vehicles.Vehicle.StreamingTest do
assert_receive :continue?
refute_receive _
end) =~ """
[warn] Discarded stale fetch result: %{
Discarded stale fetch result: %{
last: %TeslaApi.Vehicle.State.Drive{
gps_as_of: nil,
heading: 120,
@@ -298,7 +298,7 @@ defmodule TeslaMate.Vehicles.Vehicle.StreamingTest do
assert capture_log(@log_opts, fn ->
stream(name, %{shift_state: "P", time: DateTime.add(now, -1, :second)})
refute_receive _
end) =~ "[warn] Received stale stream data"
end) =~ "Received stale stream data"
end
end
@@ -429,7 +429,7 @@ defmodule TeslaMate.Vehicles.Vehicle.StreamingTest do
assert capture_log(@log_opts, fn ->
stream(name, %{shift_state: "D", time: DateTime.add(now, 1, :millisecond)})
refute_receive _
end) =~ "[warn] Received stale stream data"
end) =~ "Received stale stream data"
end
end