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

chore: Fix vendors #37

Merged
merged 4 commits into from
Oct 8, 2024
Merged
Changes from 3 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
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", ""],
do: nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to include nil as a possible input here so the null that is ultimately saved to the configuration can round-trip successfully:

defp value_from_json("vendor", vendor, _app_id) when vendor in [nil, "", "n/a"], 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
Loading