Skip to content

hts221: Auto-trigger one-shot conversion in power-down mode.#68

Merged
nedseb merged 2 commits intomainfrom
fix/hts221-auto-trigger
Mar 13, 2026
Merged

hts221: Auto-trigger one-shot conversion in power-down mode.#68
nedseb merged 2 commits intomainfrom
fix/hts221-auto-trigger

Conversation

@nedseb
Copy link
Copy Markdown
Contributor

@nedseb nedseb commented Mar 13, 2026

Summary

Closes #44 (for HTS221).

  • Add _is_power_down(), _is_one_shot_mode(), trigger_one_shot(), and _ensure_data() helpers
  • temperature() and humidity() now auto-trigger a one-shot conversion when the sensor is in power-down or one-shot mode
  • trigger_one_shot() uses read-modify-write on CTRL_REG2 to preserve HEATER/BOOT bits
  • Add read() method that returns (humidity, temperature) with a single trigger (avoids double conversion)
  • get() now delegates to read() for backward compatibility
  • Add CTRL_REG1/CTRL_REG2/STATUS_REG bit constants to const.py
  • Add hardware test: poweroff() then temperature() verifies auto-trigger works

Follows the same _ensure_data() pattern as WSEN-PADS and WSEN-HIDS.

Test plan

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

# Hardware tests (with board connected)
python3 -m pytest tests/ --port /dev/ttyACM0 -k "hts221 and hardware" -s -v

Mock test results

tests/test_scenarios.py::test_scenario[hts221/Verify device ID/mock] PASSED
tests/test_scenarios.py::test_scenario[hts221/Read WHO_AM_I via method/mock] PASSED
tests/test_scenarios.py::test_scenario[hts221/Read temperature returns float/mock] PASSED
tests/test_scenarios.py::test_scenario[hts221/Read humidity returns float/mock] PASSED
tests/test_scenarios.py::test_scenario[hts221/Status register has data ready/mock] PASSED
5 passed

Hardware test results

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] 29.44 PASSED
tests/test_scenarios.py::test_scenario[hts221/Humidity in plausible range/hardware] 37.63 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] True PASSED
tests/test_scenarios.py::test_scenario[hts221/Temperature feels correct/hardware]   Temperature: 29.26 °C
  Humidity: 38.03 %
  [MANUAL] Ces valeurs sont-elles cohérentes avec l'ambiance ? [Entree=oui / Echap=non] 
True
PASSED
7 passed
  • All mock tests pass (5/5)
  • All hardware tests pass (7/7)
  • ruff check passes

@nedseb nedseb requested review from Charly-sketch and Copilot March 13, 2026 05:34
@nedseb nedseb self-assigned this Mar 13, 2026
@nedseb nedseb added the enhancement New feature or request label Mar 13, 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

Updates the HTS221 driver to automatically trigger a fresh one-shot measurement when reading temperature/humidity while the sensor is in power-down (or configured for one-shot), and adds a combined read() API to avoid double conversions.

Changes:

  • Add _is_power_down(), _is_one_shot_mode(), trigger_one_shot(), and _ensure_data() helpers and call _ensure_data() from temperature() / humidity().
  • Add read() that returns (humidity, temperature) after a single trigger; make get() delegate to read().
  • Add CTRL_REG1/CTRL_REG2/STATUS_REG bit constants in const.py.

Reviewed changes

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

File Description
lib/hts221/hts221/device.py Adds one-shot auto-trigger logic, ensures fresh data in power-down/one-shot, and introduces a single-trigger read() API.
lib/hts221/hts221/const.py Introduces bitmask constants used for mode/status handling in the driver.

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

Comment thread lib/hts221/hts221/device.py
Comment thread lib/hts221/hts221/device.py Outdated
Comment thread lib/hts221/hts221/device.py
@nedseb nedseb force-pushed the fix/hts221-auto-trigger branch from 0551cb7 to 54b9e0c Compare March 13, 2026 12:45
@nedseb nedseb merged commit 2f8e6e3 into main Mar 13, 2026
3 checks passed
@nedseb nedseb deleted the fix/hts221-auto-trigger branch March 13, 2026 12:45
@nedseb nedseb linked an issue Mar 13, 2026 that may be closed by this pull request
@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: Auto-trigger one-shot conversion in power-down mode. drivers: Ensure read methods auto-trigger conversion in power-down mode.

2 participants