Add dialyzer type specs to refactored functions
Added comprehensive type specifications to all recently refactored functions to improve type safety and enable dialyzer checking: PollerWorker: - detect_sensor_changes/3 - extract_thresholds/1 - detect_and_log_changes/4 EquipmentLive.Form: - extract_snmp_config/1 - normalize_port/1 - test_snmp_connection/1 EquipmentLive.Show: - seconds_to_weeks/1, seconds_to_days/1 - seconds_to_hours/1, seconds_to_minutes/1 - format_time_part/2 All specs use proper Elixir types and handle nil cases appropriately.
This commit is contained in:
parent
fb4da2df6d
commit
a1e163d3ee
3 changed files with 34 additions and 0 deletions
|
|
@ -308,6 +308,12 @@ defmodule Towerops.Snmp.PollerWorker do
|
|||
end
|
||||
end
|
||||
|
||||
@spec detect_and_log_changes(
|
||||
Towerops.Snmp.Interface.t(),
|
||||
map(),
|
||||
Ecto.UUID.t(),
|
||||
DateTime.t()
|
||||
) :: :ok | nil
|
||||
defp detect_and_log_changes(interface, current_attrs, equipment_id, timestamp) do
|
||||
events =
|
||||
[]
|
||||
|
|
@ -599,6 +605,7 @@ defmodule Towerops.Snmp.PollerWorker do
|
|||
end
|
||||
end
|
||||
|
||||
@spec detect_sensor_changes(Towerops.Snmp.Sensor.t(), float(), DateTime.t()) :: :ok
|
||||
defp detect_sensor_changes(sensor, current_value, timestamp) do
|
||||
# Skip change detection if there's no previous value to compare against
|
||||
if sensor.last_value == nil do
|
||||
|
|
@ -616,6 +623,12 @@ defmodule Towerops.Snmp.PollerWorker do
|
|||
end
|
||||
end
|
||||
|
||||
@spec extract_thresholds(map()) :: %{
|
||||
warning_high: float() | nil,
|
||||
critical_high: float() | nil,
|
||||
warning_low: float() | nil,
|
||||
critical_low: float() | nil
|
||||
}
|
||||
defp extract_thresholds(metadata) do
|
||||
%{
|
||||
warning_high: metadata["warning_high"],
|
||||
|
|
|
|||
|
|
@ -180,6 +180,12 @@ defmodule ToweropsWeb.EquipmentLive.Form do
|
|||
end
|
||||
end
|
||||
|
||||
@spec extract_snmp_config(Phoenix.HTML.Form.t()) :: %{
|
||||
ip_address: String.t() | nil,
|
||||
snmp_community: String.t() | nil,
|
||||
snmp_version: String.t() | nil,
|
||||
snmp_port: integer()
|
||||
}
|
||||
defp extract_snmp_config(form) do
|
||||
form_data = form.data
|
||||
params = form.params
|
||||
|
|
@ -192,10 +198,17 @@ defmodule ToweropsWeb.EquipmentLive.Form do
|
|||
}
|
||||
end
|
||||
|
||||
@spec normalize_port(integer() | String.t() | any()) :: integer()
|
||||
defp normalize_port(port) when is_integer(port), do: port
|
||||
defp normalize_port(port) when is_binary(port), do: String.to_integer(port)
|
||||
defp normalize_port(_), do: 161
|
||||
|
||||
@spec test_snmp_connection(%{
|
||||
ip_address: String.t() | nil,
|
||||
snmp_community: String.t() | nil,
|
||||
snmp_version: String.t() | nil,
|
||||
snmp_port: integer()
|
||||
}) :: %{success: boolean(), message: String.t()}
|
||||
defp test_snmp_connection(config) do
|
||||
case Snmp.test_connection(
|
||||
config.ip_address,
|
||||
|
|
|
|||
|
|
@ -179,11 +179,19 @@ defmodule ToweropsWeb.EquipmentLive.Show do
|
|||
end
|
||||
end
|
||||
|
||||
@spec seconds_to_weeks(integer()) :: {integer(), integer()}
|
||||
defp seconds_to_weeks(seconds), do: {div(seconds, 604_800), rem(seconds, 604_800)}
|
||||
|
||||
@spec seconds_to_days(integer()) :: {integer(), integer()}
|
||||
defp seconds_to_days(seconds), do: {div(seconds, 86_400), rem(seconds, 86_400)}
|
||||
|
||||
@spec seconds_to_hours(integer()) :: {integer(), integer()}
|
||||
defp seconds_to_hours(seconds), do: {div(seconds, 3600), rem(seconds, 3600)}
|
||||
|
||||
@spec seconds_to_minutes(integer()) :: {integer(), integer()}
|
||||
defp seconds_to_minutes(seconds), do: {div(seconds, 60), rem(seconds, 60)}
|
||||
|
||||
@spec format_time_part(integer(), String.t()) :: String.t() | nil
|
||||
defp format_time_part(0, _unit), do: nil
|
||||
defp format_time_part(1, unit), do: "1 #{unit}"
|
||||
defp format_time_part(count, unit), do: "#{count} #{unit}s"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue