End trip if shift state is "P"

This commit is contained in:
Adrian Kumpf
2019-04-13 19:38:30 +02:00
parent 9f6b25d4a9
commit 8403fd444a
6 changed files with 5 additions and 22 deletions
+2 -7
View File
@@ -65,7 +65,6 @@ defmodule TeslaMate.Vehicles.Vehicle do
end
# TODO
# - close trip when shift_state == P
# - deep sleep time with checks every 30min
# - Schedule Sleep Mode: time window where idle times is set to 0 / is bypassed
# - Deep Sleep Mode: time window where polling is limited to 30min
@@ -76,7 +75,7 @@ defmodule TeslaMate.Vehicles.Vehicle do
# - make suspend settings configurable
# - make cars configurable
# - create geo fences
# - check the vehicle state during sleep attempt - does it still work?
# - check the vehicle state during sleep attempt - does it still work?
# - indices
# - cron job which "closes" drives & charging_processes (i.e there is no end_time)
@@ -323,11 +322,7 @@ defmodule TeslaMate.Vehicles.Vehicle do
{:keep_state, %Data{data | last_used: DateTime.utc_now()},
[notify_subscribers(), schedule_fetch(5)]}
"P" ->
{:keep_state, %Data{data | last_used: DateTime.utc_now()},
[notify_subscribers(), schedule_fetch(10)]}
nil ->
shift_state when is_nil(shift_state) or shift_state == "P" ->
{:ok, %Log.Trip{distance: distance, duration_min: duration}} =
call(data.deps.log, :close_trip, [trip_id])
+1 -1
View File
@@ -1,5 +1,5 @@
defmodule TeslaMateWeb.UserSocket do
use Phoenix.Socket
use Phoenix.Socket, log: :debug
## Channels
# channel "room:*", TeslaMateWeb.RoomChannel
-2
View File
@@ -2,8 +2,6 @@ defmodule TeslaMateWeb.CarLive.Index do
use Phoenix.LiveView
alias TeslaMateWeb.CarView
alias TeslaMate.Vehicles
alias TeslaMate.Log
@impl true
@@ -2,9 +2,7 @@ defmodule TeslaMateWeb.CarLive.Summary do
use Phoenix.LiveView
alias TeslaMateWeb.CarView
alias TeslaMate.Vehicles
alias TeslaMate.Log
@impl true
def mount(%{id: id}, socket) do
-1
View File
@@ -2,7 +2,6 @@ defmodule TeslaMateWeb.CarView do
use TeslaMateWeb, :view
alias TeslaMateWeb.CarView
alias TeslaMateWeb.CarLive
def render("index.json", %{car: car}) do
%{data: render_many(car, CarView, "car.json")}
@@ -122,7 +122,7 @@ defmodule TeslaMate.Vehicles.Vehicle.DrivingTest do
refute_receive _
end
test "shift_state P does not trigger position inserts", %{test: name} do
test "shift_state P ends the trip", %{test: name} do
now = DateTime.utc_now()
now_ts = DateTime.to_unix(now, :millisecond)
@@ -130,10 +130,7 @@ defmodule TeslaMate.Vehicles.Vehicle.DrivingTest do
{:ok, online_event()},
{:ok, drive_event(now_ts, "D", 5)},
{:ok, drive_event(now_ts, "D", 15)},
{:ok, drive_event(now_ts, "P", 0)},
{:ok, drive_event(now_ts, "P", 0)},
{:ok, drive_event(now_ts, "P", 0)},
{:ok, drive_event(now_ts, nil, 0)}
{:ok, drive_event(now_ts, "P", 0)}
]
:ok = start_vehicle(name, events)
@@ -148,10 +145,6 @@ defmodule TeslaMate.Vehicles.Vehicle.DrivingTest do
assert_receive {:pubsub, {:broadcast, _server, _topic, {:driving, %TeslaApi.Vehicle{}}}}
assert_receive {:insert_position, ^car_id, %{longitude: 0.1, speed: 24, trip_id: 111}}
assert_receive {:pubsub, {:broadcast, _server, _topic, {:driving, %TeslaApi.Vehicle{}}}}
assert_receive {:pubsub, {:broadcast, _server, _topic, {:driving, %TeslaApi.Vehicle{}}}}
assert_receive {:pubsub, {:broadcast, _server, _topic, {:driving, %TeslaApi.Vehicle{}}}}
assert_receive {:close_trip, 111}
assert_receive {:start_state, ^car_id, :online}