Skip to content

Commit

Permalink
feat: cancel an ongoing suspended state/trying to sleep and go back t…
Browse files Browse the repository at this point in the history
…o online

When power > 0.

power > 0 is when e.g. the climate is on which could be scheduled preconditioning or starting preheat from the app.

changes from @micves from #3262
  • Loading branch information
JakobLichterfeld authored and brianmay committed Jan 6, 2025
1 parent 1aa2d09 commit 229ab1e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/teslamate/vehicles/vehicle.ex
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,20 @@ defmodule TeslaMate.Vehicles.Vehicle do
%Stream.Data{shift_state: s, power: power}
when s in [nil, "P"] and is_number(power) and power < 0 ->
Logger.info("Suspended / Charging detected: #{power} kW", car_id: data.car.id)
{:next_state, prev_state, data, schedule_fetch(0, data)}

{:next_state, prev_state, %Data{data | last_used: DateTime.utc_now()},
schedule_fetch(0, data)}

%Stream.Data{shift_state: s, power: power}
when s in [nil, "P"] and is_number(power) and power > 0 ->
Logger.info("Suspended / Usage detected: #{power} kW", car_id: data.car.id)

# update power to be used in can_fall_asleep / try_to_suspend
vehicle = merge(data.last_response, stream_data, time: true)

{:next_state, prev_state,
%Data{data | last_response: vehicle, last_used: DateTime.utc_now()},
schedule_fetch(0, data)}

%Stream.Data{} ->
Logger.debug(inspect(stream_data), car_id: data.car.id)
Expand Down

0 comments on commit 229ab1e

Please sign in to comment.