Skip to content

Commit

Permalink
chore: Fix vendors (#37)
Browse files Browse the repository at this point in the history
* Fix list of recognized vendors.

* Map empty vendor to n/a.

* Use hardcoded list of vendors instead of converting strings to atoms.

* Add nil to guard.
  • Loading branch information
cmaddox5 authored Oct 8, 2024
1 parent 35f77a8 commit ff30a95
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/config/screen.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 | nil,
device_id: String.t(),
name: String.t(),
app_id: app_id(),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -122,14 +123,20 @@ defmodule ScreensConfig.Screen do
|> String.ends_with?(@v2_app_id_suffix)
end

for vendor <- ~w[gds mercury solari mimo c3ms outfront]a do
defp value_from_json("vendor", vendor_string, _app_id) when vendor_string in ["n/a", "", nil],
do: nil

for vendor <- @recognized_vendors do
vendor_string = Atom.to_string(vendor)

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)
Expand Down

0 comments on commit ff30a95

Please sign in to comment.