Migrate MLX90614 sensor driver to new I2C API conventions#279
Migrate MLX90614 sensor driver to new I2C API conventions#279voldemort9999 wants to merge 1 commit into
Conversation
- Rename camelCase methods to snake_case - Add type hints and NumPy-style docstrings - Replace print() with logging - Return None instead of False on read failures - Remove dead commented-out old API code - Accept optional device parameter in __init__ - Add 20 mock-based unit tests Closes fossasia#182
There was a problem hiding this comment.
Sorry @voldemort9999, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
There was a problem hiding this comment.
Pull request overview
Migrates the MLX90614 IR thermometer driver to follow the codebase's modern I2C API conventions (snake_case methods, logging, type hints, NumPy-style docstrings, None instead of False on failure, optional device parameter). Adds a mock-based test module covering initialization, source selection, conversion math, error handling, and logging.
Changes:
- Renamed methods to snake_case, removed the trivial
getValswrapper, replacedprint()withlogging.info(), and dropped commented-out dead code. - Added type hints, NumPy-style docstrings, and an optional
device: ConnectionHandlerconstructor parameter consistent withI2CSlave. - Added
tests/test_mlx90614.pywith 20 mock-based unit tests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pslab/external/MLX90614.py | Full driver cleanup: snake_case API, logging, type hints, docstrings, None-on-failure, optional device param. |
| tests/test_mlx90614.py | New mock-based unit tests covering init, source selection, conversion, error handling, logging, and return types. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
While looking at the sensor drivers, I noticed that the MLX90614 module was left in a half-migrated state — it inherits from I2CSlave (which is great), but the rest of the code still followed the old conventions: camelCase methods,
print()instead of logging,return Falseinstead of properNonereturns, and no type hints or documentation.Since this was flagged in #182, I went through and did a full cleanup to bring it in line with the rest of the codebase.
Closes #182
Changes
self.read(), so I inlined it directlyprint()withlogging.info()in read_regNoneinstead ofFalseon failed reads (more Pythonic, better for type checkers)self.I2C.configI2C()APIUsage
Tests
Added tests/test_mlx90614.py with 20 unit tests covering initialization, source selection, temperature conversion math, error handling, logging output, return types, and class attributes. All tests are mock-based and run without hardware.