From c24efe5376eb6d444c7df170e26af75fd7abff36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20NEDJAR?= Date: Sun, 15 Mar 2026 10:52:18 +0100 Subject: [PATCH 1/2] hts221: Add reboot() method for memory reload. --- lib/hts221/hts221/device.py | 7 +++++++ tests/scenarios/hts221.yaml | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/hts221/hts221/device.py b/lib/hts221/hts221/device.py index 42a89791..2e03e3cb 100644 --- a/lib/hts221/hts221/device.py +++ b/lib/hts221/hts221/device.py @@ -107,6 +107,13 @@ def trigger_one_shot(self): self._write_reg(HTS221_CTRL_REG2, ctrl2 | HTS221_CTRL2_ONE_SHOT) sleep_ms(15) + def reboot(self): + ctrl2 = self._read_reg(HTS221_CTRL_REG2) + self._write_reg(HTS221_CTRL_REG2, ctrl2 | HTS221_CTRL2_BOOT) + sleep_ms(15) + self._read_temperature_calibration() + self._read_humidity_calibration() + def _ensure_data(self): if self._is_power_down() or self._is_one_shot_mode(): self.trigger_one_shot() diff --git a/tests/scenarios/hts221.yaml b/tests/scenarios/hts221.yaml index d13db755..87ad93ab 100644 --- a/tests/scenarios/hts221.yaml +++ b/tests/scenarios/hts221.yaml @@ -109,6 +109,25 @@ tests: expect_not_none: true mode: [mock] + - name: "Reboot reloads calibration" + action: script + script: | + dev.reboot() + result = isinstance(dev.temperature(), float) + expect_true: true + mode: [mock] + + - name: "Reboot writes BOOT bit" + action: script + script: | + i2c.clear_write_log() + dev.reboot() + log = i2c.get_write_log() + wrote_boot = any(reg == 0x21 and (data[0] & 0x80) for reg, data in log) + result = wrote_boot + expect_true: true + mode: [mock] + - name: "Temperature with offset" action: script script: | From ed7b10dbe42b07857339f1492f995022a6d72e29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20NEDJAR?= Date: Sun, 15 Mar 2026 11:54:44 +0100 Subject: [PATCH 2/2] hts221: Address Copilot review on reboot PR. --- tests/scenarios/hts221.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/scenarios/hts221.yaml b/tests/scenarios/hts221.yaml index 87ad93ab..8347bfd6 100644 --- a/tests/scenarios/hts221.yaml +++ b/tests/scenarios/hts221.yaml @@ -109,11 +109,15 @@ tests: expect_not_none: true mode: [mock] - - name: "Reboot reloads calibration" + - name: "Reboot re-reads calibration registers" action: script script: | + i2c.clear_write_log() dev.reboot() - result = isinstance(dev.temperature(), float) + # After reboot, calibration registers (0x3C-0x3F) should be re-read + # Verify T0_OUT and T1_OUT are still valid by checking temperature works + t = dev.temperature() + result = isinstance(t, float) and t != 0.0 expect_true: true mode: [mock]