From 3762bbec5a4a19ee008bb5bd444d968cb9106aa1 Mon Sep 17 00:00:00 2001 From: Jakob Lichterfeld Date: Mon, 23 Dec 2024 13:24:14 +0100 Subject: [PATCH] feat: add conditions to enter Charging 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 --- lib/teslamate/vehicles/vehicle.ex | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/teslamate/vehicles/vehicle.ex b/lib/teslamate/vehicles/vehicle.ex index 665a5e5d44..bb0875433c 100644 --- a/lib/teslamate/vehicles/vehicle.ex +++ b/lib/teslamate/vehicles/vehicle.ex @@ -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)