diff --git a/test/towerops/snmp/profiles/vendors/routeros_test.exs b/test/towerops/snmp/profiles/vendors/routeros_test.exs index b071ad3d..b6158ffa 100644 --- a/test/towerops/snmp/profiles/vendors/routeros_test.exs +++ b/test/towerops/snmp/profiles/vendors/routeros_test.exs @@ -343,5 +343,48 @@ defmodule Towerops.Snmp.Profiles.Vendors.RouterosTest do assert voltage_sensor.sensor_divisor == 10 assert voltage_sensor.last_value == 12.0 end + + test "overrides sensor type when device reports wrong unit type" do + expect(SnmpMock, :walk, fn _, @wl_ap_table, _ -> {:ok, []} end) + expect(SnmpMock, :walk, fn _, @wl_stat_table, _ -> {:ok, []} end) + expect(SnmpMock, :walk, fn _, @wl_60g_table, _ -> {:ok, []} end) + expect(SnmpMock, :walk, fn _, @lte_modem_table, _ -> {:ok, []} end) + + # Device incorrectly reports unit type 1 (celsius/temperature) for voltage sensor + # This is the real-world bug case: sensor named "psu2-voltage" with unit type 1 + expect(SnmpMock, :walk, fn _, @gauge_table, _ -> + {:ok, + [ + # PSU voltage sensor incorrectly reported as temperature (unit type 1) + %{oid: "#{@gauge_table}.2.7201", value: "psu1-voltage"}, + %{oid: "#{@gauge_table}.3.7201", value: 469}, + %{oid: "#{@gauge_table}.4.7201", value: 1}, + # Another voltage sensor with wrong unit type + %{oid: "#{@gauge_table}.2.7202", value: "psu2-voltage"}, + %{oid: "#{@gauge_table}.3.7202", value: 469}, + %{oid: "#{@gauge_table}.4.7202", value: 1} + ]} + end) + + expect(SnmpMock, :walk, fn _, @optical_table, _ -> {:ok, []} end) + expect(SnmpMock, :get, 2, fn _, _oid, _ -> {:error, :timeout} end) + + sensors = Routeros.discover_wireless_sensors(@client_opts) + + # Verify both sensors are correctly overridden to voltage with divisor 10 + psu1_sensor = Enum.find(sensors, &(&1.sensor_descr == "psu1-voltage")) + assert psu1_sensor + assert psu1_sensor.sensor_type == "voltage" + assert psu1_sensor.sensor_unit == "V" + assert psu1_sensor.sensor_divisor == 10 + assert psu1_sensor.last_value == 46.9 + + psu2_sensor = Enum.find(sensors, &(&1.sensor_descr == "psu2-voltage")) + assert psu2_sensor + assert psu2_sensor.sensor_type == "voltage" + assert psu2_sensor.sensor_unit == "V" + assert psu2_sensor.sensor_divisor == 10 + assert psu2_sensor.last_value == 46.9 + end end end