feat(bme280): Add compensated temperature, pressure, humidity readings#312
feat(bme280): Add compensated temperature, pressure, humidity readings#312
Conversation
There was a problem hiding this comment.
Pull request overview
Adds full measurement support to the BME280 driver, including compensated temperature/pressure/humidity readings derived from factory calibration, plus scenario-based mock validation.
Changes:
- Implemented status helpers and one-shot triggering with measurement wait/polling.
- Added burst raw-data read and integer compensation formulas (temperature updates
t_fine). - Extended the BME280 YAML scenario with additional mock registers and measurement/status tests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
lib/bme280/bme280/device.py |
Adds status APIs, one-shot trigger/wait, raw burst read, and compensated measurement methods. |
tests/scenarios/bme280.yaml |
Adds mock data registers and scenario tests for status, compensated outputs, and one-shot triggering. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if h == 0: | ||
| return 0 |
There was a problem hiding this comment.
_compensate_humidity() returns 0 when self.t_fine - 76800 == 0, but the BME280 integer humidity compensation formula does not have a divide-by-zero risk at that point. This early-return will produce an incorrect 0%RH reading at the (valid) temperature where t_fine == 76800. Remove this check and let the formula run (clamping at the end already bounds the result).
| if h == 0: | |
| return 0 |
There was a problem hiding this comment.
Fixed in 343dab9: removed the if h == 0: return 0 early return. The clamping at the end (0 to 419430400) already bounds the result, and this check would incorrectly return 0%RH at t_fine=76800.
| """Read raw ADC values for pressure, temperature, humidity (burst read). | ||
|
|
||
| Returns (raw_temp, raw_press, raw_hum) as 20-bit/20-bit/16-bit integers. | ||
| """ | ||
| data = self._read_block(REG_DATA_START, DATA_BLOCK_SIZE) | ||
| raw_press = (data[0] << 12) | (data[1] << 4) | (data[2] >> 4) | ||
| raw_temp = (data[3] << 12) | (data[4] << 4) | (data[5] >> 4) | ||
| raw_hum = (data[6] << 8) | data[7] | ||
| return raw_temp, raw_press, raw_hum |
There was a problem hiding this comment.
The _read_raw() docstring says it reads/returns values in the order "pressure, temperature, humidity", but the function actually returns (raw_temp, raw_press, raw_hum). This mismatch makes it easy to misuse the tuple. Update the docstring (and/or return order) so the documented order matches the actual return value.
There was a problem hiding this comment.
Fixed in 343dab9: removed the misleading "pressure, temperature, humidity" ordering from the first line. The docstring now says "burst read (0xF7-0xFE, 8 bytes)" and the Returns line clearly states (raw_temp, raw_press, raw_hum).
| - name: "temperature_ready delegates to data_ready" | ||
| action: script | ||
| script: | | ||
| result = dev.temperature_ready() and dev.pressure_ready() and dev.humidity_ready() | ||
| expect_true: true |
There was a problem hiding this comment.
Test name doesn't match what is asserted: the script checks temperature_ready(), pressure_ready(), and humidity_ready(), but the name only mentions temperature_ready. Renaming the test to reflect all three methods will make failures easier to interpret.
There was a problem hiding this comment.
Fixed in 343dab9: renamed test to "All ready methods delegate to data_ready" to reflect that it checks temperature_ready(), pressure_ready(), and humidity_ready().
# [0.5.0](v0.4.0...v0.5.0) (2026-03-29) ### Features * **bme280:** Add compensated temperature, pressure, humidity readings ([#312](#312)) ([f18aeaf](f18aeaf))
|
🎉 This PR is included in version 0.5.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Closes #305
Summary
_status(),data_ready(),temperature_ready(),pressure_ready(),humidity_ready()— all based onSTATUS_MEASURINGbittrigger_one_shot()sets forced mode inctrl_meas,_wait_measurement()polls until complete_read_raw()burst-reads 8 bytes from 0xF7–0xFE, returns (raw_temp, raw_press, raw_hum)_compensate_temperature()— hundredths of °C, updatest_fine_compensate_pressure()— Pa in Q24.8 fixed point_compensate_humidity()— Q22.10 fixed point with clampingtemperature()(°C),pressure_hpa()(hPa),humidity()(%RH),read()(tuple),read_one_shot()Test plan
make test-bme280)