Skip to content

Commit 641163f

Browse files
committed
lis2mdl: Improve docstrings and add exact mock temperature assertion.
1 parent 405d872 commit 641163f

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

lib/lis2mdl/lis2mdl/device.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,23 @@ def read_temperature_raw(self) -> int:
236236
return v - 0x10000 if (v & 0x8000) else v
237237

238238
def read_temperature_c(self) -> float:
239-
"""Temperature in °C (8 LSB/°C + offset)."""
239+
"""Temperature in °C (8 LSB/°C + empirical offset).
240+
241+
The LIS2MDL temperature sensor has no guaranteed absolute zero
242+
point (see datasheet Table 4). The offset defaults to 25 °C
243+
based on empirical observation (confirmed by Zephyr RTOS
244+
PR #35912). Use ``set_temp_offset()`` to calibrate against a
245+
reference thermometer.
246+
"""
240247
return self._temp_offset + self.read_temperature_raw() / LIS2MDL_TEMP_SENSITIVITY
241248

242-
def set_temp_offset(self, offset):
243-
"""Set the temperature offset in °C for calibration."""
244-
self._temp_offset = offset
249+
def set_temp_offset(self, offset_c):
250+
"""Set the temperature offset in °C for calibration.
251+
252+
Args:
253+
offset_c: offset value in degrees Celsius (default is 25).
254+
"""
255+
self._temp_offset = float(offset_c)
245256

246257
# --- IDENTITY & HARDWARE OFFSETS ---
247258

tests/scenarios/lis2mdl.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ tests:
6767
- name: "Read temperature returns float"
6868
action: call
6969
method: read_temperature_c
70-
expect_not_none: true
70+
expect: 25.0
7171
mode: [mock]
7272

7373
- name: "Magnitude in plausible range"

0 commit comments

Comments
 (0)