Skip to content

Migrate MLX90614 sensor driver to new I2C API conventions#279

Open
voldemort9999 wants to merge 1 commit intofossasia:mainfrom
voldemort9999:fix/mlx90614-i2c-migration
Open

Migrate MLX90614 sensor driver to new I2C API conventions#279
voldemort9999 wants to merge 1 commit intofossasia:mainfrom
voldemort9999:fix/mlx90614-i2c-migration

Conversation

@voldemort9999
Copy link

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 False instead of proper None returns, 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

  • Renamed methods to snake\_case: getObjectTemperature → get_object_temperature, getAmbientTemperature → get_ambient_temperature, getRaw → get_raw, readReg → read_reg
  • Removed getVals — it was a one-line wrapper around self.read(), so I inlined it directly
  • Replaced print() with logging.info() in read_reg
  • Returns None instead of False on failed reads (more Pythonic, better for type checkers)
  • Added type hints to all methods
  • Added NumPy-style docstrings to class and all public methods
  • Removed commented-out dead code that referenced the old self.I2C.configI2C() API
  • init now accepts optional device parameter, consistent with I2CSlave signature

Usage

from pslab.external.MLX90614 import MLX90614

sensor = MLX90614()
print(sensor.get_object_temperature())   # target temp in °C
print(sensor.get_ambient_temperature())  # sensor body temp in °C

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.

=================== 20 passed in 0.08s ===================

- 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
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Sorry @voldemort9999, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MLX90614: migrate to new I2C API

1 participant