From 95d94b0ce5f8e2e6c67cab004788e3974141ee5b Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Fri, 6 Mar 2026 16:45:37 -0600 Subject: [PATCH] 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. --- lib/towerops_web/live/device_live/index.ex | 27 ++++++++++++++-------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/towerops_web/live/device_live/index.ex b/lib/towerops_web/live/device_live/index.ex index 3a6cb5cb..95e070d1 100644 --- a/lib/towerops_web/live/device_live/index.ex +++ b/lib/towerops_web/live/device_live/index.ex @@ -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