Skip to content

drivers: Add micropython.const() wrapper to all const.py files.#66

Merged
nedseb merged 2 commits intomainfrom
fix/add-micropython-const
Mar 13, 2026
Merged

drivers: Add micropython.const() wrapper to all const.py files.#66
nedseb merged 2 commits intomainfrom
fix/add-micropython-const

Conversation

@nedseb
Copy link
Copy Markdown
Contributor

@nedseb nedseb commented Mar 12, 2026

Summary

Add from micropython import const and wrap all integer constants with const() in the three remaining const.py files:

  • apds9960 — 148 integer constants wrapped (list APDS9960_DEV_ID and constants referencing other names left unwrapped)
  • bq27441 — 57 integer constants wrapped (including 1 << N bit-shift expressions)
  • wsen-pads — 38 integer constants wrapped (float conversion constants and variable-referencing assignment left unwrapped)

This enables MicroPython to inline constant values at compile time, reducing RAM usage.

Closes #58

Hardware test results

============================== test session starts ==============================
platform linux -- Python 3.13.7, pytest-8.3.5, pluggy-1.5.0 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /home/nedjar/sandbox/micropython-steami-lib
configfile: pytest.ini
plugins: typeguard-4.4.2
collected 103 items                                                                                                                                                                                                                                                         

