Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle split alert statuses for signs in headway mode #800

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/signs/utilities/messages.ex
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,24 @@ defmodule Signs.Utilities.Messages do
end
end

@spec get_alert_messages(
Engine.Alerts.Fetcher.stop_status()
| {Engine.Alerts.Fetcher.stop_status(), Engine.Alerts.Fetcher.stop_status()},
Signs.Realtime.t()
) ::
Signs.Realtime.sign_messages() | nil
defp get_alert_messages({top_alert_status, bottom_alert_status}, sign) do
top_alert_status
|> Engine.Alerts.Fetcher.higher_priority_status(bottom_alert_status)
|> get_alert_messages(sign)
end

defp get_alert_messages(alert_status, %{pa_ess_loc: "GUNS"}) do
if alert_status in [:none, :alert_along_route],
do: nil,
else: {%Alert.NoService{}, %Alert.UseRoutes{}}
end

@spec get_alert_messages(Engine.Alerts.Fetcher.stop_status(), Signs.Realtime.t()) ::
Signs.Realtime.sign_messages() | nil
defp get_alert_messages(alert_status, sign) do
sign_routes = Signs.Utilities.SourceConfig.sign_routes(sign.source_config)

Expand Down
14 changes: 14 additions & 0 deletions test/signs/realtime_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,20 @@ defmodule Signs.RealtimeTest do

Signs.Realtime.handle_info(:run_loop, @sign)
end

test "signs in headway mode with split alert_status will show the first alert" do
expect(Engine.Config.Mock, :sign_config, fn _, _ -> :headway end)
expect(Engine.Alerts.Mock, :max_stop_status, fn _, _ -> :none end)
expect(Engine.Alerts.Mock, :max_stop_status, fn _, _ -> :shuttles_closed_station end)

expect_messages({"No train service", "Use shuttle bus"})

expect_audios([{:canned, {"199", ["864"], :audio}}], [
{"There is no train service at this station. Use shuttle.", nil}
])

Signs.Realtime.handle_info(:run_loop, @multi_route_mezzanine_sign)
end
end

describe "decrement_ticks/1" do
Expand Down
Loading