Skip to content

wsen-hids: Add two-point temperature calibration methods.#111

Merged
nedseb merged 3 commits intomainfrom
fix/wsen-hids-temp-offset
Mar 14, 2026
Merged

wsen-hids: Add two-point temperature calibration methods.#111
nedseb merged 3 commits intomainfrom
fix/wsen-hids-temp-offset

Conversation

@nedseb
Copy link
Copy Markdown
Contributor

@nedseb nedseb commented Mar 14, 2026

Closes #105

Summary

Add two-point software temperature calibration to the WSEN-HIDS driver, following the harmonized interface defined in #103.

Changes

  • Add self._temp_gain = 1.0 and self._temp_offset = 0.0 in __init__
  • Add set_temp_offset(offset_c) — simple offset (resets gain to 1.0)
  • Add calibrate_temperature(ref_low, measured_low, ref_high, measured_high) — computes gain and offset from two reference points
  • Apply calibration in _convert_temperature(): return gain * factory_value + offset

API

hids = WSEN_HIDS(i2c)

# Simple offset
hids.set_temp_offset(-1.5)

# Two-point calibration (reference thermometer reads 25°C and 30°C
# when sensor reads 30°C and 35°C)
hids.calibrate_temperature(25.0, 30.0, 30.0, 35.0)

Hardware validation

Default:                       30.33 C
Offset -1.5:                   28.83 C  (= 30.33 - 1.5)
Calibrated (25@30, 30@35):     25.33 C  (gain=1.0, offset=-5.0)
Reset:                         30.33 C

Related

Test plan

  • ruff check passes
  • pytest tests/ -k mock — 44/44 passed (no regressions)
  • Hardware: set_temp_offset() and calibrate_temperature() validated on board

@nedseb nedseb requested a review from Copilot March 14, 2026 08:14
@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 software temperature calibration to the WSEN-HIDS driver (as part of the cross-driver harmonization effort) and extends the YAML scenario runner so mock scenarios can validate calibration behavior with multi-step scripts.

Changes:

  • Add _temp_gain/_temp_offset state to WSEN-HIDS and apply it in the temperature conversion path.
  • Introduce set_temp_offset() and calibrate_temperature() APIs on WSEN-HIDS.
  • Add a new YAML scenario action (script) and new mock scenario coverage for offset and two-point calibration.

Reviewed changes

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

File Description
lib/wsen-hids/wsen_hids/device.py Adds temperature calibration state + public calibration methods and applies calibration in _convert_temperature().
tests/runner/executor.py Implements mock-mode script action execution via exec() and returns result.
tests/test_scenarios.py Adds handling for action: script (with a board-scenario guard) in the scenario test runner.
tests/scenarios/wsen_hids.yaml Adds mock scenarios that validate temperature offset and two-point calibration behavior.

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

Comment thread lib/wsen-hids/wsen_hids/device.py Outdated
Comment thread tests/runner/executor.py Outdated
Comment thread tests/runner/executor.py Outdated
@nedseb
Copy link
Copy Markdown
Contributor Author

nedseb commented Mar 14, 2026

Suggestions Copilot prises en compte dans le commit 1a6bb31 :

  1. calibrate_temperature() — ZeroDivisionError : ajout d'une validation ValueError quand measured_high == measured_low.
  2. exec() — globals/locals séparés : utilisation d'un seul dict partagé pour globals et locals, avec i2c exposé en plus de dev.
  3. result manquant : vérification explicite de la présence de result dans le script, avec ValueError si absent.

@nedseb nedseb merged commit ca5e4a5 into main Mar 14, 2026
3 checks passed
@nedseb nedseb deleted the fix/wsen-hids-temp-offset branch March 14, 2026 10:02
@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.

wsen-hids: Add two-point temperature calibration methods.

2 participants