From 229ab1ecbe8e439cf2d77eb5e5b033db67a70a1f Mon Sep 17 00:00:00 2001 From: Jakob Lichterfeld Date: Mon, 23 Dec 2024 13:24:14 +0100 Subject: [PATCH] feat: cancel an ongoing suspended state/trying to sleep and go back to 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 --- lib/teslamate/vehicles/vehicle.ex | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/teslamate/vehicles/vehicle.ex b/lib/teslamate/vehicles/vehicle.ex index fe2e568760..665a5e5d44 100644 --- a/lib/teslamate/vehicles/vehicle.ex +++ b/lib/teslamate/vehicles/vehicle.ex @@ -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)