tests/test_scenarios.py::test_scenario[apds9960/Verify device ID register (mock)/mock] PASSED                                                                                                                                                                         [  0%]
tests/test_scenarios.py::test_scenario[apds9960/Verify device ID register (hardware)/hardware] PASSED                                                                                                                                                                 [  1%]
tests/test_scenarios.py::test_scenario[apds9960/Read ambient light returns expected value/mock] PASSED                                                                                                                                                                [  2%]
tests/test_scenarios.py::test_scenario[apds9960/Read proximity returns expected value/mock] PASSED                                                                                                                                                                    [  3%]
tests/test_scenarios.py::test_scenario[apds9960/Read red light returns expected value/mock] PASSED                                                                                                                                                                    [  4%]
tests/test_scenarios.py::test_scenario[apds9960/Ambient light in plausible range/hardware] PASSED                                                                                                                                                                     [  5%]
tests/test_scenarios.py::test_scenario[apds9960/Proximity in plausible range/hardware] PASSED                                                                                                                                                                         [  6%]
tests/test_scenarios.py::test_scenario[apds9960/Light and proximity values feel correct/hardware] SKIPPED (manual test requires interactive mode (-s))                                                                                                                [  7%]
tests/test_scenarios.py::test_scenario[bq27441/Read voltage/mock] PASSED                                                                                                                                                                                              [  8%]
tests/test_scenarios.py::test_scenario[bq27441/Read state of charge/mock] PASSED                                                                                                                                                                                      [  9%]
tests/test_scenarios.py::test_scenario[bq27441/Read remaining capacity/mock] PASSED                                                                                                                                                                                   [ 10%]
tests/test_scenarios.py::test_scenario[bq27441/Read full capacity/mock] PASSED                                                                                                                                                                                        [ 11%]
tests/test_scenarios.py::test_scenario[bq27441/Read average current/mock] PASSED                                                                                                                                                                                      [ 12%]
tests/test_scenarios.py::test_scenario[bq27441/Read average power/mock] PASSED                                                                                                                                                                                        [ 13%]
tests/test_scenarios.py::test_scenario[bq27441/Read state of health/mock] PASSED                                                                                                                                                                                      [ 14%]
tests/test_scenarios.py::test_scenario[bq27441/Battery connected check/hardware] SKIPPED (manual test requires interactive mode (-s))                                                                                                                                 [ 15%]
tests/test_scenarios.py::test_scenario[bq27441/Device type is BQ27441/hardware] PASSED                                                                                                                                                                                [ 16%]
tests/test_scenarios.py::test_scenario[bq27441/Voltage in plausible range/hardware] PASSED                                                                                                                                                                            [ 17%]
tests/test_scenarios.py::test_scenario[bq27441/State of charge in valid range/hardware] PASSED                                                                                                                                                                        [ 18%]
tests/test_scenarios.py::test_scenario[bq27441/Remaining capacity positive/hardware] PASSED                                                                                                                                                                           [ 19%]
tests/test_scenarios.py::test_scenario[bq27441/Full capacity positive/hardware] PASSED                                                                                                                                                                                [ 20%]
tests/test_scenarios.py::test_scenario[bq27441/Average current readable/hardware] PASSED                                                                                                                                                                              [ 21%]
tests/test_scenarios.py::test_scenario[bq27441/Average power readable/hardware] PASSED                                                                                                                                                                                [ 22%]
tests/test_scenarios.py::test_scenario[bq27441/State of health in valid range/hardware] PASSED                                                                                                                                                                        [ 23%]
tests/test_scenarios.py::test_scenario[bq27441/Battery info summary/hardware] SKIPPED (manual test requires interactive mode (-s))                                                                                                                                    [ 24%]
tests/test_scenarios.py::test_scenario[hts221/Verify device ID/mock] PASSED                                                                                                                                                                                           [ 25%]
tests/test_scenarios.py::test_scenario[hts221/Verify device ID/hardware] PASSED                                                                                                                                                                                       [ 26%]
tests/test_scenarios.py::test_scenario[hts221/Read WHO_AM_I via method/mock] PASSED                                                                                                                                                                                   [ 27%]
tests/test_scenarios.py::test_scenario[hts221/Read WHO_AM_I via method/hardware] PASSED                                                                                                                                                                               [ 28%]
tests/test_scenarios.py::test_scenario[hts221/Read temperature returns float/mock] PASSED                                                                                                                                                                             [ 29%]
tests/test_scenarios.py::test_scenario[hts221/Read humidity returns float/mock] PASSED                                                                                                                                                                                [ 30%]
tests/test_scenarios.py::test_scenario[hts221/Temperature in plausible range/hardware] PASSED                                                                                                                                                                         [ 31%]
tests/test_scenarios.py::test_scenario[hts221/Humidity in plausible range/hardware] PASSED                                                                                                                                                                            [ 32%]
tests/test_scenarios.py::test_scenario[hts221/Status register has data ready/mock] PASSED                                                                                                                                                                             [ 33%]
tests/test_scenarios.py::test_scenario[hts221/Status register has data ready/hardware] PASSED                                                                                                                                                                         [ 33%]
tests/test_scenarios.py::test_scenario[hts221/Temperature feels correct/hardware] SKIPPED (manual test requires interactive mode (-s))                                                                                                                                [ 34%]
tests/test_scenarios.py::test_scenario[lis2mdl/Verify WHO_AM_I register/mock] PASSED                                                                                                                                                                                  [ 35%]
tests/test_scenarios.py::test_scenario[lis2mdl/Verify WHO_AM_I register/hardware] PASSED                                                                                                                                                                              [ 36%]
tests/test_scenarios.py::test_scenario[lis2mdl/Read WHO_AM_I via method/mock] PASSED                                                                                                                                                                                  [ 37%]
tests/test_scenarios.py::test_scenario[lis2mdl/Read WHO_AM_I via method/hardware] PASSED                                                                                                                                                                              [ 38%]
tests/test_scenarios.py::test_scenario[lis2mdl/Read status register/mock] PASSED                                                                                                                                                                                      [ 39%]
tests/test_scenarios.py::test_scenario[lis2mdl/Read status register/hardware] PASSED                                                                                                                                                                                  [ 40%]
tests/test_scenarios.py::test_scenario[lis2mdl/Read magnetic field returns tuple/mock] PASSED                                                                                                                                                                         [ 41%]
tests/test_scenarios.py::test_scenario[lis2mdl/Read magnetic field in uT returns tuple/mock] PASSED                                                                                                                                                                   [ 42%]
tests/test_scenarios.py::test_scenario[lis2mdl/Read temperature returns float/mock] PASSED                                                                                                                                                                            [ 43%]
tests/test_scenarios.py::test_scenario[lis2mdl/Magnitude in plausible range/hardware] PASSED                                                                                                                                                                          [ 44%]
tests/test_scenarios.py::test_scenario[lis2mdl/Temperature in plausible range/hardware] PASSED                                                                                                                                                                        [ 45%]
tests/test_scenarios.py::test_scenario[lis2mdl/Soft reset then WHO_AM_I/hardware] SKIPPED (hardware_script test requires interactive mode (-s))                                                                                                                       [ 46%]
tests/test_scenarios.py::test_scenario[lis2mdl/Reboot then WHO_AM_I/hardware] SKIPPED (hardware_script test requires interactive mode (-s))                                                                                                                           [ 47%]
tests/test_scenarios.py::test_scenario[lis2mdl/Magnetic field values feel correct/hardware] SKIPPED (manual test requires interactive mode (-s))                                                                                                                      [ 48%]
tests/test_scenarios.py::test_scenario[mcp23009e/Read IODIR default value/mock] PASSED                                                                                                                                                                                [ 49%]
tests/test_scenarios.py::test_scenario[mcp23009e/Read IODIR default value/hardware] PASSED                                                                                                                                                                            [ 50%]
tests/test_scenarios.py::test_scenario[mcp23009e/Read GPIO register/mock] PASSED                                                                                                                                                                                      [ 51%]
tests/test_scenarios.py::test_scenario[mcp23009e/Read GPIO register/hardware] PASSED                                                                                                                                                                                  [ 52%]
tests/test_scenarios.py::test_scenario[mcp23009e/Read individual GPIO level/mock] PASSED                                                                                                                                                                              [ 53%]
tests/test_scenarios.py::test_scenario[mcp23009e/D-PAD buttons state/hardware] SKIPPED (manual test requires interactive mode (-s))                                                                                                                                   [ 54%]
tests/test_scenarios.py::test_scenario[mcp23009e/D-PAD UP button (polling)/hardware] SKIPPED (hardware_script test requires interactive mode (-s))                                                                                                                    [ 55%]
tests/test_scenarios.py::test_scenario[mcp23009e/D-PAD DOWN button (polling)/hardware] SKIPPED (hardware_script test requires interactive mode (-s))                                                                                                                  [ 56%]
tests/test_scenarios.py::test_scenario[mcp23009e/D-PAD LEFT button (polling)/hardware] SKIPPED (hardware_script test requires interactive mode (-s))                                                                                                                  [ 57%]
tests/test_scenarios.py::test_scenario[mcp23009e/D-PAD RIGHT button (polling)/hardware] SKIPPED (hardware_script test requires interactive mode (-s))                                                                                                                 [ 58%]
tests/test_scenarios.py::test_scenario[mcp23009e/D-PAD UP button (interrupt)/hardware] SKIPPED (hardware_script test requires interactive mode (-s))                                                                                                                  [ 59%]
tests/test_scenarios.py::test_scenario[mcp23009e/D-PAD DOWN button (interrupt)/hardware] SKIPPED (hardware_script test requires interactive mode (-s))                                                                                                                [ 60%]
tests/test_scenarios.py::test_scenario[mcp23009e/D-PAD LEFT button (interrupt)/hardware] SKIPPED (hardware_script test requires interactive mode (-s))                                                                                                                [ 61%]
tests/test_scenarios.py::test_scenario[mcp23009e/D-PAD RIGHT button (interrupt)/hardware] SKIPPED (hardware_script test requires interactive mode (-s))                                                                                                               [ 62%]
tests/test_scenarios.py::test_scenario[ssd1327/Fill black does not crash/mock] PASSED                                                                                                                                                                                 [ 63%]
tests/test_scenarios.py::test_scenario[ssd1327/Fill white does not crash/mock] PASSED                                                                                                                                                                                 [ 64%]
tests/test_scenarios.py::test_scenario[ssd1327/Text rendering does not crash/mock] PASSED                                                                                                                                                                             [ 65%]
tests/test_scenarios.py::test_scenario[ssd1327/Show does not crash/mock] PASSED                                                                                                                                                                                       [ 66%]
tests/test_scenarios.py::test_scenario[ssd1327/Display white screen/hardware] SKIPPED (hardware_script test requires interactive mode (-s))                                                                                                                           [ 66%]
tests/test_scenarios.py::test_scenario[ssd1327/Screen is white/hardware] SKIPPED (manual test requires interactive mode (-s))                                                                                                                                         [ 67%]
tests/test_scenarios.py::test_scenario[ssd1327/Display text/hardware] SKIPPED (hardware_script test requires interactive mode (-s))                                                                                                                                   [ 68%]
tests/test_scenarios.py::test_scenario[ssd1327/Text is visible/hardware] SKIPPED (manual test requires interactive mode (-s))                                                                                                                                         [ 69%]
tests/test_scenarios.py::test_scenario[ssd1327/Display grayscale gradient/hardware] SKIPPED (hardware_script test requires interactive mode (-s))                                                                                                                     [ 70%]
tests/test_scenarios.py::test_scenario[ssd1327/Grayscale gradient is visible/hardware] SKIPPED (manual test requires interactive mode (-s))                                                                                                                           [ 71%]
tests/test_scenarios.py::test_scenario[ssd1327/Scrolling animation/hardware] SKIPPED (hardware_script test requires interactive mode (-s))                                                                                                                            [ 72%]
tests/test_scenarios.py::test_scenario[ssd1327/Animation was smooth/hardware] SKIPPED (manual test requires interactive mode (-s))                                                                                                                                    [ 73%]
tests/test_scenarios.py::test_scenario[vl53l1x/Verify model ID register/mock] PASSED                                                                                                                                                                                  [ 74%]
tests/test_scenarios.py::test_scenario[vl53l1x/Verify model ID register/hardware] PASSED                                                                                                                                                                              [ 75%]
tests/test_scenarios.py::test_scenario[vl53l1x/Read distance returns expected value/mock] PASSED                                                                                                                                                                      [ 76%]
tests/test_scenarios.py::test_scenario[vl53l1x/Distance in plausible range/hardware] PASSED                                                                                                                                                                           [ 77%]
tests/test_scenarios.py::test_scenario[vl53l1x/Distance measurement feels correct/hardware] SKIPPED (manual test requires interactive mode (-s))                                                                                                                      [ 78%]
tests/test_scenarios.py::test_scenario[wsen-hids/Verify device ID register/mock] PASSED                                                                                                                                                                               [ 79%]
tests/test_scenarios.py::test_scenario[wsen-hids/Verify device ID register/hardware] PASSED                                                                                                                                                                           [ 80%]
tests/test_scenarios.py::test_scenario[wsen-hids/Read device ID via method/mock] PASSED                                                                                                                                                                               [ 81%]
tests/test_scenarios.py::test_scenario[wsen-hids/Read device ID via method/hardware] PASSED                                                                                                                                                                           [ 82%]
tests/test_scenarios.py::test_scenario[wsen-hids/Read status register/mock] PASSED                                                                                                                                                                                    [ 83%]
tests/test_scenarios.py::test_scenario[wsen-hids/Read status register/hardware] PASSED                                                                                                                                                                                [ 84%]
tests/test_scenarios.py::test_scenario[wsen-hids/Read humidity returns float/mock] PASSED                                                                                                                                                                             [ 85%]
tests/test_scenarios.py::test_scenario[wsen-hids/Read temperature returns float/mock] PASSED                                                                                                                                                                          [ 86%]
tests/test_scenarios.py::test_scenario[wsen-hids/Humidity in plausible range/hardware] PASSED                                                                                                                                                                         [ 87%]
tests/test_scenarios.py::test_scenario[wsen-hids/Temperature in plausible range/hardware] PASSED                                                                                                                                                                      [ 88%]
tests/test_scenarios.py::test_scenario[wsen-hids/Humidity and temperature feel correct/hardware] SKIPPED (manual test requires interactive mode (-s))                                                                                                                 [ 89%]
tests/test_scenarios.py::test_scenario[wsen-pads/Verify device ID register/mock] PASSED                                                                                                                                                                               [ 90%]
tests/test_scenarios.py::test_scenario[wsen-pads/Verify device ID register/hardware] PASSED                                                                                                                                                                           [ 91%]
tests/test_scenarios.py::test_scenario[wsen-pads/Read device ID via method/mock] PASSED                                                                                                                                                                               [ 92%]
tests/test_scenarios.py::test_scenario[wsen-pads/Read device ID via method/hardware] PASSED                                                                                                                                                                           [ 93%]
tests/test_scenarios.py::test_scenario[wsen-pads/Read status register/mock] PASSED                                                                                                                                                                                    [ 94%]
tests/test_scenarios.py::test_scenario[wsen-pads/Read status register/hardware] PASSED                                                                                                                                                                                [ 95%]
tests/test_scenarios.py::test_scenario[wsen-pads/Read pressure returns float/mock] PASSED                                                                                                                                                                             [ 96%]
tests/test_scenarios.py::test_scenario[wsen-pads/Read temperature returns float/mock] PASSED                                                                                                                                                                          [ 97%]
tests/test_scenarios.py::test_scenario[wsen-pads/Pressure in plausible range/hardware] PASSED                                                                                                                                                                         [ 98%]
tests/test_scenarios.py::test_scenario[wsen-pads/Temperature in plausible range/hardware] PASSED                                                                                                                                                                      [ 99%]
tests/test_scenarios.py::test_scenario[wsen-pads/Pressure and temperature feel correct/hardware] SKIPPED (manual test requires interactive mode (-s))                                                                                                                 [100%]

