fix: convert WeatherUnits module attribute to runtime function to fix compile-connected xref
Some checks are pending
Elixir CI / Build and test (push) Waiting to run
Elixir CI / Dialyzer (push) Waiting to run
Elixir CI / Build and Push Docker Image (push) Blocked by required conditions

This commit is contained in:
Graham McIntire 2026-07-29 10:16:04 -05:00
parent 7bf0eecfbe
commit 8b62afa36b

View file

@ -212,15 +212,17 @@ defmodule AprsmeWeb.WeatherLive.CallsignView do
end
end
# Weather formatters mapping
@weather_formatters %{
temperature: {&WeatherUnits.format_temperature/2, ""},
wind_speed: {&WeatherUnits.format_wind_speed/2, " "},
wind_gust: {&WeatherUnits.format_wind_speed/2, " "},
rain_1h: {&WeatherUnits.format_rain/2, " "},
rain_24h: {&WeatherUnits.format_rain/2, " "},
rain_since_midnight: {&WeatherUnits.format_rain/2, " "}
}
# Weather formatters mapping (runtime function to avoid compile-time dependency)
defp weather_formatters do
%{
temperature: {&WeatherUnits.format_temperature/2, ""},
wind_speed: {&WeatherUnits.format_wind_speed/2, " "},
wind_gust: {&WeatherUnits.format_wind_speed/2, " "},
rain_1h: {&WeatherUnits.format_rain/2, " "},
rain_24h: {&WeatherUnits.format_rain/2, " "},
rain_since_midnight: {&WeatherUnits.format_rain/2, " "}
}
end
@doc """
Checks if a weather field has a valid value (not nil, "N/A", or empty).
@ -254,7 +256,7 @@ defmodule AprsmeWeb.WeatherLive.CallsignView do
end
defp format_string_value(value, key, locale) do
case @weather_formatters[key] do
case weather_formatters()[key] do
{formatter, separator} ->
case Float.parse(value) do
{num_value, _} ->
@ -271,7 +273,7 @@ defmodule AprsmeWeb.WeatherLive.CallsignView do
end
defp format_numeric_value(value, key, locale) do
case @weather_formatters[key] do
case weather_formatters()[key] do
{formatter, separator} ->
{converted_value, unit} = formatter.(value, locale)
"#{converted_value}#{separator}#{unit}"