diff --git a/lib/config/audio_psa.ex b/lib/config/audio_psa.ex deleted file mode 100644 index 5001252..0000000 --- a/lib/config/audio_psa.ex +++ /dev/null @@ -1,67 +0,0 @@ -defmodule ScreensConfig.AudioPsa do - @moduledoc false - - @behaviour ScreensConfig.Behaviour - - @type t :: {format, String.t(), type} | nil - - @typep format :: :plaintext | :ssml - @typep type :: :takeover | :end - - @default_psa_format :plaintext - @default_psa_type :end - - @impl true - @spec from_json(map() | :default) :: t() - def from_json(%{"format" => format, "name" => name, "type" => type}) when is_binary(name) do - {format_from_json(format), name, type_from_json(type)} - end - - def from_json(_) do - nil - end - - @impl true - @spec to_json(t()) :: map() - def to_json({format, name, type}) do - %{ - format: format_to_json(format), - name: name, - type: type_to_json(type) - } - end - - def to_json(nil), do: nil - - for format <- ~w[plaintext ssml]a do - format_string = Atom.to_string(format) - - defp format_from_json(unquote(format_string)) do - unquote(format) - end - - defp format_to_json(unquote(format)) do - unquote(format_string) - end - end - - defp format_from_json(_) do - @default_psa_format - end - - for type <- ~w[takeover end]a do - type_string = Atom.to_string(type) - - defp type_from_json(unquote(type_string)) do - unquote(type) - end - - defp type_to_json(unquote(type)) do - unquote(type_string) - end - end - - defp type_from_json(_) do - @default_psa_type - end -end diff --git a/lib/config/bus.ex b/lib/config/bus.ex deleted file mode 100644 index ff88f09..0000000 --- a/lib/config/bus.ex +++ /dev/null @@ -1,26 +0,0 @@ -defmodule ScreensConfig.Bus do - @moduledoc false - - alias ScreensConfig.NearbyConnections - alias ScreensConfig.PsaConfig - - @type t :: %__MODULE__{ - stop_id: String.t(), - service_level: pos_integer(), - psa_config: PsaConfig.t(), - nearby_connections: NearbyConnections.t() - } - - @enforce_keys [:stop_id] - defstruct stop_id: nil, - service_level: 1, - psa_config: PsaConfig.from_json(:default), - nearby_connections: NearbyConnections.from_json(:default) - - use ScreensConfig.Struct, - children: [psa_config: PsaConfig, nearby_connections: NearbyConnections] - - defp value_from_json(_, value), do: value - - defp value_to_json(_, value), do: value -end diff --git a/lib/config/dup.ex b/lib/config/dup.ex deleted file mode 100644 index f105bfe..0000000 --- a/lib/config/dup.ex +++ /dev/null @@ -1,34 +0,0 @@ -defmodule ScreensConfig.Dup do - @moduledoc false - - alias ScreensConfig.Dup.{Departures, Override} - - @type t :: %__MODULE__{ - primary: Departures.t(), - secondary: Departures.t(), - override: {Override.screen0(), Override.screen1(), Override.screen2()} | nil - } - - defstruct primary: Departures.from_json(:default), - secondary: Departures.from_json(:default), - override: nil - - use ScreensConfig.Struct, children: [primary: Departures, secondary: Departures] - - defp value_from_json("override", [screen0, screen1, screen2]) do - {Override.screen0_from_json(screen0), Override.screen1_from_json(screen1), - Override.screen2_from_json(screen2)} - end - - defp value_from_json(_, value), do: value - - defp value_to_json(:override, {screen0, screen1, screen2}) do - [ - Override.screen0_to_json(screen0), - Override.screen1_to_json(screen1), - Override.screen2_to_json(screen2) - ] - end - - defp value_to_json(_, value), do: value -end diff --git a/lib/config/dup/departures.ex b/lib/config/dup/departures.ex deleted file mode 100644 index 2460a62..0000000 --- a/lib/config/dup/departures.ex +++ /dev/null @@ -1,19 +0,0 @@ -defmodule ScreensConfig.Dup.Departures do - @moduledoc false - - alias ScreensConfig.Dup.Section - - @type t :: %__MODULE__{ - header: String.t(), - sections: list(Section.t()) - } - - defstruct header: "", - sections: [] - - use ScreensConfig.Struct, with_default: true, children: [sections: {:list, Section}] - - defp value_from_json(_, value), do: value - - defp value_to_json(_, value), do: value -end diff --git a/lib/config/dup/override.ex b/lib/config/dup/override.ex deleted file mode 100644 index 6942b38..0000000 --- a/lib/config/dup/override.ex +++ /dev/null @@ -1,81 +0,0 @@ -defmodule ScreensConfig.Dup.Override do - @moduledoc false - - alias ScreensConfig.Dup.Override.{FullscreenAlert, FullscreenImage, PartialAlertList} - - @type screen0 :: PartialAlertList.t() | FullscreenAlert.t() | FullscreenImage.t() | nil - @type screen1 :: FullscreenAlert.t() | FullscreenImage.t() | nil - @type screen2 :: PartialAlertList.t() | nil - - def screen0_from_json(%{"type" => "partial"} = json) do - PartialAlertList.from_json(json) - end - - def screen0_from_json(%{"type" => "fullscreen"} = json) do - FullscreenAlert.from_json(json) - end - - def screen0_from_json(%{"type" => "image"} = json) do - FullscreenImage.from_json(json) - end - - def screen0_from_json(_) do - nil - end - - def screen1_from_json(%{"type" => "fullscreen"} = json) do - FullscreenAlert.from_json(json) - end - - def screen1_from_json(%{"type" => "image"} = json) do - FullscreenImage.from_json(json) - end - - def screen1_from_json(_) do - nil - end - - def screen2_from_json(%{"type" => "partial"} = json) do - PartialAlertList.from_json(json) - end - - def screen2_from_json(_) do - nil - end - - def screen0_to_json(%PartialAlertList{} = screen0) do - PartialAlertList.to_json(screen0) - end - - def screen0_to_json(%FullscreenAlert{} = screen0) do - FullscreenAlert.to_json(screen0) - end - - def screen0_to_json(%FullscreenImage{} = screen0) do - FullscreenImage.to_json(screen0) - end - - def screen0_to_json(_) do - nil - end - - def screen1_to_json(%FullscreenAlert{} = screen1) do - FullscreenAlert.to_json(screen1) - end - - def screen1_to_json(%FullscreenImage{} = screen1) do - FullscreenImage.to_json(screen1) - end - - def screen1_to_json(_) do - nil - end - - def screen2_to_json(%PartialAlertList{} = screen2) do - PartialAlertList.to_json(screen2) - end - - def screen2_to_json(_) do - nil - end -end diff --git a/lib/config/dup/override/fullscreen_alert.ex b/lib/config/dup/override/fullscreen_alert.ex deleted file mode 100644 index aca14ca..0000000 --- a/lib/config/dup/override/fullscreen_alert.ex +++ /dev/null @@ -1,47 +0,0 @@ -defmodule ScreensConfig.Dup.Override.FullscreenAlert do - @moduledoc false - - alias ScreensConfig.V2.FreeTextLine - - @type t :: %__MODULE__{ - header: String.t() | nil, - pattern: pattern, - color: color, - issue: FreeTextLine.t(), - remedy: FreeTextLine.t() - } - - @type pattern :: :hatched | :chevron | :x - @type color :: :red | :orange | :green | :blue | :silver | :purple | :yellow - - @enforce_keys ~w[pattern color issue remedy]a - defstruct [header: nil] ++ @enforce_keys - - use ScreensConfig.Struct, children: [issue: FreeTextLine, remedy: FreeTextLine] - - def to_json(%__MODULE__{} = t) do - t - |> super() - |> Map.put(:type, :fullscreen) - end - - for pattern <- ~w[hatched chevron x]a do - pattern_string = Atom.to_string(pattern) - - defp value_from_json("pattern", unquote(pattern_string)) do - unquote(pattern) - end - end - - for color <- ~w[red orange green blue silver purple yellow]a do - color_string = Atom.to_string(color) - - defp value_from_json("color", unquote(color_string)) do - unquote(color) - end - end - - defp value_from_json(_, value), do: value - - defp value_to_json(_, value), do: value -end diff --git a/lib/config/dup/override/fullscreen_image.ex b/lib/config/dup/override/fullscreen_image.ex deleted file mode 100644 index b0c86e6..0000000 --- a/lib/config/dup/override/fullscreen_image.ex +++ /dev/null @@ -1,21 +0,0 @@ -defmodule ScreensConfig.Dup.Override.FullscreenImage do - @moduledoc false - - @type t :: %__MODULE__{ - image_url: String.t() - } - - defstruct image_url: nil - - use ScreensConfig.Struct - - def to_json(%__MODULE__{} = t) do - t - |> super() - |> Map.put(:type, :image) - end - - defp value_from_json(_, value), do: value - - defp value_to_json(_, value), do: value -end diff --git a/lib/config/dup/override/partial_alert.ex b/lib/config/dup/override/partial_alert.ex deleted file mode 100644 index 69f1eed..0000000 --- a/lib/config/dup/override/partial_alert.ex +++ /dev/null @@ -1,27 +0,0 @@ -defmodule ScreensConfig.Dup.Override.PartialAlert do - @moduledoc false - - alias ScreensConfig.V2.FreeTextLine - - @type t :: %__MODULE__{ - color: color, - content: FreeTextLine.t() - } - - @type color :: :red | :orange | :green | :blue | :silver | :purple | :yellow - - @enforce_keys ~w[color content]a - defstruct @enforce_keys - - use ScreensConfig.Struct, children: [content: FreeTextLine] - - for color <- ~w[red orange green blue silver purple yellow]a do - color_string = Atom.to_string(color) - - defp value_from_json("color", unquote(color_string)) do - unquote(color) - end - end - - defp value_to_json(_, value), do: value -end diff --git a/lib/config/dup/override/partial_alert_list.ex b/lib/config/dup/override/partial_alert_list.ex deleted file mode 100644 index ad6141b..0000000 --- a/lib/config/dup/override/partial_alert_list.ex +++ /dev/null @@ -1,18 +0,0 @@ -defmodule ScreensConfig.Dup.Override.PartialAlertList do - @moduledoc false - - alias ScreensConfig.Dup.Override.PartialAlert - - @type t :: %__MODULE__{alerts: list(PartialAlert.t())} - - @enforce_keys [:alerts] - defstruct @enforce_keys - - use ScreensConfig.Struct, children: [alerts: {:list, PartialAlert}] - - def to_json(%__MODULE__{} = t) do - t - |> super() - |> Map.put(:type, :partial) - end -end diff --git a/lib/config/dup/section.ex b/lib/config/dup/section.ex deleted file mode 100644 index c2803d9..0000000 --- a/lib/config/dup/section.ex +++ /dev/null @@ -1,44 +0,0 @@ -defmodule ScreensConfig.Dup.Section do - @moduledoc false - - alias ScreensConfig.Dup.Section.Headway - alias ScreensConfig.RouteType - - @type t :: %__MODULE__{ - stop_ids: list(stop_id()), - route_ids: list(route_id()), - route_type: RouteType.t() | nil, - pill: :bus | :red | :orange | :green | :blue | :cr | :mattapan | :silver | :ferry, - headway: Headway.t(), - direction_id: 0 | 1 | nil - } - - @type stop_id :: String.t() - @type route_id :: String.t() - - @enforce_keys [:pill] - defstruct stop_ids: [], - route_ids: [], - route_type: nil, - pill: nil, - headway: Headway.from_json(:default), - direction_id: nil - - use ScreensConfig.Struct, children: [headway: Headway] - - for pill <- ~w[bus red orange green blue cr mattapan silver ferry]a do - pill_string = Atom.to_string(pill) - - defp value_from_json("pill", unquote(pill_string)) do - unquote(pill) - end - end - - defp value_from_json("route_type", route_type) when is_binary(route_type) do - RouteType.from_string(route_type) - end - - defp value_from_json(_, value), do: value - - defp value_to_json(_, value), do: value -end diff --git a/lib/config/dup/section/headway.ex b/lib/config/dup/section/headway.ex deleted file mode 100644 index 04a5a86..0000000 --- a/lib/config/dup/section/headway.ex +++ /dev/null @@ -1,25 +0,0 @@ -defmodule ScreensConfig.Dup.Section.Headway do - @moduledoc false - - @typep sign_id :: String.t() - @typep headway_id :: String.t() | nil - @typep override :: {pos_integer, pos_integer} | nil - - @type t :: %__MODULE__{ - sign_ids: [sign_id], - headway_id: headway_id, - override: override - } - - defstruct sign_ids: [], - headway_id: nil, - override: nil - - use ScreensConfig.Struct, with_default: true - - defp value_from_json("override", [lo, hi]), do: {lo, hi} - defp value_from_json(_, value), do: value - - defp value_to_json(:override, {lo, hi}), do: [lo, hi] - defp value_to_json(_, value), do: value -end diff --git a/lib/config/gl.ex b/lib/config/gl.ex deleted file mode 100644 index 1987438..0000000 --- a/lib/config/gl.ex +++ /dev/null @@ -1,32 +0,0 @@ -defmodule ScreensConfig.Gl do - @moduledoc false - - alias ScreensConfig.PsaConfig - - @type t :: %__MODULE__{ - stop_id: String.t(), - platform_id: String.t(), - route_id: String.t(), - direction_id: 0 | 1, - headway_mode: boolean(), - service_level: pos_integer(), - psa_config: PsaConfig.t(), - nearby_departures: list(String.t()) - } - - @enforce_keys [:stop_id, :platform_id, :route_id, :direction_id] - defstruct stop_id: nil, - platform_id: nil, - route_id: nil, - direction_id: nil, - headway_mode: false, - service_level: 1, - psa_config: PsaConfig.from_json(:default), - nearby_departures: [] - - use ScreensConfig.Struct, children: [psa_config: PsaConfig] - - defp value_from_json(_, value), do: value - - defp value_to_json(_, value), do: value -end diff --git a/lib/config/nearby_connection.ex b/lib/config/nearby_connection.ex deleted file mode 100644 index 286a0ef..0000000 --- a/lib/config/nearby_connection.ex +++ /dev/null @@ -1,22 +0,0 @@ -defmodule ScreensConfig.NearbyConnection do - @moduledoc false - - @behaviour ScreensConfig.Behaviour - - @type t :: {stop_id, list(route_id)} - @typep stop_id :: String.t() - @typep route_id :: String.t() - - @impl true - @spec from_json(map()) :: t() - def from_json(%{"stop" => stop, "routes_at_stop" => routes_at_stop}) - when is_list(routes_at_stop) do - {stop, routes_at_stop} - end - - @impl true - @spec to_json(t()) :: map() - def to_json({stop, routes_at_stop}) do - %{"stop" => stop, "routes_at_stop" => routes_at_stop} - end -end diff --git a/lib/config/nearby_connections.ex b/lib/config/nearby_connections.ex deleted file mode 100644 index 67c4bd2..0000000 --- a/lib/config/nearby_connections.ex +++ /dev/null @@ -1,23 +0,0 @@ -defmodule ScreensConfig.NearbyConnections do - @moduledoc false - - @behaviour ScreensConfig.Behaviour - - alias ScreensConfig.NearbyConnection - - @type t :: list(NearbyConnection.t()) - - @impl true - @spec from_json(list() | :default) :: t() - def from_json(json) when is_list(json) do - Enum.map(json, &NearbyConnection.from_json/1) - end - - def from_json(:default), do: [] - - @impl true - @spec to_json(t()) :: list() - def to_json(nearby_connections) do - Enum.map(nearby_connections, &NearbyConnection.to_json/1) - end -end diff --git a/lib/config/psa_config.ex b/lib/config/psa_config.ex deleted file mode 100644 index 8987ba5..0000000 --- a/lib/config/psa_config.ex +++ /dev/null @@ -1,21 +0,0 @@ -defmodule ScreensConfig.PsaConfig do - @moduledoc false - - alias ScreensConfig.PsaConfig.{OverrideList, PsaList} - - @type t :: %__MODULE__{ - default_list: PsaList.t(), - scheduled_overrides: [OverrideList.t()] - } - - defstruct default_list: PsaList.from_json(:default), - scheduled_overrides: [] - - use ScreensConfig.Struct, - with_default: true, - children: [default_list: PsaList, scheduled_overrides: {:list, OverrideList}] - - defp value_from_json(_, value), do: value - - defp value_to_json(_, value), do: value -end diff --git a/lib/config/psa_config/override_list.ex b/lib/config/psa_config/override_list.ex deleted file mode 100644 index 963c37b..0000000 --- a/lib/config/psa_config/override_list.ex +++ /dev/null @@ -1,39 +0,0 @@ -defmodule ScreensConfig.PsaConfig.OverrideList do - @moduledoc false - - alias ScreensConfig.PsaConfig.PsaList - - @type t :: %__MODULE__{ - psa_list: PsaList.t(), - start_time: nullable_datetime(), - end_time: nullable_datetime() - } - - @typep nullable_datetime :: DateTime.t() | nil - - @enforce_keys ~w[psa_list start_time end_time]a - defstruct @enforce_keys - - use ScreensConfig.Struct, children: [psa_list: PsaList] - - for datetime_key <- ~w[start_time end_time]a do - datetime_key_string = Atom.to_string(datetime_key) - - defp value_from_json(unquote(datetime_key_string), nil), do: nil - - defp value_from_json(unquote(datetime_key_string), iso_string) do - {:ok, dt, _offset} = DateTime.from_iso8601(iso_string) - dt - end - - defp value_to_json(unquote(datetime_key), nil), do: nil - - defp value_to_json(unquote(datetime_key), datetime) do - DateTime.to_iso8601(datetime) - end - end - - defp value_from_json(_, value), do: value - - defp value_to_json(_, value), do: value -end diff --git a/lib/config/psa_config/psa_list.ex b/lib/config/psa_config/psa_list.ex deleted file mode 100644 index 02b360b..0000000 --- a/lib/config/psa_config/psa_list.ex +++ /dev/null @@ -1,53 +0,0 @@ -defmodule ScreensConfig.PsaConfig.PsaList do - @moduledoc false - - @behaviour ScreensConfig.Behaviour - - @type t :: { - psa_type, - list(String.t()) - } - - @default_psa_type nil - - @type psa_type :: bus_psa_type | gl_psa_type | solari_psa_type | nil - - @type bus_psa_type :: :double | :takeover - @type gl_psa_type :: :double | :takeover | :departure - @type solari_psa_type :: :slide_in | :takeover - - @impl true - @spec from_json(map() | :default) :: t() - def from_json(%{} = json) do - type = Map.get(json, "type", :default) - paths = Map.get(json, "paths", []) - paths = if is_list(paths), do: paths, else: [] - - {type_from_json(type), paths} - end - - def from_json(:default) do - {@default_psa_type, []} - end - - @impl true - @spec to_json(t()) :: map() - def to_json({type, paths}) do - %{ - type: type, - paths: paths - } - end - - for psa_type <- ~w[slide_in double takeover departure]a do - psa_type_string = Atom.to_string(psa_type) - - defp type_from_json(unquote(psa_type_string)) do - unquote(psa_type) - end - end - - defp type_from_json(_) do - @default_psa_type - end -end diff --git a/lib/config/query.ex b/lib/config/query.ex deleted file mode 100644 index d9a8722..0000000 --- a/lib/config/query.ex +++ /dev/null @@ -1,15 +0,0 @@ -defmodule ScreensConfig.Query do - @moduledoc false - - alias ScreensConfig.Query.{Opts, Params} - - @type t :: %__MODULE__{ - params: Params.t(), - opts: Opts.t() - } - - defstruct params: Params.from_json(:default), - opts: Opts.from_json(:default) - - use ScreensConfig.Struct, with_default: true, children: [params: Params, opts: Opts] -end diff --git a/lib/config/query/opts.ex b/lib/config/query/opts.ex deleted file mode 100644 index 7aa0b7f..0000000 --- a/lib/config/query/opts.ex +++ /dev/null @@ -1,16 +0,0 @@ -defmodule ScreensConfig.Query.Opts do - @moduledoc false - # credo:disable-for-this-file Credo.Check.Design.DuplicatedCode - - @type t :: %__MODULE__{ - include_schedules: boolean() - } - - defstruct include_schedules: false - - use ScreensConfig.Struct, with_default: true - - defp value_from_json(_, value), do: value - - defp value_to_json(_, value), do: value -end diff --git a/lib/config/query/params.ex b/lib/config/query/params.ex deleted file mode 100644 index 7e31c22..0000000 --- a/lib/config/query/params.ex +++ /dev/null @@ -1,30 +0,0 @@ -defmodule ScreensConfig.Query.Params do - @moduledoc false - # credo:disable-for-this-file Credo.Check.Design.DuplicatedCode - - alias ScreensConfig.RouteType - - @type t :: %__MODULE__{ - stop_ids: list(String.t()), - route_ids: list(String.t()), - direction_id: 0 | 1 | :both, - route_type: RouteType.t() | nil - } - - defstruct stop_ids: [], - route_ids: [], - direction_id: :both, - route_type: nil - - use ScreensConfig.Struct, with_default: true - - defp value_from_json("direction_id", "both"), do: :both - - defp value_from_json("route_type", route_type) when is_binary(route_type) do - RouteType.from_string(route_type) - end - - defp value_from_json(_, value), do: value - - defp value_to_json(_, value), do: value -end diff --git a/lib/config/route.ex b/lib/config/route.ex deleted file mode 100644 index 3f119f4..0000000 --- a/lib/config/route.ex +++ /dev/null @@ -1,5 +0,0 @@ -defmodule ScreensConfig.Routes.Route do - @moduledoc false - - @type id :: String.t() -end diff --git a/lib/config/screen.ex b/lib/config/screen.ex index 4c06fe5..d29a07b 100644 --- a/lib/config/screen.ex +++ b/lib/config/screen.ex @@ -3,87 +3,60 @@ defmodule ScreensConfig.Screen do @behaviour ScreensConfig.Behaviour - alias ScreensConfig.{Bus, Dup, Gl, Solari, V2} - alias ScreensConfig.Util + alias ScreensConfig.{Util, V2} @type app_id :: - :bus_eink - | :bus_eink_v2 + :bus_eink_v2 | :bus_shelter_v2 | :busway_v2 - | :dup | :dup_v2 | :elevator_v2 - | :gl_eink_single - | :gl_eink_double | :gl_eink_v2 - | :solari - | :solari_large - | :solari_large_v2 | :pre_fare_v2 @type t :: %__MODULE__{ - vendor: :gds | :mercury | :solari | :c3ms | :outfront | :lg_mri | :mimo | nil, - device_id: String.t(), - name: String.t(), app_id: app_id(), - refresh_if_loaded_before: DateTime.t() | nil, - disabled: boolean(), - hidden_from_screenplay: boolean(), app_params: - Bus.t() - | Dup.t() - | Gl.t() - | Solari.t() - | V2.BusEink.t() + V2.BusEink.t() | V2.BusShelter.t() | V2.Busway.t() | V2.Dup.t() | V2.Elevator.t() | V2.GlEink.t() - | V2.PreFare.t() - | V2.SolariLarge.t(), - tags: list(String.t()) + | V2.PreFare.t(), + device_id: String.t(), + disabled: boolean(), + hidden_from_screenplay: boolean(), + name: String.t(), + refresh_if_loaded_before: DateTime.t() | nil, + tags: list(String.t()), + vendor: :c3ms | :gds | :lg_mri | :mercury | :mimo | :outfront | :solari | nil } - # If a Screens client app uses widgets, its ID must end with this suffix. - @v2_app_id_suffix "_v2" - - @recognized_app_ids ~w[bus_eink dup gl_eink_single gl_eink_double solari solari_large]a - @recognized_v2_app_ids ~w[bus_eink_v2 bus_shelter_v2 busway_v2 dup_v2 elevator_v2 gl_eink_v2 solari_large_v2 pre_fare_v2]a - @recognized_app_id_strings Enum.map( - @recognized_app_ids ++ @recognized_v2_app_ids, - &Atom.to_string/1 - ) + @recognized_app_ids ~w[bus_eink_v2 bus_shelter_v2 busway_v2 dup_v2 elevator_v2 gl_eink_v2 solari_large_v2 pre_fare_v2]a + @recognized_app_id_strings Enum.map(@recognized_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, bus_eink_v2: V2.BusEink, bus_shelter_v2: V2.BusShelter, busway_v2: V2.Busway, - dup: Dup, dup_v2: V2.Dup, elevator_v2: V2.Elevator, - gl_eink_single: Gl, - gl_eink_double: Gl, gl_eink_v2: V2.GlEink, - solari: Solari, - solari_large: Solari, - solari_large_v2: V2.SolariLarge, pre_fare_v2: V2.PreFare } - @enforce_keys [:vendor, :device_id, :name, :app_id, :app_params] - defstruct vendor: nil, + @enforce_keys ~w[app_id app_params device_id name vendor]a + defstruct app_id: nil, + app_params: nil, device_id: nil, - name: nil, - app_id: nil, - refresh_if_loaded_before: nil, disabled: false, hidden_from_screenplay: false, - app_params: nil, - tags: [] + name: nil, + refresh_if_loaded_before: nil, + tags: [], + vendor: nil @impl true @spec from_json(map()) :: t() | nil @@ -116,13 +89,6 @@ defmodule ScreensConfig.Screen do %__MODULE__{screen_config | refresh_if_loaded_before: time} end - @spec v2_screen?(t()) :: boolean() - def v2_screen?(screen_config) do - screen_config.app_id - |> Atom.to_string() - |> String.ends_with?(@v2_app_id_suffix) - end - defp value_from_json("vendor", vendor_string, _app_id) when vendor_string in ["n/a", "", nil], do: nil diff --git a/lib/config/solari.ex b/lib/config/solari.ex deleted file mode 100644 index 4af6a81..0000000 --- a/lib/config/solari.ex +++ /dev/null @@ -1,37 +0,0 @@ -defmodule ScreensConfig.Solari do - @moduledoc false - - alias ScreensConfig.{AudioPsa, PsaConfig, Solari.Section} - - @type t :: %__MODULE__{ - station_name: String.t(), - overhead: boolean(), - section_headers: :normal | :vertical | :none, - sections: list(Section.t()), - psa_config: PsaConfig.t(), - audio_psa: AudioPsa.t() - } - - @enforce_keys [:station_name] - defstruct station_name: nil, - overhead: false, - section_headers: :normal, - sections: [], - psa_config: PsaConfig.from_json(:default), - audio_psa: AudioPsa.from_json(:default) - - use ScreensConfig.Struct, - children: [sections: {:list, Section}, psa_config: PsaConfig, audio_psa: AudioPsa] - - for headers <- ~w[normal vertical none]a do - headers_string = Atom.to_string(headers) - - defp value_from_json("section_headers", unquote(headers_string)) do - unquote(headers) - end - end - - defp value_from_json(_, value), do: value - - defp value_to_json(_, value), do: value -end diff --git a/lib/config/solari/section.ex b/lib/config/solari/section.ex deleted file mode 100644 index 1b3edf3..0000000 --- a/lib/config/solari/section.ex +++ /dev/null @@ -1,48 +0,0 @@ -defmodule ScreensConfig.Solari.Section do - @moduledoc false - - alias ScreensConfig.Query - alias ScreensConfig.Solari.Section.{Audio, Headway, Layout} - - @type t :: %__MODULE__{ - name: String.t(), - arrow: :n | :e | :s | :w | :ne | :se | :sw | :nw | nil, - query: Query.t(), - layout: Layout.t(), - audio: Audio.t(), - pill: :bus | :red | :orange | :green | :blue | :cr | :mattapan | :silver, - headway: Headway.t() - } - - @enforce_keys [:name, :pill] - defstruct name: nil, - arrow: nil, - query: Query.from_json(:default), - layout: Layout.from_json(:default), - audio: Audio.from_json(:default), - pill: nil, - headway: Headway.from_json(:default) - - use ScreensConfig.Struct, - children: [query: Query, layout: Layout, audio: Audio, headway: Headway] - - for arrow <- ~w[n e s w ne se sw nw]a do - arrow_string = Atom.to_string(arrow) - - defp value_from_json("arrow", unquote(arrow_string)) do - unquote(arrow) - end - end - - for pill <- ~w[bus red orange green blue cr mattapan silver]a do - pill_string = Atom.to_string(pill) - - defp value_from_json("pill", unquote(pill_string)) do - unquote(pill) - end - end - - defp value_from_json(_, value), do: value - - defp value_to_json(_, value), do: value -end diff --git a/lib/config/solari/section/audio.ex b/lib/config/solari/section/audio.ex deleted file mode 100644 index 9048dd9..0000000 --- a/lib/config/solari/section/audio.ex +++ /dev/null @@ -1,15 +0,0 @@ -defmodule ScreensConfig.Solari.Section.Audio do - @moduledoc false - - @type t :: %__MODULE__{ - wayfinding: String.t() | nil - } - - defstruct wayfinding: nil - - use ScreensConfig.Struct, with_default: true - - defp value_from_json(_, value), do: value - - defp value_to_json(_, value), do: value -end diff --git a/lib/config/solari/section/headway.ex b/lib/config/solari/section/headway.ex deleted file mode 100644 index fde172a..0000000 --- a/lib/config/solari/section/headway.ex +++ /dev/null @@ -1,23 +0,0 @@ -defmodule ScreensConfig.Solari.Section.Headway do - @moduledoc false - - @typep sign_id :: String.t() - @typep headway_id :: String.t() - @typep headsign :: String.t() - - @type t :: %__MODULE__{ - sign_ids: [sign_id], - headway_id: headway_id, - headsigns: [headsign] - } - - defstruct sign_ids: [], - headway_id: nil, - headsigns: [] - - use ScreensConfig.Struct, with_default: true - - defp value_from_json(_, value), do: value - - defp value_to_json(_, value), do: value -end diff --git a/lib/config/solari/section/layout.ex b/lib/config/solari/section/layout.ex deleted file mode 100644 index 25882b4..0000000 --- a/lib/config/solari/section/layout.ex +++ /dev/null @@ -1,69 +0,0 @@ -defmodule ScreensConfig.Solari.Section.Layout do - @moduledoc false - - alias ScreensConfig.Solari.Section.Layout.{Bidirectional, Upcoming} - - @behaviour ScreensConfig.Behaviour - - @type t :: - Bidirectional.t() - | Upcoming.t() - - @default_type :upcoming - - @opts_modules %{ - bidirectional: Bidirectional, - upcoming: Upcoming - } - - @impl true - @spec from_json(map() | :default) :: t() - def from_json(%{} = json) do - type = Map.get(json, "type", :default) - opts = Map.get(json, "opts", :default) - - opts_from_json(opts, type) - end - - def from_json(:default) do - @opts_modules[@default_type].from_json(:default) - end - - @impl true - @spec to_json(t()) :: map() - def to_json(%Bidirectional{} = layout) do - %{ - "type" => "bidirectional", - "opts" => Bidirectional.to_json(layout) - } - end - - def to_json(%Upcoming{} = layout) do - %{ - "type" => "upcoming", - "opts" => Upcoming.to_json(layout) - } - end - - for type <- ~w[bidirectional upcoming]a do - type_string = Atom.to_string(type) - - opts_module = @opts_modules[type] - - defp type_to_json(unquote(type)) do - unquote(type_string) - end - - defp opts_from_json(opts, unquote(type_string)) do - unquote(opts_module).from_json(opts) - end - - defp opts_to_json(opts, unquote(type)) do - unquote(opts_module).to_json(opts) - end - end - - defp opts_from_json(_, _) do - @opts_modules[@default_type].from_json(:default) - end -end diff --git a/lib/config/solari/section/layout/bidirectional.ex b/lib/config/solari/section/layout/bidirectional.ex deleted file mode 100644 index b3469cb..0000000 --- a/lib/config/solari/section/layout/bidirectional.ex +++ /dev/null @@ -1,17 +0,0 @@ -defmodule ScreensConfig.Solari.Section.Layout.Bidirectional do - @moduledoc false - - alias ScreensConfig.Solari.Section.Layout.RouteConfig - - @type t :: %__MODULE__{ - routes: RouteConfig.t() - } - - defstruct routes: RouteConfig.from_json(:default) - - use ScreensConfig.Struct, with_default: true, children: [routes: RouteConfig] - - defp value_from_json(_, value), do: value - - defp value_to_json(_, value), do: value -end diff --git a/lib/config/solari/section/layout/route_config.ex b/lib/config/solari/section/layout/route_config.ex deleted file mode 100644 index 65d9ff6..0000000 --- a/lib/config/solari/section/layout/route_config.ex +++ /dev/null @@ -1,53 +0,0 @@ -defmodule ScreensConfig.Solari.Section.Layout.RouteConfig do - @moduledoc false - - alias ScreensConfig.Solari.Section.Layout.RouteConfig.RouteDescriptor - - @behaviour ScreensConfig.Behaviour - - @type t :: {:exclude | :include, list(RouteDescriptor.t())} - - @default_action :exclude - - @impl true - @spec from_json(map() | :default) :: t() - def from_json(%{} = json) do - action = Map.get(json, "action", :default) - route_list = Map.get(json, "route_list", []) - route_list = if is_list(route_list), do: route_list, else: [] - - { - action_from_json(action), - Enum.map(route_list, &RouteDescriptor.from_json/1) - } - end - - def from_json(:default) do - {@default_action, []} - end - - @impl true - @spec to_json(t()) :: map() - def to_json({action, route_list}) do - %{ - "action" => action_to_json(action), - "route_list" => Enum.map(route_list, &RouteDescriptor.to_json/1) - } - end - - for action <- ~w[exclude include]a do - action_string = Atom.to_string(action) - - defp action_from_json(unquote(action_string)) do - unquote(action) - end - - defp action_to_json(unquote(action)) do - unquote(action_string) - end - end - - defp action_from_json(_) do - @default_action - end -end diff --git a/lib/config/solari/section/layout/route_config/route_descriptor.ex b/lib/config/solari/section/layout/route_config/route_descriptor.ex deleted file mode 100644 index 37acf83..0000000 --- a/lib/config/solari/section/layout/route_config/route_descriptor.ex +++ /dev/null @@ -1,21 +0,0 @@ -defmodule ScreensConfig.Solari.Section.Layout.RouteConfig.RouteDescriptor do - @moduledoc false - - @behaviour ScreensConfig.Behaviour - - @type t :: {String.t(), direction_id} - - @type direction_id :: 0 | 1 - - @impl true - @spec from_json(map()) :: t() - def from_json(%{"route" => route, "direction_id" => direction_id}) do - {route, direction_id} - end - - @impl true - @spec to_json(t()) :: map() - def to_json({route, direction_id}) do - %{"route" => route, "direction_id" => direction_id} - end -end diff --git a/lib/config/solari/section/layout/upcoming.ex b/lib/config/solari/section/layout/upcoming.ex deleted file mode 100644 index 05e2bab..0000000 --- a/lib/config/solari/section/layout/upcoming.ex +++ /dev/null @@ -1,33 +0,0 @@ -defmodule ScreensConfig.Solari.Section.Layout.Upcoming do - @moduledoc false - - alias ScreensConfig.Solari.Section.Layout.RouteConfig - - @type t :: %__MODULE__{ - num_rows: pos_integer() | :infinity, - paged: boolean(), - visible_rows: pos_integer() | :infinity, - routes: RouteConfig.t(), - max_minutes: pos_integer() | :infinity - } - - defstruct num_rows: 1, - paged: false, - visible_rows: 1, - routes: RouteConfig.from_json(:default), - max_minutes: :infinity - - use ScreensConfig.Struct, with_default: true, children: [routes: RouteConfig] - - for key <- ~w[num_rows visible_rows max_minutes]a do - key_string = Atom.to_string(key) - - defp value_from_json(unquote(key_string), "infinity"), do: :infinity - - defp value_to_json(unquote(key), :infinity), do: "infinity" - end - - defp value_from_json(_, value), do: value - - defp value_to_json(_, value), do: value -end diff --git a/lib/config/stop.ex b/lib/config/stop.ex deleted file mode 100644 index 7fc00d0..0000000 --- a/lib/config/stop.ex +++ /dev/null @@ -1,5 +0,0 @@ -defmodule ScreensConfig.Stops.Stop do - @moduledoc false - - @type id :: String.t() -end diff --git a/lib/config/v2/line_map.ex b/lib/config/v2/line_map.ex index 189f44a..1be2886 100644 --- a/lib/config/v2/line_map.ex +++ b/lib/config/v2/line_map.ex @@ -2,10 +2,10 @@ defmodule ScreensConfig.V2.LineMap do @moduledoc false @type t :: %__MODULE__{ - stop_id: ScreensConfig.Stops.Stop.id(), - station_id: ScreensConfig.Stops.Stop.id(), + stop_id: String.t(), + station_id: String.t(), direction_id: 0 | 1, - route_id: ScreensConfig.Routes.Route.id() + route_id: String.t() } @enforce_keys [:stop_id, :station_id, :direction_id, :route_id] diff --git a/lib/config/v2/solari_large.ex b/lib/config/v2/solari_large.ex deleted file mode 100644 index 87ece54..0000000 --- a/lib/config/v2/solari_large.ex +++ /dev/null @@ -1,18 +0,0 @@ -defmodule ScreensConfig.V2.SolariLarge do - @moduledoc false - # credo:disable-for-this-file Credo.Check.Design.DuplicatedCode - - alias ScreensConfig.V2.Departures - alias ScreensConfig.V2.Header.CurrentStopName - - @type t :: %__MODULE__{ - departures: Departures.t(), - header: CurrentStopName.t() - } - - @enforce_keys [:departures, :header] - defstruct departures: nil, - header: nil - - use ScreensConfig.Struct, children: [departures: Departures, header: CurrentStopName] -end