================== 76 passed, 27 skipped in 131.29s (0:02:11) ===================

Test plan

  • ruff check passes
  • All mock tests pass (pytest tests/ -k mock — 41 passed)
  • Hardware test: verify drivers still work correctly on the board

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

This pull request updates remaining driver const.py modules to use micropython.const() so MicroPython can inline integer constants and reduce RAM usage across these drivers.

Changes:

  • Add from micropython import const to the remaining const.py modules.
  • Wrap integer register/bitmask/timing constants in const(...) for apds9960, bq27441, and wsen-pads.

Reviewed changes

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

File Description
lib/apds9960/apds9960/const.py Imports const and wraps integer constants for APDS9960 registers/bitfields/defaults.
lib/bq27441/bq27441/const.py Imports const and wraps integer constants for commands/flags/opconfig bits/timeouts.
lib/wsen-pads/wsen_pads/const.py Imports const and wraps integer constants for I2C addr/regs/bitmasks/ODR values/delays.

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

Comment thread lib/bq27441/bq27441/const.py Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@nedseb nedseb merged commit 6c36de8 into main Mar 13, 2026
4 checks passed
@nedseb nedseb deleted the fix/add-micropython-const branch March 13, 2026 11:44
@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.

drivers: Add micropython.const() wrapper to all const.py files.

2 participants