fix: data encoding in protocol_request.py

test: add unit test for noise floor recording in test_engine.py
This commit is contained in:
Rightup
2026-07-26 23:06:44 +01:00
parent aae40fd1e1
commit d79683350f
2 changed files with 10 additions and 3 deletions
+5 -3
View File
@@ -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
+5
View File
@@ -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()