From d79683350fd44f62b0f7011f6c6ddc2736e7f818 Mon Sep 17 00:00:00 2001 From: Rightup Date: Sun, 26 Jul 2026 23:06:44 +0100 Subject: [PATCH] fix: data encoding in protocol_request.py test: add unit test for noise floor recording in test_engine.py --- repeater/handler_helpers/protocol_request.py | 8 +++++--- tests/test_engine.py | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/repeater/handler_helpers/protocol_request.py b/repeater/handler_helpers/protocol_request.py index 12aa6e5..7322b4b 100644 --- a/repeater/handler_helpers/protocol_request.py +++ b/repeater/handler_helpers/protocol_request.py @@ -20,11 +20,11 @@ from openhop_core.node.handlers.protocol_request import ( ) from openhop_core.protocol.cayenne_lpp import ( TELEM_CHANNEL_SELF, + encode_current, + encode_power, encode_relative_humidity, encode_temperature, encode_voltage, - encode_current, - encode_power ) from openhop_core.protocol.constants import TELEM_PERM_ENVIRONMENT @@ -168,7 +168,7 @@ class ProtocolRequestHelper: # n_sent_flood, n_sent_direct, n_recv_flood, n_recv_direct, # uint16 err_events, int16 last_snr (×4), uint16 n_direct_dups, n_flood_dups, # uint32 total_rx_air_time_secs, n_recv_errors → 56 bytes - + # Battery Readings: uses first configured sensor that reports bus/pack voltage. readings = self._get_sensor_readings() batt = int(min(max(self._battery_voltage(readings) * 1000, 0), 0xFFFF)) @@ -294,8 +294,10 @@ class ProtocolRequestHelper: channel = TELEM_CHANNEL_SELF + 1 if self._has_sensor_data(readings, "bus_voltage_v"): lpp.extend(encode_voltage(channel, self._battery_voltage(readings))) + channel += 1 if self._has_sensor_data(readings, "current_ma"): lpp.extend(encode_current(channel, self._battery_current(readings))) + channel += 1 if self._has_sensor_data(readings, "power_mw"): lpp.extend(encode_power(channel, self._battery_power(readings))) channel += 1 diff --git a/tests/test_engine.py b/tests/test_engine.py index 3e48784..38728bc 100644 --- a/tests/test_engine.py +++ b/tests/test_engine.py @@ -2834,6 +2834,11 @@ class TestEngineTransmissionAndBackgroundLifecycle: await handler._record_noise_floor_async() handler.storage.record_noise_floor.assert_not_called() + with patch.object(handler, "get_noise_floor", return_value=0.0): + await handler._record_noise_floor_async() + handler.storage.record_noise_floor.assert_called_once_with(0.0) + assert handler._cached_noise_floor == 0.0 + with patch.object(handler, "get_noise_floor", side_effect=RuntimeError("noise fail")): await handler._record_noise_floor_async()