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..8347bfd6 100644 --- a/tests/scenarios/hts221.yaml +++ b/tests/scenarios/hts221.yaml @@ -109,6 +109,29 @@ tests: expect_not_none: true mode: [mock] + - name: "Reboot re-reads calibration registers" + action: script + script: | + i2c.clear_write_log() + dev.reboot() + # 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] + + - 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: |