fix: resolve dialyzer warnings in device_live/index.ex

Convert compile-time module attributes to runtime functions to avoid
dialyzer warnings about compile-time constant comparisons:

- tick_interval_ms: function instead of @tick_interval_ms
- debounce_ms: function instead of @debounce_ms

This fixes warnings where dialyzer knew the comparisons could never
be false/true based on compile-time values.
This commit is contained in:
Graham McIntire 2026-03-06 16:45:37 -06:00
parent 2a9f73e381
commit 95d94b0ce5
No known key found for this signature in database

View file

@ -282,15 +282,20 @@ defmodule ToweropsWeb.DeviceLive.Index do
{:noreply, reload_device_stream(socket)}
end
@tick_interval_ms if Mix.env() == :test, do: :infinity, else: to_timeout(second: 15)
defp tick_interval_ms do
if Mix.env() == :test, do: :infinity, else: to_timeout(second: 15)
end
defp schedule_tick do
if @tick_interval_ms != :infinity do
Process.send_after(self(), :tick, @tick_interval_ms)
case tick_interval_ms() do
:infinity -> :ok
interval -> Process.send_after(self(), :tick, interval)
end
end
@debounce_ms if Mix.env() == :test, do: 0, else: 100
defp debounce_ms do
if Mix.env() == :test, do: 0, else: 100
end
defp schedule_debounced_reload(socket, event) do
# Cancel any pending debounced reload
@ -302,12 +307,14 @@ defmodule ToweropsWeb.DeviceLive.Index do
if event == :device_status_changed && socket.assigns.active_tab == "discovered" do
assign(socket, :pending_reload_ref, nil)
else
if @debounce_ms == 0 do
# In test: reload immediately so render(view) sees the update
reload_device_stream(socket)
else
ref = Process.send_after(self(), :debounced_device_reload, @debounce_ms)
assign(socket, :pending_reload_ref, ref)
case debounce_ms() do
0 ->
# In test: reload immediately so render(view) sees the update
reload_device_stream(socket)
ms ->
ref = Process.send_after(self(), :debounced_device_reload, ms)
assign(socket, :pending_reload_ref, ref)
end
end
end