From 6d597f7e76fbb0ef1e2b0b8efdb3b7d9a7d19c5a Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Wed, 11 Feb 2026 14:09:22 -0600 Subject: [PATCH] round sensor readings to 1 decimal place division by sensor_divisor produced full float precision values like 34.09999999. apply Float.round/2 in both the phoenix poller and agent channel paths. --- CHANGELOG.txt | 6 ++++++ lib/towerops/workers/device_poller_worker.ex | 2 +- lib/towerops_web/channels/agent_channel.ex | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 4c94d41b..5929a2e4 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,6 +1,12 @@ CHANGELOG - towerops-web ======================== +2026-02-11 - fix: round sensor values to 1 decimal place + - Files: lib/towerops/workers/device_poller_worker.ex (poll_simple_sensor/2), + lib/towerops_web/channels/agent_channel.ex (process_sensor_reading/3) + - Bug: Division by sensor_divisor produced full float precision (e.g. 34.09999999) + - Fix: Wrap division result with Float.round(..., 1) in both Phoenix and agent paths + 2026-02-11 - fix: update device status from agent monitoring checks - File: lib/towerops_web/channels/agent_channel.ex (store_monitoring_check/2) - Bug: Devices polled by remote agents stayed in "unknown" state because diff --git a/lib/towerops/workers/device_poller_worker.ex b/lib/towerops/workers/device_poller_worker.ex index 86493674..efb56775 100644 --- a/lib/towerops/workers/device_poller_worker.ex +++ b/lib/towerops/workers/device_poller_worker.ex @@ -792,7 +792,7 @@ defmodule Towerops.Workers.DevicePollerWorker do decoded_value = decode_snmp_value(raw_value) if is_number(decoded_value) do - value = decoded_value / sensor.sensor_divisor + value = Float.round(decoded_value / sensor.sensor_divisor, 1) {:ok, value} else {:error, :non_numeric} diff --git a/lib/towerops_web/channels/agent_channel.ex b/lib/towerops_web/channels/agent_channel.ex index 116504f5..4180d314 100644 --- a/lib/towerops_web/channels/agent_channel.ex +++ b/lib/towerops_web/channels/agent_channel.ex @@ -1539,7 +1539,7 @@ defmodule ToweropsWeb.AgentChannel do value -> with parsed_value when not is_nil(parsed_value) <- parse_float(value) do - final_value = parsed_value / sensor.sensor_divisor + final_value = Float.round(parsed_value / sensor.sensor_divisor, 1) Snmp.create_sensor_reading(%{ sensor_id: sensor.id,