Skip to content

Commit

Permalink
feat: don't try to sleep if power > 0
Browse files Browse the repository at this point in the history
power > 0 is when e.g. the climate is on which could be scheduled
preconditioning or starting preheat from the app.

This code will make sure it doesn't enter 'trying to sleep' (the internal state
suspended) when power > 0.

changes from @micves from #3262
  • Loading branch information
JakobLichterfeld authored and brianmay committed Jan 6, 2025
1 parent d097283 commit 1aa2d09
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/teslamate/vehicles/vehicle.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,12 @@ defmodule TeslaMate.Vehicles.Vehicle do
{:keep_state, %Data{data | last_used: DateTime.utc_now()},
[broadcast_summary(), schedule_fetch(default_interval() * i, data)]}

{:error, :power_usage} ->
if suspend?, do: Logger.warning("Power usage ...", car_id: car.id)

{:keep_state, %Data{data | last_used: DateTime.utc_now()},
[broadcast_summary(), schedule_fetch(default_interval() * i, data)]}

{:error, :unlocked} ->
if suspend?, do: Logger.warning("Unlocked ...", car_id: car.id)

Expand Down Expand Up @@ -1501,6 +1507,10 @@ defmodule TeslaMate.Vehicles.Vehicle do
%CarSettings{req_not_unlocked: true}} ->
{:error, :unlocked}

{%Vehicle{drive_state: %Drive{power: power}}, _}
when is_number(power) and power > 0 ->
{:error, :power_usage}

{%Vehicle{}, %CarSettings{}} ->
:ok
end
Expand Down

0 comments on commit 1aa2d09

Please sign in to comment.