From 409aadd7a199898bc00af49d68c6899fa93aaefa Mon Sep 17 00:00:00 2001 From: Adrian Kumpf Date: Sun, 3 Nov 2019 13:02:03 +0100 Subject: [PATCH] Display remaining time while charging Resolves #221 --- .../templates/car/summary.html.leex | 14 +++++++- priv/gettext/de/LC_MESSAGES/default.po | 34 +++++++++++-------- priv/gettext/default.pot | 34 +++++++++++-------- priv/gettext/en/LC_MESSAGES/default.po | 34 +++++++++++-------- .../mqtt/pubsub/vehicle_subscriber_test.exs | 2 +- .../controllers/car_controller_test.exs | 4 ++- 6 files changed, 77 insertions(+), 45 deletions(-) diff --git a/lib/teslamate_web/templates/car/summary.html.leex b/lib/teslamate_web/templates/car/summary.html.leex index f1954fa6..1fb3db35 100644 --- a/lib/teslamate_web/templates/car/summary.html.leex +++ b/lib/teslamate_web/templates/car/summary.html.leex @@ -90,6 +90,12 @@ end )%> + <%= if @summary.state == :charging and not is_nil(@summary.time_to_full_charge) do %> + + <%= gettext "Remaining Time" %> + <%= round(@summary.time_to_full_charge * 60) %> min + + <% end %> <%= unless is_nil(@summary.ideal_battery_range_km) do %> <%= @@ -124,7 +130,7 @@ %> <% end %> - <%= if @summary.state in [:charging, :charging_complete] do %> + <%= if @summary.state == :charging do %> <%= unless is_nil(@summary.charge_energy_added) do %> <%= gettext "Charged" %> @@ -135,6 +141,12 @@ <%= gettext "Charger Power" %> <%= @summary.charger_power %> kW + + <% end %> + <%= unless is_nil(@summary.time_to_full_charge) do %> + + <%= gettext "Remaining Time" %> + <%= round(@summary.time_to_full_charge * 60) %> min <% end %> <% end %> diff --git a/priv/gettext/de/LC_MESSAGES/default.po b/priv/gettext/de/LC_MESSAGES/default.po index 8c59a3d7..c1ec0540 100644 --- a/priv/gettext/de/LC_MESSAGES/default.po +++ b/priv/gettext/de/LC_MESSAGES/default.po @@ -17,17 +17,17 @@ msgid "Status" msgstr "Status" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:167 +#: lib/teslamate_web/templates/car/summary.html.leex:179 msgid "Speed" msgstr "Geschwindigkeit" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:161 +#: lib/teslamate_web/templates/car/summary.html.leex:173 msgid "State of Charge" msgstr "Ladezustand" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:130 +#: lib/teslamate_web/templates/car/summary.html.leex:136 msgid "Charged" msgstr "Geladen" @@ -85,7 +85,7 @@ msgid "Settings" msgstr "Einstellungen" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:145 +#: lib/teslamate_web/templates/car/summary.html.leex:157 msgid "Scheduled charging" msgstr "Ladezeitpunkt" @@ -95,7 +95,7 @@ msgid "Plugged in" msgstr "Eingesteckt" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:154 +#: lib/teslamate_web/templates/car/summary.html.leex:166 msgid "Charge limit" msgstr "Ladelimit" @@ -234,17 +234,17 @@ msgid "User present" msgstr "Benutzer anwesend" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:221 +#: lib/teslamate_web/templates/car/summary.html.leex:233 msgid "cancel sleep attempt" msgstr "Schlafversuch abbrechen" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:217 +#: lib/teslamate_web/templates/car/summary.html.leex:229 msgid "try to sleep" msgstr "versuchen zu schlafen" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:117 +#: lib/teslamate_web/templates/car/summary.html.leex:123 msgid "Range (est.)" msgstr "Reichweite (gesch.)" @@ -290,12 +290,12 @@ msgid "Temperature readings" msgstr "Temperaturmesswerte" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:98 +#: lib/teslamate_web/templates/car/summary.html.leex:104 msgid "Range (rated)" msgstr "Reichweite (rated)" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:136 +#: lib/teslamate_web/templates/car/summary.html.leex:142 msgid "Charger Power" msgstr "Ladeleistung" @@ -320,7 +320,7 @@ msgid "rated" msgstr "rated" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:97 +#: lib/teslamate_web/templates/car/summary.html.leex:103 msgid "Range (ideal)" msgstr "Reichweite (ideal)" @@ -355,17 +355,17 @@ msgid "Delete '%{geo_fence}'?" msgstr "'%{geo_fence}' löschen?" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:192 +#: lib/teslamate_web/templates/car/summary.html.leex:204 msgid "Inside temperature" msgstr "Innentemperatur" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:180 +#: lib/teslamate_web/templates/car/summary.html.leex:192 msgid "Outside temperature" msgstr "Außentemperatur" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:205 +#: lib/teslamate_web/templates/car/summary.html.leex:217 msgid "Version" msgstr "" @@ -411,3 +411,9 @@ msgstr "Phasenkorrektur auf bestehende Ladevorgänge anwenden" #: lib/teslamate_web/templates/geo_fence/form.html.leex:65 msgid "Some firmware versions incorrectly report 2 phases when charging at some chargers. With phase correction, a fixed value can be set when charging at this location, which overwrites the reported phases." msgstr "Einige Firmware-Versionen melden beim Laden an manchen Ladestationnen fälschlicherweise 2 Phasen. Mit der Phasenkorrektur kann beim Laden an diesem Ort ein fixer Wert eingestellt werden, der die gemeldeten Phasen überschreibt." + +#, elixir-format +#: lib/teslamate_web/templates/car/summary.html.leex:95 +#: lib/teslamate_web/templates/car/summary.html.leex:148 +msgid "Remaining Time" +msgstr "Restlaufzeit" diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index 19e5899d..de83bf6d 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -16,17 +16,17 @@ msgid "Status" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:167 +#: lib/teslamate_web/templates/car/summary.html.leex:179 msgid "Speed" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:161 +#: lib/teslamate_web/templates/car/summary.html.leex:173 msgid "State of Charge" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:130 +#: lib/teslamate_web/templates/car/summary.html.leex:136 msgid "Charged" msgstr "" @@ -84,7 +84,7 @@ msgid "Settings" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:145 +#: lib/teslamate_web/templates/car/summary.html.leex:157 msgid "Scheduled charging" msgstr "" @@ -94,7 +94,7 @@ msgid "Plugged in" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:154 +#: lib/teslamate_web/templates/car/summary.html.leex:166 msgid "Charge limit" msgstr "" @@ -233,17 +233,17 @@ msgid "User present" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:221 +#: lib/teslamate_web/templates/car/summary.html.leex:233 msgid "cancel sleep attempt" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:217 +#: lib/teslamate_web/templates/car/summary.html.leex:229 msgid "try to sleep" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:117 +#: lib/teslamate_web/templates/car/summary.html.leex:123 msgid "Range (est.)" msgstr "" @@ -289,12 +289,12 @@ msgid "Temperature readings" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:98 +#: lib/teslamate_web/templates/car/summary.html.leex:104 msgid "Range (rated)" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:136 +#: lib/teslamate_web/templates/car/summary.html.leex:142 msgid "Charger Power" msgstr "" @@ -319,7 +319,7 @@ msgid "rated" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:97 +#: lib/teslamate_web/templates/car/summary.html.leex:103 msgid "Range (ideal)" msgstr "" @@ -354,17 +354,17 @@ msgid "Delete '%{geo_fence}'?" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:192 +#: lib/teslamate_web/templates/car/summary.html.leex:204 msgid "Inside temperature" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:180 +#: lib/teslamate_web/templates/car/summary.html.leex:192 msgid "Outside temperature" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:205 +#: lib/teslamate_web/templates/car/summary.html.leex:217 msgid "Version" msgstr "" @@ -410,3 +410,9 @@ msgstr "" #: lib/teslamate_web/templates/geo_fence/form.html.leex:65 msgid "Some firmware versions incorrectly report 2 phases when charging at some chargers. With phase correction, a fixed value can be set when charging at this location, which overwrites the reported phases." msgstr "" + +#, elixir-format +#: lib/teslamate_web/templates/car/summary.html.leex:95 +#: lib/teslamate_web/templates/car/summary.html.leex:148 +msgid "Remaining Time" +msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/default.po b/priv/gettext/en/LC_MESSAGES/default.po index 3ee1b551..3707d4f7 100644 --- a/priv/gettext/en/LC_MESSAGES/default.po +++ b/priv/gettext/en/LC_MESSAGES/default.po @@ -17,17 +17,17 @@ msgid "Status" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:167 +#: lib/teslamate_web/templates/car/summary.html.leex:179 msgid "Speed" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:161 +#: lib/teslamate_web/templates/car/summary.html.leex:173 msgid "State of Charge" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:130 +#: lib/teslamate_web/templates/car/summary.html.leex:136 msgid "Charged" msgstr "" @@ -85,7 +85,7 @@ msgid "Settings" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:145 +#: lib/teslamate_web/templates/car/summary.html.leex:157 msgid "Scheduled charging" msgstr "" @@ -95,7 +95,7 @@ msgid "Plugged in" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:154 +#: lib/teslamate_web/templates/car/summary.html.leex:166 msgid "Charge limit" msgstr "" @@ -234,17 +234,17 @@ msgid "User present" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:221 +#: lib/teslamate_web/templates/car/summary.html.leex:233 msgid "cancel sleep attempt" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:217 +#: lib/teslamate_web/templates/car/summary.html.leex:229 msgid "try to sleep" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:117 +#: lib/teslamate_web/templates/car/summary.html.leex:123 msgid "Range (est.)" msgstr "" @@ -290,12 +290,12 @@ msgid "Temperature readings" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:98 +#: lib/teslamate_web/templates/car/summary.html.leex:104 msgid "Range (rated)" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:136 +#: lib/teslamate_web/templates/car/summary.html.leex:142 msgid "Charger Power" msgstr "" @@ -320,7 +320,7 @@ msgid "rated" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:97 +#: lib/teslamate_web/templates/car/summary.html.leex:103 msgid "Range (ideal)" msgstr "" @@ -355,17 +355,17 @@ msgid "Delete '%{geo_fence}'?" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:192 +#: lib/teslamate_web/templates/car/summary.html.leex:204 msgid "Inside temperature" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:180 +#: lib/teslamate_web/templates/car/summary.html.leex:192 msgid "Outside temperature" msgstr "" #, elixir-format -#: lib/teslamate_web/templates/car/summary.html.leex:205 +#: lib/teslamate_web/templates/car/summary.html.leex:217 msgid "Version" msgstr "" @@ -411,3 +411,9 @@ msgstr "" #: lib/teslamate_web/templates/geo_fence/form.html.leex:65 msgid "Some firmware versions incorrectly report 2 phases when charging at some chargers. With phase correction, a fixed value can be set when charging at this location, which overwrites the reported phases." msgstr "" + +#, elixir-format +#: lib/teslamate_web/templates/car/summary.html.leex:95 +#: lib/teslamate_web/templates/car/summary.html.leex:148 +msgid "Remaining Time" +msgstr "" diff --git a/test/teslamate/mqtt/pubsub/vehicle_subscriber_test.exs b/test/teslamate/mqtt/pubsub/vehicle_subscriber_test.exs index 2c739a5b..8681b8ce 100644 --- a/test/teslamate/mqtt/pubsub/vehicle_subscriber_test.exs +++ b/test/teslamate/mqtt/pubsub/vehicle_subscriber_test.exs @@ -98,7 +98,7 @@ defmodule TeslaMate.Mqtt.PubSub.VehicleSubscriberTest do ideal_battery_range_km: 230.52, rated_battery_range_km: 230.52, scheduled_charging_start_time: DateTime.utc_now() |> DateTime.add(60 * 60 * 10, :second), - time_to_full_charge: (DateTime.utc_now() |> DateTime.to_unix()) + :timer.minutes(25) + time_to_full_charge: 2.5 } send(pid, summary) diff --git a/test/teslamate_web/controllers/car_controller_test.exs b/test/teslamate_web/controllers/car_controller_test.exs index d3951640..13a6f46c 100644 --- a/test/teslamate_web/controllers/car_controller_test.exs +++ b/test/teslamate_web/controllers/car_controller_test.exs @@ -163,7 +163,8 @@ defmodule TeslaMateWeb.CarControllerTest do charge_port_latch: "Engaged", charge_port_door_open: true, scheduled_charging_start_time: 1_565_620_707, - charge_limit_soc: 85 + charge_limit_soc: 85, + time_to_full_charge: 1.83 } )} ] @@ -175,6 +176,7 @@ defmodule TeslaMateWeb.CarControllerTest do assert html = response(conn, 200) assert html =~ ~r/

FooCar<\/p>/ assert table_row(html, "Status", "charging") + assert table_row(html, "Remaining Time", "110 min") assert icon(html, "Plugged in", "power-plug") assert table_row(html, "Range (ideal)", "321.87 km") assert table_row(html, "Range (est.)", "289.68 km")