From 6a1bf925ea6e14eeb315dc58b796ebbd4a846710 Mon Sep 17 00:00:00 2001 From: cmaddox5 Date: Tue, 8 Oct 2024 11:40:13 -0400 Subject: [PATCH 1/4] Fix list of recognized vendors. --- lib/config/screen.ex | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/config/screen.ex b/lib/config/screen.ex index 8fb52c7..dcb56a2 100644 --- a/lib/config/screen.ex +++ b/lib/config/screen.ex @@ -23,7 +23,7 @@ defmodule ScreensConfig.Screen do | :pre_fare_v2 @type t :: %__MODULE__{ - vendor: :gds | :mercury | :solari | :c3ms | :outfront | :lg_mri | :mimo, + vendor: :gds | :mercury | :solari | :c3ms | :outfront | :lg_mri | :mimo | :n_a, device_id: String.t(), name: String.t(), app_id: app_id(), @@ -122,12 +122,12 @@ defmodule ScreensConfig.Screen do |> String.ends_with?(@v2_app_id_suffix) end - for vendor <- ~w[gds mercury solari mimo c3ms outfront]a do - vendor_string = Atom.to_string(vendor) + defp value_from_json("vendor", "n/a", _app_id) do + :n_a + end - defp value_from_json("vendor", unquote(vendor_string), _app_id) do - unquote(vendor) - end + defp value_from_json("vendor", vendor_string, _app_id) do + String.to_existing_atom(vendor_string) end defp value_from_json("app_id", _app_id_string, app_id), do: app_id From e2834e0c2a234644045a1c71c7afe5790a1923ab Mon Sep 17 00:00:00 2001 From: cmaddox5 Date: Tue, 8 Oct 2024 11:44:53 -0400 Subject: [PATCH 2/4] Map empty vendor to n/a. --- lib/config/screen.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config/screen.ex b/lib/config/screen.ex index dcb56a2..2243625 100644 --- a/lib/config/screen.ex +++ b/lib/config/screen.ex @@ -122,7 +122,7 @@ defmodule ScreensConfig.Screen do |> String.ends_with?(@v2_app_id_suffix) end - defp value_from_json("vendor", "n/a", _app_id) do + defp value_from_json("vendor", vendor_string, _app_id) when vendor_string in ["n/a", ""] do :n_a end From d18b263312d8bde8673ac335cea61bf66353c6c4 Mon Sep 17 00:00:00 2001 From: cmaddox5 Date: Tue, 8 Oct 2024 14:01:59 -0400 Subject: [PATCH 3/4] Use hardcoded list of vendors instead of converting strings to atoms. --- lib/config/screen.ex | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/config/screen.ex b/lib/config/screen.ex index 2243625..ffbc9b1 100644 --- a/lib/config/screen.ex +++ b/lib/config/screen.ex @@ -23,7 +23,7 @@ defmodule ScreensConfig.Screen do | :pre_fare_v2 @type t :: %__MODULE__{ - vendor: :gds | :mercury | :solari | :c3ms | :outfront | :lg_mri | :mimo | :n_a, + vendor: :gds | :mercury | :solari | :c3ms | :outfront | :lg_mri | :mimo | nil, device_id: String.t(), name: String.t(), app_id: app_id(), @@ -55,6 +55,7 @@ defmodule ScreensConfig.Screen do @recognized_app_ids ++ @recognized_v2_app_ids, &Atom.to_string/1 ) + @recognized_vendors ~w[gds mercury solari c3ms outfront lg_mri mimo]a @app_config_modules_by_app_id %{ bus_eink: Bus, @@ -122,14 +123,20 @@ defmodule ScreensConfig.Screen do |> String.ends_with?(@v2_app_id_suffix) end - defp value_from_json("vendor", vendor_string, _app_id) when vendor_string in ["n/a", ""] do - :n_a - end + defp value_from_json("vendor", vendor_string, _app_id) when vendor_string in ["n/a", ""], + do: nil + + for vendor <- @recognized_vendors do + vendor_string = Atom.to_string(vendor) - defp value_from_json("vendor", vendor_string, _app_id) do - String.to_existing_atom(vendor_string) + defp value_from_json("vendor", unquote(vendor_string), _app_id) do + unquote(vendor) + end end + defp value_from_json("vendor", unknown_vendor, _app_id), + do: raise("unknown vendor #{unknown_vendor}") + defp value_from_json("app_id", _app_id_string, app_id), do: app_id defp value_from_json("refresh_if_loaded_before", timestamp, _app_id) From 68d8da47950fe3300756564ee7cc7a63af2f322a Mon Sep 17 00:00:00 2001 From: cmaddox5 Date: Tue, 8 Oct 2024 14:11:15 -0400 Subject: [PATCH 4/4] Add nil to guard. --- lib/config/screen.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config/screen.ex b/lib/config/screen.ex index ffbc9b1..4c06fe5 100644 --- a/lib/config/screen.ex +++ b/lib/config/screen.ex @@ -123,7 +123,7 @@ defmodule ScreensConfig.Screen do |> String.ends_with?(@v2_app_id_suffix) end - defp value_from_json("vendor", vendor_string, _app_id) when vendor_string in ["n/a", ""], + defp value_from_json("vendor", vendor_string, _app_id) when vendor_string in ["n/a", "", nil], do: nil for vendor <- @recognized_vendors do