Skip to content

hts221: Add two-point temperature calibration.#115

Merged
nedseb merged 1 commit intomainfrom
fix/hts221-temp-calibration
Mar 14, 2026
Merged

hts221: Add two-point temperature calibration.#115
nedseb merged 1 commit intomainfrom
fix/hts221-temp-calibration

Conversation

@nedseb
Copy link
Copy Markdown
Contributor

@nedseb nedseb commented Mar 14, 2026

Summary

  • Add set_temp_offset() and calibrate_temperature() methods for two-point calibration (gain + offset)
  • Rename internal calibrate_temperature() / calibrate_humidity() to _read_temperature_calibration() / _read_humidity_calibration() to free the public name for user calibration
  • Apply calibration in both temperature() and read()
  • Add 3 mock test scenarios for offset, two-point calibration, and read() calibration

Closes #104

Test plan

Mock tests (CI)

python3 -m pytest tests/ -k "hts221 and mock" -v

Hardware tests (STeaMi board)

python3 -m pytest tests/ --port /dev/ttyACM0 -k "hts221 and hardware" -s -v
  • ruff check passes
  • All mock tests pass (11 tests including 3 new calibration tests)
  • Hardware validation on STeaMi board

Test results

$python3 -m pytest tests/ --port /dev/ttyACM0 -k "hts221 and hardware" -s -v

======================================================= test session starts ========================================================
platform linux -- Python 3.13.7, pytest-8.3.5, pluggy-1.5.0 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /home/nedjar/sandbox/micropython-steami-lib
configfile: pytest.ini
plugins: typeguard-4.4.2
collected 162 items / 154 deselected / 8 selected                                                                                  

tests/test_scenarios.py::test_scenario[board_i2c_scan/HTS221/WSEN-HIDS device ID (0x5F)/hardware] 0xBC
PASSED
tests/test_scenarios.py::test_scenario[hts221/Verify device ID/hardware] 0xBC
PASSED
tests/test_scenarios.py::test_scenario[hts221/Read WHO_AM_I via method/hardware] 0xBC
PASSED
tests/test_scenarios.py::test_scenario[hts221/Temperature in plausible range/hardware] 24.09
PASSED
tests/test_scenarios.py::test_scenario[hts221/Humidity in plausible range/hardware] 65.43
PASSED
tests/test_scenarios.py::test_scenario[hts221/Status register has data ready/hardware] 3
PASSED
tests/test_scenarios.py::test_scenario[hts221/Auto-trigger after poweroff/hardware] PASSED
tests/test_scenarios.py::test_scenario[hts221/Temperature feels correct/hardware]   Temperature: 24.35 °C
  Humidity: 64.54 %
  [MANUAL] Ces valeurs sont-elles cohérentes avec l'ambiance ? [Entree=oui / Echap=non] 
PASSED

================================================ 8 passed, 154 deselected in 19.08s ================================================

@nedseb nedseb requested a review from Copilot March 14, 2026 12:04
@nedseb nedseb self-assigned this Mar 14, 2026
@nedseb nedseb added the enhancement New feature or request label Mar 14, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds two-point temperature calibration support to the HTS221 driver, consistent with the harmonized calibration interface used by other drivers (WSEN-PADS, WSEN-HIDS, LIS2MDL).

Changes:

  • Renamed internal factory calibration methods to _read_temperature_calibration()/_read_humidity_calibration() and added public set_temp_offset() and calibrate_temperature() methods
  • Applied _temp_gain/_temp_offset calibration in both temperature() and read()
  • Added 3 mock test scenarios for the new calibration features

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
lib/hts221/hts221/device.py Renamed internal calibration methods, added gain/offset fields and public calibration API
tests/scenarios/hts221.yaml Added mock test scenarios for offset, two-point calibration, and read() calibration

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@nedseb nedseb merged commit b175677 into main Mar 14, 2026
10 checks passed
@nedseb nedseb deleted the fix/hts221-temp-calibration branch March 14, 2026 12:15
@semantic-release-updater
Copy link
Copy Markdown

🎉 This PR is included in version 0.0.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hts221: Add two-point temperature calibration methods.

2 participants