Skip to content

Commit

Permalink
feat: add conditions to enter Charging
Browse files Browse the repository at this point in the history
Only goes to Charging when the car is plugged in (power < 0) and its not preconditioning or in dog mode.

changes from @micves from #3262
  • Loading branch information
JakobLichterfeld authored and brianmay committed Jan 6, 2025
1 parent 229ab1e commit 3762bbe
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/teslamate/vehicles/vehicle.ex
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,21 @@ defmodule TeslaMate.Vehicles.Vehicle do
[broadcast_summary(), schedule_fetch(0, data)]}

%Stream.Data{shift_state: nil, power: power} when is_number(power) and power < 0 ->
Logger.info("Charging detected: #{power} kW", car_id: data.car.id)
{:keep_state_and_data, schedule_fetch(0, data)}
vehicle = merge(data.last_response, stream_data, time: true)

# Only detect as charging if we are not doing something else while plugged in.
# In case we are doing both charging and other thing a normal fetch will discover it later
case {vehicle} do
{%Vehicle{climate_state: %Climate{is_preconditioning: true}}} ->
:keep_state_and_data

{%Vehicle{climate_state: %Climate{climate_keeper_mode: "dog"}}} ->
:keep_state_and_data

{%Vehicle{}} ->
Logger.info("Online / Charging detected: #{power} kW", car_id: data.car.id)
{:keep_state_and_data, schedule_fetch(0, data)}
end

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

0 comments on commit 3762bbe

Please sign in to comment.