Skip to content

examples: Replace test scripts with practical examples for wsen-hids.#239

Merged
nedseb merged 17 commits intomainfrom
test/wsen-hids-expand-example
Mar 26, 2026
Merged

examples: Replace test scripts with practical examples for wsen-hids.#239
nedseb merged 17 commits intomainfrom
test/wsen-hids-expand-example

Conversation

@Charly-sketch
Copy link
Copy Markdown
Contributor

@Charly-sketch Charly-sketch commented Mar 25, 2026

Summary

Replace the monolithic full_test.py (482 lines of PASS/FAIL tests) with 8 practical, user-facing examples for the WSEN-HIDS humidity and temperature sensor.

Closes #187

Changes

Removed

File Reason
full_test.py PASS/FAIL test suite, not a user-facing example. Test coverage is now handled by tests/scenarios/wsen_hids.yaml

Added — 8 practical examples

Example Description
humidity_temperature.py Beginner-friendly: single read of humidity and temperature
one_shot_mode.py Trigger a one-shot measurement and read on demand
continuous_mode.py Run sensor continuously and read values periodically
comfort_monitor.py Loop every 2 s, display comfort indicator (Dry / Comfortable / Humid) based on humidity thresholds
data_logger.py Log CSV to DAPLink flash + serial. Erasure is opt-in via ERASE_FLASH_ON_START flag
dew_point.py Compute dew point using the Magnus formula (with safe clamp for 0% humidity)
heater_demo.py Enable the built-in heater, compare humidity/temperature before and after
low_power_sampling.py One-shot every 10 s with power_off() between reads. Requires firmware >= v0.1.0 (#238)

Updated

File Change
README.md Replaced generic examples section with a table listing all 8 examples with descriptions

Review feedback addressed

  • data_logger.py: clear_flash() is now opt-in via ERASE_FLASH_ON_START = False (not unconditional)
  • low_power_sampling.py: docstring references wsen_hids: one-shot measurement timeout after power cycle #238 firmware requirement, power_off immediately after measurement
  • dew_point.py: humidity clamped to 0.01 to avoid log(0) domain error
  • comfort_monitor.py: validated by Copilot
  • heater_demo.py: French comment removed
  • README: low_power_sampling entry updated with firmware requirement

Test plan

  • make lint passes
  • make test-examples passes (syntax + import validation)
  • Manual test on hardware for each example

@Charly-sketch Charly-sketch changed the title WIP | examples: Replace test scripts with practical examples for wsen-hids. examples: Replace test scripts with practical examples for wsen-hids. Mar 25, 2026
@Charly-sketch Charly-sketch marked this pull request as ready for review March 25, 2026 13:45
Copy link
Copy Markdown
Contributor

@nedseb nedseb left a comment

Choose a reason for hiding this comment

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

Bon travail, les exemples sont variés et utiles. Quelques points à corriger :

Bloquants

1. low_power_sampling.py — le bug #238 est maintenant corrigé (PR #240 mergée)

La description de la PR dit que low_power_sampling.py n'a pas été ajouté car le bug power_off()/power_on() n'est pas résolu. Mais il l'est depuis la PR #240. Vérifie que l'exemple fonctionne correctement sur hardware — il devrait maintenant.

Cependant, il est quand même ajouté dans les fichiers ! La description et le code sont contradictoires. Si l'exemple fonctionne, supprime le commentaire dans la description. Sinon, retire le fichier.

2. data_logger.py — dépendance non documentée

Cet exemple importe daplink_flash mais la description de la PR et l'issue #187 ne mentionnent pas cette dépendance. De plus, l'exemple utilise sleep(0.5) et sleep(5) au lieu de sleep_ms(500) et sleep_ms(5000) — la convention du projet est sleep_ms (voir CONTRIBUTING.md).

3. comfort_monitor.py — utilise sleep(2) au lieu de sleep_ms(2000)

Même remarque : la convention du projet est from time import sleep_ms.

4. heater_demo.py — utilise sleep(10) au lieu de sleep_ms(10000)

Idem.

5. dew_point.py — utilise math.log

Vérifie que math.log est disponible en MicroPython sur le STM32WB55. Si oui, c'est OK. Sinon, il faut utiliser une approximation.

Non bloquants

6. Docstrings trop longues sur une seule ligne

Les docstrings de comfort_monitor.py, data_logger.py, heater_demo.py, low_power_sampling.py font plus de 99 caractères (limite ruff). Mets-les sur plusieurs lignes.

7. data_logger.py — pas de header CSV dans le fichier flash

Le CSV header timestamp,humidity,temperature est imprimé sur la console mais pas écrit dans le fichier flash. L'utilisateur qui récupère le fichier CSV n'aura pas les noms de colonnes.

8. Vérification du contenu de full_test.py

L'issue #187 demande de vérifier que le contenu des tests de full_test.py est couvert par les scénarios YAML avant de le supprimer. Peux-tu confirmer que c'est le cas ? Liste les tests couverts et ceux qui ne le sont pas.

@nedseb
Copy link
Copy Markdown
Contributor

nedseb commented Mar 25, 2026

Revue de codex (il fume un peu mais il a de l'idée) :

  1. Moyen: lib/wsen-hids/examples/heater_demo.py:20 à lib/wsen-hids/examples/heater_demo.py:26 prend une mesure alors que le chauffage est encore activé. Ça contredit explicitement la doc du driver en lib/wsen-hids/README.md:263, qui dit de ne pas mesurer pendant que le heater est actif. En l’état, l’exemple risque surtout d’enseigner un mauvais usage de l’API. Je ferais soit un exemple “chauffage ON puis OFF puis lecture après stabilisation”, soit je reformulerais clairement que la lecture faite ici est volontairement biaisée et purement démonstrative.

  2. Moyen: lib/wsen-hids/examples/data_logger.py:14 appelle flash.clear_flash(), qui efface toute la flash externe, pas juste le fichier de log courant. Pour un exemple supposé simple, c’est une action très destructive: l’utilisateur peut perdre d’autres captures ou fichiers sans s’y attendre. Si le but est juste de repartir d’un log vide, il faudrait soit documenter très visiblement cet effet de bord, soit utiliser une stratégie moins globale si l’API le permet.

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

This PR updates the wsen-hids library documentation and example suite to replace a PASS/FAIL-style test script with practical, user-oriented example scripts for common WSEN-HIDS workflows.

Changes:

  • Removed the non-example full_test.py script from lib/wsen-hids/examples/.
  • Added multiple new usage examples (single read, comfort monitor loop, dew point, heater demo, CSV logging, low-power sampling).
  • Updated lib/wsen-hids/README.md to document the new example set.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
lib/wsen-hids/examples/full_test.py Removed a test-suite-like script from examples.
lib/wsen-hids/examples/humidity_temperature.py Adds a minimal one-shot read example.
lib/wsen-hids/examples/comfort_monitor.py Adds a periodic comfort indicator example.
lib/wsen-hids/examples/data_logger.py Adds a CSV logger example (also writes to DAPLink flash).
lib/wsen-hids/examples/dew_point.py Adds dew point calculation example using humidity + temperature.
lib/wsen-hids/examples/heater_demo.py Adds heater usage demonstration example.
lib/wsen-hids/examples/low_power_sampling.py Adds power-cycle sampling example intended for low power operation.
lib/wsen-hids/README.md Replaces the examples section with an overview table of available scripts.

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

Comment thread lib/wsen-hids/examples/low_power_sampling.py
Comment thread lib/wsen-hids/examples/data_logger.py Outdated
Comment thread lib/wsen-hids/README.md Outdated
Comment thread lib/wsen-hids/examples/dew_point.py
Comment thread lib/wsen-hids/examples/dew_point.py Outdated
Comment thread lib/wsen-hids/examples/comfort_monitor.py
Comment thread lib/wsen-hids/examples/heater_demo.py
@nedseb
Copy link
Copy Markdown
Contributor

nedseb commented Mar 26, 2026

Corrections pushed in 97bfc69:

  1. data_logger.py — Added ERASE_FLASH_ON_START = False flag instead of unconditional clear_flash(). The user must explicitly opt in to destructive erasure.

  2. low_power_sampling.py — Rewritten with proper docstring referencing wsen_hids: one-shot measurement timeout after power cycle #238 (firmware >= v0.1.0 required). Power-down now happens immediately after measurement, before printing.

  3. README.md — Updated low_power_sampling description with firmware requirement and issue reference.

The PR is ready to merge.

@nedseb nedseb merged commit 79c609a into main Mar 26, 2026
4 checks passed
@nedseb nedseb deleted the test/wsen-hids-expand-example branch March 26, 2026 08:02
@semantic-release-updater
Copy link
Copy Markdown

🎉 This PR is included in version 0.1.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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

examples: Replace test scripts with practical examples for wsen-hids.

3 participants