Skip to content

Commit

Permalink
fix: handle split alert statuses for signs in headway mode
Browse files Browse the repository at this point in the history
@PaulJKim pointed out that mezzanine signs when set to `:headway` mode
check alert status but that code hadn't been updated to handle when
alert statuses are different between `top` and `bottom` source
configurations.

This change intercepts split alert status values passed to
`get_alert_messages/2`, dispatches out to the existing behavior for each
alert status individually and finally takes the first non-`nil` message
(if it exists; will return `nil` otherwise).
  • Loading branch information
sloanelybutsurely committed Jul 22, 2024
1 parent 26a4332 commit 9a2c6cf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/signs/utilities/messages.ex
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,24 @@ defmodule Signs.Utilities.Messages do
Content.Message.Empty.new()
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, bottom_alert_status]
|> Enum.map(&get_alert_messages(&1, sign))
|> Enum.find(&(not is_nil(&1)))
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
13 changes: 13 additions & 0 deletions test/signs/realtime_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,19 @@ 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

0 comments on commit 9a2c6cf

Please sign in to comment.