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

Add door open/close state #3208

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/tesla_api/vehicle.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,28 @@ 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"
],
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
Expand Down
46 changes: 45 additions & 1 deletion lib/teslamate/vehicles/vehicle/summary.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]),
Expand Down Expand Up @@ -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
Expand Down
Loading