Skip to content

fix(bq27441): Harmonize temperature() return value with project convention.#274

Merged
nedseb merged 2 commits intomainfrom
fix/bq27441-temperature-convention
Mar 28, 2026
Merged

fix(bq27441): Harmonize temperature() return value with project convention.#274
nedseb merged 2 commits intomainfrom
fix/bq27441-temperature-convention

Conversation

@nedseb
Copy link
Copy Markdown
Contributor

@nedseb nedseb commented Mar 28, 2026

Summary

  • temperature() now returns degrees Celsius (convention), with TempMeasureType.BATTERY as default
  • Added temperature_k() returning Kelvin and temperature_dk() returning raw decikelvin
  • Updated mock tests and README accordingly

Closes #255

Test plan

  • ruff check passes
  • All 13 bq27441 mock tests pass
  • Hardware validation on STeaMi board

Copilot AI review requested due to automatic review settings March 28, 2026 06:10
@nedseb nedseb added the bug Something isn't working label Mar 28, 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 bq27441 driver temperature API to follow the repository’s measurement convention (default temperature() in °C), and updates mock scenario coverage + driver documentation accordingly.

Changes:

  • Changed BQ27441.temperature() to return °C by default (battery temperature by default).
  • Added temperature_k() (Kelvin) and temperature_dk() (raw decikelvin), with a shared _read_temperature_dk() helper.
  • Updated the bq27441 scenario tests and the driver README to reflect the new API.

Reviewed changes

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

File Description
lib/bq27441/bq27441/device.py Adjusts temperature API units and introduces Kelvin/raw accessors.
tests/scenarios/bq27441.yaml Updates mock scenario expectations for the new temperature APIs.
lib/bq27441/README.md Documents the new °C default and the added Kelvin/raw temperature methods.

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

Comment thread lib/bq27441/bq27441/device.py Outdated
elif temp_measure_type == TempMeasureType.INTERNAL_TEMP:
temp = self.read_word(BQ27441_COMMAND_INT_TEMP)
return self.read_word(BQ27441_COMMAND_INT_TEMP)
return 0
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

_read_temperature_dk() returns 0 for an unknown temp_measure_type, but temperature()/temperature_k() convert that sentinel into -273.15 °C / 0.0 K, which can silently mask invalid inputs. Consider raising a ValueError for unsupported temp_measure_type, or returning None/propagating a sentinel so callers can detect misuse (and to avoid reporting absolute zero as a real temperature).

Suggested change
return 0
else:
raise ValueError("Unsupported TempMeasureType: {!r}".format(temp_measure_type))

Copilot uses AI. Check for mistakes.
Comment thread tests/scenarios/bq27441.yaml Outdated
action: script
script: |
result = dev.temperature_k()
expect: 298.1
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

This test asserts an exact float equality (expect: 298.1). Since the scenario runner uses result == expected for expect, this can be brittle for floats; using expect_range (like the Celsius test) would make the test more robust.

Suggested change
expect: 298.1
expect_range: [298.09, 298.11]

Copilot uses AI. Check for mistakes.
Comment thread lib/bq27441/README.md
Comment on lines +113 to +118
bq.temperature() # Battery temperature in °C (default)
bq.temperature(TempMeasureType.INTERNAL_TEMP) # Internal IC temperature in °C

**Note:** Temperature is returned as a raw register value (units of 0.1 K). To convert to °C: `temp_c = raw / 10.0 - 273.15`.
bq.temperature_k() # Battery temperature in Kelvin
bq.temperature_dk() # Battery temperature in decikelvin (raw)
```
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

The Temperature section was updated to show temperature() returning °C, but later in the README "Notes" section it still states that temperature readings are raw 0.1 K register values. That note should be updated to reflect the new API (and point users to temperature_k() / temperature_dk() for non-°C units).

Copilot uses AI. Check for mistakes.
@nedseb
Copy link
Copy Markdown
Contributor Author

nedseb commented Mar 28, 2026

Les trois remarques de Copilot ont été corrigées dans c9edae7 :

  1. _read_temperature_dk() lève maintenant un ValueError pour un TempMeasureType invalide au lieu de retourner 0 silencieusement (ce qui donnait -273.15 °C).
  2. Test Kelvin passé en expect_range pour éviter la fragilité des comparaisons float exactes.
  3. Note obsolète du README mise à jour : temperature() retourne des °C, avec renvoi vers temperature_k() et temperature_dk().

Tous les tests mock passent (13/13).

@nedseb nedseb merged commit ac3f14d into main Mar 28, 2026
7 checks passed
@nedseb nedseb deleted the fix/bq27441-temperature-convention branch March 28, 2026 06:17
semantic-release-updater Bot pushed a commit that referenced this pull request Mar 28, 2026
## [0.1.4](v0.1.3...v0.1.4) (2026-03-28)

### Bug Fixes

* **bq27441:** Harmonize temperature() return value with project convention. ([#274](#274)) ([ac3f14d](ac3f14d))
@semantic-release-updater
Copy link
Copy Markdown

🎉 This PR is included in version 0.1.4 🎉

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

bug Something isn't working released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(bq27441): Harmonize temperature() return value with project convention.

2 participants