From 62eb7f9949cbdeb0cbd0ce355e4109b36a20c32d Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Tue, 10 Mar 2026 13:25:51 -0500 Subject: [PATCH] fix: infer device role during discovery and handle string price values Device Type Fix: - Add Topology.maybe_update_device_role() call after discovery completes - Device types (AP, router, switch, etc.) now inferred immediately after discovery - Previously devices showed 'unknown' until first polling cycle completed - Role inference uses SNMP manufacturer, model, and system description Billing Fix: - Handle string values from Settings.get_setting() in default_price_per_device() - Add case clause to convert string '2.00' to Decimal struct - Fixes CaseClauseError crash on /orgs/:slug/settings page All discovery tests passing. --- lib/towerops/billing.ex | 1 + lib/towerops/snmp/discovery.ex | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/lib/towerops/billing.ex b/lib/towerops/billing.ex index 9aeff595..6e203565 100644 --- a/lib/towerops/billing.ex +++ b/lib/towerops/billing.ex @@ -39,6 +39,7 @@ defmodule Towerops.Billing do case Settings.get_setting("default_price_per_device") do nil -> @default_price_per_device %Decimal{} = decimal -> decimal + string when is_binary(string) -> Decimal.new(string) end end diff --git a/lib/towerops/snmp/discovery.ex b/lib/towerops/snmp/discovery.ex index fb262b09..9aca0c72 100644 --- a/lib/towerops/snmp/discovery.ex +++ b/lib/towerops/snmp/discovery.ex @@ -33,6 +33,7 @@ defmodule Towerops.Snmp.Discovery do alias Towerops.Snmp.Sensor alias Towerops.Snmp.Storage alias Towerops.Snmp.Vlan + alias Towerops.Topology alias Towerops.Workers.DiscoveryWorker require Logger @@ -276,6 +277,10 @@ defmodule Towerops.Snmp.Discovery do {:ok, check_counts} = Towerops.Snmp.create_checks_from_discovery(device, discovered_device) log_check_creation_results(device.id, check_counts) + # Infer and update device role from SNMP data + Logger.info("Inferring device role...", device_id: device.id) + _ = Topology.maybe_update_device_role(device) + _ = Phoenix.PubSub.broadcast( Towerops.PubSub,