Closed evaherrada closed 1 year ago
Assigning Tekktrik as well to look into this. We'll work together to decide what the best solution is.
Interesting that it thinks it's duplicate code even though one is I2CDevice and the other is SPIDevice. This could also be refactored, but see more of an argument for ignoring it given it's not truly duplicate.
Oh, never mind, I read the CI wrong. It's likely we could set up a base class for each device type.
This library is a candidate for refactoring based on pylint
warning of duplicate code. The solution for this library would be to refactor the code to not have duplicated portions of code. In most cases, this might mean making base classes/functions so code can be recycled, but in some cases it may mean removing duplicate functionality (e.g., for compatibility).
To determine the duplicate code section, allow pylint
to warn against duplicated code by removing ,duplicate-code
from .pre-commit-config.yaml
and then running pre-commit
:
Then, refactor the duplicated code sections until it passes pre-commit
. The modified .pre-commit-config.yaml
file and refactored code can then be submitted as a PR.
Going to give the refactor a try. #CircuitPythonDay2022
I've got a pull request: https://github.com/adafruit/Adafruit_CircuitPython_BME280/pull/62
Questions about naming things:
I extracted the bus specific parts to classes named I2C_Impl and SPI_Impl in protocol.py. Are these *_Impls, proxies, or delegates? Is there a better name than protocol.py?
Tested with Blinka/MCP2221. Tested with 8.0.0-beta.0 on 2022-08-18; Adafruit QT Py M0 with samd21e18: Had to run the .mpy; no room for the advanced.py or .mpy files. But it worked!
from adafruit_bme280 import basic
i2c = board.I2C()
sensor = basic.Adafruit_BME280_I2C(i2c, address=0x76)
print("Temp:",sensor.temperature)
print("RH: ",sensor.relative_humidity)
print("Alt: ",sensor.altitude)
https://github.com/adafruit/Adafruit_CircuitPython_BME280/runs/6993430685?check_suite_focus=true#step:11:33