From 08b62060857d0a768f4fe469612aada01f6f1f95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Fortuna?= Date: Wed, 17 May 2023 15:51:41 +0200 Subject: [PATCH 1/2] Update summary.ex add : Driver Front state Driver Rear state Passenger Front state Passenger Rear state --- lib/teslamate/vehicles/vehicle/summary.ex | 46 ++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/lib/teslamate/vehicles/vehicle/summary.ex b/lib/teslamate/vehicles/vehicle/summary.ex index ccf85e574b..73673b22f1 100644 --- a/lib/teslamate/vehicles/vehicle/summary.ex +++ b/lib/teslamate/vehicles/vehicle/summary.ex @@ -9,7 +9,7 @@ defmodule TeslaMate.Vehicles.Vehicle.Summary do car display_name state since healthy latitude longitude heading battery_level usable_battery_level ideal_battery_range_km est_battery_range_km rated_battery_range_km charge_energy_added speed outside_temp inside_temp is_climate_on is_preconditioning locked sentry_mode - plugged_in scheduled_charging_start_time charge_limit_soc charger_power windows_open doors_open + plugged_in scheduled_charging_start_time charge_limit_soc charger_power windows_open doors_open driver_front_state driver_rear_state passenger_front_state passenger_rear_state odometer shift_state charge_port_door_open time_to_full_charge charger_phases charger_actual_current charger_voltage version update_available update_version is_user_present geofence model trim_badging exterior_color wheel_type spoiler_type trunk_open frunk_open elevation power @@ -113,6 +113,10 @@ defmodule TeslaMate.Vehicles.Vehicle.Summary do sentry_mode: get_in_struct(vehicle, [:vehicle_state, :sentry_mode]), windows_open: window_open(vehicle), doors_open: doors_open(vehicle), + driver_front_state: driver_front_state(vehicle), + driver_rear_state: driver_rear_state(vehicle), + passenger_front_state: passenger_front_state(vehicle), + passenger_rear_state: passenger_rear_state(vehicle), trunk_open: trunk_open(vehicle), frunk_open: frunk_open(vehicle), is_user_present: get_in_struct(vehicle, [:vehicle_state, :is_user_present]), @@ -161,6 +165,46 @@ defmodule TeslaMate.Vehicles.Vehicle.Summary do nil end end + + defp driver_front_state(%Vehicle{vehicle_state: vehicle_state}) do + case vehicle_state do + %VehicleState{df: df} when is_number(df) -> + df > 0 + + _ -> + nil + end + end + + defp driver_rear_state(%Vehicle{vehicle_state: vehicle_state}) do + case vehicle_state do + %VehicleState{dr: dr} when is_number(dr) -> + dr > 0 + + _ -> + nil + end + end + + defp passenger_front_state(%Vehicle{vehicle_state: vehicle_state}) do + case vehicle_state do + %VehicleState{pf: pf} when is_number(pf) -> + pf > 0 + + _ -> + nil + end + end + + defp passenger_rear_state(%Vehicle{vehicle_state: vehicle_state}) do + case vehicle_state do + %VehicleState{pr: pr} when is_number(pr) -> + pr > 0 + + _ -> + nil + end + end defp trunk_open(%Vehicle{vehicle_state: %VehicleState{rt: rt}}) when is_number(rt), do: rt > 0 defp trunk_open(_vehicle), do: nil From a256dea95611ae7a70f6d188a36e80083da375e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Fortuna?= Date: Mon, 13 Nov 2023 16:14:40 +0100 Subject: [PATCH 2/2] Hand new location endpoint --- lib/tesla_api/vehicle.ex | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/tesla_api/vehicle.ex b/lib/tesla_api/vehicle.ex index 1ff0690bee..beb691b607 100644 --- a/lib/tesla_api/vehicle.ex +++ b/lib/tesla_api/vehicle.ex @@ -51,7 +51,7 @@ defmodule TeslaApi.Vehicle do _global -> "https://owner-api.teslamotors.com" end - TeslaApi.get(endpoint_url <> "/api/1/vehicles/#{id}/vehicle_data", + vehicle_data = TeslaApi.get(endpoint_url <> "/api/1/vehicles/#{id}/vehicle_data", query: [ endpoints: "charge_state;climate_state;closures_state;drive_state;gui_settings;location_data;vehicle_config;vehicle_state;vehicle_data_combo" @@ -59,6 +59,20 @@ defmodule TeslaApi.Vehicle do opts: [access_token: auth.token] ) |> handle_response(transform: &result/1) + + if elem(vehicle_data, 1).drive_state.gps_as_of == nil do + vehicle_location_data = TeslaApi.get(endpoint_url <> "/api/1/vehicles/#{id}/vehicle_data?endpoints=location_data", + opts: [access_token: auth.token] + ) + |> handle_response(transform: &result/1) + + { + elem(vehicle_data,0), + %TeslaApi.Vehicle{elem(vehicle_data, 1) | drive_state: elem(vehicle_location_data, 1).drive_state} + } + else + vehicle_data + end end def result(v) do