From b5fa0242a39dfa94d6790c4976d5e5cbe6b52826 Mon Sep 17 00:00:00 2001
From: Nir Klinger <45952578+NirKli@users.noreply.github.com>
Date: Tue, 12 Dec 2023 14:18:03 +0200
Subject: [PATCH] Fix an issue when car is could enter sleep mode while dog
mode is enabled (#3538)
* Fix an issue when car is could enter sleep mode while dog mode is enabled.
* Update pot files
* revert change
* Fix tests
* Fix tests and issue when try to sleep was not showing
* Fix lint issue
---
lib/teslamate/vehicles/vehicle.ex | 9 +++
lib/teslamate/vehicles/vehicle/summary.ex | 3 +-
lib/teslamate_web/live/car_live/summary.ex | 1 +
.../live/car_live/summary.html.heex | 8 +-
priv/gettext/default.pot | 80 +++++++++++--------
.../vehicles/vehicle/suspend_test.exs | 33 ++++++++
.../live/car_summary_live_test.exs | 5 +-
7 files changed, 100 insertions(+), 39 deletions(-)
diff --git a/lib/teslamate/vehicles/vehicle.ex b/lib/teslamate/vehicles/vehicle.ex
index 147be4d8de..5957ece6cf 100644
--- a/lib/teslamate/vehicles/vehicle.ex
+++ b/lib/teslamate/vehicles/vehicle.ex
@@ -1354,6 +1354,12 @@ defmodule TeslaMate.Vehicles.Vehicle do
{:keep_state, %Data{data | last_used: DateTime.utc_now()},
[broadcast_summary(), schedule_fetch(30 * i, data)]}
+ {:error, :dogmode} ->
+ if suspend?, do: Logger.warning("Dog Mode is enabled ...", car_id: car.id)
+
+ {:keep_state, %Data{data | last_used: DateTime.utc_now()},
+ [broadcast_summary(), schedule_fetch(30 * i, data)]}
+
{:error, :user_present} ->
if suspend?, do: Logger.warning("User present ...", car_id: car.id)
@@ -1413,6 +1419,9 @@ defmodule TeslaMate.Vehicles.Vehicle do
{%Vehicle{climate_state: %Climate{is_preconditioning: true}}, _} ->
{:error, :preconditioning}
+ {%Vehicle{climate_state: %Climate{climate_keeper_mode: "dog"}}, _} ->
+ {:error, :dogmode}
+
{%Vehicle{vehicle_state: %VehicleState{sentry_mode: true}}, _} ->
{:error, :sentry_mode}
diff --git a/lib/teslamate/vehicles/vehicle/summary.ex b/lib/teslamate/vehicles/vehicle/summary.ex
index 29f8e0b846..ae9f88e48b 100644
--- a/lib/teslamate/vehicles/vehicle/summary.ex
+++ b/lib/teslamate/vehicles/vehicle/summary.ex
@@ -14,7 +14,7 @@ defmodule TeslaMate.Vehicles.Vehicle.Summary do
charger_actual_current charger_voltage version update_available update_version is_user_present geofence
model trim_badging exterior_color wheel_type spoiler_type trunk_open frunk_open elevation power
charge_current_request charge_current_request_max tpms_pressure_fl tpms_pressure_fr tpms_pressure_rl tpms_pressure_rr
- tpms_soft_warning_fl tpms_soft_warning_fr tpms_soft_warning_rl tpms_soft_warning_rr
+ tpms_soft_warning_fl tpms_soft_warning_fr tpms_soft_warning_rl tpms_soft_warning_rr climate_keeper_mode
)a
def into(nil, %{state: :start, healthy?: healthy?, car: car}) do
@@ -106,6 +106,7 @@ defmodule TeslaMate.Vehicles.Vehicle.Summary do
# Climate State
is_climate_on: get_in_struct(vehicle, [:climate_state, :is_climate_on]),
is_preconditioning: get_in_struct(vehicle, [:climate_state, :is_preconditioning]),
+ climate_keeper_mode: get_in_struct(vehicle, [:climate_state, :climate_keeper_mode]),
outside_temp: get_in_struct(vehicle, [:climate_state, :outside_temp]),
inside_temp: get_in_struct(vehicle, [:climate_state, :inside_temp]),
diff --git a/lib/teslamate_web/live/car_live/summary.ex b/lib/teslamate_web/live/car_live/summary.ex
index d70c27c57e..e241222082 100644
--- a/lib/teslamate_web/live/car_live/summary.ex
+++ b/lib/teslamate_web/live/car_live/summary.ex
@@ -136,6 +136,7 @@ defmodule TeslaMateWeb.CarLive.Summary do
defp error_to_str(:trunk_open), do: gettext("Trunk is open")
defp error_to_str(:sentry_mode), do: gettext("Sentry mode is enabled")
defp error_to_str(:preconditioning), do: gettext("Preconditioning")
+ defp error_to_str(:dogmode), do: gettext("Dog mode is enabled")
defp error_to_str(:user_present), do: gettext("Driver present")
defp error_to_str(:downloading_update), do: gettext("Downloading update")
defp error_to_str(:update_in_progress), do: gettext("Update in progress")
diff --git a/lib/teslamate_web/live/car_live/summary.html.heex b/lib/teslamate_web/live/car_live/summary.html.heex
index 3fe836a45a..0234ccc5ac 100644
--- a/lib/teslamate_web/live/car_live/summary.html.heex
+++ b/lib/teslamate_web/live/car_live/summary.html.heex
@@ -44,6 +44,11 @@
<% end %>
+ <%= if @summary.climate_keeper_mode == "dog" do %>
+
+
+
+ <% end %>
<%= if not is_nil(@summary.battery_level) and not is_nil(@summary.usable_battery_level) and @summary.battery_level - @summary.usable_battery_level > 2 do %>
@@ -327,7 +332,8 @@
@summary.state == :online and
!@summary.sentry_mode and
!@summary.is_user_present and
- !@summary.is_preconditioning ->
+ !@summary.is_preconditioning and
+ @summary.climate_keeper_mode == "off" ->
link gettext("try to sleep"), to: "#", phx_click: "suspend_logging",
class: "button is-info is-small is-outlined is-fullwidth" <>
(if @loading, do: " is-loading", else: "")
diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot
index 514f90334f..cdeb93096c 100644
--- a/priv/gettext/default.pot
+++ b/priv/gettext/default.pot
@@ -10,22 +10,22 @@
msgid ""
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:133
+#: lib/teslamate_web/live/car_live/summary.html.heex:138
#, elixir-autogen, elixir-format
msgid "Status"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:266
+#: lib/teslamate_web/live/car_live/summary.html.heex:271
#, elixir-autogen, elixir-format
msgid "Speed"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:258
+#: lib/teslamate_web/live/car_live/summary.html.heex:263
#, elixir-autogen, elixir-format
msgid "State of Charge"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:194
+#: lib/teslamate_web/live/car_live/summary.html.heex:199
#, elixir-autogen, elixir-format
msgid "Charged"
msgstr ""
@@ -60,12 +60,12 @@ msgstr ""
msgid "updating"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:78
+#: lib/teslamate_web/live/car_live/summary.html.heex:83
#, elixir-autogen, elixir-format
msgid "Locked"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:73
+#: lib/teslamate_web/live/car_live/summary.html.heex:78
#, elixir-autogen, elixir-format
msgid "Sentry Mode"
msgstr ""
@@ -87,17 +87,17 @@ msgstr ""
msgid "Settings"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:209
+#: lib/teslamate_web/live/car_live/summary.html.heex:214
#, elixir-autogen, elixir-format
msgid "Scheduled Charging"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:58
+#: lib/teslamate_web/live/car_live/summary.html.heex:63
#, elixir-autogen, elixir-format
msgid "Plugged In"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:218
+#: lib/teslamate_web/live/car_live/summary.html.heex:223
#, elixir-autogen, elixir-format
msgid "Charge Limit"
msgstr ""
@@ -220,28 +220,28 @@ msgstr ""
msgid "Sentry mode is enabled"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.ex:139
-#: lib/teslamate_web/live/car_live/summary.html.heex:53
+#: lib/teslamate_web/live/car_live/summary.ex:140
+#: lib/teslamate_web/live/car_live/summary.html.heex:58
#, elixir-autogen, elixir-format
msgid "Driver present"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:336
+#: lib/teslamate_web/live/car_live/summary.html.heex:342
#, elixir-autogen, elixir-format
msgid "cancel sleep attempt"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:331
+#: lib/teslamate_web/live/car_live/summary.html.heex:337
#, elixir-autogen, elixir-format
msgid "try to sleep"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:181
+#: lib/teslamate_web/live/car_live/summary.html.heex:186
#, elixir-autogen, elixir-format
msgid "Range (est.)"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:136
+#: lib/teslamate_web/live/car_live/summary.html.heex:141
#, elixir-autogen, elixir-format
msgid "for"
msgstr ""
@@ -256,12 +256,12 @@ msgstr ""
msgid "Vehicle must be locked"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:162
+#: lib/teslamate_web/live/car_live/summary.html.heex:167
#, elixir-autogen, elixir-format
msgid "Range (rated)"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:200
+#: lib/teslamate_web/live/car_live/summary.html.heex:205
#, elixir-autogen, elixir-format
msgid "Charger Power"
msgstr ""
@@ -286,7 +286,7 @@ msgstr ""
msgid "rated"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:161
+#: lib/teslamate_web/live/car_live/summary.html.heex:166
#, elixir-autogen, elixir-format
msgid "Range (ideal)"
msgstr ""
@@ -296,12 +296,12 @@ msgstr ""
msgid "The car's estimate of remaining range is based on a fixed energy consumption in Wh/km. The Wh/km factor is determined by Tesla and is not country specific whereas the rated range is based on regulatory tests in the different markets for that vehicle."
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.ex:141
+#: lib/teslamate_web/live/car_live/summary.ex:142
#, elixir-autogen, elixir-format
msgid "Update in progress"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:63
+#: lib/teslamate_web/live/car_live/summary.html.heex:68
#, elixir-autogen, elixir-format
msgid "Windows open"
msgstr ""
@@ -311,33 +311,33 @@ msgstr ""
msgid "Delete '%{geo_fence}'?"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:291
+#: lib/teslamate_web/live/car_live/summary.html.heex:296
#, elixir-autogen, elixir-format
msgid "Inside Temperature"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:279
+#: lib/teslamate_web/live/car_live/summary.html.heex:284
#, elixir-autogen, elixir-format
msgid "Outside Temperature"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:316
+#: lib/teslamate_web/live/car_live/summary.html.heex:321
#: lib/teslamate_web/live/settings_live/index.html.heex:283
#, elixir-autogen, elixir-format
msgid "Version"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:117
+#: lib/teslamate_web/live/car_live/summary.html.heex:122
#, elixir-autogen, elixir-format
msgid "Health check failed"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:78
+#: lib/teslamate_web/live/car_live/summary.html.heex:83
#, elixir-autogen, elixir-format
msgid "Unlocked"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:148
+#: lib/teslamate_web/live/car_live/summary.html.heex:153
#, elixir-autogen, elixir-format
msgid "Remaining Time"
msgstr ""
@@ -374,22 +374,22 @@ msgstr ""
msgid "Geo-fence \"%{name}\" updated"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.ex:143
+#: lib/teslamate_web/live/car_live/summary.ex:144
#, elixir-autogen, elixir-format
msgid "An error occurred"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.ex:142
+#: lib/teslamate_web/live/car_live/summary.ex:143
#, elixir-autogen, elixir-format
msgid "Timeout"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:48
+#: lib/teslamate_web/live/car_live/summary.html.heex:53
#, elixir-autogen, elixir-format
msgid "Reduced Battery Range"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:251
+#: lib/teslamate_web/live/car_live/summary.html.heex:256
#, elixir-autogen, elixir-format
msgid "≈ %{range} at 100%"
msgstr ""
@@ -485,7 +485,7 @@ msgstr ""
msgid "Session fee"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:68
+#: lib/teslamate_web/live/car_live/summary.html.heex:73
#, elixir-autogen, elixir-format
msgid "Doors open"
msgstr ""
@@ -523,7 +523,7 @@ msgstr ""
msgid "Continue"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:304
+#: lib/teslamate_web/live/car_live/summary.html.heex:309
#, elixir-autogen, elixir-format
msgid "Mileage"
msgstr ""
@@ -565,7 +565,7 @@ msgstr ""
msgid "Per Minute"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:83
+#: lib/teslamate_web/live/car_live/summary.html.heex:88
#, elixir-autogen, elixir-format
msgid "Software Update available (%{version})"
msgstr ""
@@ -605,7 +605,7 @@ msgstr ""
msgid "Your Tesla account is locked due to too many failed sign in attempts. To unlock your account, reset your password"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.ex:140
+#: lib/teslamate_web/live/car_live/summary.ex:141
#, elixir-autogen, elixir-format
msgid "Downloading update"
msgstr ""
@@ -635,7 +635,17 @@ msgstr ""
msgid "Tire Pressure"
msgstr ""
-#: lib/teslamate_web/live/car_live/summary.html.heex:91
+#: lib/teslamate_web/live/car_live/summary.html.heex:96
#, elixir-autogen, elixir-format
msgid "Low tire pressure, check (%{tire_low}) tire"
msgstr ""
+
+#: lib/teslamate_web/live/car_live/summary.html.heex:48
+#, elixir-autogen, elixir-format
+msgid "Dog Mode"
+msgstr ""
+
+#: lib/teslamate_web/live/car_live/summary.ex:139
+#, elixir-autogen, elixir-format
+msgid "Dog mode is enabled"
+msgstr ""
diff --git a/test/teslamate/vehicles/vehicle/suspend_test.exs b/test/teslamate/vehicles/vehicle/suspend_test.exs
index 1331e9effe..b89ee958d2 100644
--- a/test/teslamate/vehicles/vehicle/suspend_test.exs
+++ b/test/teslamate/vehicles/vehicle/suspend_test.exs
@@ -142,6 +142,39 @@ defmodule TeslaMate.Vehicles.Vehicle.SuspendTest do
refute_receive _
end
+ @tag :capture_log
+ test "does not suspend if dog mode is active", %{test: name} do
+ not_suspendable =
+ online_event(
+ drive_state: %{timestamp: 0, latitude: 0.0, longitude: 0.0},
+ climate_state: %{climate_keeper_mode: "dog"}
+ )
+
+ events = [
+ {:ok, online_event()},
+ {:ok, not_suspendable}
+ ]
+
+ suspend_after_idle_ms = 10
+ suspend_ms = 100
+
+ :ok =
+ start_vehicle(name, events,
+ settings: %{
+ suspend_after_idle_min: round(suspend_after_idle_ms / 60),
+ suspend_min: suspend_ms
+ }
+ )
+
+ assert_receive {:start_state, car, :online, date: _}
+ assert_receive {ApiMock, {:stream, 1000, _}}
+ assert_receive {:insert_position, ^car, %{}}
+ assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :online}}}
+ refute_receive _, round(suspend_ms * 0.5)
+
+ refute_receive _
+ end
+
@tag :capture_log
test "does not suspend if user is present", %{test: name} do
not_suspendable =
diff --git a/test/teslamate_web/live/car_summary_live_test.exs b/test/teslamate_web/live/car_summary_live_test.exs
index 22290ebb3f..31a2396cb0 100644
--- a/test/teslamate_web/live/car_summary_live_test.exs
+++ b/test/teslamate_web/live/car_summary_live_test.exs
@@ -57,7 +57,7 @@ defmodule TeslaMateWeb.CarLive.SummaryTest do
online_event(
display_name: "FooCar",
drive_state: %{timestamp: now, latitude: 0.0, longitude: 0.0},
- climate_state: %{timestamp: now, is_preconditioning: false},
+ climate_state: %{timestamp: now, is_preconditioning: false, climate_keeper_mode: "off"},
vehicle_state: %{timestamp: now, sentry_mode: false, locked: true, car_version: ""}
)}
]
@@ -103,6 +103,7 @@ defmodule TeslaMateWeb.CarLive.SummaryTest do
{"Sentry mode is enabled", "online", %{},
vehicle_state: %{timestamp: 0, sentry_mode: true, locked: true, car_version: ""}},
{"Preconditioning", "online", %{}, climate_state: %{is_preconditioning: true}},
+ {"Dog mode is enabled", "online", %{}, climate_state: %{climate_keeper_mode: "dog"}},
{"Driver present", "online", %{},
vehicle_state: %{timestamp: 0, is_user_present: true, car_version: ""}},
{"Update in progress", "updating", %{},
@@ -180,7 +181,7 @@ defmodule TeslaMateWeb.CarLive.SummaryTest do
online_event(
display_name: "FooCar",
drive_state: %{timestamp: now, latitude: 0.0, longitude: 0.0},
- climate_state: %{timestamp: now, is_preconditioning: false},
+ climate_state: %{timestamp: now, is_preconditioning: false, climate_keeper_mode: "off"},
vehicle_state: %{timestamp: now, sentry_mode: false, locked: true, car_version: ""}
)}
]