From e947bde6bb5ea37d3ee443545686448261882290 Mon Sep 17 00:00:00 2001 From: hh Date: Sat, 17 Nov 2018 08:51:21 +0100 Subject: [PATCH 001/125] adafruit_bme280.py: Fix the value of dig_H5 The calculation of dig_H5 from the calibration data did not match the definition of the data sheet and the Bosch sample code. As a result, the compensated relative humidity data could have been calculated wrong. --- adafruit_bme280.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_bme280.py b/adafruit_bme280.py index 5078dba..24c7502 100644 --- a/adafruit_bme280.py +++ b/adafruit_bme280.py @@ -198,7 +198,7 @@ def _read_coefficients(self): self._humidity_calib[1] = float(coeff[0]) self._humidity_calib[2] = float(coeff[1]) self._humidity_calib[3] = float((coeff[2] << 4) | (coeff[3] & 0xF)) - self._humidity_calib[4] = float(((coeff[3] & 0xF0) << 4) | coeff[4]) + self._humidity_calib[4] = float((coeff[4] << 4) | (coeff[3] >> 4)) self._humidity_calib[5] = float(coeff[5]) def _read_byte(self, register): From e3cadc96cb1d7c2bffcb3503bbaad4aa54dc52d2 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Fri, 21 Dec 2018 13:22:49 -0600 Subject: [PATCH 002/125] change 'travis-ci.org' to 'travis-ci.com' --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index a721d05..5aa2e4a 100644 --- a/README.rst +++ b/README.rst @@ -9,8 +9,8 @@ Introduction :target: https://discord.gg/nBQh6qu :alt: Discord -.. image:: https://travis-ci.org/adafruit/Adafruit_CircuitPython_BME280.svg?branch=master - :target: https://travis-ci.org/adafruit/Adafruit_CircuitPython_BME280 +.. image:: https://travis-ci.com/adafruit/Adafruit_CircuitPython_BME280.svg?branch=master + :target: https://travis-ci.com/adafruit/Adafruit_CircuitPython_BME280 :alt: Build Status I2C and SPI driver for the Bosch BME280 Temperature, Humidity, and Barometric Pressure sensor From 3ebd5c307557fe4970f15560d1c4be9bdf9f101f Mon Sep 17 00:00:00 2001 From: Jeff Raber Date: Wed, 27 Feb 2019 00:37:49 -0600 Subject: [PATCH 003/125] Add class attributes to allow more control over the sensor Add attributes for IIR filter, standby period, operation mode, and overscan for temperature, pressure and humidity. Add Enum classes for the overscan, standby, and iir filter values --- adafruit_bme280.py | 232 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 215 insertions(+), 17 deletions(-) diff --git a/adafruit_bme280.py b/adafruit_bme280.py index 24c7502..5d6c1c6 100644 --- a/adafruit_bme280.py +++ b/adafruit_bme280.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. """ -`adafruit_bme280` - Adafruit BME680 - Temperature, Humidity, Pressure & Gas Sensor +`adafruit_bme280` - Adafruit BME280 - Temperature, Humidity & Barometic Pressure Sensor ==================================================================================== CircuitPython driver from BME280 Temperature, Humidity and Barometic Pressure sensor @@ -28,7 +28,8 @@ * Author(s): ladyada """ import math -import time +from time import sleep +from enum import Enum from micropython import const try: import struct @@ -67,34 +68,77 @@ _BME280_HUMIDITY_MIN = const(0) _BME280_HUMIDITY_MAX = const(100) +class IIR_FILTER(Enum): + """Enum class for iir_filter values""" + DISABLE = 0 + X_2 = 1 + X_4 = 2 + X_8 = 3 + X_16 = 4 + +class OVERSCAN(Enum): + """Enum class for overscan values for temperature, pressure, and humidity""" + DISABLE = 0 + X_1 = 1 + X_2 = 2 + X_4 = 3 + X_8 = 4 + X_16 = 5 + +class MODE(Enum): + """Enum class for mode values""" + SLEEP = 0 + FORCE = 1 + NORMAL = 3 + +class STANDBY(Enum): + """ + Enum class for standby values + TC_X[_Y] where X=milliseconds and Y=tenths of a millisecond + """ + TC_0_5 = 0 #0.5ms + TC_10 = 6 #10ms + TC_20 = 7 #20ms + TC_62_5 = 1 #62.5ms + TC_125 = 2 #125ms + TC_250 = 3 #250ms + TC_500 = 4 #500ms + TC_1000 = 5 #1000ms + class Adafruit_BME280: """Driver from BME280 Temperature, Humidity and Barometic Pressure sensor""" def __init__(self): - """Check the BME280 was found, read the coefficients and enable the sensor for continuous - reads""" + """Check the BME280 was found, read the coefficients and enable the sensor""" # Check device ID. chip_id = self._read_byte(_BME280_REGISTER_CHIPID) if _BME280_CHIPID != chip_id: raise RuntimeError('Failed to find BME280! Chip ID 0x%x' % chip_id) - self._write_register_byte(_BME280_REGISTER_SOFTRESET, 0xB6) - time.sleep(0.5) + #Set some reasonable defaults. + self._iir_filter = IIR_FILTER.DISABLE + self._overscan_humidity = OVERSCAN.X_2 + self._overscan_temperature = OVERSCAN.X_2 + self._overscan_pressure = OVERSCAN.X_16 + self._t_standby = STANDBY.TC_0_5 + self._mode = MODE.SLEEP + self._reset() self._read_coefficients() + self._write_ctrl_meas() + self._write_config() self.sea_level_pressure = 1013.25 """Pressure in hectoPascals at sea level. Used to calibrate `altitude`.""" - # turn on humidity oversample 16x - self._write_register_byte(_BME280_REGISTER_CTRL_HUM, 0x03) self._t_fine = None def _read_temperature(self): # perform one measurement - self._write_register_byte(_BME280_REGISTER_CTRL_MEAS, 0xFE) # high res, forced mode - - # Wait for conversion to complete - while self._read_byte(_BME280_REGISTER_STATUS) & 0x08: - time.sleep(0.002) - raw_temperature = self._read24(_BME280_REGISTER_TEMPDATA) / 16 # lowest 4 bits get dropped + if self.mode != MODE.NORMAL: + self.mode = MODE.FORCE + # Wait for conversion to complete + while self._get_status() & 0x08: + sleep(0.002) + raw_temperature = self._read24(_BME280_REGISTER_TEMPDATA) / 16 # lowest 4 bits get dropped + if raw_temperature == 0x80000: #0x80000 means the measurment was skipped + return #print("raw temp: ", UT) - var1 = (raw_temperature / 16384.0 - self._temp_calib[0] / 1024.0) * self._temp_calib[1] #print(var1) var2 = ((raw_temperature / 131072.0 - self._temp_calib[0] / 8192.0) * ( @@ -104,6 +148,150 @@ def _read_temperature(self): self._t_fine = int(var1 + var2) #print("t_fine: ", self.t_fine) + def _reset(self): + """Soft reset the sensor""" + self._write_register_byte(_BME280_REGISTER_SOFTRESET, 0xB6) + sleep(0.004) #Datasheet says 2ms. Using 4ms just to be safe + + def _write_ctrl_meas(self): + """ + Write the values to the ctrl_meas and ctrl_hum registers in the device + ctrl_meas sets the pressure and temperature data acquistion options + ctrl_hum sets the humidty oversampling and must be written to first + """ + self._write_register_byte(_BME280_REGISTER_CTRL_HUM, self.overscan_humidity) + self._write_register_byte(_BME280_REGISTER_CTRL_MEAS, self._ctrl_meas) + + def _get_status(self): + """Get the value from the status register in the device """ + return self._read_byte(_BME280_REGISTER_STATUS) + + def _read_config(self): + """Read the value from the config register in the device """ + return self._read_byte(_BME280_REGISTER_CONFIG) + + def _write_config(self): + """Write the value to the config register in the device """ + if self._mode == MODE.NORMAL: + #Writes to the config register may be ignored while in Normal mode + normal_flag = True + self.mode = MODE.SLEEP #So we switch to Sleep mode first + self._write_register_byte(_BME280_REGISTER_CONFIG, self._config) + if normal_flag: + self.mode = MODE.NORMAL + + @property + def mode(self): + """ + Operation mode + Allowed values are set in the MODE enum class + """ + return self._mode + + @mode.setter + def mode(self, value): + if not value in MODE: + raise ValueError('Mode \'%s\' not supported' % (value)) + if self._mode == value: + return + self._mode = value + self._write_ctrl_meas() + + @property + def standby_period(self): + """ + Control the inactive period when in Normal mode + Allowed standby periods are set the STANDBY enum class + """ + return self._t_standby + + @standby_period.setter + def standy_period(self, value): + if not value in STANDBY: + raise ValueError('Standby Period \'%s\' not supported' % (value)) + if self._t_standby == value: + return + self._t_standby = value + self._write_config() + + @property + def overscan_humidity(self): + """Humidity Oversampling + Allowed values are set in the OVERSCAN enum class """ + return self._overscan_humidity + + @overscan_humidity.setter + def overscan_humidity(self, value): + if not value in OVERSCAN: + raise ValueError('Overscan value \'%s\' not supported' % (value)) + self._overscan_humidity = value + self._write_ctrl_meas() + + @property + def overscan_temperature(self): + """ + Temperature Oversampling + Allowed values are set in the OVERSCAN enum class + """ + return self._overscan_humidity + + @overscan_temperature.setter + def overscan_temperature(self, value): + if not value in OVERSCAN: + raise ValueError('Overscan value \'%s\' not supported' % (value)) + self._overscan_temperature = value + self._write_ctrl_meas() + + @property + def overscan_pressure(self): + """ + Pressure Oversampling + Allowed values are set in the OVERSCAN enum class + """ + return self._overscan_pressure + + @overscan_pressure.setter + def overscan_pressure(self, value): + if not value in OVERSCAN: + raise ValueError('Overscan value \'%s\' not supported' % (value)) + self._overscan_pressure = value + self._write_ctrl_meas() + + @property + def iir_filter(self): + """ + Controls the time constant of the IIR filter + Allowed values are set in the IIR_FILTER enum class + """ + return self._iir_filter + + @iir_filter.setter + def iir_filter(self, value): + if not value in IIR_FILTER: + raise ValueError('IIR Filter \'%s\' not supported' % (value)) + self._iir_filter = value + self._write_config() + + @property + def _config(self): + """Value to be written to the device's config register """ + config = 0 + if self.mode == MODE.NORMAL: + config += (self._t_standby << 5) + if self._iir_filter: + config += (self._iir_filter.value << 2) + if isinstance(self, Adafruit_BME280_SPI): + config += 1 #enable SPI interface + return config + + @property + def _ctrl_meas(self): + """Value to be written to the device's ctrl_meas register """ + ctrl_meas = (self.overscan_temperature.value << 5) + ctrl_meas += (self.overscan_pressure.value << 2) + ctrl_meas += self.mode.value + return ctrl_meas + @property def temperature(self): """The compensated temperature in degrees celsius.""" @@ -112,12 +300,17 @@ def temperature(self): @property def pressure(self): - """The compensated pressure in hectoPascals.""" + """ + The compensated pressure in hectoPascals. + returns None if pressure measurement is disabled + """ self._read_temperature() # Algorithm from the BME280 driver # https://github.com/BoschSensortec/BME280_driver/blob/master/bme280.c adc = self._read24(_BME280_REGISTER_PRESSUREDATA) / 16 # lowest 4 bits get dropped + if adc == 0x80000: #0x80000 means the measurement was skipped + return None var1 = float(self._t_fine) / 2.0 - 64000.0 var2 = var1 * var1 * self._pressure_calib[5] / 32768.0 var2 = var2 + var1 * self._pressure_calib[4] * 2.0 @@ -145,9 +338,14 @@ def pressure(self): @property def humidity(self): - """The relative humidity in RH %""" + """ + The relative humidity in RH % + returns None if humidity measurement is disabled + """ self._read_temperature() hum = self._read_register(_BME280_REGISTER_HUMIDDATA, 2) + if hum == 0x8000: #0x8000 means the reading was skipped + return None #print("Humidity data: ", hum) adc = float(hum[0] << 8 | hum[1]) #print("adc:", adc) From dc89e0becdbe0a68e6deca7863a8ac37f1ebb7a5 Mon Sep 17 00:00:00 2001 From: Jeff Raber Date: Wed, 27 Feb 2019 01:36:06 -0600 Subject: [PATCH 004/125] Fix-up overscan_tempearure as it was returning the wrong value --- adafruit_bme280.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_bme280.py b/adafruit_bme280.py index 5d6c1c6..5eac5c0 100644 --- a/adafruit_bme280.py +++ b/adafruit_bme280.py @@ -233,7 +233,7 @@ def overscan_temperature(self): Temperature Oversampling Allowed values are set in the OVERSCAN enum class """ - return self._overscan_humidity + return self._overscan_temperature @overscan_temperature.setter def overscan_temperature(self, value): From 032d38c7494edd2f6b3115861d6f3408e3e40475 Mon Sep 17 00:00:00 2001 From: Jeff Raber Date: Wed, 27 Feb 2019 01:38:19 -0600 Subject: [PATCH 005/125] Increase underline length to make sphinx happy --- adafruit_bme280.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_bme280.py b/adafruit_bme280.py index 5eac5c0..87c4f30 100644 --- a/adafruit_bme280.py +++ b/adafruit_bme280.py @@ -21,7 +21,7 @@ # THE SOFTWARE. """ `adafruit_bme280` - Adafruit BME280 - Temperature, Humidity & Barometic Pressure Sensor -==================================================================================== +========================================================================================= CircuitPython driver from BME280 Temperature, Humidity and Barometic Pressure sensor From 29af22eabcd643e9d82dd68c4f3885e3713294b5 Mon Sep 17 00:00:00 2001 From: Jeff Raber Date: Wed, 27 Feb 2019 08:35:14 -0600 Subject: [PATCH 006/125] Default normal_flag to False to avoid UnboundLocalError in _write_config --- adafruit_bme280.py | 1 + 1 file changed, 1 insertion(+) diff --git a/adafruit_bme280.py b/adafruit_bme280.py index 87c4f30..ae6d616 100644 --- a/adafruit_bme280.py +++ b/adafruit_bme280.py @@ -171,6 +171,7 @@ def _read_config(self): return self._read_byte(_BME280_REGISTER_CONFIG) def _write_config(self): + normal_flag = False """Write the value to the config register in the device """ if self._mode == MODE.NORMAL: #Writes to the config register may be ignored while in Normal mode From e9d73206396f07dde247c07e4f9528f587037b48 Mon Sep 17 00:00:00 2001 From: Jeff Raber Date: Wed, 27 Feb 2019 08:50:04 -0600 Subject: [PATCH 007/125] Fix typo: standy -> standby --- adafruit_bme280.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_bme280.py b/adafruit_bme280.py index ae6d616..7950c48 100644 --- a/adafruit_bme280.py +++ b/adafruit_bme280.py @@ -207,7 +207,7 @@ def standby_period(self): return self._t_standby @standby_period.setter - def standy_period(self, value): + def standby_period(self, value): if not value in STANDBY: raise ValueError('Standby Period \'%s\' not supported' % (value)) if self._t_standby == value: From 3284ed4fc087e5043e22341e5afebb38b0fa4931 Mon Sep 17 00:00:00 2001 From: Jeff Raber Date: Wed, 27 Feb 2019 08:58:32 -0600 Subject: [PATCH 008/125] Fix __write_config, docstring comes first --- adafruit_bme280.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_bme280.py b/adafruit_bme280.py index 7950c48..b2df116 100644 --- a/adafruit_bme280.py +++ b/adafruit_bme280.py @@ -171,8 +171,8 @@ def _read_config(self): return self._read_byte(_BME280_REGISTER_CONFIG) def _write_config(self): - normal_flag = False """Write the value to the config register in the device """ + normal_flag = False if self._mode == MODE.NORMAL: #Writes to the config register may be ignored while in Normal mode normal_flag = True From 3b37d55d0ee7a41e3cf8736de3025adab1381059 Mon Sep 17 00:00:00 2001 From: Jeff Raber Date: Thu, 28 Feb 2019 07:52:20 -0600 Subject: [PATCH 009/125] Add disable=too-many-instance-attributes to keep pylint happy --- adafruit_bme280.py | 1 + 1 file changed, 1 insertion(+) diff --git a/adafruit_bme280.py b/adafruit_bme280.py index b2df116..a803535 100644 --- a/adafruit_bme280.py +++ b/adafruit_bme280.py @@ -107,6 +107,7 @@ class STANDBY(Enum): class Adafruit_BME280: """Driver from BME280 Temperature, Humidity and Barometic Pressure sensor""" + # pylint: disable=too-many-instance-attributes def __init__(self): """Check the BME280 was found, read the coefficients and enable the sensor""" # Check device ID. From ccf536384a707f017a0484334b6ec181f9dcca8d Mon Sep 17 00:00:00 2001 From: Jeff Raber Date: Thu, 28 Feb 2019 22:57:54 -0600 Subject: [PATCH 010/125] Added and example for setting the mode, overscan, standby, and iir_filter --- examples/bme280_normal_mode.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 examples/bme280_normal_mode.py diff --git a/examples/bme280_normal_mode.py b/examples/bme280_normal_mode.py new file mode 100644 index 0000000..71c2768 --- /dev/null +++ b/examples/bme280_normal_mode.py @@ -0,0 +1,33 @@ +import time + +import board +import busio +import adafruit_bme280 + +# Create library object using our Bus I2C port +i2c = busio.I2C(board.SCL, board.SDA) +bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) + +# OR create library object using our Bus SPI port +#spi = busio.SPI(board.SCK, board.MOSI, board.MISO) +#bme_cs = digitalio.DigitalInOut(board.D10) +#bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs) + +# change this to match the location's pressure (hPa) at sea level +bme280.sea_level_pressure = 1013.25 +#refer to the BMP280 datasheet to understand what these do +bme280.mode = adafruit_bme280.MODE.NORMAL +bme280.standby_period = adafruit_bme280.STANDBY.TC_500 +bme280.iir_filter = adafruit_bme280.IIR_FILTER.X_16 +bme_280.overscan_pressure = adafruit_bme280.OVERSCAN.X_16 +bme_280.overscan_humidity = adafruit_bme280.OVERSCAN.X_1 +bme_280.overscan_temperature = adafruit_bme280.OVERSCAN.X_2 +#The sensor will need a moment to gather inital readings +sleep(1) + +while True: + print("\nTemperature: %0.1f C" % bme280.temperature) + print("Humidity: %0.1f %%" % bme280.humidity) + print("Pressure: %0.1f hPa" % bme280.pressure) + print("Altitude = %0.2f meters" % bme280.altitude) + time.sleep(2) From a8c12e76b080f1e5072142ce3135fe8e878887fd Mon Sep 17 00:00:00 2001 From: Jeff Raber Date: Fri, 1 Mar 2019 00:46:21 -0600 Subject: [PATCH 011/125] Fix-up example --- examples/bme280_normal_mode.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/bme280_normal_mode.py b/examples/bme280_normal_mode.py index 71c2768..f664512 100644 --- a/examples/bme280_normal_mode.py +++ b/examples/bme280_normal_mode.py @@ -19,11 +19,11 @@ bme280.mode = adafruit_bme280.MODE.NORMAL bme280.standby_period = adafruit_bme280.STANDBY.TC_500 bme280.iir_filter = adafruit_bme280.IIR_FILTER.X_16 -bme_280.overscan_pressure = adafruit_bme280.OVERSCAN.X_16 -bme_280.overscan_humidity = adafruit_bme280.OVERSCAN.X_1 -bme_280.overscan_temperature = adafruit_bme280.OVERSCAN.X_2 +bme280.overscan_pressure = adafruit_bme280.OVERSCAN.X_16 +bme280.overscan_humidity = adafruit_bme280.OVERSCAN.X_1 +bme280.overscan_temperature = adafruit_bme280.OVERSCAN.X_2 #The sensor will need a moment to gather inital readings -sleep(1) +time.sleep(1) while True: print("\nTemperature: %0.1f C" % bme280.temperature) From ef0eef61455e793a4c608ac9d377527f3e71e822 Mon Sep 17 00:00:00 2001 From: Jeff Raber Date: Fri, 1 Mar 2019 08:13:40 -0600 Subject: [PATCH 012/125] Refactor to remove dependency on the enum class Removed references to the enum class, while keeping the same functionality Updated the 'normal mode' example --- adafruit_bme280.py | 140 +++++++++++++++++---------------- examples/bme280_normal_mode.py | 18 +++-- 2 files changed, 85 insertions(+), 73 deletions(-) diff --git a/adafruit_bme280.py b/adafruit_bme280.py index a803535..e2f7a6f 100644 --- a/adafruit_bme280.py +++ b/adafruit_bme280.py @@ -29,7 +29,6 @@ """ import math from time import sleep -from enum import Enum from micropython import const try: import struct @@ -68,42 +67,49 @@ _BME280_HUMIDITY_MIN = const(0) _BME280_HUMIDITY_MAX = const(100) -class IIR_FILTER(Enum): - """Enum class for iir_filter values""" - DISABLE = 0 - X_2 = 1 - X_4 = 2 - X_8 = 3 - X_16 = 4 - -class OVERSCAN(Enum): - """Enum class for overscan values for temperature, pressure, and humidity""" - DISABLE = 0 - X_1 = 1 - X_2 = 2 - X_4 = 3 - X_8 = 4 - X_16 = 5 - -class MODE(Enum): - """Enum class for mode values""" - SLEEP = 0 - FORCE = 1 - NORMAL = 3 - -class STANDBY(Enum): - """ - Enum class for standby values - TC_X[_Y] where X=milliseconds and Y=tenths of a millisecond - """ - TC_0_5 = 0 #0.5ms - TC_10 = 6 #10ms - TC_20 = 7 #20ms - TC_62_5 = 1 #62.5ms - TC_125 = 2 #125ms - TC_250 = 3 #250ms - TC_500 = 4 #500ms - TC_1000 = 5 #1000ms +"""iir_filter values""" +IIR_FILTER_DISABLE = const(0) +IIR_FILTER_X2 = const(0x01) +IIR_FILTER_X4 = const(0x02) +IIR_FILTER_X8 = const(0x03) +IIR_FILTER_X16 = const(0x04) + +_BME280_IIR_FILTERS = frozenset((IIR_FILTER_DISABLE, IIR_FILTER_X2, + IIR_FILTER_X4, IIR_FILTER_X8, IIR_FILTER_X16)) + +"""overscan values for temperature, pressure, and humidity""" +OVERSCAN_DISABLE = const(0x00) +OVERSCAN_X1 = const(0x01) +OVERSCAN_X2 = const(0x02) +OVERSCAN_X4 = const(0x03) +OVERSCAN_X8 = const(0x04) +OVERSCAN_X16 = const(0x05) + +_BME280_OVERSCANS = frozenset((OVERSCAN_DISABLE, OVERSCAN_X1, OVERSCAN_X2, + OVERSCAN_X4, OVERSCAN_X8, OVERSCAN_X16)) + +"""mode values""" +MODE_SLEEP = const(0x00) +MODE_FORCE = const(0x01) +MODE_NORMAL = const(0x03) + +_BME280_MODES = frozenset((MODE_SLEEP, MODE_FORCE, MODE_NORMAL)) +""" +standby timeconstant values +TC_X[_Y] where X=milliseconds and Y=tenths of a millisecond +""" +STANDBY_TC_0_5 = const(0x00) #0.5ms +STANDBY_TC_10 = const(0x06) #10ms +STANDBY_TC_20 = const(0x07) #20ms +STANDBY_TC_62_5 = const(0x01) #62.5ms +STANDBY_TC_125 = const(0x02) #125ms +STANDBY_TC_250 = const(0x03) #250ms +STANDBY_TC_500 = const(0x04) #500ms +STANDBY_TC_1000 = const(0x05) #1000ms + +_BME280_STANDBY_TCS = frozenset((STANDBY_TC_0_5, STANDBY_TC_10, STANDBY_TC_20, + STANDBY_TC_62_5, STANDBY_TC_125, STANDBY_TC_250, + STANDBY_TC_500, STANDBY_TC_1000)) class Adafruit_BME280: """Driver from BME280 Temperature, Humidity and Barometic Pressure sensor""" @@ -115,12 +121,12 @@ def __init__(self): if _BME280_CHIPID != chip_id: raise RuntimeError('Failed to find BME280! Chip ID 0x%x' % chip_id) #Set some reasonable defaults. - self._iir_filter = IIR_FILTER.DISABLE - self._overscan_humidity = OVERSCAN.X_2 - self._overscan_temperature = OVERSCAN.X_2 - self._overscan_pressure = OVERSCAN.X_16 - self._t_standby = STANDBY.TC_0_5 - self._mode = MODE.SLEEP + self._iir_filter = IIR_FILTER_DISABLE + self._overscan_humidity = OVERSCAN_X1 + self._overscan_temperature = OVERSCAN_X1 + self._overscan_pressure = OVERSCAN_X16 + self._t_standby = STANDBY_TC_125 + self._mode = MODE_SLEEP self._reset() self._read_coefficients() self._write_ctrl_meas() @@ -131,8 +137,8 @@ def __init__(self): def _read_temperature(self): # perform one measurement - if self.mode != MODE.NORMAL: - self.mode = MODE.FORCE + if self.mode != MODE_NORMAL: + self.mode = MODE_FORCE # Wait for conversion to complete while self._get_status() & 0x08: sleep(0.002) @@ -174,25 +180,25 @@ def _read_config(self): def _write_config(self): """Write the value to the config register in the device """ normal_flag = False - if self._mode == MODE.NORMAL: + if self._mode == MODE_NORMAL: #Writes to the config register may be ignored while in Normal mode normal_flag = True - self.mode = MODE.SLEEP #So we switch to Sleep mode first + self.mode = MODE_SLEEP #So we switch to Sleep mode first self._write_register_byte(_BME280_REGISTER_CONFIG, self._config) if normal_flag: - self.mode = MODE.NORMAL + self.mode = MODE_NORMAL @property def mode(self): """ Operation mode - Allowed values are set in the MODE enum class + Allowed values are the constants MODE_* """ return self._mode @mode.setter def mode(self, value): - if not value in MODE: + if not value in _BME280_MODES: raise ValueError('Mode \'%s\' not supported' % (value)) if self._mode == value: return @@ -203,13 +209,13 @@ def mode(self, value): def standby_period(self): """ Control the inactive period when in Normal mode - Allowed standby periods are set the STANDBY enum class + Allowed standby periods are the constants STANDBY_TC_* """ return self._t_standby @standby_period.setter def standby_period(self, value): - if not value in STANDBY: + if not value in _BME280_STANDBY_TCS: raise ValueError('Standby Period \'%s\' not supported' % (value)) if self._t_standby == value: return @@ -218,13 +224,15 @@ def standby_period(self, value): @property def overscan_humidity(self): - """Humidity Oversampling - Allowed values are set in the OVERSCAN enum class """ + """ + Humidity Oversampling + Allowed values are the constants OVERSCAN_* + """ return self._overscan_humidity @overscan_humidity.setter def overscan_humidity(self, value): - if not value in OVERSCAN: + if not value in _BME280_OVERSCANS: raise ValueError('Overscan value \'%s\' not supported' % (value)) self._overscan_humidity = value self._write_ctrl_meas() @@ -233,13 +241,13 @@ def overscan_humidity(self, value): def overscan_temperature(self): """ Temperature Oversampling - Allowed values are set in the OVERSCAN enum class + Allowed values are the constants OVERSCAN_* """ return self._overscan_temperature @overscan_temperature.setter def overscan_temperature(self, value): - if not value in OVERSCAN: + if not value in _BME280_OVERSCANS: raise ValueError('Overscan value \'%s\' not supported' % (value)) self._overscan_temperature = value self._write_ctrl_meas() @@ -248,13 +256,13 @@ def overscan_temperature(self, value): def overscan_pressure(self): """ Pressure Oversampling - Allowed values are set in the OVERSCAN enum class + Allowed values are the constants OVERSCAN_* """ return self._overscan_pressure @overscan_pressure.setter def overscan_pressure(self, value): - if not value in OVERSCAN: + if not value in _BME280_OVERSCANS: raise ValueError('Overscan value \'%s\' not supported' % (value)) self._overscan_pressure = value self._write_ctrl_meas() @@ -263,13 +271,13 @@ def overscan_pressure(self, value): def iir_filter(self): """ Controls the time constant of the IIR filter - Allowed values are set in the IIR_FILTER enum class + Allowed values are the constants IIR_FILTER_* """ return self._iir_filter @iir_filter.setter def iir_filter(self, value): - if not value in IIR_FILTER: + if not value in _BME280_IIR_FILTERS: raise ValueError('IIR Filter \'%s\' not supported' % (value)) self._iir_filter = value self._write_config() @@ -278,10 +286,10 @@ def iir_filter(self, value): def _config(self): """Value to be written to the device's config register """ config = 0 - if self.mode == MODE.NORMAL: + if self.mode == MODE_NORMAL: config += (self._t_standby << 5) if self._iir_filter: - config += (self._iir_filter.value << 2) + config += (self._iir_filter << 2) if isinstance(self, Adafruit_BME280_SPI): config += 1 #enable SPI interface return config @@ -289,9 +297,9 @@ def _config(self): @property def _ctrl_meas(self): """Value to be written to the device's ctrl_meas register """ - ctrl_meas = (self.overscan_temperature.value << 5) - ctrl_meas += (self.overscan_pressure.value << 2) - ctrl_meas += self.mode.value + ctrl_meas = (self.overscan_temperature << 5) + ctrl_meas += (self.overscan_pressure << 2) + ctrl_meas += self.mode return ctrl_meas @property diff --git a/examples/bme280_normal_mode.py b/examples/bme280_normal_mode.py index f664512..3167b49 100644 --- a/examples/bme280_normal_mode.py +++ b/examples/bme280_normal_mode.py @@ -1,3 +1,8 @@ +""" +Example showing how the BME280 library can be used to set the various +parameters supported by the sensor. +Refer to the BME280 datasheet to understand what these parameters do +""" import time import board @@ -15,13 +20,12 @@ # change this to match the location's pressure (hPa) at sea level bme280.sea_level_pressure = 1013.25 -#refer to the BMP280 datasheet to understand what these do -bme280.mode = adafruit_bme280.MODE.NORMAL -bme280.standby_period = adafruit_bme280.STANDBY.TC_500 -bme280.iir_filter = adafruit_bme280.IIR_FILTER.X_16 -bme280.overscan_pressure = adafruit_bme280.OVERSCAN.X_16 -bme280.overscan_humidity = adafruit_bme280.OVERSCAN.X_1 -bme280.overscan_temperature = adafruit_bme280.OVERSCAN.X_2 +bme280.mode = adafruit_bme280.MODE_NORMAL +bme280.standby_period = adafruit_bme280.STANDBY_TC_500 +bme280.iir_filter = adafruit_bme280.IIR_FILTER_X16 +bme280.overscan_pressure = adafruit_bme280.OVERSCAN_X16 +bme280.overscan_humidity = adafruit_bme280.OVERSCAN_X1 +bme280.overscan_temperature = adafruit_bme280.OVERSCAN_X2 #The sensor will need a moment to gather inital readings time.sleep(1) From 79d4e8556e9926d9aa8379cce42577d452a49905 Mon Sep 17 00:00:00 2001 From: Jeff Raber Date: Thu, 7 Mar 2019 02:04:27 -0600 Subject: [PATCH 013/125] Do not return None when temp, pressure, or humidity value = 0x80000 0x800000 is the *default* value and is a valid value --- adafruit_bme280.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/adafruit_bme280.py b/adafruit_bme280.py index e2f7a6f..e695abc 100644 --- a/adafruit_bme280.py +++ b/adafruit_bme280.py @@ -143,8 +143,6 @@ def _read_temperature(self): while self._get_status() & 0x08: sleep(0.002) raw_temperature = self._read24(_BME280_REGISTER_TEMPDATA) / 16 # lowest 4 bits get dropped - if raw_temperature == 0x80000: #0x80000 means the measurment was skipped - return #print("raw temp: ", UT) var1 = (raw_temperature / 16384.0 - self._temp_calib[0] / 1024.0) * self._temp_calib[1] #print(var1) @@ -319,8 +317,6 @@ def pressure(self): # Algorithm from the BME280 driver # https://github.com/BoschSensortec/BME280_driver/blob/master/bme280.c adc = self._read24(_BME280_REGISTER_PRESSUREDATA) / 16 # lowest 4 bits get dropped - if adc == 0x80000: #0x80000 means the measurement was skipped - return None var1 = float(self._t_fine) / 2.0 - 64000.0 var2 = var1 * var1 * self._pressure_calib[5] / 32768.0 var2 = var2 + var1 * self._pressure_calib[4] * 2.0 @@ -354,8 +350,6 @@ def humidity(self): """ self._read_temperature() hum = self._read_register(_BME280_REGISTER_HUMIDDATA, 2) - if hum == 0x8000: #0x8000 means the reading was skipped - return None #print("Humidity data: ", hum) adc = float(hum[0] << 8 | hum[1]) #print("adc:", adc) From f40fb2c9d4fe25530978273d8346959c5c85877a Mon Sep 17 00:00:00 2001 From: Jeff Raber Date: Thu, 7 Mar 2019 03:17:02 -0600 Subject: [PATCH 014/125] Add properties for the typical and maximum measurement time Changed_BME280_OVERSCANS from frozenset to dict to allow lookup of the associated value for the measurement time calculation --- adafruit_bme280.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/adafruit_bme280.py b/adafruit_bme280.py index e695abc..b426fb4 100644 --- a/adafruit_bme280.py +++ b/adafruit_bme280.py @@ -85,8 +85,8 @@ OVERSCAN_X8 = const(0x04) OVERSCAN_X16 = const(0x05) -_BME280_OVERSCANS = frozenset((OVERSCAN_DISABLE, OVERSCAN_X1, OVERSCAN_X2, - OVERSCAN_X4, OVERSCAN_X8, OVERSCAN_X16)) +_BME280_OVERSCANS = {OVERSCAN_DISABLE:0, OVERSCAN_X1:1, OVERSCAN_X2:2, + OVERSCAN_X4:4, OVERSCAN_X8:8, OVERSCAN_X16:16} """mode values""" MODE_SLEEP = const(0x00) @@ -300,6 +300,30 @@ def _ctrl_meas(self): ctrl_meas += self.mode return ctrl_meas + @property + def measurement_time_typical(self): + """Typical time in milliseconds required to complete a measurement in normal mode""" + meas_time_ms = 1.0 + if self.overscan_temperature != OVERSCAN_DISABLE: + meas_time_ms += (2 * _BME280_OVERSCANS.get(self.overscan_temperature)) + if self.overscan_pressure != OVERSCAN_DISABLE: + meas_time_ms += (2 * _BME280_OVERSCANS.get(self.overscan_pressure) + 0.5) + if self.overscan_humidity != OVERSCAN_DISABLE: + meas_time_ms += (2 * _BME280_OVERSCANS.get(self.overscan_humidity) + 0.5) + return meas_time_ms + + @property + def measurement_time_max(self): + """Maximum time in milliseconds required to complete a measurement in normal mode""" + meas_time_ms = 1.25 + if self.overscan_temperature != OVERSCAN_DISABLE: + meas_time_ms += (2.3 * _BME280_OVERSCANS.get(self.overscan_temperature)) + if self.overscan_pressure != OVERSCAN_DISABLE: + meas_time_ms += (2.3 * _BME280_OVERSCANS.get(self.overscan_pressure) + 0.575) + if self.overscan_humidity != OVERSCAN_DISABLE: + meas_time_ms += (2.3 * _BME280_OVERSCANS.get(self.overscan_humidity) + 0.575) + return meas_time_ms + @property def temperature(self): """The compensated temperature in degrees celsius.""" From 9c37a711e252eb7598095bf4753e7d3a89028427 Mon Sep 17 00:00:00 2001 From: Jeff Raber Date: Tue, 12 Mar 2019 23:42:40 -0500 Subject: [PATCH 015/125] Always write the new mode to the sensor In FORCE mode, the sensor changes back to SLEEP after completeing a single measurement, but we are not updating the mode internally. It's better to always write the mode to the sensor, and trust the caller not to change it needlessly. --- adafruit_bme280.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/adafruit_bme280.py b/adafruit_bme280.py index b426fb4..65699bc 100644 --- a/adafruit_bme280.py +++ b/adafruit_bme280.py @@ -198,8 +198,6 @@ def mode(self): def mode(self, value): if not value in _BME280_MODES: raise ValueError('Mode \'%s\' not supported' % (value)) - if self._mode == value: - return self._mode = value self._write_ctrl_meas() From 0a10d868a68ac5ac8e87ab0277d4672a9d260e03 Mon Sep 17 00:00:00 2001 From: Jeff Raber Date: Wed, 13 Mar 2019 00:34:33 -0500 Subject: [PATCH 016/125] Don't enable SPI 3-wire interface --- adafruit_bme280.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/adafruit_bme280.py b/adafruit_bme280.py index 65699bc..1e3e09c 100644 --- a/adafruit_bme280.py +++ b/adafruit_bme280.py @@ -286,8 +286,6 @@ def _config(self): config += (self._t_standby << 5) if self._iir_filter: config += (self._iir_filter << 2) - if isinstance(self, Adafruit_BME280_SPI): - config += 1 #enable SPI interface return config @property From cf742459294157e58c84b756bd1483fd5d8e1c39 Mon Sep 17 00:00:00 2001 From: Barbudor Date: Fri, 31 May 2019 23:51:07 +0200 Subject: [PATCH 017/125] fix issue#25 (removed frozenset()) + refactor pressure property Removed `frozenset()` on `_BME280_IIR_FILTERS`, `_BME280_MODES`, `_BME280_STANDBY_TCS`. Kept as tuples. Removed useless `if/else` in property `pressure` (was pointed by pylint) --- adafruit_bme280.py | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/adafruit_bme280.py b/adafruit_bme280.py index 1e3e09c..47a4e58 100644 --- a/adafruit_bme280.py +++ b/adafruit_bme280.py @@ -74,8 +74,8 @@ IIR_FILTER_X8 = const(0x03) IIR_FILTER_X16 = const(0x04) -_BME280_IIR_FILTERS = frozenset((IIR_FILTER_DISABLE, IIR_FILTER_X2, - IIR_FILTER_X4, IIR_FILTER_X8, IIR_FILTER_X16)) +_BME280_IIR_FILTERS = (IIR_FILTER_DISABLE, IIR_FILTER_X2, + IIR_FILTER_X4, IIR_FILTER_X8, IIR_FILTER_X16) """overscan values for temperature, pressure, and humidity""" OVERSCAN_DISABLE = const(0x00) @@ -93,7 +93,7 @@ MODE_FORCE = const(0x01) MODE_NORMAL = const(0x03) -_BME280_MODES = frozenset((MODE_SLEEP, MODE_FORCE, MODE_NORMAL)) +_BME280_MODES = (MODE_SLEEP, MODE_FORCE, MODE_NORMAL) """ standby timeconstant values TC_X[_Y] where X=milliseconds and Y=tenths of a millisecond @@ -107,9 +107,9 @@ STANDBY_TC_500 = const(0x04) #500ms STANDBY_TC_1000 = const(0x05) #1000ms -_BME280_STANDBY_TCS = frozenset((STANDBY_TC_0_5, STANDBY_TC_10, STANDBY_TC_20, - STANDBY_TC_62_5, STANDBY_TC_125, STANDBY_TC_250, - STANDBY_TC_500, STANDBY_TC_1000)) +_BME280_STANDBY_TCS = (STANDBY_TC_0_5, STANDBY_TC_10, STANDBY_TC_20, + STANDBY_TC_62_5, STANDBY_TC_125, STANDBY_TC_250, + STANDBY_TC_500, STANDBY_TC_1000) class Adafruit_BME280: """Driver from BME280 Temperature, Humidity and Barometic Pressure sensor""" @@ -344,23 +344,20 @@ def pressure(self): var3 = self._pressure_calib[2] * var1 * var1 / 524288.0 var1 = (var3 + self._pressure_calib[1] * var1) / 524288.0 var1 = (1.0 + var1 / 32768.0) * self._pressure_calib[0] - if var1 == 0: + if var1 == 0: # avoid exception caused by division by zero (as per Arduino lib) return 0 - if var1: - pressure = 1048576.0 - adc - pressure = ((pressure - var2 / 4096.0) * 6250.0) / var1 - var1 = self._pressure_calib[8] * pressure * pressure / 2147483648.0 - var2 = pressure * self._pressure_calib[7] / 32768.0 - pressure = pressure + (var1 + var2 + self._pressure_calib[6]) / 16.0 - - pressure /= 100 - if pressure < _BME280_PRESSURE_MIN_HPA: - return _BME280_PRESSURE_MIN_HPA - if pressure > _BME280_PRESSURE_MAX_HPA: - return _BME280_PRESSURE_MAX_HPA - return pressure - else: + pressure = 1048576.0 - adc + pressure = ((pressure - var2 / 4096.0) * 6250.0) / var1 + var1 = self._pressure_calib[8] * pressure * pressure / 2147483648.0 + var2 = pressure * self._pressure_calib[7] / 32768.0 + pressure = pressure + (var1 + var2 + self._pressure_calib[6]) / 16.0 + + pressure /= 100 + if pressure < _BME280_PRESSURE_MIN_HPA: return _BME280_PRESSURE_MIN_HPA + if pressure > _BME280_PRESSURE_MAX_HPA: + return _BME280_PRESSURE_MAX_HPA + return pressure @property def humidity(self): From a2d13f1ada7c0cbc5cacfe04bf2d30cbdd849b96 Mon Sep 17 00:00:00 2001 From: Barbudor Date: Sat, 1 Jun 2019 13:25:35 +0200 Subject: [PATCH 018/125] refactor `pressure` property to handle ZeroDivision case Recap: in the `pressure` property there is a test `if var1 == 0:` in order to avoid a division-by-zero exception. Current code return a pressure of 0 in that case. It was suggested that my PR makes this a little more pythonic by usage of exception raise. Analysis of the root cause: because last calculation is ```var1 = (1.0 + var1 / 32768.0) * self._pressure_calib[0]``` the only reason for `var1` to be 0 is `self._pressure_calib[0]` is 0. Calibration values are read at init time from registers in the chip. So the root cause probably relates to a register read problem. Analysis of other similar codes Bosch bme280.c (Github): if var1 == 0, return minimum valid pressure (300hPa). Adafruit CiPy BMP280 driver: => initially, no tests were performed => In Feb, jraber implemeted return 0 in a commit named "Adopt changes from the BME280 library" => In Mar, jraber implemeted return minimum value in a commit named "Remove unnecessary 'if' and 'else' in the pressure property" Adafruit CiPy BMP680 driver: not tested => ZeroDivisionError I feel that returning silently the minimun valid pressure is not correct to draw attention on a possible hardware reliability problem. Returning 0 could make sense only if we were sure that the user was testing the return value against 0. Alternatively, letting the ZeroDivisionError occur will not provide proper clue to the user as to the root cause of the problem and will probably lead to this issue to be raised again as a bug in GitHub. Proposed solution: Test against 0 and raise a ArithmeticError with message "Invalid calculation possibly related to error while reading the calibration registers" --- .gitignore | 1 + adafruit_bme280.py | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 0dd8629..6337ada 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ __pycache__ _build *.pyc +*.mpy .env build* bundles diff --git a/adafruit_bme280.py b/adafruit_bme280.py index 47a4e58..8f2145b 100644 --- a/adafruit_bme280.py +++ b/adafruit_bme280.py @@ -344,8 +344,9 @@ def pressure(self): var3 = self._pressure_calib[2] * var1 * var1 / 524288.0 var1 = (var3 + self._pressure_calib[1] * var1) / 524288.0 var1 = (1.0 + var1 / 32768.0) * self._pressure_calib[0] - if var1 == 0: # avoid exception caused by division by zero (as per Arduino lib) - return 0 + if not var1: # avoid exception caused by division by zero + raise ArithmeticError("Invalid result possibly related to error while \ +reading the calibration registers") pressure = 1048576.0 - adc pressure = ((pressure - var2 / 4096.0) * 6250.0) / var1 var1 = self._pressure_calib[8] * pressure * pressure / 2147483648.0 From 8975faee831700c77015532b64aeb591aa555293 Mon Sep 17 00:00:00 2001 From: Barbudor Date: Sat, 1 Jun 2019 15:55:02 +0200 Subject: [PATCH 019/125] fix #19 with proper struct unpack tested with simulation: # 0xE1 / 0xE2 dig_H2 [7:0] / [15:8] signed short # 0xE3 dig_H3 [7:0] unsigned char # 0xE4 / 0xE5[3:0] dig_H4 [11:4] / [3:0] signed short # 0xE5[7:4] / 0xE6 dig_H5 [3:0] / [11:4] signed short # 0xE7 dig_H6 signed char >>> coeff = [ 0x12, 0xFF, 0xAA, 0xEE, 0x46, 0xCC, 0x88 ] >>> coeff = list(struct.unpack('>> float(coeff[0]) # 0xFF12 -> -238.0 -238.0 >>> float(coeff[1]) # 0xAA -> 170.0 170.0 >>> float((coeff[2] << 4) | (coeff[3] & 0xF)) # 0xEE6 -> -282.0 -282.0 >>> float((coeff[4] << 4) | (coeff[3] >> 4)) # 0xCC4 -> -828.0 -828.0 >>> float(coeff[5]) # 0x88 -> -120.0 -120.0 >>> --- adafruit_bme280.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_bme280.py b/adafruit_bme280.py index 8f2145b..1796d9a 100644 --- a/adafruit_bme280.py +++ b/adafruit_bme280.py @@ -414,7 +414,7 @@ def _read_coefficients(self): self._humidity_calib = [0]*6 self._humidity_calib[0] = self._read_byte(_BME280_REGISTER_DIG_H1) coeff = self._read_register(_BME280_REGISTER_DIG_H2, 7) - coeff = list(struct.unpack(' Date: Sat, 27 Jul 2019 00:16:10 +0100 Subject: [PATCH 020/125] Minor comment cleanup A typo and a couple of trivial formatting tweaks for consistency. No code changes. --- examples/bme280_normal_mode.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/bme280_normal_mode.py b/examples/bme280_normal_mode.py index 3167b49..e255dc3 100644 --- a/examples/bme280_normal_mode.py +++ b/examples/bme280_normal_mode.py @@ -18,7 +18,7 @@ #bme_cs = digitalio.DigitalInOut(board.D10) #bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs) -# change this to match the location's pressure (hPa) at sea level +# Change this to match the location's pressure (hPa) at sea level bme280.sea_level_pressure = 1013.25 bme280.mode = adafruit_bme280.MODE_NORMAL bme280.standby_period = adafruit_bme280.STANDBY_TC_500 @@ -26,7 +26,7 @@ bme280.overscan_pressure = adafruit_bme280.OVERSCAN_X16 bme280.overscan_humidity = adafruit_bme280.OVERSCAN_X1 bme280.overscan_temperature = adafruit_bme280.OVERSCAN_X2 -#The sensor will need a moment to gather inital readings +# The sensor will need a moment to gather initial readings time.sleep(1) while True: From 8311b768574041262b15fe10e555818c2e804961 Mon Sep 17 00:00:00 2001 From: dherrada <33632497+dherrada@users.noreply.github.com> Date: Thu, 17 Oct 2019 18:16:39 -0400 Subject: [PATCH 021/125] Removed building locally section from README, replaced with documentation section --- README.rst | 48 +++--------------------------------------------- 1 file changed, 3 insertions(+), 45 deletions(-) diff --git a/README.rst b/README.rst index 5aa2e4a..2e151ee 100644 --- a/README.rst +++ b/README.rst @@ -91,49 +91,7 @@ Contributions are welcome! Please read our `Code of Conduct `_ before contributing to help this project stay welcoming. -Building Locally -================ - -To build this library locally you'll need to install the -`circuitpython-build-tools `_ package. - -.. code-block:: shell - - python3 -m venv .env - source .env/bin/activate - pip3 install circuitpython-build-tools - -Once installed, make sure you are in the virtual environment: - -.. code-block:: shell - - source .env/bin/activate - -Then run the build: - -.. code-block:: shell - - circuitpython-build-bundles --filename_prefix adafruit-circuitpython-veml6070 --library_location . - -Sphinx Documentation --------------------- - -Sphinx is used to build the documentation based on rST files and comments in the code. First, -install dependencies (feel free to reuse the virtual environment from above): - -.. code-block:: shell - - python3 -m venv .env - source .env/bin/activate - pip3 install Sphinx sphinx-rtd-theme - -Now, once you have the virtual environment activated: - -.. code-block:: shell - - cd docs - sphinx-build -E -W -b html . _build/html +Documentation +============= -This will output the documentation to ``docs/_build/html``. Open the index.html in your browser to -view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to -locally verify it will pass. +For information on building library documentation, please check out `this guide `_. From ac5d1c7bb28411aa0fcff0284c4e315fd0c41d49 Mon Sep 17 00:00:00 2001 From: dherrada Date: Fri, 27 Dec 2019 22:24:07 -0500 Subject: [PATCH 022/125] Moved repository from Travis to GitHub Actions --- .github/workflows/build.yml | 50 +++++++++++++++++++++ .github/workflows/release.yml | 81 +++++++++++++++++++++++++++++++++++ .gitignore | 1 - .travis.yml | 32 -------------- README.rst | 4 +- 5 files changed, 133 insertions(+), 35 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/release.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..66ce4db --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,50 @@ +name: Build CI + +on: [pull_request, push] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Dump GitHub context + env: + GITHUB_CONTEXT: ${{ toJson(github) }} + run: echo "$GITHUB_CONTEXT" + - name: Translate Repo Name For Build Tools filename_prefix + id: repo-name + run: | + echo ::set-output name=repo-name::$( + echo ${{ github.repository }} | + awk -F '\/' '{ print tolower($2) }' | + tr '_' '-' + ) + - name: Set up Python 3.6 + uses: actions/setup-python@v1 + with: + python-version: 3.6 + - name: Versions + run: | + python3 --version + - name: Checkout Current Repo + uses: actions/checkout@v1 + with: + submodules: true + - name: Checkout tools repo + uses: actions/checkout@v2 + with: + repository: adafruit/actions-ci-circuitpython-libs + path: actions-ci + - name: Install deps + run: | + source actions-ci/install.sh + - name: Library version + run: git describe --dirty --always --tags + - name: PyLint + run: | + pylint $( find . -path './adafruit*.py' ) + ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace examples/*.py) + - name: Build assets + run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . + - name: Build docs + working-directory: docs + run: sphinx-build -E -W -b html . _build/html diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..18efb9c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,81 @@ +name: Release Actions + +on: + release: + types: [published] + +jobs: + upload-release-assets: + runs-on: ubuntu-latest + steps: + - name: Dump GitHub context + env: + GITHUB_CONTEXT: ${{ toJson(github) }} + run: echo "$GITHUB_CONTEXT" + - name: Translate Repo Name For Build Tools filename_prefix + id: repo-name + run: | + echo ::set-output name=repo-name::$( + echo ${{ github.repository }} | + awk -F '\/' '{ print tolower($2) }' | + tr '_' '-' + ) + - name: Set up Python 3.6 + uses: actions/setup-python@v1 + with: + python-version: 3.6 + - name: Versions + run: | + python3 --version + - name: Checkout Current Repo + uses: actions/checkout@v1 + with: + submodules: true + - name: Checkout tools repo + uses: actions/checkout@v2 + with: + repository: adafruit/actions-ci-circuitpython-libs + path: actions-ci + - name: Install deps + run: | + source actions-ci/install.sh + - name: Build assets + run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . + - name: Upload Release Assets + # the 'official' actions version does not yet support dynamically + # supplying asset names to upload. @csexton's version chosen based on + # discussion in the issue below, as its the simplest to implement and + # allows for selecting files with a pattern. + # https://github.com/actions/upload-release-asset/issues/4 + #uses: actions/upload-release-asset@v1.0.1 + uses: csexton/release-asset-action@master + with: + pattern: "bundles/*" + github-token: ${{ secrets.GITHUB_TOKEN }} + + upload-pypi: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Check For setup.py + id: need-pypi + run: | + echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) + - name: Set up Python + if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + uses: actions/setup-python@v1 + with: + python-version: '3.x' + - name: Install dependencies + if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + - name: Build and publish + if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + env: + TWINE_USERNAME: ${{ secrets.pypi_username }} + TWINE_PASSWORD: ${{ secrets.pypi_password }} + run: | + python setup.py sdist + twine upload dist/* diff --git a/.gitignore b/.gitignore index 6337ada..97a036d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,4 @@ _build *.pyc *.mpy .env -build* bundles diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 4ec28fa..0000000 --- a/.travis.yml +++ /dev/null @@ -1,32 +0,0 @@ -dist: trusty -sudo: false -language: python -python: -- '3.6' -cache: - pip: true -deploy: -- provider: releases - api_key: "$GITHUB_TOKEN" - file_glob: true - file: "$TRAVIS_BUILD_DIR/bundles/*" - skip_cleanup: true - overwrite: true - on: - tags: true -- provider: pypi - user: adafruit-travis - on: - tags: true - password: - secure: hDbyx3IZpDVgmgbtrcZjmqgBCzDTwO0q0CqJJOMdCfAs7sGwW4GjhbAAxOqQAd9RS2pWbrmTRkToOxx/KML9HY+do1z4W2SPXCqYdVVAx5E2Krr8N5PjFmliTnOtWe+Y6JKQYE6di88CqIv9eaYiDEdOlExt69wRQh1pgJTOvNtmndGiXN2swQYVI8ta/pRVUtlpV2/KPczPnWH4CfWpw5ow8T+ldk+0lgPGO3c4IhcgIY1IVWimAbIPlrFT7QAGeqE+YvC3Fyl5HflCbo81GYJkCjo8LWnN27pIwFa51Z8XTh2CtjlOns5U4InuJx/dqQ9aMUsagv+HEBmwA/J+dyFf8c1KuaJkmvF0Q+nqHLfBd4hQ1V78eURqu2LWz0K/vCLUK21icCwjZKrLDysa58WJQnBqgJmE2yVnVC8w/1w9vY5taRVZbzMD4mEurYdo06b0QqiL7NyYhIEMmTFkEu5JEbFPZexk29UvPH4KsDtJEyfkfSqr8y5K1R7gn04Ej0RbAcJWLBtWIPtxeN//nGT6JPDpv/ZJIdemaWZ4iqE7Qw24bQhH+Dgk+tpaXW7Dzm49AXs3R9KzC+fAEag5FKgWHyttucB3j9zVf2SQ3YnYL12PCQxAzWSVcIqrR43uQTtonRHvo3F+4j4LTL7Ck+fFBNh2BJvLA6s75CQa6T8= -install: -- pip install -r requirements.txt -- pip install pylint circuitpython-build-tools Sphinx sphinx-rtd-theme -- pip install --force-reinstall pylint==1.9.2 -script: -- pylint adafruit_bme280.py -- ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name examples/*.py) -- circuitpython-build-bundles --filename_prefix adafruit-circuitpython-bme280 --library_location - . -- cd docs && sphinx-build -E -W -b html . _build/html && cd .. diff --git a/README.rst b/README.rst index 2e151ee..b1dc21f 100644 --- a/README.rst +++ b/README.rst @@ -9,8 +9,8 @@ Introduction :target: https://discord.gg/nBQh6qu :alt: Discord -.. image:: https://travis-ci.com/adafruit/Adafruit_CircuitPython_BME280.svg?branch=master - :target: https://travis-ci.com/adafruit/Adafruit_CircuitPython_BME280 +.. image:: https://github.com/adafruit/Adafruit_CircuitPython_BME280/workflows/Build%20CI/badge.svg + :target: https://github.com/adafruit/Adafruit_CircuitPython_BME280/actions/ :alt: Build Status I2C and SPI driver for the Bosch BME280 Temperature, Humidity, and Barometric Pressure sensor From 80757ff2146c62ac7192c94b060c67d4751868b4 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Wed, 8 Jan 2020 21:09:22 -0600 Subject: [PATCH 023/125] update pylint examples directive Signed-off-by: sommersoft --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 66ce4db..11ce574 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,7 +42,7 @@ jobs: - name: PyLint run: | pylint $( find . -path './adafruit*.py' ) - ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace examples/*.py) + ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace $( find . -path "./examples/*.py" )) - name: Build assets run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . - name: Build docs From 39affff5f36f1108c39f081ad899e4fbd2fc4454 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Tue, 3 Mar 2020 00:28:48 -0600 Subject: [PATCH 024/125] build.yml: move pylint, black, and Sphinx installs to each repo; add description to 'actions-ci/install.sh' Signed-off-by: sommersoft --- .github/workflows/build.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 11ce574..fff3aa9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,9 +34,13 @@ jobs: with: repository: adafruit/actions-ci-circuitpython-libs path: actions-ci - - name: Install deps + - name: Install dependencies + # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) run: | source actions-ci/install.sh + - name: Pip install pylint, black, & Sphinx + run: | + pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme - name: Library version run: git describe --dirty --always --tags - name: PyLint From 3dd1c232d353f00d1cba9e32d6ab619aa2be3a08 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Fri, 13 Mar 2020 13:18:42 -0500 Subject: [PATCH 025/125] update code of conduct --- CODE_OF_CONDUCT.md | 125 ++++++++++++++++++++++++++++++++------------- 1 file changed, 90 insertions(+), 35 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 1617586..d79c514 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,74 +1,129 @@ -# Contributor Covenant Code of Conduct +# Adafruit Community Code of Conduct ## Our Pledge In the interest of fostering an open and welcoming environment, we as -contributors and maintainers pledge to making participation in our project and +contributors and leaders pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body -size, disability, ethnicity, gender identity and expression, level of experience, -nationality, personal appearance, race, religion, or sexual identity and -orientation. +size, disability, ethnicity, gender identity and expression, level or type of +experience, education, socio-economic status, nationality, personal appearance, +race, religion, or sexual identity and orientation. ## Our Standards +We are committed to providing a friendly, safe and welcoming environment for +all. + Examples of behavior that contributes to creating a positive environment include: +* Be kind and courteous to others * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences +* Collaborating with other community members * Gracefully accepting constructive criticism * Focusing on what is best for the community * Showing empathy towards other community members Examples of unacceptable behavior by participants include: -* The use of sexualized language or imagery and unwelcome sexual attention or -advances +* The use of sexualized language or imagery and sexual attention or advances +* The use of inappropriate images, including in a community member's avatar +* The use of inappropriate language, including in a community member's nickname +* Any spamming, flaming, baiting or other attention-stealing behavior +* Excessive or unwelcome helping; answering outside the scope of the question + asked * Trolling, insulting/derogatory comments, and personal or political attacks +* Promoting or spreading disinformation, lies, or conspiracy theories against + a person, group, organisation, project, or community * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a - professional setting +* Other conduct which could reasonably be considered inappropriate + +The goal of the standards and moderation guidelines outlined here is to build +and maintain a respectful community. We ask that you don’t just aim to be +"technically unimpeachable", but rather try to be your best self. + +We value many things beyond technical expertise, including collaboration and +supporting others within our community. Providing a positive experience for +other community members can have a much more significant impact than simply +providing the correct answer. ## Our Responsibilities -Project maintainers are responsible for clarifying the standards of acceptable +Project leaders are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. -Project maintainers have the right and responsibility to remove, edit, or -reject comments, commits, code, wiki edits, issues, and other contributions +Project leaders have the right and responsibility to remove, edit, or +reject messages, comments, commits, code, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or -permanently any contributor for other behaviors that they deem inappropriate, -threatening, offensive, or harmful. +permanently any community member for other behaviors that they deem +inappropriate, threatening, offensive, or harmful. -## Scope +## Moderation -This Code of Conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. Examples of -representing a project or community include using an official project e-mail -address, posting via an official social media account, or acting as an appointed -representative at an online or offline event. Representation of a project may be -further defined and clarified by project maintainers. +Instances of behaviors that violate the Adafruit Community Code of Conduct +may be reported by any member of the community. Community members are +encouraged to report these situations, including situations they witness +involving other community members. + +You may report in the following ways: + +In any situation, you may send an email to . -## Enforcement +On the Adafruit Discord, you may send an open message from any channel +to all Community Helpers by tagging @community helpers. You may also send an +open message from any channel, or a direct message to @kattni#1507, +@tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, +@Mr. Certainly#0472 or @Andon#8175. -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team at support@adafruit.com. All -complaints will be reviewed and investigated and will result in a response that -is deemed necessary and appropriate to the circumstances. The project team is -obligated to maintain confidentiality with regard to the reporter of an incident. -Further details of specific enforcement policies may be posted separately. +Email and direct message reports will be kept confidential. -Project maintainers who do not follow or enforce the Code of Conduct in good -faith may face temporary or permanent repercussions as determined by other -members of the project's leadership. +In situations on Discord where the issue is particularly egregious, possibly +illegal, requires immediate action, or violates the Discord terms of service, +you should also report the message directly to Discord. + +These are the steps for upholding our community’s standards of conduct. + +1. Any member of the community may report any situation that violates the +Adafruit Community Code of Conduct. All reports will be reviewed and +investigated. +2. If the behavior is an egregious violation, the community member who +committed the violation may be banned immediately, without warning. +3. Otherwise, moderators will first respond to such behavior with a warning. +4. Moderators follow a soft "three strikes" policy - the community member may +be given another chance, if they are receptive to the warning and change their +behavior. +5. If the community member is unreceptive or unreasonable when warned by a +moderator, or the warning goes unheeded, they may be banned for a first or +second offense. Repeated offenses will result in the community member being +banned. + +## Scope + +This Code of Conduct and the enforcement policies listed above apply to all +Adafruit Community venues. This includes but is not limited to any community +spaces (both public and private), the entire Adafruit Discord server, and +Adafruit GitHub repositories. Examples of Adafruit Community spaces include +but are not limited to meet-ups, audio chats on the Adafruit Discord, or +interaction at a conference. + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. As a community +member, you are representing our community, and are expected to behave +accordingly. ## Attribution -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, -available at [http://contributor-covenant.org/version/1/4][version] +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 1.4, available at +, +and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html). -[homepage]: http://contributor-covenant.org -[version]: http://contributor-covenant.org/version/1/4/ +For other projects adopting the Adafruit Community Code of +Conduct, please contact the maintainers of those projects for enforcement. +If you wish to use this code of conduct for your own project, consider +explicitly mentioning your moderation policy or making a copy with your +own moderation policy so as to avoid confusion. From 44a11a1b9717e679be18b11493197ed8ac34fb15 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sun, 15 Mar 2020 11:49:22 -0500 Subject: [PATCH 026/125] update code of coduct: discord moderation contact section Signed-off-by: sommersoft --- CODE_OF_CONDUCT.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index d79c514..134d510 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -74,10 +74,10 @@ You may report in the following ways: In any situation, you may send an email to . On the Adafruit Discord, you may send an open message from any channel -to all Community Helpers by tagging @community helpers. You may also send an -open message from any channel, or a direct message to @kattni#1507, -@tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, -@Mr. Certainly#0472 or @Andon#8175. +to all Community Moderators by tagging @community moderators. You may +also send an open message from any channel, or a direct message to +@kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442, +@sommersoft#0222, @Mr. Certainly#0472 or @Andon#8175. Email and direct message reports will be kept confidential. From 6fb01e73c455e56fbc88e514f332db2d66cc897d Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 16 Mar 2020 15:16:30 -0400 Subject: [PATCH 027/125] Ran black, updated to pylint 2.x --- .github/workflows/build.yml | 2 +- .pylintrc | 16 ++- adafruit_bme280.py | 183 ++++++++++++++++++++------------- docs/conf.py | 116 ++++++++++++--------- examples/bme280_normal_mode.py | 6 +- examples/bme280_simpletest.py | 6 +- setup.py | 50 ++++----- 7 files changed, 220 insertions(+), 159 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fff3aa9..97fe64d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,7 +40,7 @@ jobs: source actions-ci/install.sh - name: Pip install pylint, black, & Sphinx run: | - pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme + pip install pylint black==19.10b0 Sphinx sphinx-rtd-theme - name: Library version run: git describe --dirty --always --tags - name: PyLint diff --git a/.pylintrc b/.pylintrc index 88388a6..d8f0ee8 100644 --- a/.pylintrc +++ b/.pylintrc @@ -18,6 +18,7 @@ ignore-patterns= #init-hook= # Use multiple processes to speed up Pylint. +# jobs=1 jobs=2 # List of plugins (as comma separated values of python modules names) to load, @@ -50,7 +51,8 @@ confidence= # --enable=similarities". If you want to run only the classes checker, but have # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" -disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error +# disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call +disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option @@ -117,7 +119,8 @@ spelling-store-unknown-words=no [MISCELLANEOUS] # List of note tags to take in consideration, separated by a comma. -notes=FIXME,XXX,TODO +# notes=FIXME,XXX,TODO +notes=FIXME,XXX [TYPECHECK] @@ -200,6 +203,7 @@ redefining-builtins-modules=six.moves,future.builtins [FORMAT] # Expected format of line ending, e.g. empty (any line ending), LF or CRLF. +# expected-line-ending-format= expected-line-ending-format=LF # Regexp for a line that is allowed to be longer than the limit. @@ -272,9 +276,11 @@ class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ # Naming hint for class names +# class-name-hint=[A-Z_][a-zA-Z0-9]+$ class-name-hint=[A-Z_][a-zA-Z0-9_]+$ # Regular expression matching correct class names +# class-rgx=[A-Z_][a-zA-Z0-9]+$ class-rgx=[A-Z_][a-zA-Z0-9_]+$ # Naming hint for constant names @@ -294,7 +300,8 @@ function-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ # Good variable names which should always be accepted, separated by a comma -good-names=r,g,b,i,j,k,n,ex,Run,_ +# good-names=i,j,k,ex,Run,_ +good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_ # Include a hint for the correct naming format with invalid-name include-naming-hint=no @@ -391,6 +398,7 @@ valid-metaclass-classmethod-first-arg=mcs max-args=5 # Maximum number of attributes for a class (see R0902). +# max-attributes=7 max-attributes=11 # Maximum number of boolean expressions in a if statement @@ -415,7 +423,7 @@ max-returns=6 max-statements=50 # Minimum number of public methods for a class (see R0903). -min-public-methods=2 +min-public-methods=1 [EXCEPTIONS] diff --git a/adafruit_bme280.py b/adafruit_bme280.py index 1796d9a..92d8d18 100644 --- a/adafruit_bme280.py +++ b/adafruit_bme280.py @@ -30,6 +30,7 @@ import math from time import sleep from micropython import const + try: import struct except ImportError: @@ -74,8 +75,13 @@ IIR_FILTER_X8 = const(0x03) IIR_FILTER_X16 = const(0x04) -_BME280_IIR_FILTERS = (IIR_FILTER_DISABLE, IIR_FILTER_X2, - IIR_FILTER_X4, IIR_FILTER_X8, IIR_FILTER_X16) +_BME280_IIR_FILTERS = ( + IIR_FILTER_DISABLE, + IIR_FILTER_X2, + IIR_FILTER_X4, + IIR_FILTER_X8, + IIR_FILTER_X16, +) """overscan values for temperature, pressure, and humidity""" OVERSCAN_DISABLE = const(0x00) @@ -85,8 +91,14 @@ OVERSCAN_X8 = const(0x04) OVERSCAN_X16 = const(0x05) -_BME280_OVERSCANS = {OVERSCAN_DISABLE:0, OVERSCAN_X1:1, OVERSCAN_X2:2, - OVERSCAN_X4:4, OVERSCAN_X8:8, OVERSCAN_X16:16} +_BME280_OVERSCANS = { + OVERSCAN_DISABLE: 0, + OVERSCAN_X1: 1, + OVERSCAN_X2: 2, + OVERSCAN_X4: 4, + OVERSCAN_X8: 8, + OVERSCAN_X16: 16, +} """mode values""" MODE_SLEEP = const(0x00) @@ -98,29 +110,38 @@ standby timeconstant values TC_X[_Y] where X=milliseconds and Y=tenths of a millisecond """ -STANDBY_TC_0_5 = const(0x00) #0.5ms -STANDBY_TC_10 = const(0x06) #10ms -STANDBY_TC_20 = const(0x07) #20ms -STANDBY_TC_62_5 = const(0x01) #62.5ms -STANDBY_TC_125 = const(0x02) #125ms -STANDBY_TC_250 = const(0x03) #250ms -STANDBY_TC_500 = const(0x04) #500ms -STANDBY_TC_1000 = const(0x05) #1000ms - -_BME280_STANDBY_TCS = (STANDBY_TC_0_5, STANDBY_TC_10, STANDBY_TC_20, - STANDBY_TC_62_5, STANDBY_TC_125, STANDBY_TC_250, - STANDBY_TC_500, STANDBY_TC_1000) +STANDBY_TC_0_5 = const(0x00) # 0.5ms +STANDBY_TC_10 = const(0x06) # 10ms +STANDBY_TC_20 = const(0x07) # 20ms +STANDBY_TC_62_5 = const(0x01) # 62.5ms +STANDBY_TC_125 = const(0x02) # 125ms +STANDBY_TC_250 = const(0x03) # 250ms +STANDBY_TC_500 = const(0x04) # 500ms +STANDBY_TC_1000 = const(0x05) # 1000ms + +_BME280_STANDBY_TCS = ( + STANDBY_TC_0_5, + STANDBY_TC_10, + STANDBY_TC_20, + STANDBY_TC_62_5, + STANDBY_TC_125, + STANDBY_TC_250, + STANDBY_TC_500, + STANDBY_TC_1000, +) + class Adafruit_BME280: """Driver from BME280 Temperature, Humidity and Barometic Pressure sensor""" + # pylint: disable=too-many-instance-attributes def __init__(self): """Check the BME280 was found, read the coefficients and enable the sensor""" # Check device ID. chip_id = self._read_byte(_BME280_REGISTER_CHIPID) if _BME280_CHIPID != chip_id: - raise RuntimeError('Failed to find BME280! Chip ID 0x%x' % chip_id) - #Set some reasonable defaults. + raise RuntimeError("Failed to find BME280! Chip ID 0x%x" % chip_id) + # Set some reasonable defaults. self._iir_filter = IIR_FILTER_DISABLE self._overscan_humidity = OVERSCAN_X1 self._overscan_temperature = OVERSCAN_X1 @@ -142,21 +163,27 @@ def _read_temperature(self): # Wait for conversion to complete while self._get_status() & 0x08: sleep(0.002) - raw_temperature = self._read24(_BME280_REGISTER_TEMPDATA) / 16 # lowest 4 bits get dropped - #print("raw temp: ", UT) - var1 = (raw_temperature / 16384.0 - self._temp_calib[0] / 1024.0) * self._temp_calib[1] - #print(var1) - var2 = ((raw_temperature / 131072.0 - self._temp_calib[0] / 8192.0) * ( - raw_temperature / 131072.0 - self._temp_calib[0] / 8192.0)) * self._temp_calib[2] - #print(var2) + raw_temperature = ( + self._read24(_BME280_REGISTER_TEMPDATA) / 16 + ) # lowest 4 bits get dropped + # print("raw temp: ", UT) + var1 = ( + raw_temperature / 16384.0 - self._temp_calib[0] / 1024.0 + ) * self._temp_calib[1] + # print(var1) + var2 = ( + (raw_temperature / 131072.0 - self._temp_calib[0] / 8192.0) + * (raw_temperature / 131072.0 - self._temp_calib[0] / 8192.0) + ) * self._temp_calib[2] + # print(var2) self._t_fine = int(var1 + var2) - #print("t_fine: ", self.t_fine) + # print("t_fine: ", self.t_fine) def _reset(self): """Soft reset the sensor""" self._write_register_byte(_BME280_REGISTER_SOFTRESET, 0xB6) - sleep(0.004) #Datasheet says 2ms. Using 4ms just to be safe + sleep(0.004) # Datasheet says 2ms. Using 4ms just to be safe def _write_ctrl_meas(self): """ @@ -179,9 +206,9 @@ def _write_config(self): """Write the value to the config register in the device """ normal_flag = False if self._mode == MODE_NORMAL: - #Writes to the config register may be ignored while in Normal mode + # Writes to the config register may be ignored while in Normal mode normal_flag = True - self.mode = MODE_SLEEP #So we switch to Sleep mode first + self.mode = MODE_SLEEP # So we switch to Sleep mode first self._write_register_byte(_BME280_REGISTER_CONFIG, self._config) if normal_flag: self.mode = MODE_NORMAL @@ -197,7 +224,7 @@ def mode(self): @mode.setter def mode(self, value): if not value in _BME280_MODES: - raise ValueError('Mode \'%s\' not supported' % (value)) + raise ValueError("Mode '%s' not supported" % (value)) self._mode = value self._write_ctrl_meas() @@ -212,7 +239,7 @@ def standby_period(self): @standby_period.setter def standby_period(self, value): if not value in _BME280_STANDBY_TCS: - raise ValueError('Standby Period \'%s\' not supported' % (value)) + raise ValueError("Standby Period '%s' not supported" % (value)) if self._t_standby == value: return self._t_standby = value @@ -229,7 +256,7 @@ def overscan_humidity(self): @overscan_humidity.setter def overscan_humidity(self, value): if not value in _BME280_OVERSCANS: - raise ValueError('Overscan value \'%s\' not supported' % (value)) + raise ValueError("Overscan value '%s' not supported" % (value)) self._overscan_humidity = value self._write_ctrl_meas() @@ -244,7 +271,7 @@ def overscan_temperature(self): @overscan_temperature.setter def overscan_temperature(self, value): if not value in _BME280_OVERSCANS: - raise ValueError('Overscan value \'%s\' not supported' % (value)) + raise ValueError("Overscan value '%s' not supported" % (value)) self._overscan_temperature = value self._write_ctrl_meas() @@ -259,7 +286,7 @@ def overscan_pressure(self): @overscan_pressure.setter def overscan_pressure(self, value): if not value in _BME280_OVERSCANS: - raise ValueError('Overscan value \'%s\' not supported' % (value)) + raise ValueError("Overscan value '%s' not supported" % (value)) self._overscan_pressure = value self._write_ctrl_meas() @@ -274,7 +301,7 @@ def iir_filter(self): @iir_filter.setter def iir_filter(self, value): if not value in _BME280_IIR_FILTERS: - raise ValueError('IIR Filter \'%s\' not supported' % (value)) + raise ValueError("IIR Filter '%s' not supported" % (value)) self._iir_filter = value self._write_config() @@ -283,16 +310,16 @@ def _config(self): """Value to be written to the device's config register """ config = 0 if self.mode == MODE_NORMAL: - config += (self._t_standby << 5) + config += self._t_standby << 5 if self._iir_filter: - config += (self._iir_filter << 2) + config += self._iir_filter << 2 return config @property def _ctrl_meas(self): """Value to be written to the device's ctrl_meas register """ - ctrl_meas = (self.overscan_temperature << 5) - ctrl_meas += (self.overscan_pressure << 2) + ctrl_meas = self.overscan_temperature << 5 + ctrl_meas += self.overscan_pressure << 2 ctrl_meas += self.mode return ctrl_meas @@ -301,11 +328,11 @@ def measurement_time_typical(self): """Typical time in milliseconds required to complete a measurement in normal mode""" meas_time_ms = 1.0 if self.overscan_temperature != OVERSCAN_DISABLE: - meas_time_ms += (2 * _BME280_OVERSCANS.get(self.overscan_temperature)) + meas_time_ms += 2 * _BME280_OVERSCANS.get(self.overscan_temperature) if self.overscan_pressure != OVERSCAN_DISABLE: - meas_time_ms += (2 * _BME280_OVERSCANS.get(self.overscan_pressure) + 0.5) + meas_time_ms += 2 * _BME280_OVERSCANS.get(self.overscan_pressure) + 0.5 if self.overscan_humidity != OVERSCAN_DISABLE: - meas_time_ms += (2 * _BME280_OVERSCANS.get(self.overscan_humidity) + 0.5) + meas_time_ms += 2 * _BME280_OVERSCANS.get(self.overscan_humidity) + 0.5 return meas_time_ms @property @@ -313,11 +340,11 @@ def measurement_time_max(self): """Maximum time in milliseconds required to complete a measurement in normal mode""" meas_time_ms = 1.25 if self.overscan_temperature != OVERSCAN_DISABLE: - meas_time_ms += (2.3 * _BME280_OVERSCANS.get(self.overscan_temperature)) + meas_time_ms += 2.3 * _BME280_OVERSCANS.get(self.overscan_temperature) if self.overscan_pressure != OVERSCAN_DISABLE: - meas_time_ms += (2.3 * _BME280_OVERSCANS.get(self.overscan_pressure) + 0.575) + meas_time_ms += 2.3 * _BME280_OVERSCANS.get(self.overscan_pressure) + 0.575 if self.overscan_humidity != OVERSCAN_DISABLE: - meas_time_ms += (2.3 * _BME280_OVERSCANS.get(self.overscan_humidity) + 0.575) + meas_time_ms += 2.3 * _BME280_OVERSCANS.get(self.overscan_humidity) + 0.575 return meas_time_ms @property @@ -336,7 +363,9 @@ def pressure(self): # Algorithm from the BME280 driver # https://github.com/BoschSensortec/BME280_driver/blob/master/bme280.c - adc = self._read24(_BME280_REGISTER_PRESSUREDATA) / 16 # lowest 4 bits get dropped + adc = ( + self._read24(_BME280_REGISTER_PRESSUREDATA) / 16 + ) # lowest 4 bits get dropped var1 = float(self._t_fine) / 2.0 - 64000.0 var2 = var1 * var1 * self._pressure_calib[5] / 32768.0 var2 = var2 + var1 * self._pressure_calib[4] * 2.0 @@ -344,9 +373,11 @@ def pressure(self): var3 = self._pressure_calib[2] * var1 * var1 / 524288.0 var1 = (var3 + self._pressure_calib[1] * var1) / 524288.0 var1 = (1.0 + var1 / 32768.0) * self._pressure_calib[0] - if not var1: # avoid exception caused by division by zero - raise ArithmeticError("Invalid result possibly related to error while \ -reading the calibration registers") + if not var1: # avoid exception caused by division by zero + raise ArithmeticError( + "Invalid result possibly related to error while \ +reading the calibration registers" + ) pressure = 1048576.0 - adc pressure = ((pressure - var2 / 4096.0) * 6250.0) / var1 var1 = self._pressure_calib[8] * pressure * pressure / 2147483648.0 @@ -368,24 +399,26 @@ def humidity(self): """ self._read_temperature() hum = self._read_register(_BME280_REGISTER_HUMIDDATA, 2) - #print("Humidity data: ", hum) + # print("Humidity data: ", hum) adc = float(hum[0] << 8 | hum[1]) - #print("adc:", adc) + # print("adc:", adc) # Algorithm from the BME280 driver # https://github.com/BoschSensortec/BME280_driver/blob/master/bme280.c var1 = float(self._t_fine) - 76800.0 - #print("var1 ", var1) - var2 = (self._humidity_calib[3] * 64.0 + (self._humidity_calib[4] / 16384.0) * var1) - #print("var2 ",var2) + # print("var1 ", var1) + var2 = ( + self._humidity_calib[3] * 64.0 + (self._humidity_calib[4] / 16384.0) * var1 + ) + # print("var2 ",var2) var3 = adc - var2 - #print("var3 ",var3) + # print("var3 ",var3) var4 = self._humidity_calib[1] / 65536.0 - #print("var4 ",var4) - var5 = (1.0 + (self._humidity_calib[2] / 67108864.0) * var1) - #print("var5 ",var5) + # print("var4 ",var4) + var5 = 1.0 + (self._humidity_calib[2] / 67108864.0) * var1 + # print("var5 ",var5) var6 = 1.0 + (self._humidity_calib[5] / 67108864.0) * var1 * var5 - #print("var6 ",var6) + # print("var6 ",var6) var6 = var3 * var4 * (var5 * var6) humidity = var6 * (1.0 - self._humidity_calib[0] * var6 / 524288.0) @@ -400,24 +433,24 @@ def humidity(self): def altitude(self): """The altitude based on current ``pressure`` versus the sea level pressure (``sea_level_pressure``) - which you must enter ahead of time)""" - pressure = self.pressure # in Si units for hPascal + pressure = self.pressure # in Si units for hPascal return 44330 * (1.0 - math.pow(pressure / self.sea_level_pressure, 0.1903)) def _read_coefficients(self): """Read & save the calibration coefficients""" coeff = self._read_register(_BME280_REGISTER_DIG_T1, 24) - coeff = list(struct.unpack('> 4)) self._humidity_calib[5] = float(coeff[5]) @@ -439,10 +472,13 @@ def _read_register(self, register, length): def _write_register_byte(self, register, value): raise NotImplementedError() + class Adafruit_BME280_I2C(Adafruit_BME280): """Driver for BME280 connected over I2C""" + def __init__(self, i2c, address=_BME280_ADDRESS): - import adafruit_bus_device.i2c_device as i2c_device + import adafruit_bus_device.i2c_device as i2c_device # pylint: disable=import-outside-toplevel + self._i2c = i2c_device.I2CDevice(i2c, address) super().__init__() @@ -451,31 +487,34 @@ def _read_register(self, register, length): i2c.write(bytes([register & 0xFF])) result = bytearray(length) i2c.readinto(result) - #print("$%02X => %s" % (register, [hex(i) for i in result])) + # print("$%02X => %s" % (register, [hex(i) for i in result])) return result def _write_register_byte(self, register, value): with self._i2c as i2c: i2c.write(bytes([register & 0xFF, value & 0xFF])) - #print("$%02X <= 0x%02X" % (register, value)) + # print("$%02X <= 0x%02X" % (register, value)) + class Adafruit_BME280_SPI(Adafruit_BME280): """Driver for BME280 connected over SPI""" + def __init__(self, spi, cs, baudrate=100000): - import adafruit_bus_device.spi_device as spi_device + import adafruit_bus_device.spi_device as spi_device # pylint: disable=import-outside-toplevel + self._spi = spi_device.SPIDevice(spi, cs, baudrate=baudrate) super().__init__() def _read_register(self, register, length): register = (register | 0x80) & 0xFF # Read single, bit 7 high. with self._spi as spi: - spi.write(bytearray([register])) #pylint: disable=no-member + spi.write(bytearray([register])) # pylint: disable=no-member result = bytearray(length) - spi.readinto(result) #pylint: disable=no-member - #print("$%02X => %s" % (register, [hex(i) for i in result])) + spi.readinto(result) # pylint: disable=no-member + # print("$%02X => %s" % (register, [hex(i) for i in result])) return result def _write_register_byte(self, register, value): register &= 0x7F # Write, bit 7 low. with self._spi as spi: - spi.write(bytes([register, value & 0xFF])) #pylint: disable=no-member + spi.write(bytes([register, value & 0xFF])) # pylint: disable=no-member diff --git a/docs/conf.py b/docs/conf.py index a94d4fa..4f0d705 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -2,7 +2,8 @@ import os import sys -sys.path.insert(0, os.path.abspath('..')) + +sys.path.insert(0, os.path.abspath("..")) # -- General configuration ------------------------------------------------ @@ -10,35 +11,42 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.intersphinx', - 'sphinx.ext.viewcode', + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.viewcode", ] # API docs fix -intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} +intersphinx_mapping = { + "python": ("https://docs.python.org/3.4", None), + "BusDevice": ( + "https://circuitpython.readthedocs.io/projects/busdevice/en/latest/", + None, + ), + "CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None), +} # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] -source_suffix = '.rst' +source_suffix = ".rst" # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'Adafruit BME280 Library' -copyright = u'2017 ladyada' -author = u'ladyada' +project = u"Adafruit BME280 Library" +copyright = u"2017 ladyada" +author = u"ladyada" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = u'1.0' +version = u"1.0" # The full version, including alpha/beta/rc tags. -release = u'1.0' +release = u"1.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -50,7 +58,7 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"] # The reST default role (used for this markup: `text`) to use for all # documents. @@ -62,7 +70,7 @@ add_function_parentheses = True # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False @@ -76,59 +84,62 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -on_rtd = os.environ.get('READTHEDOCS', None) == 'True' +on_rtd = os.environ.get("READTHEDOCS", None) == "True" if not on_rtd: # only import and set the theme if we're building docs locally try: import sphinx_rtd_theme - html_theme = 'sphinx_rtd_theme' - html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.'] + + html_theme = "sphinx_rtd_theme" + html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] except: - html_theme = 'default' - html_theme_path = ['.'] + html_theme = "default" + html_theme_path = ["."] else: - html_theme_path = ['.'] + html_theme_path = ["."] # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # The name of an image file (relative to this directory) to use as a favicon of # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. # -html_favicon = '_static/favicon.ico' +html_favicon = "_static/favicon.ico" # Output file base name for HTML help builder. -htmlhelp_basename = 'AdafruitBME280Librarydoc' +htmlhelp_basename = "AdafruitBME280Librarydoc" # -- Options for LaTeX output --------------------------------------------- latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # - # 'papersize': 'letterpaper', - - # The font size ('10pt', '11pt' or '12pt'). - # - # 'pointsize': '10pt', - - # Additional stuff for the LaTeX preamble. - # - # 'preamble': '', - - # Latex figure (float) alignment - # - # 'figure_align': 'htbp', + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'AdafruitBME280Library.tex', u'Adafruit BME280 Library Documentation', - author, 'manual'), + ( + master_doc, + "AdafruitBME280Library.tex", + u"Adafruit BME280 Library Documentation", + author, + "manual", + ), ] # -- Options for manual page output --------------------------------------- @@ -136,8 +147,13 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'adafruitBME280library', u'Adafruit BME280 Library Documentation', - [author], 1) + ( + master_doc, + "adafruitBME280library", + u"Adafruit BME280 Library Documentation", + [author], + 1, + ) ] # -- Options for Texinfo output ------------------------------------------- @@ -146,10 +162,16 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'AdafruitBME280Library', u'Adafruit BME280 Library Documentation', - author, 'AdafruitBME280Library', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "AdafruitBME280Library", + u"Adafruit BME280 Library Documentation", + author, + "AdafruitBME280Library", + "One line description of project.", + "Miscellaneous", + ), ] # API docs fix -autodoc_mock_imports = ['micropython'] +autodoc_mock_imports = ["micropython"] diff --git a/examples/bme280_normal_mode.py b/examples/bme280_normal_mode.py index e255dc3..28d8944 100644 --- a/examples/bme280_normal_mode.py +++ b/examples/bme280_normal_mode.py @@ -14,9 +14,9 @@ bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) # OR create library object using our Bus SPI port -#spi = busio.SPI(board.SCK, board.MOSI, board.MISO) -#bme_cs = digitalio.DigitalInOut(board.D10) -#bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs) +# spi = busio.SPI(board.SCK, board.MOSI, board.MISO) +# bme_cs = digitalio.DigitalInOut(board.D10) +# bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs) # Change this to match the location's pressure (hPa) at sea level bme280.sea_level_pressure = 1013.25 diff --git a/examples/bme280_simpletest.py b/examples/bme280_simpletest.py index c85a3f1..8ed1c0e 100644 --- a/examples/bme280_simpletest.py +++ b/examples/bme280_simpletest.py @@ -9,9 +9,9 @@ bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) # OR create library object using our Bus SPI port -#spi = busio.SPI(board.SCK, board.MOSI, board.MISO) -#bme_cs = digitalio.DigitalInOut(board.D10) -#bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs) +# spi = busio.SPI(board.SCK, board.MOSI, board.MISO) +# bme_cs = digitalio.DigitalInOut(board.D10) +# bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs) # change this to match the location's pressure (hPa) at sea level bme280.sea_level_pressure = 1013.25 diff --git a/setup.py b/setup.py index 4c78897..f6de9ad 100644 --- a/setup.py +++ b/setup.py @@ -7,6 +7,7 @@ # Always prefer setuptools over distutils from setuptools import setup, find_packages + # To use a consistent encoding from codecs import open from os import path @@ -14,47 +15,38 @@ here = path.abspath(path.dirname(__file__)) # Get the long description from the README file -with open(path.join(here, 'README.rst'), encoding='utf-8') as f: +with open(path.join(here, "README.rst"), encoding="utf-8") as f: long_description = f.read() setup( - name='adafruit-circuitpython-bme280', - + name="adafruit-circuitpython-bme280", use_scm_version=True, - setup_requires=['setuptools_scm'], - - description='CircuitPython library for the Bosch BME280 temperature/humidity/pressure sensor.', + setup_requires=["setuptools_scm"], + description="CircuitPython library for the Bosch BME280 temperature/humidity/pressure sensor.", long_description=long_description, - long_description_content_type='text/x-rst', - + long_description_content_type="text/x-rst", # The project's main homepage. - url='https://github.com/adafruit/Adafruit_CircuitPython_BME280', - + url="https://github.com/adafruit/Adafruit_CircuitPython_BME280", # Author details - author='Adafruit Industries', - author_email='circuitpython@adafruit.com', - - install_requires=['Adafruit-Blinka', 'adafruit-circuitpython-busdevice'], - + author="Adafruit Industries", + author_email="circuitpython@adafruit.com", + install_requires=["Adafruit-Blinka", "adafruit-circuitpython-busdevice"], # Choose your license - license='MIT', - + license="MIT", # See https://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=[ - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Developers', - 'Topic :: Software Development :: Libraries', - 'Topic :: System :: Hardware', - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries", + "Topic :: System :: Hardware", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", ], - # What does your project relate to? - keywords='adafruit bme280 sensor hardware micropython circuitpython', - + keywords="adafruit bme280 sensor hardware micropython circuitpython", # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). - py_modules=['adafruit_bme280'], + py_modules=["adafruit_bme280"], ) From 575558059f99720e66d7a61ed9bd897259f033e6 Mon Sep 17 00:00:00 2001 From: dherrada Date: Tue, 17 Mar 2020 14:46:05 -0400 Subject: [PATCH 028/125] Re-added --force-reinstall --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 97fe64d..1dad804 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,7 +40,7 @@ jobs: source actions-ci/install.sh - name: Pip install pylint, black, & Sphinx run: | - pip install pylint black==19.10b0 Sphinx sphinx-rtd-theme + pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme - name: Library version run: git describe --dirty --always --tags - name: PyLint From b34ce92a37055a88c1f53c75cbc6dd3bb3afedf5 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Tue, 7 Apr 2020 15:02:31 -0500 Subject: [PATCH 029/125] build.yml: add black formatting check Signed-off-by: sommersoft --- .github/workflows/build.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1dad804..b6977a9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,6 +43,9 @@ jobs: pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme - name: Library version run: git describe --dirty --always --tags + - name: Check formatting + run: | + black --check --target-version=py35 . - name: PyLint run: | pylint $( find . -path './adafruit*.py' ) From fdad5ab978c76c852a992db531181834b1d15dd8 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Wed, 8 Apr 2020 13:08:26 -0400 Subject: [PATCH 030/125] Black reformatting with Python 3 target. --- docs/conf.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 4f0d705..2119dfe 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -35,18 +35,18 @@ master_doc = "index" # General information about the project. -project = u"Adafruit BME280 Library" -copyright = u"2017 ladyada" -author = u"ladyada" +project = "Adafruit BME280 Library" +copyright = "2017 ladyada" +author = "ladyada" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = u"1.0" +version = "1.0" # The full version, including alpha/beta/rc tags. -release = u"1.0" +release = "1.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -136,7 +136,7 @@ ( master_doc, "AdafruitBME280Library.tex", - u"Adafruit BME280 Library Documentation", + "Adafruit BME280 Library Documentation", author, "manual", ), @@ -150,7 +150,7 @@ ( master_doc, "adafruitBME280library", - u"Adafruit BME280 Library Documentation", + "Adafruit BME280 Library Documentation", [author], 1, ) @@ -165,7 +165,7 @@ ( master_doc, "AdafruitBME280Library", - u"Adafruit BME280 Library Documentation", + "Adafruit BME280 Library Documentation", author, "AdafruitBME280Library", "One line description of project.", From e224735f6964b779df44f0e34233ecbc4876d6b7 Mon Sep 17 00:00:00 2001 From: JanHBade Date: Sun, 14 Jun 2020 13:16:26 +0200 Subject: [PATCH 031/125] Update README.rst Fixes Issue #36 (https://github.com/adafruit/Adafruit_CircuitPython_BME280/issues/36) --- README.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.rst b/README.rst index b1dc21f..6bcf51e 100644 --- a/README.rst +++ b/README.rst @@ -68,6 +68,8 @@ Usage Example # Create library object using our Bus I2C port i2c = busio.I2C(board.SCL, board.SDA) bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) + #or with other sensoe address + bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76) # OR create library object using our Bus SPI port #spi = busio.SPI(board.SCK, board.MOSI, board.MISO) From 0b9d6f69e3bb30050e3b6e9111093f9a0af14484 Mon Sep 17 00:00:00 2001 From: JanHBade Date: Sun, 14 Jun 2020 13:16:57 +0200 Subject: [PATCH 032/125] Update README.rst typo --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 6bcf51e..69dcdeb 100644 --- a/README.rst +++ b/README.rst @@ -68,7 +68,7 @@ Usage Example # Create library object using our Bus I2C port i2c = busio.I2C(board.SCL, board.SDA) bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) - #or with other sensoe address + #or with other sensor address bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76) # OR create library object using our Bus SPI port From 1a7065908264512d6f2408887df325c8b6925272 Mon Sep 17 00:00:00 2001 From: JanHBade Date: Sun, 14 Jun 2020 13:17:20 +0200 Subject: [PATCH 033/125] Update README.rst --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 69dcdeb..dd67b25 100644 --- a/README.rst +++ b/README.rst @@ -69,7 +69,7 @@ Usage Example i2c = busio.I2C(board.SCL, board.SDA) bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) #or with other sensor address - bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76) + #bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76) # OR create library object using our Bus SPI port #spi = busio.SPI(board.SCK, board.MOSI, board.MISO) From 25c8977b2cee006b220b4eed1ffabdb36a6f3e34 Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 8 Jul 2020 16:49:04 -0400 Subject: [PATCH 034/125] Fixed discord invite link --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index dd67b25..62d4478 100644 --- a/README.rst +++ b/README.rst @@ -6,7 +6,7 @@ Introduction :alt: Documentation Status .. image :: https://img.shields.io/discord/327254708534116352.svg - :target: https://discord.gg/nBQh6qu + :target: https://adafru.it/discord :alt: Discord .. image:: https://github.com/adafruit/Adafruit_CircuitPython_BME280/workflows/Build%20CI/badge.svg From 0095abaa2d160cf8560a988dc9cdd83b486e2bc8 Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Mon, 14 Sep 2020 17:39:59 -0500 Subject: [PATCH 035/125] Add relative_humidity property --- adafruit_bme280.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/adafruit_bme280.py b/adafruit_bme280.py index 92d8d18..c8ce35b 100644 --- a/adafruit_bme280.py +++ b/adafruit_bme280.py @@ -391,6 +391,14 @@ def pressure(self): return _BME280_PRESSURE_MAX_HPA return pressure + @property + def relative_humidity(self): + """ + The relative humidity in RH % + returns None if humidity measurement is disabled + """ + return self.humidity + @property def humidity(self): """ From a1be6526d1beacf7525ad7736968e86249ff33a0 Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Tue, 24 Nov 2020 21:20:30 -0600 Subject: [PATCH 036/125] update readme and examples --- README.rst | 2 +- examples/bme280_normal_mode.py | 2 +- examples/bme280_simpletest.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 62d4478..994ca6c 100644 --- a/README.rst +++ b/README.rst @@ -81,7 +81,7 @@ Usage Example while True: print("\nTemperature: %0.1f C" % bme280.temperature) - print("Humidity: %0.1f %%" % bme280.humidity) + print("Humidity: %0.1f %%" % bme280.relative_humidity) print("Pressure: %0.1f hPa" % bme280.pressure) print("Altitude = %0.2f meters" % bme280.altitude) time.sleep(2) diff --git a/examples/bme280_normal_mode.py b/examples/bme280_normal_mode.py index 28d8944..c7c183f 100644 --- a/examples/bme280_normal_mode.py +++ b/examples/bme280_normal_mode.py @@ -31,7 +31,7 @@ while True: print("\nTemperature: %0.1f C" % bme280.temperature) - print("Humidity: %0.1f %%" % bme280.humidity) + print("Humidity: %0.1f %%" % bme280.relative_humidity) print("Pressure: %0.1f hPa" % bme280.pressure) print("Altitude = %0.2f meters" % bme280.altitude) time.sleep(2) diff --git a/examples/bme280_simpletest.py b/examples/bme280_simpletest.py index 8ed1c0e..a65d86c 100644 --- a/examples/bme280_simpletest.py +++ b/examples/bme280_simpletest.py @@ -18,7 +18,7 @@ while True: print("\nTemperature: %0.1f C" % bme280.temperature) - print("Humidity: %0.1f %%" % bme280.humidity) + print("Humidity: %0.1f %%" % bme280.relative_humidity) print("Pressure: %0.1f hPa" % bme280.pressure) print("Altitude = %0.2f meters" % bme280.altitude) time.sleep(2) From eb2e799fade479ae9492ba4f331dec3dbd609833 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 11 Jan 2021 15:06:44 -0500 Subject: [PATCH 037/125] Added pre-commit and SPDX copyright Signed-off-by: dherrada --- .github/workflows/build.yml | 28 ++++++++++++++++++++++++---- .github/workflows/release.yml | 4 ++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b6977a9..59baa53 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + name: Build CI on: [pull_request, push] @@ -38,20 +42,36 @@ jobs: # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) run: | source actions-ci/install.sh - - name: Pip install pylint, black, & Sphinx + - name: Pip install pylint, Sphinx, pre-commit run: | - pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme + pip install --force-reinstall pylint Sphinx sphinx-rtd-theme pre-commit - name: Library version run: git describe --dirty --always --tags - - name: Check formatting + - name: Pre-commit hooks run: | - black --check --target-version=py35 . + pre-commit run --all-files - name: PyLint run: | pylint $( find . -path './adafruit*.py' ) ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace $( find . -path "./examples/*.py" )) - name: Build assets run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . + - name: Archive bundles + uses: actions/upload-artifact@v2 + with: + name: bundles + path: ${{ github.workspace }}/bundles/ - name: Build docs working-directory: docs run: sphinx-build -E -W -b html . _build/html + - name: Check For setup.py + id: need-pypi + run: | + echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) + - name: Build Python package + if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + run: | + pip install --upgrade setuptools wheel twine readme_renderer testresources + python setup.py sdist + python setup.py bdist_wheel --universal + twine check dist/* diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 18efb9c..6d0015a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + name: Release Actions on: From 22f319d833f5352975192bc8713ab90b3f844356 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 11 Jan 2021 16:06:47 -0500 Subject: [PATCH 038/125] Added pre-commit-config file Signed-off-by: dherrada --- .pre-commit-config.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..aab5f1c --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò +# +# SPDX-License-Identifier: Unlicense + +repos: +- repo: https://github.com/python/black + rev: stable + hooks: + - id: black +- repo: https://github.com/fsfe/reuse-tool + rev: latest + hooks: + - id: reuse +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.3.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace From 3650b6b29cb90d6a4a59faf77807780ee5927872 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 14 Jan 2021 13:09:10 -0500 Subject: [PATCH 039/125] Ran pre-commit, added licenses --- .gitignore | 4 + .pylintrc | 4 + .readthedocs.yml | 4 + CODE_OF_CONDUCT.md | 14 +- LICENSES/CC-BY-4.0.txt | 324 +++++++++++++++++++++++++++++++ LICENSES/MIT.txt | 19 ++ LICENSES/Unlicense.txt | 20 ++ README.rst.license | 3 + adafruit_bme280.py | 25 +-- docs/_static/favicon.ico.license | 3 + docs/api.rst.license | 3 + docs/conf.py | 4 + docs/examples.rst.license | 3 + docs/index.rst.license | 3 + examples/bme280_normal_mode.py | 3 + examples/bme280_simpletest.py | 3 + requirements.txt | 4 + setup.py | 4 + 18 files changed, 422 insertions(+), 25 deletions(-) create mode 100644 LICENSES/CC-BY-4.0.txt create mode 100644 LICENSES/MIT.txt create mode 100644 LICENSES/Unlicense.txt create mode 100644 README.rst.license create mode 100644 docs/_static/favicon.ico.license create mode 100644 docs/api.rst.license create mode 100644 docs/examples.rst.license create mode 100644 docs/index.rst.license diff --git a/.gitignore b/.gitignore index 97a036d..1be4e54 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + __pycache__ _build *.pyc diff --git a/.pylintrc b/.pylintrc index d8f0ee8..5c31f66 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + [MASTER] # A comma-separated list of package or module names from where C extensions may diff --git a/.readthedocs.yml b/.readthedocs.yml index f4243ad..ffa84c4 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + python: version: 3 requirements_file: requirements.txt diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 134d510..8a55c07 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,3 +1,9 @@ + + # Adafruit Community Code of Conduct ## Our Pledge @@ -43,7 +49,7 @@ Examples of unacceptable behavior by participants include: The goal of the standards and moderation guidelines outlined here is to build and maintain a respectful community. We ask that you don’t just aim to be -"technically unimpeachable", but rather try to be your best self. +"technically unimpeachable", but rather try to be your best self. We value many things beyond technical expertise, including collaboration and supporting others within our community. Providing a positive experience for @@ -74,9 +80,9 @@ You may report in the following ways: In any situation, you may send an email to . On the Adafruit Discord, you may send an open message from any channel -to all Community Moderators by tagging @community moderators. You may -also send an open message from any channel, or a direct message to -@kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442, +to all Community Moderators by tagging @community moderators. You may +also send an open message from any channel, or a direct message to +@kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, @Mr. Certainly#0472 or @Andon#8175. Email and direct message reports will be kept confidential. diff --git a/LICENSES/CC-BY-4.0.txt b/LICENSES/CC-BY-4.0.txt new file mode 100644 index 0000000..3f92dfc --- /dev/null +++ b/LICENSES/CC-BY-4.0.txt @@ -0,0 +1,324 @@ +Creative Commons Attribution 4.0 International Creative Commons Corporation +("Creative Commons") is not a law firm and does not provide legal services +or legal advice. Distribution of Creative Commons public licenses does not +create a lawyer-client or other relationship. Creative Commons makes its licenses +and related information available on an "as-is" basis. Creative Commons gives +no warranties regarding its licenses, any material licensed under their terms +and conditions, or any related information. Creative Commons disclaims all +liability for damages resulting from their use to the fullest extent possible. + +Using Creative Commons Public Licenses + +Creative Commons public licenses provide a standard set of terms and conditions +that creators and other rights holders may use to share original works of +authorship and other material subject to copyright and certain other rights +specified in the public license below. The following considerations are for +informational purposes only, are not exhaustive, and do not form part of our +licenses. + +Considerations for licensors: Our public licenses are intended for use by +those authorized to give the public permission to use material in ways otherwise +restricted by copyright and certain other rights. Our licenses are irrevocable. +Licensors should read and understand the terms and conditions of the license +they choose before applying it. Licensors should also secure all rights necessary +before applying our licenses so that the public can reuse the material as +expected. Licensors should clearly mark any material not subject to the license. +This includes other CC-licensed material, or material used under an exception +or limitation to copyright. More considerations for licensors : wiki.creativecommons.org/Considerations_for_licensors + +Considerations for the public: By using one of our public licenses, a licensor +grants the public permission to use the licensed material under specified +terms and conditions. If the licensor's permission is not necessary for any +reason–for example, because of any applicable exception or limitation to copyright–then +that use is not regulated by the license. Our licenses grant only permissions +under copyright and certain other rights that a licensor has authority to +grant. Use of the licensed material may still be restricted for other reasons, +including because others have copyright or other rights in the material. A +licensor may make special requests, such as asking that all changes be marked +or described. Although not required by our licenses, you are encouraged to +respect those requests where reasonable. More considerations for the public +: wiki.creativecommons.org/Considerations_for_licensees Creative Commons Attribution +4.0 International Public License + +By exercising the Licensed Rights (defined below), You accept and agree to +be bound by the terms and conditions of this Creative Commons Attribution +4.0 International Public License ("Public License"). To the extent this Public +License may be interpreted as a contract, You are granted the Licensed Rights +in consideration of Your acceptance of these terms and conditions, and the +Licensor grants You such rights in consideration of benefits the Licensor +receives from making the Licensed Material available under these terms and +conditions. + +Section 1 – Definitions. + +a. Adapted Material means material subject to Copyright and Similar Rights +that is derived from or based upon the Licensed Material and in which the +Licensed Material is translated, altered, arranged, transformed, or otherwise +modified in a manner requiring permission under the Copyright and Similar +Rights held by the Licensor. For purposes of this Public License, where the +Licensed Material is a musical work, performance, or sound recording, Adapted +Material is always produced where the Licensed Material is synched in timed +relation with a moving image. + +b. Adapter's License means the license You apply to Your Copyright and Similar +Rights in Your contributions to Adapted Material in accordance with the terms +and conditions of this Public License. + +c. Copyright and Similar Rights means copyright and/or similar rights closely +related to copyright including, without limitation, performance, broadcast, +sound recording, and Sui Generis Database Rights, without regard to how the +rights are labeled or categorized. For purposes of this Public License, the +rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. + +d. Effective Technological Measures means those measures that, in the absence +of proper authority, may not be circumvented under laws fulfilling obligations +under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, +and/or similar international agreements. + +e. Exceptions and Limitations means fair use, fair dealing, and/or any other +exception or limitation to Copyright and Similar Rights that applies to Your +use of the Licensed Material. + +f. Licensed Material means the artistic or literary work, database, or other +material to which the Licensor applied this Public License. + +g. Licensed Rights means the rights granted to You subject to the terms and +conditions of this Public License, which are limited to all Copyright and +Similar Rights that apply to Your use of the Licensed Material and that the +Licensor has authority to license. + +h. Licensor means the individual(s) or entity(ies) granting rights under this +Public License. + +i. Share means to provide material to the public by any means or process that +requires permission under the Licensed Rights, such as reproduction, public +display, public performance, distribution, dissemination, communication, or +importation, and to make material available to the public including in ways +that members of the public may access the material from a place and at a time +individually chosen by them. + +j. Sui Generis Database Rights means rights other than copyright resulting +from Directive 96/9/EC of the European Parliament and of the Council of 11 +March 1996 on the legal protection of databases, as amended and/or succeeded, +as well as other essentially equivalent rights anywhere in the world. + +k. You means the individual or entity exercising the Licensed Rights under +this Public License. Your has a corresponding meaning. + +Section 2 – Scope. + + a. License grant. + +1. Subject to the terms and conditions of this Public License, the Licensor +hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, +irrevocable license to exercise the Licensed Rights in the Licensed Material +to: + + A. reproduce and Share the Licensed Material, in whole or in part; and + + B. produce, reproduce, and Share Adapted Material. + +2. Exceptions and Limitations. For the avoidance of doubt, where Exceptions +and Limitations apply to Your use, this Public License does not apply, and +You do not need to comply with its terms and conditions. + + 3. Term. The term of this Public License is specified in Section 6(a). + +4. Media and formats; technical modifications allowed. The Licensor authorizes +You to exercise the Licensed Rights in all media and formats whether now known +or hereafter created, and to make technical modifications necessary to do +so. The Licensor waives and/or agrees not to assert any right or authority +to forbid You from making technical modifications necessary to exercise the +Licensed Rights, including technical modifications necessary to circumvent +Effective Technological Measures. For purposes of this Public License, simply +making modifications authorized by this Section 2(a)(4) never produces Adapted +Material. + + 5. Downstream recipients. + +A. Offer from the Licensor – Licensed Material. Every recipient of the Licensed +Material automatically receives an offer from the Licensor to exercise the +Licensed Rights under the terms and conditions of this Public License. + +B. No downstream restrictions. You may not offer or impose any additional +or different terms or conditions on, or apply any Effective Technological +Measures to, the Licensed Material if doing so restricts exercise of the Licensed +Rights by any recipient of the Licensed Material. + +6. No endorsement. Nothing in this Public License constitutes or may be construed +as permission to assert or imply that You are, or that Your use of the Licensed +Material is, connected with, or sponsored, endorsed, or granted official status +by, the Licensor or others designated to receive attribution as provided in +Section 3(a)(1)(A)(i). + + b. Other rights. + +1. Moral rights, such as the right of integrity, are not licensed under this +Public License, nor are publicity, privacy, and/or other similar personality +rights; however, to the extent possible, the Licensor waives and/or agrees +not to assert any such rights held by the Licensor to the limited extent necessary +to allow You to exercise the Licensed Rights, but not otherwise. + +2. Patent and trademark rights are not licensed under this Public License. + +3. To the extent possible, the Licensor waives any right to collect royalties +from You for the exercise of the Licensed Rights, whether directly or through +a collecting society under any voluntary or waivable statutory or compulsory +licensing scheme. In all other cases the Licensor expressly reserves any right +to collect such royalties. + +Section 3 – License Conditions. + +Your exercise of the Licensed Rights is expressly made subject to the following +conditions. + + a. Attribution. + +1. If You Share the Licensed Material (including in modified form), You must: + +A. retain the following if it is supplied by the Licensor with the Licensed +Material: + +i. identification of the creator(s) of the Licensed Material and any others +designated to receive attribution, in any reasonable manner requested by the +Licensor (including by pseudonym if designated); + + ii. a copyright notice; + + iii. a notice that refers to this Public License; + + iv. a notice that refers to the disclaimer of warranties; + +v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; + +B. indicate if You modified the Licensed Material and retain an indication +of any previous modifications; and + +C. indicate the Licensed Material is licensed under this Public License, and +include the text of, or the URI or hyperlink to, this Public License. + +2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner +based on the medium, means, and context in which You Share the Licensed Material. +For example, it may be reasonable to satisfy the conditions by providing a +URI or hyperlink to a resource that includes the required information. + +3. If requested by the Licensor, You must remove any of the information required +by Section 3(a)(1)(A) to the extent reasonably practicable. + +4. If You Share Adapted Material You produce, the Adapter's License You apply +must not prevent recipients of the Adapted Material from complying with this +Public License. + +Section 4 – Sui Generis Database Rights. + +Where the Licensed Rights include Sui Generis Database Rights that apply to +Your use of the Licensed Material: + +a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, +reuse, reproduce, and Share all or a substantial portion of the contents of +the database; + +b. if You include all or a substantial portion of the database contents in +a database in which You have Sui Generis Database Rights, then the database +in which You have Sui Generis Database Rights (but not its individual contents) +is Adapted Material; and + +c. You must comply with the conditions in Section 3(a) if You Share all or +a substantial portion of the contents of the database. + +For the avoidance of doubt, this Section 4 supplements and does not replace +Your obligations under this Public License where the Licensed Rights include +other Copyright and Similar Rights. + +Section 5 – Disclaimer of Warranties and Limitation of Liability. + +a. Unless otherwise separately undertaken by the Licensor, to the extent possible, +the Licensor offers the Licensed Material as-is and as-available, and makes +no representations or warranties of any kind concerning the Licensed Material, +whether express, implied, statutory, or other. This includes, without limitation, +warranties of title, merchantability, fitness for a particular purpose, non-infringement, +absence of latent or other defects, accuracy, or the presence or absence of +errors, whether or not known or discoverable. Where disclaimers of warranties +are not allowed in full or in part, this disclaimer may not apply to You. + +b. To the extent possible, in no event will the Licensor be liable to You +on any legal theory (including, without limitation, negligence) or otherwise +for any direct, special, indirect, incidental, consequential, punitive, exemplary, +or other losses, costs, expenses, or damages arising out of this Public License +or use of the Licensed Material, even if the Licensor has been advised of +the possibility of such losses, costs, expenses, or damages. Where a limitation +of liability is not allowed in full or in part, this limitation may not apply +to You. + +c. The disclaimer of warranties and limitation of liability provided above +shall be interpreted in a manner that, to the extent possible, most closely +approximates an absolute disclaimer and waiver of all liability. + +Section 6 – Term and Termination. + +a. This Public License applies for the term of the Copyright and Similar Rights +licensed here. However, if You fail to comply with this Public License, then +Your rights under this Public License terminate automatically. + +b. Where Your right to use the Licensed Material has terminated under Section +6(a), it reinstates: + +1. automatically as of the date the violation is cured, provided it is cured +within 30 days of Your discovery of the violation; or + + 2. upon express reinstatement by the Licensor. + +c. For the avoidance of doubt, this Section 6(b) does not affect any right +the Licensor may have to seek remedies for Your violations of this Public +License. + +d. For the avoidance of doubt, the Licensor may also offer the Licensed Material +under separate terms or conditions or stop distributing the Licensed Material +at any time; however, doing so will not terminate this Public License. + + e. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. + +Section 7 – Other Terms and Conditions. + +a. The Licensor shall not be bound by any additional or different terms or +conditions communicated by You unless expressly agreed. + +b. Any arrangements, understandings, or agreements regarding the Licensed +Material not stated herein are separate from and independent of the terms +and conditions of this Public License. + +Section 8 – Interpretation. + +a. For the avoidance of doubt, this Public License does not, and shall not +be interpreted to, reduce, limit, restrict, or impose conditions on any use +of the Licensed Material that could lawfully be made without permission under +this Public License. + +b. To the extent possible, if any provision of this Public License is deemed +unenforceable, it shall be automatically reformed to the minimum extent necessary +to make it enforceable. If the provision cannot be reformed, it shall be severed +from this Public License without affecting the enforceability of the remaining +terms and conditions. + +c. No term or condition of this Public License will be waived and no failure +to comply consented to unless expressly agreed to by the Licensor. + +d. Nothing in this Public License constitutes or may be interpreted as a limitation +upon, or waiver of, any privileges and immunities that apply to the Licensor +or You, including from the legal processes of any jurisdiction or authority. + +Creative Commons is not a party to its public licenses. Notwithstanding, Creative +Commons may elect to apply one of its public licenses to material it publishes +and in those instances will be considered the "Licensor." The text of the +Creative Commons public licenses is dedicated to the public domain under the +CC0 Public Domain Dedication. Except for the limited purpose of indicating +that material is shared under a Creative Commons public license or as otherwise +permitted by the Creative Commons policies published at creativecommons.org/policies, +Creative Commons does not authorize the use of the trademark "Creative Commons" +or any other trademark or logo of Creative Commons without its prior written +consent including, without limitation, in connection with any unauthorized +modifications to any of its public licenses or any other arrangements, understandings, +or agreements concerning use of licensed material. For the avoidance of doubt, +this paragraph does not form part of the public licenses. + +Creative Commons may be contacted at creativecommons.org. diff --git a/LICENSES/MIT.txt b/LICENSES/MIT.txt new file mode 100644 index 0000000..204b93d --- /dev/null +++ b/LICENSES/MIT.txt @@ -0,0 +1,19 @@ +MIT License Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/LICENSES/Unlicense.txt b/LICENSES/Unlicense.txt new file mode 100644 index 0000000..24a8f90 --- /dev/null +++ b/LICENSES/Unlicense.txt @@ -0,0 +1,20 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or distribute +this software, either in source code form or as a compiled binary, for any +purpose, commercial or non-commercial, and by any means. + +In jurisdictions that recognize copyright laws, the author or authors of this +software dedicate any and all copyright interest in the software to the public +domain. We make this dedication for the benefit of the public at large and +to the detriment of our heirs and successors. We intend this dedication to +be an overt act of relinquishment in perpetuity of all present and future +rights to this software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH +THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information, +please refer to diff --git a/README.rst.license b/README.rst.license new file mode 100644 index 0000000..11cd75d --- /dev/null +++ b/README.rst.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries + +SPDX-License-Identifier: MIT diff --git a/adafruit_bme280.py b/adafruit_bme280.py index c8ce35b..456b70c 100644 --- a/adafruit_bme280.py +++ b/adafruit_bme280.py @@ -1,24 +1,7 @@ -# The MIT License (MIT) +# SPDX-FileCopyrightText: 2017 ladyada for Adafruit Industries # -# Copyright (c) 2017 ladyada for Adafruit Industries -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. +# SPDX-License-Identifier: MIT + """ `adafruit_bme280` - Adafruit BME280 - Temperature, Humidity & Barometic Pressure Sensor ========================================================================================= @@ -440,7 +423,7 @@ def humidity(self): @property def altitude(self): """The altitude based on current ``pressure`` versus the sea level pressure - (``sea_level_pressure``) - which you must enter ahead of time)""" + (``sea_level_pressure``) - which you must enter ahead of time)""" pressure = self.pressure # in Si units for hPascal return 44330 * (1.0 - math.pow(pressure / self.sea_level_pressure, 0.1903)) diff --git a/docs/_static/favicon.ico.license b/docs/_static/favicon.ico.license new file mode 100644 index 0000000..86a3fbf --- /dev/null +++ b/docs/_static/favicon.ico.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2018 Phillip Torrone for Adafruit Industries + +SPDX-License-Identifier: CC-BY-4.0 diff --git a/docs/api.rst.license b/docs/api.rst.license new file mode 100644 index 0000000..9aae48d --- /dev/null +++ b/docs/api.rst.license @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT diff --git a/docs/conf.py b/docs/conf.py index 2119dfe..f151910 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,5 +1,9 @@ # -*- coding: utf-8 -*- +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT + import os import sys diff --git a/docs/examples.rst.license b/docs/examples.rst.license new file mode 100644 index 0000000..9aae48d --- /dev/null +++ b/docs/examples.rst.license @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT diff --git a/docs/index.rst.license b/docs/index.rst.license new file mode 100644 index 0000000..9aae48d --- /dev/null +++ b/docs/index.rst.license @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT diff --git a/examples/bme280_normal_mode.py b/examples/bme280_normal_mode.py index c7c183f..d0133b8 100644 --- a/examples/bme280_normal_mode.py +++ b/examples/bme280_normal_mode.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + """ Example showing how the BME280 library can be used to set the various parameters supported by the sensor. diff --git a/examples/bme280_simpletest.py b/examples/bme280_simpletest.py index a65d86c..8ec49ee 100644 --- a/examples/bme280_simpletest.py +++ b/examples/bme280_simpletest.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + import time import board diff --git a/requirements.txt b/requirements.txt index 3031961..f675e3b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,6 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + Adafruit-Blinka adafruit-circuitpython-busdevice diff --git a/setup.py b/setup.py index f6de9ad..54753be 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT + """A setuptools based setup module. See: From 287979991b5b69f01315bf17e18fddeb48cc6b3b Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 3 Feb 2021 16:38:51 -0500 Subject: [PATCH 040/125] Hardcoded Black and REUSE versions Signed-off-by: dherrada --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index aab5f1c..07f886c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,11 +4,11 @@ repos: - repo: https://github.com/python/black - rev: stable + rev: 20.8b1 hooks: - id: black - repo: https://github.com/fsfe/reuse-tool - rev: latest + rev: v0.12.1 hooks: - id: reuse - repo: https://github.com/pre-commit/pre-commit-hooks From 59cb3eb3b0333a2126357cabeac0204ece69e9ac Mon Sep 17 00:00:00 2001 From: dherrada Date: Tue, 2 Mar 2021 16:46:17 -0500 Subject: [PATCH 041/125] Removed pylint process from github workflow Signed-off-by: dherrada --- .github/workflows/build.yml | 8 ++------ .pre-commit-config.yaml | 15 +++++++++++++++ .pylintrc | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 59baa53..621d5ef 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,18 +42,14 @@ jobs: # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) run: | source actions-ci/install.sh - - name: Pip install pylint, Sphinx, pre-commit + - name: Pip install Sphinx, pre-commit run: | - pip install --force-reinstall pylint Sphinx sphinx-rtd-theme pre-commit + pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit - name: Library version run: git describe --dirty --always --tags - name: Pre-commit hooks run: | pre-commit run --all-files - - name: PyLint - run: | - pylint $( find . -path './adafruit*.py' ) - ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace $( find . -path "./examples/*.py" )) - name: Build assets run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . - name: Archive bundles diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 07f886c..354c761 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,3 +17,18 @@ repos: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace +- repo: https://github.com/pycqa/pylint + rev: pylint-2.7.1 + hooks: + - id: pylint + name: pylint (library code) + types: [python] + exclude: "^(docs/|examples/|setup.py$)" +- repo: local + hooks: + - id: pylint_examples + name: pylint (examples code) + description: Run pylint rules on "examples/*.py" files + entry: /usr/bin/env bash -c + args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name $example; done)'] + language: system diff --git a/.pylintrc b/.pylintrc index 5c31f66..9ed669e 100644 --- a/.pylintrc +++ b/.pylintrc @@ -250,7 +250,7 @@ ignore-comments=yes ignore-docstrings=yes # Ignore imports when computing similarities. -ignore-imports=no +ignore-imports=yes # Minimum lines number of a similarity. min-similarity-lines=4 From 73286f482df1217568755d8a73511de393bfa6a2 Mon Sep 17 00:00:00 2001 From: dherrada Date: Tue, 2 Mar 2021 17:17:50 -0500 Subject: [PATCH 042/125] Re-added pylint install to build.yml Signed-off-by: dherrada --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 621d5ef..3baf502 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,9 +42,9 @@ jobs: # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) run: | source actions-ci/install.sh - - name: Pip install Sphinx, pre-commit + - name: Pip install pylint, Sphinx, pre-commit run: | - pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit + pip install --force-reinstall pylint Sphinx sphinx-rtd-theme pre-commit - name: Library version run: git describe --dirty --always --tags - name: Pre-commit hooks From a1c3464d4421babf8360e7439ad856ec5324ac71 Mon Sep 17 00:00:00 2001 From: dherrada Date: Fri, 19 Mar 2021 13:46:41 -0400 Subject: [PATCH 043/125] "Increase duplicate code check threshold " --- .pylintrc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.pylintrc b/.pylintrc index 9ed669e..0238b90 100644 --- a/.pylintrc +++ b/.pylintrc @@ -22,8 +22,7 @@ ignore-patterns= #init-hook= # Use multiple processes to speed up Pylint. -# jobs=1 -jobs=2 +jobs=1 # List of plugins (as comma separated values of python modules names) to load, # usually to register additional checkers. @@ -253,7 +252,7 @@ ignore-docstrings=yes ignore-imports=yes # Minimum lines number of a similarity. -min-similarity-lines=4 +min-similarity-lines=12 [BASIC] From 1fd7cb1754d914034aab0a3b63ef3f0bb4054368 Mon Sep 17 00:00:00 2001 From: Andrew Mulholland <833193+gbaman@users.noreply.github.com> Date: Tue, 6 Apr 2021 23:40:13 +0100 Subject: [PATCH 044/125] Remove pressure boundraries Remove pressure boundaries as the sensor can continue to read values outside the documented 300hPa - 1100hPa full accuracy range, even if at then a reduced accuracy. --- adafruit_bme280.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/adafruit_bme280.py b/adafruit_bme280.py index 456b70c..1bdd16e 100644 --- a/adafruit_bme280.py +++ b/adafruit_bme280.py @@ -46,8 +46,6 @@ _BME280_REGISTER_TEMPDATA = const(0xFA) _BME280_REGISTER_HUMIDDATA = const(0xFD) -_BME280_PRESSURE_MIN_HPA = const(300) -_BME280_PRESSURE_MAX_HPA = const(1100) _BME280_HUMIDITY_MIN = const(0) _BME280_HUMIDITY_MAX = const(100) @@ -368,10 +366,6 @@ def pressure(self): pressure = pressure + (var1 + var2 + self._pressure_calib[6]) / 16.0 pressure /= 100 - if pressure < _BME280_PRESSURE_MIN_HPA: - return _BME280_PRESSURE_MIN_HPA - if pressure > _BME280_PRESSURE_MAX_HPA: - return _BME280_PRESSURE_MAX_HPA return pressure @property From a647ad6f354ddb9d8ef5196e8e13d442e18eb591 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Mon, 12 Apr 2021 17:09:10 -0400 Subject: [PATCH 045/125] Including function documentation and exposing examples to Readthedocs API --- adafruit_bme280.py | 55 +++++++++++++++++++++++++++++++++++++++++----- docs/examples.rst | 10 +++++++++ 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/adafruit_bme280.py b/adafruit_bme280.py index 1bdd16e..3048b4a 100644 --- a/adafruit_bme280.py +++ b/adafruit_bme280.py @@ -138,6 +138,9 @@ def __init__(self): self._t_fine = None def _read_temperature(self): + """Private function to read the temperature + :return: None + """ # perform one measurement if self.mode != MODE_NORMAL: self.mode = MODE_FORCE @@ -459,15 +462,28 @@ def _write_register_byte(self, register, value): class Adafruit_BME280_I2C(Adafruit_BME280): - """Driver for BME280 connected over I2C""" + """Driver for BME280 connected over I2C + + :param i2c: i2c object created with to use with BME280 sensor + :param int address: address of the BME280 sensor. Defaults to 0x77 + + """ - def __init__(self, i2c, address=_BME280_ADDRESS): + def __init__(self, i2c, address: int = _BME280_ADDRESS) -> None: import adafruit_bus_device.i2c_device as i2c_device # pylint: disable=import-outside-toplevel self._i2c = i2c_device.I2CDevice(i2c, address) super().__init__() def _read_register(self, register, length): + """Private function to read a register with a provided length + + :param register: register to read from + :param length: length in bytes to read + :return: bytearray with register information + :rtype: bytearray + + """ with self._i2c as i2c: i2c.write(bytes([register & 0xFF])) result = bytearray(length) @@ -476,21 +492,41 @@ def _read_register(self, register, length): return result def _write_register_byte(self, register, value): + """Private function to write on a register with a provided value + + :param register: register to write to + :param value: value to write on the selected register + :return: None + + """ with self._i2c as i2c: i2c.write(bytes([register & 0xFF, value & 0xFF])) # print("$%02X <= 0x%02X" % (register, value)) class Adafruit_BME280_SPI(Adafruit_BME280): - """Driver for BME280 connected over SPI""" + """Driver for BME280 connected over SPI + + :param spi: spi object created with to use with BME280 sensor + :param ~microcontroller.Pin cs: pin used for cs + :param int baudrate: the desired clock rate in Hertz of the spi. Defaults to 100000 - def __init__(self, spi, cs, baudrate=100000): + """ + + def __init__(self, spi, cs, baudrate: int = 100000) -> None: import adafruit_bus_device.spi_device as spi_device # pylint: disable=import-outside-toplevel self._spi = spi_device.SPIDevice(spi, cs, baudrate=baudrate) super().__init__() - def _read_register(self, register, length): + def _read_register(self, register: int, length: int) -> bytearray: + """Private function to read a register with a provided length + + :param int register: register to read from + :param int length: length in bytes to read + :return bytearray: bytearray with register information + + """ register = (register | 0x80) & 0xFF # Read single, bit 7 high. with self._spi as spi: spi.write(bytearray([register])) # pylint: disable=no-member @@ -499,7 +535,14 @@ def _read_register(self, register, length): # print("$%02X => %s" % (register, [hex(i) for i in result])) return result - def _write_register_byte(self, register, value): + def _write_register_byte(self, register: int, value: int) -> None: + """Private function to write on a register with a provided value + + :param register: register to write to + :param value: value to write on the selected register + :return: None + + """ register &= 0x7F # Write, bit 7 low. with self._spi as spi: spi.write(bytes([register, value & 0xFF])) # pylint: disable=no-member diff --git a/docs/examples.rst b/docs/examples.rst index 3f7434a..4369d8e 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -6,3 +6,13 @@ Ensure your device works with this simple test. .. literalinclude:: ../examples/bme280_simpletest.py :caption: examples/bme280_simpletest.py :linenos: + +Normal Mode +----------- + +Example showing how the BME280 library can be used to set the various +parameters supported by the sensor + +.. literalinclude:: ../examples/bme280_normal_mode.py + :caption: examples/bme280_normal_mode.py + :linenos: From e731d0f3c5435125d3ee5c90044b10df7ca4f137 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Fri, 23 Apr 2021 17:40:58 -0400 Subject: [PATCH 046/125] Adding Note regarding the altitude capabilities of the sensor. Changing the use of busio. Including learning guide. --- README.rst | 5 +- adafruit_bme280.py | 164 +++++++++++++++++++++++---------- docs/index.rst | 2 + examples/bme280_normal_mode.py | 6 +- examples/bme280_simpletest.py | 6 +- 5 files changed, 123 insertions(+), 60 deletions(-) diff --git a/README.rst b/README.rst index 994ca6c..6ae3497 100644 --- a/README.rst +++ b/README.rst @@ -61,18 +61,17 @@ Usage Example import board import digitalio - import busio import time import adafruit_bme280 # Create library object using our Bus I2C port - i2c = busio.I2C(board.SCL, board.SDA) + i2c = board.I2C() # uses board.SCL and board.SDA bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) #or with other sensor address #bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76) # OR create library object using our Bus SPI port - #spi = busio.SPI(board.SCK, board.MOSI, board.MISO) + #spi = board.SPI() #bme_cs = digitalio.DigitalInOut(board.D10) #bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs) diff --git a/adafruit_bme280.py b/adafruit_bme280.py index 3048b4a..ff17407 100644 --- a/adafruit_bme280.py +++ b/adafruit_bme280.py @@ -3,12 +3,28 @@ # SPDX-License-Identifier: MIT """ -`adafruit_bme280` - Adafruit BME280 - Temperature, Humidity & Barometic Pressure Sensor +`adafruit_bme280` ========================================================================================= -CircuitPython driver from BME280 Temperature, Humidity and Barometic Pressure sensor +CircuitPython driver from BME280 Temperature, Humidity and Barometric +Pressure sensor * Author(s): ladyada + +Implementation Notes +-------------------- + +**Hardware:** + +* Adafruit `BME280 Temperature, Humidity and Barometric Pressure sensor + `_ (Product ID: 2652) + + +**Software and Dependencies:** + +* Adafruit CircuitPython firmware for the supported boards: + https://github.com/adafruit/circuitpython/releases +* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice """ import math from time import sleep @@ -113,7 +129,13 @@ class Adafruit_BME280: - """Driver from BME280 Temperature, Humidity and Barometic Pressure sensor""" + """Driver from BME280 Temperature, Humidity and Barometric Pressure sensor + + .. note:: + The operational range of the BMP280 is 300-1100 hPa. + Pressure measurements outside this range may not be as accurate. + + """ # pylint: disable=too-many-instance-attributes def __init__(self): @@ -138,9 +160,6 @@ def __init__(self): self._t_fine = None def _read_temperature(self): - """Private function to read the temperature - :return: None - """ # perform one measurement if self.mode != MODE_NORMAL: self.mode = MODE_FORCE @@ -172,8 +191,8 @@ def _reset(self): def _write_ctrl_meas(self): """ Write the values to the ctrl_meas and ctrl_hum registers in the device - ctrl_meas sets the pressure and temperature data acquistion options - ctrl_hum sets the humidty oversampling and must be written to first + ctrl_meas sets the pressure and temperature data acquisition options + ctrl_hum sets the humidity oversampling and must be written to first """ self._write_register_byte(_BME280_REGISTER_CTRL_HUM, self.overscan_humidity) self._write_register_byte(_BME280_REGISTER_CTRL_MEAS, self._ctrl_meas) @@ -333,7 +352,7 @@ def measurement_time_max(self): @property def temperature(self): - """The compensated temperature in degrees celsius.""" + """The compensated temperature in degrees Celsius.""" self._read_temperature() return self._t_fine / 5120.0 @@ -359,8 +378,7 @@ def pressure(self): var1 = (1.0 + var1 / 32768.0) * self._pressure_calib[0] if not var1: # avoid exception caused by division by zero raise ArithmeticError( - "Invalid result possibly related to error while \ -reading the calibration registers" + "Invalid result possibly related to error while reading the calibration registers" ) pressure = 1048576.0 - adc pressure = ((pressure - var2 / 4096.0) * 6250.0) / var1 @@ -464,26 +482,56 @@ def _write_register_byte(self, register, value): class Adafruit_BME280_I2C(Adafruit_BME280): """Driver for BME280 connected over I2C - :param i2c: i2c object created with to use with BME280 sensor - :param int address: address of the BME280 sensor. Defaults to 0x77 + :param ~busio.I2C i2c: The I2C bus the BME280 is connected to. + :param int address: I2C device address. Defaults to :const:`0x77`. + but another address can be passed in as an argument + + .. note:: + The operational range of the BMP280 is 300-1100 hPa. + Pressure measurements outside this range may not be as accurate. + + **Quickstart: Importing and using the BME280** + + Here is an example of using the :class:`Adafruit_BME280_I2C`. + First you will need to import the libraries to use the sensor + + .. code-block:: python + + import board + import adafruit_bme280 + + Once this is done you can define your `board.I2C` object and define your sensor object + + .. code-block:: python + + i2c = board.I2C() # uses board.SCL and board.SDA + bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) + + You need to setup the pressure at sea level + + .. code-block:: python + + bme280.sea_level_pressure = 1013.25 + + Now you have access to the :attr:`temperature`, :attr:`relative_humidity` + :attr:`pressure` and :attr:`altitude` attributes + + .. code-block:: python + + temperature = bme280.temperature + relative_humidity = bme280.relative_humidity + pressure = bme280.pressure + altitude = bme280.altitude """ - def __init__(self, i2c, address: int = _BME280_ADDRESS) -> None: + def __init__(self, i2c, address=_BME280_ADDRESS): import adafruit_bus_device.i2c_device as i2c_device # pylint: disable=import-outside-toplevel self._i2c = i2c_device.I2CDevice(i2c, address) super().__init__() def _read_register(self, register, length): - """Private function to read a register with a provided length - - :param register: register to read from - :param length: length in bytes to read - :return: bytearray with register information - :rtype: bytearray - - """ with self._i2c as i2c: i2c.write(bytes([register & 0xFF])) result = bytearray(length) @@ -492,13 +540,6 @@ def _read_register(self, register, length): return result def _write_register_byte(self, register, value): - """Private function to write on a register with a provided value - - :param register: register to write to - :param value: value to write on the selected register - :return: None - - """ with self._i2c as i2c: i2c.write(bytes([register & 0xFF, value & 0xFF])) # print("$%02X <= 0x%02X" % (register, value)) @@ -507,26 +548,58 @@ def _write_register_byte(self, register, value): class Adafruit_BME280_SPI(Adafruit_BME280): """Driver for BME280 connected over SPI - :param spi: spi object created with to use with BME280 sensor - :param ~microcontroller.Pin cs: pin used for cs - :param int baudrate: the desired clock rate in Hertz of the spi. Defaults to 100000 + :param ~busio.SPI spi: SPI device + :param ~digitalio.DigitalInOut cs: Chip Select + :param int baudrate: Clock rate, default is 100000. Can be changed with :meth:`baudrate` + + .. note:: + The operational range of the BMP280 is 300-1100 hPa. + Pressure measurements outside this range may not be as accurate. + + **Quickstart: Importing and using the BME280** + + Here is an example of using the :class:`Adafruit_BME280_SPI` class. + First you will need to import the libraries to use the sensor + + .. code-block:: python + + import board + from digitalio import DigitalInOut, Direction + import adafruit_bme280 + + Once this is done you can define your `board.SPI` object and define your sensor object + + .. code-block:: python + + cs = digitalio.DigitalInOut(board.D10) + spi = board.SPI() + bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, cs) + + You need to setup the pressure at sea level + + .. code-block:: python + + bme280.sea_level_pressure = 1013.25 + + Now you have access to the :attr:`temperature`, :attr:`relative_humidity` + :attr:`pressure` and :attr:`altitude` attributes + + .. code-block:: python + + temperature = bme280.temperature + relative_humidity = bme280.relative_humidity + pressure = bme280.pressure + altitude = bme280.altitude """ - def __init__(self, spi, cs, baudrate: int = 100000) -> None: + def __init__(self, spi, cs, baudrate=100000): import adafruit_bus_device.spi_device as spi_device # pylint: disable=import-outside-toplevel self._spi = spi_device.SPIDevice(spi, cs, baudrate=baudrate) super().__init__() - def _read_register(self, register: int, length: int) -> bytearray: - """Private function to read a register with a provided length - - :param int register: register to read from - :param int length: length in bytes to read - :return bytearray: bytearray with register information - - """ + def _read_register(self, register, length): register = (register | 0x80) & 0xFF # Read single, bit 7 high. with self._spi as spi: spi.write(bytearray([register])) # pylint: disable=no-member @@ -535,14 +608,7 @@ def _read_register(self, register: int, length: int) -> bytearray: # print("$%02X => %s" % (register, [hex(i) for i in result])) return result - def _write_register_byte(self, register: int, value: int) -> None: - """Private function to write on a register with a provided value - - :param register: register to write to - :param value: value to write on the selected register - :return: None - - """ + def _write_register_byte(self, register, value): register &= 0x7F # Write, bit 7 low. with self._spi as spi: spi.write(bytes([register, value & 0xFF])) # pylint: disable=no-member diff --git a/docs/index.rst b/docs/index.rst index 93bf229..d06bd75 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -23,6 +23,8 @@ Table of Contents .. toctree:: :caption: Tutorials + Adafruit BME280 I2C or SPI Temperature Humidity Pressure Sensor Learnng Guide + .. toctree:: :caption: Related Products diff --git a/examples/bme280_normal_mode.py b/examples/bme280_normal_mode.py index d0133b8..dfce626 100644 --- a/examples/bme280_normal_mode.py +++ b/examples/bme280_normal_mode.py @@ -7,17 +7,15 @@ Refer to the BME280 datasheet to understand what these parameters do """ import time - import board -import busio import adafruit_bme280 # Create library object using our Bus I2C port -i2c = busio.I2C(board.SCL, board.SDA) +i2c = board.I2C() # uses board.SCL and board.SDA bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) # OR create library object using our Bus SPI port -# spi = busio.SPI(board.SCK, board.MOSI, board.MISO) +# spi = board.SPI() # bme_cs = digitalio.DigitalInOut(board.D10) # bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs) diff --git a/examples/bme280_simpletest.py b/examples/bme280_simpletest.py index 8ec49ee..2800b95 100644 --- a/examples/bme280_simpletest.py +++ b/examples/bme280_simpletest.py @@ -2,17 +2,15 @@ # SPDX-License-Identifier: MIT import time - import board -import busio import adafruit_bme280 # Create library object using our Bus I2C port -i2c = busio.I2C(board.SCL, board.SDA) +i2c = board.I2C() # uses board.SCL and board.SDA bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) # OR create library object using our Bus SPI port -# spi = busio.SPI(board.SCK, board.MOSI, board.MISO) +# spi = board.SPI() # bme_cs = digitalio.DigitalInOut(board.D10) # bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs) From 0a404e7dcb54d9ad48cc58c85a83d53dd7ee56d1 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 23 Apr 2021 18:14:55 -0400 Subject: [PATCH 047/125] Clarify comment phrasing. --- README.rst | 4 ++-- examples/bme280_normal_mode.py | 4 ++-- examples/bme280_simpletest.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index 6ae3497..7880ad9 100644 --- a/README.rst +++ b/README.rst @@ -64,13 +64,13 @@ Usage Example import time import adafruit_bme280 - # Create library object using our Bus I2C port + # Create sensor object, using the board's default I2C bus. i2c = board.I2C() # uses board.SCL and board.SDA bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) #or with other sensor address #bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76) - # OR create library object using our Bus SPI port + # OR create sensor object, using the board's default SPI bus. #spi = board.SPI() #bme_cs = digitalio.DigitalInOut(board.D10) #bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs) diff --git a/examples/bme280_normal_mode.py b/examples/bme280_normal_mode.py index dfce626..8a2c5d2 100644 --- a/examples/bme280_normal_mode.py +++ b/examples/bme280_normal_mode.py @@ -10,11 +10,11 @@ import board import adafruit_bme280 -# Create library object using our Bus I2C port +# Create sensor object, using the board's default I2C bus. i2c = board.I2C() # uses board.SCL and board.SDA bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) -# OR create library object using our Bus SPI port +# OR create sensor object, using the board's default SPI bus. # spi = board.SPI() # bme_cs = digitalio.DigitalInOut(board.D10) # bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs) diff --git a/examples/bme280_simpletest.py b/examples/bme280_simpletest.py index 2800b95..d653584 100644 --- a/examples/bme280_simpletest.py +++ b/examples/bme280_simpletest.py @@ -5,11 +5,11 @@ import board import adafruit_bme280 -# Create library object using our Bus I2C port +# Create sensor object, using the board's default I2C bus. i2c = board.I2C() # uses board.SCL and board.SDA bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) -# OR create library object using our Bus SPI port +# OR create sensor object, using the board's default SPI bus. # spi = board.SPI() # bme_cs = digitalio.DigitalInOut(board.D10) # bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs) From e5d7968fe155ff7929ac98f37599376223053c46 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Mon, 3 May 2021 18:29:28 -0400 Subject: [PATCH 048/125] veryfing_references --- README.rst | 5 +++-- adafruit_bme280.py | 11 +++++++---- docs/index.rst | 2 +- examples/bme280_normal_mode.py | 2 ++ 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 7880ad9..134772a 100644 --- a/README.rst +++ b/README.rst @@ -57,10 +57,9 @@ To install in a virtual environment in your current project: Usage Example ============= -.. code-block:: python +.. code-block:: python3 import board - import digitalio import time import adafruit_bme280 @@ -71,6 +70,8 @@ Usage Example #bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76) # OR create sensor object, using the board's default SPI bus. + # SPI setup + # from digitalio import DigitalInOut #spi = board.SPI() #bme_cs = digitalio.DigitalInOut(board.D10) #bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs) diff --git a/adafruit_bme280.py b/adafruit_bme280.py index ff17407..7990d9e 100644 --- a/adafruit_bme280.py +++ b/adafruit_bme280.py @@ -16,15 +16,18 @@ **Hardware:** -* Adafruit `BME280 Temperature, Humidity and Barometric Pressure sensor +* `Adafruit BME280 Temperature, Humidity and Barometric Pressure sensor `_ (Product ID: 2652) **Software and Dependencies:** * Adafruit CircuitPython firmware for the supported boards: - https://github.com/adafruit/circuitpython/releases -* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice + https://circuitpython.org/downloads + +* Adafruit's Bus Device library: + https://github.com/adafruit/Adafruit_CircuitPython_BusDevice + """ import math from time import sleep @@ -564,7 +567,7 @@ class Adafruit_BME280_SPI(Adafruit_BME280): .. code-block:: python import board - from digitalio import DigitalInOut, Direction + from digitalio import DigitalInOut import adafruit_bme280 Once this is done you can define your `board.SPI` object and define your sensor object diff --git a/docs/index.rst b/docs/index.rst index d06bd75..62fb9df 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -23,7 +23,7 @@ Table of Contents .. toctree:: :caption: Tutorials - Adafruit BME280 I2C or SPI Temperature Humidity Pressure Sensor Learnng Guide + Adafruit BME280 I2C or SPI Temperature Humidity Pressure Sensor Learning Guide .. toctree:: :caption: Related Products diff --git a/examples/bme280_normal_mode.py b/examples/bme280_normal_mode.py index 8a2c5d2..c5f1dd2 100644 --- a/examples/bme280_normal_mode.py +++ b/examples/bme280_normal_mode.py @@ -15,6 +15,8 @@ bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) # OR create sensor object, using the board's default SPI bus. +# SPI setup +# from digitalio import DigitalInOut # spi = board.SPI() # bme_cs = digitalio.DigitalInOut(board.D10) # bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs) From eee0955b0b9b231cac1962b6317fbcb98ec09a2b Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Wed, 19 May 2021 08:51:30 -0700 Subject: [PATCH 049/125] Add Pico example and update gitignore --- .gitignore | 10 +++++++++- examples/bme280_simpletest_pico.py | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 examples/bme280_simpletest_pico.py diff --git a/.gitignore b/.gitignore index 1be4e54..a966824 100644 --- a/.gitignore +++ b/.gitignore @@ -2,9 +2,17 @@ # # SPDX-License-Identifier: Unlicense +*.mpy +.idea __pycache__ _build *.pyc -*.mpy .env +.python-version +build*/ bundles +*.DS_Store +.eggs +dist +**/*.egg-info +.vscode diff --git a/examples/bme280_simpletest_pico.py b/examples/bme280_simpletest_pico.py new file mode 100644 index 0000000..7ddc93a --- /dev/null +++ b/examples/bme280_simpletest_pico.py @@ -0,0 +1,26 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + +import time +import board +import busio +import adafruit_bme280 + +# Create sensor object, using the board's default I2C bus. +i2c = busio.I2C(board.GP1, board.GP0) # SCL, SDA +bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) + +# OR create sensor object, using the board's default SPI bus. +# spi = busio.SPI(board.GP2, MISO=board.GP0, MOSI=board.GP3) +# bme_cs = digitalio.DigitalInOut(board.GP1) +# bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs) + +# change this to match the location's pressure (hPa) at sea level +bme280.sea_level_pressure = 1013.25 + +while True: + print("\nTemperature: %0.1f C" % bme280.temperature) + print("Humidity: %0.1f %%" % bme280.relative_humidity) + print("Pressure: %0.1f hPa" % bme280.pressure) + print("Altitude = %0.2f meters" % bme280.altitude) + time.sleep(2) From 7699692a8e109613e66457bbed695bb3579bb2da Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Wed, 19 May 2021 09:06:38 -0700 Subject: [PATCH 050/125] Re-ran pre-commit hooks --- examples/bme280_simpletest_pico.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/bme280_simpletest_pico.py b/examples/bme280_simpletest_pico.py index 7ddc93a..d433b44 100644 --- a/examples/bme280_simpletest_pico.py +++ b/examples/bme280_simpletest_pico.py @@ -7,7 +7,7 @@ import adafruit_bme280 # Create sensor object, using the board's default I2C bus. -i2c = busio.I2C(board.GP1, board.GP0) # SCL, SDA +i2c = busio.I2C(board.GP1, board.GP0) # SCL, SDA bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) # OR create sensor object, using the board's default SPI bus. From 64157b7035147b505e3140d0c2409646f2a0d605 Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 19 May 2021 13:32:42 -0400 Subject: [PATCH 051/125] Added pull request template Signed-off-by: dherrada --- .../adafruit_circuitpython_pr.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md diff --git a/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md b/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md new file mode 100644 index 0000000..71ef8f8 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md @@ -0,0 +1,13 @@ +# SPDX-FileCopyrightText: 2021 Adafruit Industries +# +# SPDX-License-Identifier: MIT + +Thank you for contributing! Before you submit a pull request, please read the following. + +Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://circuitpython.readthedocs.io/en/latest/docs/design_guide.html + +If your changes are to documentation, please verify that the documentation builds locally by following the steps found here: https://adafru.it/build-docs + +Before submitting the pull request, make sure you've run Pylint and Black locally on your code. You can do this manually or using pre-commit. Instructions are available here: https://adafru.it/check-your-code + +Please remove all of this text before submitting. Include an explanation or list of changes included in your PR, as well as, if applicable, a link to any related issues. From 51ec4c06ec705ccc11129aa2ed56a9771e1996cf Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 19 May 2021 13:35:18 -0400 Subject: [PATCH 052/125] Added help text and problem matcher Signed-off-by: dherrada --- .github/workflows/build.yml | 2 ++ .github/workflows/failure-help-text.yml | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 .github/workflows/failure-help-text.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3baf502..0ab7182 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -71,3 +71,5 @@ jobs: python setup.py sdist python setup.py bdist_wheel --universal twine check dist/* + - name: Setup problem matchers + uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1 diff --git a/.github/workflows/failure-help-text.yml b/.github/workflows/failure-help-text.yml new file mode 100644 index 0000000..0b1194f --- /dev/null +++ b/.github/workflows/failure-help-text.yml @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2021 Scott Shawcroft for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: Failure help text + +on: + workflow_run: + workflows: ["Build CI"] + types: + - completed + +jobs: + post-help: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.event == 'pull_request' }} + steps: + - name: Post comment to help + uses: adafruit/circuitpython-action-library-ci-failed@v1 From 6247a9bd791240cb336a43b4b8daa90c376f0816 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Wed, 19 May 2021 21:20:57 -0400 Subject: [PATCH 053/125] adding_example_pico _to _API --- docs/examples.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/examples.rst b/docs/examples.rst index 4369d8e..58b760b 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -16,3 +16,12 @@ parameters supported by the sensor .. literalinclude:: ../examples/bme280_normal_mode.py :caption: examples/bme280_normal_mode.py :linenos: + +RP Pico Example +--------------- + +Example showing how the BME280 library using a RP Pico + +.. literalinclude:: ../examples/bme280_simpletest_pico.py + :caption: examples/bme280_simpletest_pico.py + :linenos: From d1a7d9844357ff2e3df9d7a57c0fe2e3239b8dfe Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 24 May 2021 09:54:31 -0400 Subject: [PATCH 054/125] Moved CI to Python 3.7 Signed-off-by: dherrada --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0ab7182..c4c975d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,10 +22,10 @@ jobs: awk -F '\/' '{ print tolower($2) }' | tr '_' '-' ) - - name: Set up Python 3.6 + - name: Set up Python 3.7 uses: actions/setup-python@v1 with: - python-version: 3.6 + python-version: 3.7 - name: Versions run: | python3 --version From ec1f27f2c05a20fcc82510c048229d6b829bc684 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Tue, 25 May 2021 06:59:24 -0400 Subject: [PATCH 055/125] memory_optimization --- .../advanced.py | 0 adafruit_bme280/basic.py | 379 ++++++++++++++++++ 2 files changed, 379 insertions(+) rename adafruit_bme280.py => adafruit_bme280/advanced.py (100%) create mode 100644 adafruit_bme280/basic.py diff --git a/adafruit_bme280.py b/adafruit_bme280/advanced.py similarity index 100% rename from adafruit_bme280.py rename to adafruit_bme280/advanced.py diff --git a/adafruit_bme280/basic.py b/adafruit_bme280/basic.py new file mode 100644 index 0000000..3aae496 --- /dev/null +++ b/adafruit_bme280/basic.py @@ -0,0 +1,379 @@ +# SPDX-FileCopyrightText: 2017 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +""" +`adafruit_bme280` +========================================================================================= + +CircuitPython driver from BME280 Temperature, Humidity and Barometric +Pressure sensor + +* Author(s): ladyada + +Implementation Notes +-------------------- + +**Hardware:** + +* `Adafruit BME280 Temperature, Humidity and Barometric Pressure sensor + `_ (Product ID: 2652) + + +**Software and Dependencies:** + +* Adafruit CircuitPython firmware for the supported boards: + https://circuitpython.org/downloads + +* Adafruit's Bus Device library: + https://github.com/adafruit/Adafruit_CircuitPython_BusDevice + +""" +import math +from time import sleep +from micropython import const + +try: + import struct +except ImportError: + import ustruct as struct + + +__version__ = "2.6.4" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BME280.git" + +# I2C ADDRESS/BITS/SETTINGS +# ----------------------------------------------------------------------- +_BME280_ADDRESS = const(0x77) +_BME280_CHIPID = const(0x60) + +_BME280_REGISTER_CHIPID = const(0xD0) +_BME280_REGISTER_DIG_T1 = const(0x88) +_BME280_REGISTER_DIG_H1 = const(0xA1) +_BME280_REGISTER_DIG_H2 = const(0xE1) +_BME280_REGISTER_DIG_H3 = const(0xE3) +_BME280_REGISTER_DIG_H4 = const(0xE4) +_BME280_REGISTER_DIG_H5 = const(0xE5) +_BME280_REGISTER_DIG_H6 = const(0xE7) + +_BME280_REGISTER_SOFTRESET = const(0xE0) +_BME280_REGISTER_CTRL_HUM = const(0xF2) +_BME280_REGISTER_STATUS = const(0xF3) +_BME280_REGISTER_CTRL_MEAS = const(0xF4) +_BME280_REGISTER_CONFIG = const(0xF5) +_BME280_REGISTER_PRESSUREDATA = const(0xF7) +_BME280_REGISTER_TEMPDATA = const(0xFA) +_BME280_REGISTER_HUMIDDATA = const(0xFD) + +_BME280_HUMIDITY_MIN = const(0) +_BME280_HUMIDITY_MAX = const(100) + +"""iir_filter values""" +IIR_FILTER_DISABLE = const(0) + +"""overscan values for temperature, pressure, and humidity""" +OVERSCAN_DISABLE = const(0x00) +OVERSCAN_X1 = const(0x01) +OVERSCAN_X2 = const(0x02) +OVERSCAN_X4 = const(0x03) +OVERSCAN_X8 = const(0x04) +OVERSCAN_X16 = const(0x05) + +_BME280_OVERSCANS = { + OVERSCAN_DISABLE: 0, + OVERSCAN_X1: 1, + OVERSCAN_X2: 2, + OVERSCAN_X4: 4, + OVERSCAN_X8: 8, + OVERSCAN_X16: 16, +} + +"""mode values""" +MODE_SLEEP = const(0x00) +MODE_FORCE = const(0x01) +MODE_NORMAL = const(0x03) + +_BME280_MODES = (MODE_SLEEP, MODE_FORCE, MODE_NORMAL) + +STANDBY_TC_125 = const(0x02) # 125ms + + +class Adafruit_BME280: + """Driver from BME280 Temperature, Humidity and Barometric Pressure sensor + + .. note:: + The operational range of the BMP280 is 300-1100 hPa. + Pressure measurements outside this range may not be as accurate. + + """ + + # pylint: disable=too-many-instance-attributes + def __init__(self): + """Check the BME280 was found, read the coefficients and enable the sensor""" + # Check device ID. + chip_id = self._read_byte(_BME280_REGISTER_CHIPID) + if _BME280_CHIPID != chip_id: + raise RuntimeError("Failed to find BME280! Chip ID 0x%x" % chip_id) + # Set some reasonable defaults. + self._iir_filter = IIR_FILTER_DISABLE + self.overscan_humidity = 1 + self.overscan_temperature = 1 + self.overscan_pressure = OVERSCAN_X16 + self._t_standby = STANDBY_TC_125 + self._mode = MODE_SLEEP + self._reset() + self._read_coefficients() + self._write_ctrl_meas() + self._write_config() + self.sea_level_pressure = 1013.25 + """Pressure in hectoPascals at sea level. Used to calibrate `altitude`.""" + self._t_fine = None + + def _read_temperature(self): + # perform one measurement + if self.mode != MODE_NORMAL: + self.mode = MODE_FORCE + # Wait for conversion to complete + while self._get_status() & 0x08: + sleep(0.002) + raw_temperature = ( + self._read24(_BME280_REGISTER_TEMPDATA) / 16 + ) # lowest 4 bits get dropped + # print("raw temp: ", UT) + var1 = ( + raw_temperature / 16384.0 - self._temp_calib[0] / 1024.0 + ) * self._temp_calib[1] + # print(var1) + var2 = ( + (raw_temperature / 131072.0 - self._temp_calib[0] / 8192.0) + * (raw_temperature / 131072.0 - self._temp_calib[0] / 8192.0) + ) * self._temp_calib[2] + # print(var2) + + self._t_fine = int(var1 + var2) + # print("t_fine: ", self.t_fine) + + def _reset(self): + """Soft reset the sensor""" + self._write_register_byte(_BME280_REGISTER_SOFTRESET, 0xB6) + sleep(0.004) # Datasheet says 2ms. Using 4ms just to be safe + + def _write_ctrl_meas(self): + """ + Write the values to the ctrl_meas and ctrl_hum registers in the device + ctrl_meas sets the pressure and temperature data acquisition options + ctrl_hum sets the humidity oversampling and must be written to first + """ + + self._write_register_byte(_BME280_REGISTER_CTRL_HUM, self.overscan_humidity) + self._write_register_byte(_BME280_REGISTER_CTRL_MEAS, self._ctrl_meas) + + def _get_status(self): + """Get the value from the status register in the device """ + return self._read_byte(_BME280_REGISTER_STATUS) + + def _read_config(self): + """Read the value from the config register in the device """ + return self._read_byte(_BME280_REGISTER_CONFIG) + + def _write_config(self): + """Write the value to the config register in the device """ + + self._write_register_byte(_BME280_REGISTER_CONFIG, self._config) + + @property + def mode(self): + """ + Operation mode + Allowed values are the constants MODE_* + """ + return self._mode + + @mode.setter + def mode(self, value): + if not value in _BME280_MODES: + raise ValueError("Mode '%s' not supported" % (value)) + self._mode = value + self._write_ctrl_meas() + + @property + def _config(self): + """Value to be written to the device's config register """ + config = 0 + if self.mode == MODE_NORMAL: + config += self._t_standby << 5 + if self._iir_filter: + config += self._iir_filter << 2 + return config + + @property + def _ctrl_meas(self): + """Value to be written to the device's ctrl_meas register """ + ctrl_meas = self.overscan_temperature << 5 + ctrl_meas += self.overscan_pressure << 2 + ctrl_meas += self.mode + return ctrl_meas + + @property + def temperature(self): + """The compensated temperature in degrees Celsius.""" + self._read_temperature() + return self._t_fine / 5120.0 + + @property + def pressure(self): + """ + The compensated pressure in hectoPascals. + returns None if pressure measurement is disabled + """ + self._read_temperature() + + # Algorithm from the BME280 driver + # https://github.com/BoschSensortec/BME280_driver/blob/master/bme280.c + adc = ( + self._read24(_BME280_REGISTER_PRESSUREDATA) / 16 + ) # lowest 4 bits get dropped + var1 = float(self._t_fine) / 2.0 - 64000.0 + var2 = var1 * var1 * self._pressure_calib[5] / 32768.0 + var2 = var2 + var1 * self._pressure_calib[4] * 2.0 + var2 = var2 / 4.0 + self._pressure_calib[3] * 65536.0 + var3 = self._pressure_calib[2] * var1 * var1 / 524288.0 + var1 = (var3 + self._pressure_calib[1] * var1) / 524288.0 + var1 = (1.0 + var1 / 32768.0) * self._pressure_calib[0] + if not var1: # avoid exception caused by division by zero + raise ArithmeticError( + "Invalid result possibly related to error while reading the calibration registers" + ) + pressure = 1048576.0 - adc + pressure = ((pressure - var2 / 4096.0) * 6250.0) / var1 + var1 = self._pressure_calib[8] * pressure * pressure / 2147483648.0 + var2 = pressure * self._pressure_calib[7] / 32768.0 + pressure = pressure + (var1 + var2 + self._pressure_calib[6]) / 16.0 + + pressure /= 100 + return pressure + + @property + def relative_humidity(self): + """ + The relative humidity in RH % + returns None if humidity measurement is disabled + """ + return self.humidity + + @property + def humidity(self): + """ + The relative humidity in RH % + returns None if humidity measurement is disabled + """ + self._read_temperature() + hum = self._read_register(_BME280_REGISTER_HUMIDDATA, 2) + adc = float(hum[0] << 8 | hum[1]) + + # Algorithm from the BME280 driver + # https://github.com/BoschSensortec/BME280_driver/blob/master/bme280.c + var1 = float(self._t_fine) - 76800.0 + var2 = ( + self._humidity_calib[3] * 64.0 + (self._humidity_calib[4] / 16384.0) * var1 + ) + var3 = adc - var2 + var4 = self._humidity_calib[1] / 65536.0 + var5 = 1.0 + (self._humidity_calib[2] / 67108864.0) * var1 + var6 = 1.0 + (self._humidity_calib[5] / 67108864.0) * var1 * var5 + var6 = var3 * var4 * (var5 * var6) + humidity = var6 * (1.0 - self._humidity_calib[0] * var6 / 524288.0) + + if humidity > _BME280_HUMIDITY_MAX: + return _BME280_HUMIDITY_MAX + if humidity < _BME280_HUMIDITY_MIN: + return _BME280_HUMIDITY_MIN + # else... + return humidity + + @property + def altitude(self): + """The altitude based on current ``pressure`` versus the sea level pressure + (``sea_level_pressure``) - which you must enter ahead of time)""" + pressure = self.pressure # in Si units for hPascal + return 44330 * (1.0 - math.pow(pressure / self.sea_level_pressure, 0.1903)) + + def _read_coefficients(self): + """Read & save the calibration coefficients""" + coeff = self._read_register(_BME280_REGISTER_DIG_T1, 24) + coeff = list(struct.unpack("> 4)) + self._humidity_calib[5] = float(coeff[5]) + + def _read_byte(self, register): + """Read a byte register value and return it""" + return self._read_register(register, 1)[0] + + def _read24(self, register): + """Read an unsigned 24-bit value as a floating point and return it.""" + ret = 0.0 + for b in self._read_register(register, 3): + ret *= 256.0 + ret += float(b & 0xFF) + return ret + + def _read_register(self, register, length): + raise NotImplementedError() + + def _write_register_byte(self, register, value): + raise NotImplementedError() + + +class Adafruit_BME280_I2C(Adafruit_BME280): + def __init__(self, i2c, address=_BME280_ADDRESS): + import adafruit_bus_device.i2c_device as i2c_device # pylint: disable=import-outside-toplevel + + self._i2c = i2c_device.I2CDevice(i2c, address) + super().__init__() + + def _read_register(self, register, length): + with self._i2c as i2c: + i2c.write(bytes([register & 0xFF])) + result = bytearray(length) + i2c.readinto(result) + # print("$%02X => %s" % (register, [hex(i) for i in result])) + return result + + def _write_register_byte(self, register, value): + with self._i2c as i2c: + i2c.write(bytes([register & 0xFF, value & 0xFF])) + # print("$%02X <= 0x%02X" % (register, value)) + + +class Adafruit_BME280_SPI(Adafruit_BME280): + + def __init__(self, spi, cs, baudrate=100000): + import adafruit_bus_device.spi_device as spi_device # pylint: disable=import-outside-toplevel + + self._spi = spi_device.SPIDevice(spi, cs, baudrate=baudrate) + super().__init__() + + def _read_register(self, register, length): + register = (register | 0x80) & 0xFF # Read single, bit 7 high. + with self._spi as spi: + spi.write(bytearray([register])) # pylint: disable=no-member + result = bytearray(length) + spi.readinto(result) # pylint: disable=no-member + return result + + def _write_register_byte(self, register, value): + register &= 0x7F # Write, bit 7 low. + with self._spi as spi: + spi.write(bytes([register, value & 0xFF])) # pylint: disable=no-member + From 69c78c5681a69785686200a5fcbab63d38d30fef Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Wed, 26 May 2021 14:45:34 -0400 Subject: [PATCH 056/125] updating_class --- README.rst | 13 +- adafruit_bme280/advanced.py | 243 ++--------------------------- adafruit_bme280/basic.py | 205 ++++++++++++++++-------- docs/api.rst | 6 + examples/bme280_normal_mode.py | 18 +-- examples/bme280_simpletest.py | 6 +- examples/bme280_simpletest_pico.py | 6 +- 7 files changed, 173 insertions(+), 324 deletions(-) diff --git a/README.rst b/README.rst index 134772a..6630553 100644 --- a/README.rst +++ b/README.rst @@ -61,20 +61,11 @@ Usage Example import board import time - import adafruit_bme280 + from adafruit_bme280 import basic # Create sensor object, using the board's default I2C bus. i2c = board.I2C() # uses board.SCL and board.SDA - bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) - #or with other sensor address - #bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76) - - # OR create sensor object, using the board's default SPI bus. - # SPI setup - # from digitalio import DigitalInOut - #spi = board.SPI() - #bme_cs = digitalio.DigitalInOut(board.D10) - #bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs) + bme280 = basic.Adafruit_BME280_I2C(i2c) # change this to match the location's pressure (hPa) at sea level bme280.sea_level_pressure = 1013.25 diff --git a/adafruit_bme280/advanced.py b/adafruit_bme280/advanced.py index 7990d9e..18191de 100644 --- a/adafruit_bme280/advanced.py +++ b/adafruit_bme280/advanced.py @@ -3,13 +3,13 @@ # SPDX-License-Identifier: MIT """ -`adafruit_bme280` +`adafruit_bme280.advanced` ========================================================================================= CircuitPython driver from BME280 Temperature, Humidity and Barometric Pressure sensor -* Author(s): ladyada +* Author(s): ladyada, Jose David M. Implementation Notes -------------------- @@ -29,15 +29,8 @@ https://github.com/adafruit/Adafruit_CircuitPython_BusDevice """ -import math -from time import sleep from micropython import const - -try: - import struct -except ImportError: - import ustruct as struct - +from adafruit_bme280.basic import Adafruit_BME280 __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BME280.git" @@ -131,7 +124,7 @@ ) -class Adafruit_BME280: +class Adafruit_BME280_Advanced(Adafruit_BME280): """Driver from BME280 Temperature, Humidity and Barometric Pressure sensor .. note:: @@ -143,96 +136,12 @@ class Adafruit_BME280: # pylint: disable=too-many-instance-attributes def __init__(self): """Check the BME280 was found, read the coefficients and enable the sensor""" - # Check device ID. - chip_id = self._read_byte(_BME280_REGISTER_CHIPID) - if _BME280_CHIPID != chip_id: - raise RuntimeError("Failed to find BME280! Chip ID 0x%x" % chip_id) - # Set some reasonable defaults. - self._iir_filter = IIR_FILTER_DISABLE self._overscan_humidity = OVERSCAN_X1 self._overscan_temperature = OVERSCAN_X1 self._overscan_pressure = OVERSCAN_X16 - self._t_standby = STANDBY_TC_125 self._mode = MODE_SLEEP - self._reset() - self._read_coefficients() - self._write_ctrl_meas() - self._write_config() - self.sea_level_pressure = 1013.25 - """Pressure in hectoPascals at sea level. Used to calibrate `altitude`.""" - self._t_fine = None - - def _read_temperature(self): - # perform one measurement - if self.mode != MODE_NORMAL: - self.mode = MODE_FORCE - # Wait for conversion to complete - while self._get_status() & 0x08: - sleep(0.002) - raw_temperature = ( - self._read24(_BME280_REGISTER_TEMPDATA) / 16 - ) # lowest 4 bits get dropped - # print("raw temp: ", UT) - var1 = ( - raw_temperature / 16384.0 - self._temp_calib[0] / 1024.0 - ) * self._temp_calib[1] - # print(var1) - var2 = ( - (raw_temperature / 131072.0 - self._temp_calib[0] / 8192.0) - * (raw_temperature / 131072.0 - self._temp_calib[0] / 8192.0) - ) * self._temp_calib[2] - # print(var2) - - self._t_fine = int(var1 + var2) - # print("t_fine: ", self.t_fine) - - def _reset(self): - """Soft reset the sensor""" - self._write_register_byte(_BME280_REGISTER_SOFTRESET, 0xB6) - sleep(0.004) # Datasheet says 2ms. Using 4ms just to be safe - - def _write_ctrl_meas(self): - """ - Write the values to the ctrl_meas and ctrl_hum registers in the device - ctrl_meas sets the pressure and temperature data acquisition options - ctrl_hum sets the humidity oversampling and must be written to first - """ - self._write_register_byte(_BME280_REGISTER_CTRL_HUM, self.overscan_humidity) - self._write_register_byte(_BME280_REGISTER_CTRL_MEAS, self._ctrl_meas) - - def _get_status(self): - """Get the value from the status register in the device """ - return self._read_byte(_BME280_REGISTER_STATUS) - - def _read_config(self): - """Read the value from the config register in the device """ - return self._read_byte(_BME280_REGISTER_CONFIG) - - def _write_config(self): - """Write the value to the config register in the device """ - normal_flag = False - if self._mode == MODE_NORMAL: - # Writes to the config register may be ignored while in Normal mode - normal_flag = True - self.mode = MODE_SLEEP # So we switch to Sleep mode first - self._write_register_byte(_BME280_REGISTER_CONFIG, self._config) - if normal_flag: - self.mode = MODE_NORMAL - - @property - def mode(self): - """ - Operation mode - Allowed values are the constants MODE_* - """ - return self._mode - - @mode.setter - def mode(self, value): - if not value in _BME280_MODES: - raise ValueError("Mode '%s' not supported" % (value)) - self._mode = value - self._write_ctrl_meas() + self._t_standby = STANDBY_TC_125 + super().__init__() @property def standby_period(self): @@ -353,136 +262,8 @@ def measurement_time_max(self): meas_time_ms += 2.3 * _BME280_OVERSCANS.get(self.overscan_humidity) + 0.575 return meas_time_ms - @property - def temperature(self): - """The compensated temperature in degrees Celsius.""" - self._read_temperature() - return self._t_fine / 5120.0 - - @property - def pressure(self): - """ - The compensated pressure in hectoPascals. - returns None if pressure measurement is disabled - """ - self._read_temperature() - - # Algorithm from the BME280 driver - # https://github.com/BoschSensortec/BME280_driver/blob/master/bme280.c - adc = ( - self._read24(_BME280_REGISTER_PRESSUREDATA) / 16 - ) # lowest 4 bits get dropped - var1 = float(self._t_fine) / 2.0 - 64000.0 - var2 = var1 * var1 * self._pressure_calib[5] / 32768.0 - var2 = var2 + var1 * self._pressure_calib[4] * 2.0 - var2 = var2 / 4.0 + self._pressure_calib[3] * 65536.0 - var3 = self._pressure_calib[2] * var1 * var1 / 524288.0 - var1 = (var3 + self._pressure_calib[1] * var1) / 524288.0 - var1 = (1.0 + var1 / 32768.0) * self._pressure_calib[0] - if not var1: # avoid exception caused by division by zero - raise ArithmeticError( - "Invalid result possibly related to error while reading the calibration registers" - ) - pressure = 1048576.0 - adc - pressure = ((pressure - var2 / 4096.0) * 6250.0) / var1 - var1 = self._pressure_calib[8] * pressure * pressure / 2147483648.0 - var2 = pressure * self._pressure_calib[7] / 32768.0 - pressure = pressure + (var1 + var2 + self._pressure_calib[6]) / 16.0 - - pressure /= 100 - return pressure - - @property - def relative_humidity(self): - """ - The relative humidity in RH % - returns None if humidity measurement is disabled - """ - return self.humidity - - @property - def humidity(self): - """ - The relative humidity in RH % - returns None if humidity measurement is disabled - """ - self._read_temperature() - hum = self._read_register(_BME280_REGISTER_HUMIDDATA, 2) - # print("Humidity data: ", hum) - adc = float(hum[0] << 8 | hum[1]) - # print("adc:", adc) - - # Algorithm from the BME280 driver - # https://github.com/BoschSensortec/BME280_driver/blob/master/bme280.c - var1 = float(self._t_fine) - 76800.0 - # print("var1 ", var1) - var2 = ( - self._humidity_calib[3] * 64.0 + (self._humidity_calib[4] / 16384.0) * var1 - ) - # print("var2 ",var2) - var3 = adc - var2 - # print("var3 ",var3) - var4 = self._humidity_calib[1] / 65536.0 - # print("var4 ",var4) - var5 = 1.0 + (self._humidity_calib[2] / 67108864.0) * var1 - # print("var5 ",var5) - var6 = 1.0 + (self._humidity_calib[5] / 67108864.0) * var1 * var5 - # print("var6 ",var6) - var6 = var3 * var4 * (var5 * var6) - humidity = var6 * (1.0 - self._humidity_calib[0] * var6 / 524288.0) - - if humidity > _BME280_HUMIDITY_MAX: - return _BME280_HUMIDITY_MAX - if humidity < _BME280_HUMIDITY_MIN: - return _BME280_HUMIDITY_MIN - # else... - return humidity - - @property - def altitude(self): - """The altitude based on current ``pressure`` versus the sea level pressure - (``sea_level_pressure``) - which you must enter ahead of time)""" - pressure = self.pressure # in Si units for hPascal - return 44330 * (1.0 - math.pow(pressure / self.sea_level_pressure, 0.1903)) - - def _read_coefficients(self): - """Read & save the calibration coefficients""" - coeff = self._read_register(_BME280_REGISTER_DIG_T1, 24) - coeff = list(struct.unpack("> 4)) - self._humidity_calib[5] = float(coeff[5]) - - def _read_byte(self, register): - """Read a byte register value and return it""" - return self._read_register(register, 1)[0] - - def _read24(self, register): - """Read an unsigned 24-bit value as a floating point and return it.""" - ret = 0.0 - for b in self._read_register(register, 3): - ret *= 256.0 - ret += float(b & 0xFF) - return ret - - def _read_register(self, register, length): - raise NotImplementedError() - - def _write_register_byte(self, register, value): - raise NotImplementedError() - -class Adafruit_BME280_I2C(Adafruit_BME280): +class Adafruit_BME280_I2C(Adafruit_BME280_Advanced): """Driver for BME280 connected over I2C :param ~busio.I2C i2c: The I2C bus the BME280 is connected to. @@ -501,14 +282,14 @@ class Adafruit_BME280_I2C(Adafruit_BME280): .. code-block:: python import board - import adafruit_bme280 + from adafruit_bme280 import advanced Once this is done you can define your `board.I2C` object and define your sensor object .. code-block:: python i2c = board.I2C() # uses board.SCL and board.SDA - bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) + bme280 = advanced.Adafruit_BME280_I2C(i2c) You need to setup the pressure at sea level @@ -548,7 +329,7 @@ def _write_register_byte(self, register, value): # print("$%02X <= 0x%02X" % (register, value)) -class Adafruit_BME280_SPI(Adafruit_BME280): +class Adafruit_BME280_SPI(Adafruit_BME280_Advanced): """Driver for BME280 connected over SPI :param ~busio.SPI spi: SPI device @@ -568,7 +349,7 @@ class Adafruit_BME280_SPI(Adafruit_BME280): import board from digitalio import DigitalInOut - import adafruit_bme280 + from adafruit_bme280 import advanced Once this is done you can define your `board.SPI` object and define your sensor object @@ -576,7 +357,7 @@ class Adafruit_BME280_SPI(Adafruit_BME280): cs = digitalio.DigitalInOut(board.D10) spi = board.SPI() - bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, cs) + bme280 = advanced.Adafruit_BME280_SPI(spi, cs) You need to setup the pressure at sea level diff --git a/adafruit_bme280/basic.py b/adafruit_bme280/basic.py index 3aae496..5dd52d2 100644 --- a/adafruit_bme280/basic.py +++ b/adafruit_bme280/basic.py @@ -3,13 +3,13 @@ # SPDX-License-Identifier: MIT """ -`adafruit_bme280` +`adafruit_bme280.basic` ========================================================================================= CircuitPython driver from BME280 Temperature, Humidity and Barometric Pressure sensor -* Author(s): ladyada +* Author(s): ladyada, Jose David M. Implementation Notes -------------------- @@ -44,65 +44,42 @@ # I2C ADDRESS/BITS/SETTINGS # ----------------------------------------------------------------------- + +"""General Information""" _BME280_ADDRESS = const(0x77) _BME280_CHIPID = const(0x60) - _BME280_REGISTER_CHIPID = const(0xD0) -_BME280_REGISTER_DIG_T1 = const(0x88) -_BME280_REGISTER_DIG_H1 = const(0xA1) -_BME280_REGISTER_DIG_H2 = const(0xE1) -_BME280_REGISTER_DIG_H3 = const(0xE3) -_BME280_REGISTER_DIG_H4 = const(0xE4) -_BME280_REGISTER_DIG_H5 = const(0xE5) -_BME280_REGISTER_DIG_H6 = const(0xE7) - -_BME280_REGISTER_SOFTRESET = const(0xE0) -_BME280_REGISTER_CTRL_HUM = const(0xF2) -_BME280_REGISTER_STATUS = const(0xF3) -_BME280_REGISTER_CTRL_MEAS = const(0xF4) -_BME280_REGISTER_CONFIG = const(0xF5) -_BME280_REGISTER_PRESSUREDATA = const(0xF7) -_BME280_REGISTER_TEMPDATA = const(0xFA) -_BME280_REGISTER_HUMIDDATA = const(0xFD) - -_BME280_HUMIDITY_MIN = const(0) -_BME280_HUMIDITY_MAX = const(100) - -"""iir_filter values""" -IIR_FILTER_DISABLE = const(0) - """overscan values for temperature, pressure, and humidity""" -OVERSCAN_DISABLE = const(0x00) OVERSCAN_X1 = const(0x01) -OVERSCAN_X2 = const(0x02) -OVERSCAN_X4 = const(0x03) -OVERSCAN_X8 = const(0x04) OVERSCAN_X16 = const(0x05) - -_BME280_OVERSCANS = { - OVERSCAN_DISABLE: 0, - OVERSCAN_X1: 1, - OVERSCAN_X2: 2, - OVERSCAN_X4: 4, - OVERSCAN_X8: 8, - OVERSCAN_X16: 16, -} - +"""mode values""" +_BME280_MODES = (0x00, 0x01, 0x03) +"""iir_filter values""" +IIR_FILTER_DISABLE = const(0) +""" +standby timeconstant values +TC_X[_Y] where X=milliseconds and Y=tenths of a millisecond +""" +STANDBY_TC_125 = const(0x02) # 125ms """mode values""" MODE_SLEEP = const(0x00) MODE_FORCE = const(0x01) MODE_NORMAL = const(0x03) - -_BME280_MODES = (MODE_SLEEP, MODE_FORCE, MODE_NORMAL) - -STANDBY_TC_125 = const(0x02) # 125ms +"""Other Registers""" +_BME280_REGISTER_SOFTRESET = const(0xE0) +_BME280_REGISTER_CTRL_HUM = const(0xF2) +_BME280_REGISTER_STATUS = const(0xF3) +_BME280_REGISTER_CTRL_MEAS = const(0xF4) +_BME280_REGISTER_CONFIG = const(0xF5) +_BME280_REGISTER_TEMPDATA = const(0xFA) +_BME280_REGISTER_HUMIDDATA = const(0xFD) class Adafruit_BME280: """Driver from BME280 Temperature, Humidity and Barometric Pressure sensor .. note:: - The operational range of the BMP280 is 300-1100 hPa. + The operational range of the BME280 is 300-1100 hPa. Pressure measurements outside this range may not be as accurate. """ @@ -116,8 +93,8 @@ def __init__(self): raise RuntimeError("Failed to find BME280! Chip ID 0x%x" % chip_id) # Set some reasonable defaults. self._iir_filter = IIR_FILTER_DISABLE - self.overscan_humidity = 1 - self.overscan_temperature = 1 + self.overscan_humidity = OVERSCAN_X1 + self.overscan_temperature = OVERSCAN_X1 self.overscan_pressure = OVERSCAN_X16 self._t_standby = STANDBY_TC_125 self._mode = MODE_SLEEP @@ -139,19 +116,17 @@ def _read_temperature(self): raw_temperature = ( self._read24(_BME280_REGISTER_TEMPDATA) / 16 ) # lowest 4 bits get dropped - # print("raw temp: ", UT) + var1 = ( raw_temperature / 16384.0 - self._temp_calib[0] / 1024.0 ) * self._temp_calib[1] - # print(var1) + var2 = ( (raw_temperature / 131072.0 - self._temp_calib[0] / 8192.0) * (raw_temperature / 131072.0 - self._temp_calib[0] / 8192.0) ) * self._temp_calib[2] - # print(var2) self._t_fine = int(var1 + var2) - # print("t_fine: ", self.t_fine) def _reset(self): """Soft reset the sensor""" @@ -164,7 +139,6 @@ def _write_ctrl_meas(self): ctrl_meas sets the pressure and temperature data acquisition options ctrl_hum sets the humidity oversampling and must be written to first """ - self._write_register_byte(_BME280_REGISTER_CTRL_HUM, self.overscan_humidity) self._write_register_byte(_BME280_REGISTER_CTRL_MEAS, self._ctrl_meas) @@ -178,8 +152,14 @@ def _read_config(self): def _write_config(self): """Write the value to the config register in the device """ - + normal_flag = False + if self._mode == MODE_NORMAL: + # Writes to the config register may be ignored while in Normal mode + normal_flag = True + self.mode = MODE_SLEEP # So we switch to Sleep mode first self._write_register_byte(_BME280_REGISTER_CONFIG, self._config) + if normal_flag: + self.mode = MODE_NORMAL @property def mode(self): @@ -200,7 +180,7 @@ def mode(self, value): def _config(self): """Value to be written to the device's config register """ config = 0 - if self.mode == MODE_NORMAL: + if self.mode == 0x03: # MODE_NORMAL config += self._t_standby << 5 if self._iir_filter: config += self._iir_filter << 2 @@ -231,7 +211,7 @@ def pressure(self): # Algorithm from the BME280 driver # https://github.com/BoschSensortec/BME280_driver/blob/master/bme280.c adc = ( - self._read24(_BME280_REGISTER_PRESSUREDATA) / 16 + self._read24(0xF7) / 16 # BME280_REGISTER_PRESSUREDATA ) # lowest 4 bits get dropped var1 = float(self._t_fine) / 2.0 - 64000.0 var2 = var1 * var1 * self._pressure_calib[5] / 32768.0 @@ -268,7 +248,7 @@ def humidity(self): returns None if humidity measurement is disabled """ self._read_temperature() - hum = self._read_register(_BME280_REGISTER_HUMIDDATA, 2) + hum = self._read_register(0xFD, 2) # BME280_REGISTER_HUMIDDATA adc = float(hum[0] << 8 | hum[1]) # Algorithm from the BME280 driver @@ -284,31 +264,31 @@ def humidity(self): var6 = var3 * var4 * (var5 * var6) humidity = var6 * (1.0 - self._humidity_calib[0] * var6 / 524288.0) - if humidity > _BME280_HUMIDITY_MAX: - return _BME280_HUMIDITY_MAX - if humidity < _BME280_HUMIDITY_MIN: - return _BME280_HUMIDITY_MIN + if humidity > 100: + return 100 + if humidity < 0: + return 0 # else... return humidity @property def altitude(self): - """The altitude based on current ``pressure`` versus the sea level pressure + """The altitude based on current :attr:`pressure` versus the sea level pressure (``sea_level_pressure``) - which you must enter ahead of time)""" pressure = self.pressure # in Si units for hPascal return 44330 * (1.0 - math.pow(pressure / self.sea_level_pressure, 0.1903)) def _read_coefficients(self): """Read & save the calibration coefficients""" - coeff = self._read_register(_BME280_REGISTER_DIG_T1, 24) + coeff = self._read_register(0x88, 24) # BME280_REGISTER_DIG_T1 coeff = list(struct.unpack(" %s" % (register, [hex(i) for i in result])) return result def _write_register_byte(self, register, value): @@ -358,6 +383,53 @@ def _write_register_byte(self, register, value): class Adafruit_BME280_SPI(Adafruit_BME280): + """Driver for BME280 connected over SPI + + :param ~busio.SPI spi: SPI device + :param ~digitalio.DigitalInOut cs: Chip Select + :param int baudrate: Clock rate, default is 100000. Can be changed with :meth:`baudrate` + + .. note:: + The operational range of the BMP280 is 300-1100 hPa. + Pressure measurements outside this range may not be as accurate. + + **Quickstart: Importing and using the BME280** + + Here is an example of using the :class:`Adafruit_BME280_SPI` class. + First you will need to import the libraries to use the sensor + + .. code-block:: python + + import board + from digitalio import DigitalInOut + from adafruit_bme280 import basic + + Once this is done you can define your `board.SPI` object and define your sensor object + + .. code-block:: python + + cs = digitalio.DigitalInOut(board.D10) + spi = board.SPI() + bme280 = basic.Adafruit_BME280_SPI(spi, cs) + + You need to setup the pressure at sea level + + .. code-block:: python + + bme280.sea_level_pressure = 1013.25 + + Now you have access to the :attr:`temperature`, :attr:`relative_humidity` + :attr:`pressure` and :attr:`altitude` attributes + + .. code-block:: python + + temperature = bme280.temperature + relative_humidity = bme280.relative_humidity + pressure = bme280.pressure + altitude = bme280.altitude + + """ + def __init__(self, spi, cs, baudrate=100000): import adafruit_bus_device.spi_device as spi_device # pylint: disable=import-outside-toplevel @@ -376,4 +448,3 @@ def _write_register_byte(self, register, value): register &= 0x7F # Write, bit 7 low. with self._spi as spi: spi.write(bytes([register, value & 0xFF])) # pylint: disable=no-member - diff --git a/docs/api.rst b/docs/api.rst index 0622224..8818b61 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -3,3 +3,9 @@ .. automodule:: adafruit_bme280 :members: + +.. automodule:: adafruit_bme280.basic + :members: + +.. automodule:: adafruit_bme280.advanced + :members: diff --git a/examples/bme280_normal_mode.py b/examples/bme280_normal_mode.py index c5f1dd2..53a3f9e 100644 --- a/examples/bme280_normal_mode.py +++ b/examples/bme280_normal_mode.py @@ -8,27 +8,27 @@ """ import time import board -import adafruit_bme280 +from adafruit_bme280 import advanced # Create sensor object, using the board's default I2C bus. i2c = board.I2C() # uses board.SCL and board.SDA -bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) +bme280 = advanced.Adafruit_BME280_I2C(i2c) # OR create sensor object, using the board's default SPI bus. # SPI setup # from digitalio import DigitalInOut # spi = board.SPI() # bme_cs = digitalio.DigitalInOut(board.D10) -# bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs) +# bme280 = advanced.Adafruit_BME280_SPI(spi, bme_cs) # Change this to match the location's pressure (hPa) at sea level bme280.sea_level_pressure = 1013.25 -bme280.mode = adafruit_bme280.MODE_NORMAL -bme280.standby_period = adafruit_bme280.STANDBY_TC_500 -bme280.iir_filter = adafruit_bme280.IIR_FILTER_X16 -bme280.overscan_pressure = adafruit_bme280.OVERSCAN_X16 -bme280.overscan_humidity = adafruit_bme280.OVERSCAN_X1 -bme280.overscan_temperature = adafruit_bme280.OVERSCAN_X2 +bme280.mode = advanced.MODE_NORMAL +bme280.standby_period = advanced.STANDBY_TC_500 +bme280.iir_filter = advanced.IIR_FILTER_X16 +bme280.overscan_pressure = advanced.OVERSCAN_X16 +bme280.overscan_humidity = advanced.OVERSCAN_X1 +bme280.overscan_temperature = advanced.OVERSCAN_X2 # The sensor will need a moment to gather initial readings time.sleep(1) diff --git a/examples/bme280_simpletest.py b/examples/bme280_simpletest.py index d653584..285b7e0 100644 --- a/examples/bme280_simpletest.py +++ b/examples/bme280_simpletest.py @@ -3,16 +3,16 @@ import time import board -import adafruit_bme280 +from adafruit_bme280 import basic # Create sensor object, using the board's default I2C bus. i2c = board.I2C() # uses board.SCL and board.SDA -bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) +bme280 = basic.Adafruit_BME280_I2C(i2c) # OR create sensor object, using the board's default SPI bus. # spi = board.SPI() # bme_cs = digitalio.DigitalInOut(board.D10) -# bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs) +# bme280 = basic.Adafruit_BME280_SPI(spi, bme_cs) # change this to match the location's pressure (hPa) at sea level bme280.sea_level_pressure = 1013.25 diff --git a/examples/bme280_simpletest_pico.py b/examples/bme280_simpletest_pico.py index d433b44..fdd1fcc 100644 --- a/examples/bme280_simpletest_pico.py +++ b/examples/bme280_simpletest_pico.py @@ -4,16 +4,16 @@ import time import board import busio -import adafruit_bme280 +from adafruit_bme280 import basic # Create sensor object, using the board's default I2C bus. i2c = busio.I2C(board.GP1, board.GP0) # SCL, SDA -bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) +bme280 = basic.Adafruit_BME280_I2C(i2c) # OR create sensor object, using the board's default SPI bus. # spi = busio.SPI(board.GP2, MISO=board.GP0, MOSI=board.GP3) # bme_cs = digitalio.DigitalInOut(board.GP1) -# bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs) +# bme280 = basic.Adafruit_BME280_SPI(spi, bme_cs) # change this to match the location's pressure (hPa) at sea level bme280.sea_level_pressure = 1013.25 From 361109542aa4065760698d5bab01002799473aec Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Wed, 26 May 2021 14:48:37 -0400 Subject: [PATCH 057/125] include init.py --- adafruit_bme280/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 adafruit_bme280/__init__.py diff --git a/adafruit_bme280/__init__.py b/adafruit_bme280/__init__.py new file mode 100644 index 0000000..e69de29 From 3e3e5cf6733a140e3e71de926316e48a596699d4 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Wed, 26 May 2021 14:59:34 -0400 Subject: [PATCH 058/125] pylint ver --- adafruit_bme280/advanced.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_bme280/advanced.py b/adafruit_bme280/advanced.py index 18191de..f774c6e 100644 --- a/adafruit_bme280/advanced.py +++ b/adafruit_bme280/advanced.py @@ -123,7 +123,7 @@ STANDBY_TC_1000, ) - +# pylint: disable=abstract-method class Adafruit_BME280_Advanced(Adafruit_BME280): """Driver from BME280 Temperature, Humidity and Barometric Pressure sensor From 4254c14fd977865ae5c1d7b0aaabfb104920ec45 Mon Sep 17 00:00:00 2001 From: jposada202020 <34255413+jposada202020@users.noreply.github.com> Date: Tue, 1 Jun 2021 19:14:49 -0400 Subject: [PATCH 059/125] Update examples/bme280_normal_mode.py Co-authored-by: Scott Shawcroft --- examples/bme280_normal_mode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/bme280_normal_mode.py b/examples/bme280_normal_mode.py index 53a3f9e..8c7cc6b 100644 --- a/examples/bme280_normal_mode.py +++ b/examples/bme280_normal_mode.py @@ -8,7 +8,7 @@ """ import time import board -from adafruit_bme280 import advanced +import adafruit_bme280.advanced as adafruit_bme280 # Create sensor object, using the board's default I2C bus. i2c = board.I2C() # uses board.SCL and board.SDA From 3f6f12591eabf221b6bf88e3648f9f807988939d Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Wed, 2 Jun 2021 14:10:38 -0400 Subject: [PATCH 060/125] improving_importing_description --- examples/bme280_normal_mode.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/bme280_normal_mode.py b/examples/bme280_normal_mode.py index 8c7cc6b..85dd156 100644 --- a/examples/bme280_normal_mode.py +++ b/examples/bme280_normal_mode.py @@ -12,23 +12,23 @@ # Create sensor object, using the board's default I2C bus. i2c = board.I2C() # uses board.SCL and board.SDA -bme280 = advanced.Adafruit_BME280_I2C(i2c) +bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) # OR create sensor object, using the board's default SPI bus. # SPI setup # from digitalio import DigitalInOut # spi = board.SPI() # bme_cs = digitalio.DigitalInOut(board.D10) -# bme280 = advanced.Adafruit_BME280_SPI(spi, bme_cs) +# bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs) # Change this to match the location's pressure (hPa) at sea level bme280.sea_level_pressure = 1013.25 -bme280.mode = advanced.MODE_NORMAL -bme280.standby_period = advanced.STANDBY_TC_500 -bme280.iir_filter = advanced.IIR_FILTER_X16 -bme280.overscan_pressure = advanced.OVERSCAN_X16 -bme280.overscan_humidity = advanced.OVERSCAN_X1 -bme280.overscan_temperature = advanced.OVERSCAN_X2 +bme280.mode = adafruit_bme280.MODE_NORMAL +bme280.standby_period = adafruit_bme280.STANDBY_TC_500 +bme280.iir_filter = adafruit_bme280.IIR_FILTER_X16 +bme280.overscan_pressure = adafruit_bme280.OVERSCAN_X16 +bme280.overscan_humidity = adafruit_bme280.OVERSCAN_X1 +bme280.overscan_temperature = adafruit_bme280.OVERSCAN_X2 # The sensor will need a moment to gather initial readings time.sleep(1) From 2b0af3c52567a1d8f2d0e02668c4bc5e919e955e Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Wed, 2 Jun 2021 14:24:16 -0400 Subject: [PATCH 061/125] improving_importing_description --- examples/bme280_simpletest.py | 6 +++--- examples/bme280_simpletest_pico.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/bme280_simpletest.py b/examples/bme280_simpletest.py index 285b7e0..2f1c39a 100644 --- a/examples/bme280_simpletest.py +++ b/examples/bme280_simpletest.py @@ -3,16 +3,16 @@ import time import board -from adafruit_bme280 import basic +from adafruit_bme280 import basic as adafruit_bme280 # Create sensor object, using the board's default I2C bus. i2c = board.I2C() # uses board.SCL and board.SDA -bme280 = basic.Adafruit_BME280_I2C(i2c) +bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) # OR create sensor object, using the board's default SPI bus. # spi = board.SPI() # bme_cs = digitalio.DigitalInOut(board.D10) -# bme280 = basic.Adafruit_BME280_SPI(spi, bme_cs) +# bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs) # change this to match the location's pressure (hPa) at sea level bme280.sea_level_pressure = 1013.25 diff --git a/examples/bme280_simpletest_pico.py b/examples/bme280_simpletest_pico.py index fdd1fcc..435e41a 100644 --- a/examples/bme280_simpletest_pico.py +++ b/examples/bme280_simpletest_pico.py @@ -4,16 +4,16 @@ import time import board import busio -from adafruit_bme280 import basic +from adafruit_bme280 import basic as adafruit_bme280 # Create sensor object, using the board's default I2C bus. i2c = busio.I2C(board.GP1, board.GP0) # SCL, SDA -bme280 = basic.Adafruit_BME280_I2C(i2c) +bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) # OR create sensor object, using the board's default SPI bus. # spi = busio.SPI(board.GP2, MISO=board.GP0, MOSI=board.GP3) # bme_cs = digitalio.DigitalInOut(board.GP1) -# bme280 = basic.Adafruit_BME280_SPI(spi, bme_cs) +# bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs) # change this to match the location's pressure (hPa) at sea level bme280.sea_level_pressure = 1013.25 From ccb982df8523c78a95b6aa83d0c717c4704b5dc9 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 7 Jun 2021 14:13:24 -0400 Subject: [PATCH 062/125] Moved default branch to main --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 6630553..9a454bd 100644 --- a/README.rst +++ b/README.rst @@ -81,7 +81,7 @@ Contributing ============ Contributions are welcome! Please read our `Code of Conduct -`_ +`_ before contributing to help this project stay welcoming. Documentation From 898df9d20a5df936c88f6751133f169426117f68 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Thu, 10 Jun 2021 07:35:04 -0400 Subject: [PATCH 063/125] aligning_example_code and adding_library_usage_explanation --- README.rst | 31 +++++++++++++++++++++++++++++-- adafruit_bme280/advanced.py | 8 ++++---- adafruit_bme280/basic.py | 8 ++++---- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/README.rst b/README.rst index 9a454bd..f8f37e4 100644 --- a/README.rst +++ b/README.rst @@ -13,6 +13,10 @@ Introduction :target: https://github.com/adafruit/Adafruit_CircuitPython_BME280/actions/ :alt: Build Status +.. image:: https://img.shields.io/badge/code%20style-black-000000.svg + :target: https://github.com/psf/black + :alt: Code Style: Black + I2C and SPI driver for the Bosch BME280 Temperature, Humidity, and Barometric Pressure sensor Installation and Dependencies @@ -54,6 +58,29 @@ To install in a virtual environment in your current project: source .env/bin/activate pip3 install adafruit-circuitpython-bme280 + +Installing to a connected CircuitPython Device +============================================== +Some devices, eg. the QT-PY, are very limited in memory. The BME280 library contains +two variants - basic and advanced - which give different levels of functionality. + +Installing the BME280 library could have the following outcomes: + + * It installs successfully and your code runs successfully. Woo-hoo! Continue with + your amazing project. + * It installs successfully and your code fails to run with a memory allocation + error. Try one of the following: + + * If your :data:`code.py` is large, especially if it has lots of comments, you + can shrink it into a :data:`.mpy` file instead. See the Adafruit + `Learn Guide `_ + on shrinking your code. + * Only use the basic BME280 implementation, and remove the following file: + :data:`/lib/adafruit_bme280/advanced.mpy` where is the + mounted location of your device. Make sure that your code only uses the basic + implementation. + + Usage Example ============= @@ -61,11 +88,11 @@ Usage Example import board import time - from adafruit_bme280 import basic + from adafruit_bme280 import basic as adafruit_bme280 # Create sensor object, using the board's default I2C bus. i2c = board.I2C() # uses board.SCL and board.SDA - bme280 = basic.Adafruit_BME280_I2C(i2c) + bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) # change this to match the location's pressure (hPa) at sea level bme280.sea_level_pressure = 1013.25 diff --git a/adafruit_bme280/advanced.py b/adafruit_bme280/advanced.py index f774c6e..812d3dc 100644 --- a/adafruit_bme280/advanced.py +++ b/adafruit_bme280/advanced.py @@ -282,14 +282,14 @@ class Adafruit_BME280_I2C(Adafruit_BME280_Advanced): .. code-block:: python import board - from adafruit_bme280 import advanced + import adafruit_bme280.advanced as adafruit_bme280 Once this is done you can define your `board.I2C` object and define your sensor object .. code-block:: python i2c = board.I2C() # uses board.SCL and board.SDA - bme280 = advanced.Adafruit_BME280_I2C(i2c) + bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) You need to setup the pressure at sea level @@ -349,7 +349,7 @@ class Adafruit_BME280_SPI(Adafruit_BME280_Advanced): import board from digitalio import DigitalInOut - from adafruit_bme280 import advanced + import adafruit_bme280.advanced as adafruit_bme280 Once this is done you can define your `board.SPI` object and define your sensor object @@ -357,7 +357,7 @@ class Adafruit_BME280_SPI(Adafruit_BME280_Advanced): cs = digitalio.DigitalInOut(board.D10) spi = board.SPI() - bme280 = advanced.Adafruit_BME280_SPI(spi, cs) + bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, cs) You need to setup the pressure at sea level diff --git a/adafruit_bme280/basic.py b/adafruit_bme280/basic.py index 5dd52d2..0fd3974 100644 --- a/adafruit_bme280/basic.py +++ b/adafruit_bme280/basic.py @@ -335,14 +335,14 @@ class Adafruit_BME280_I2C(Adafruit_BME280): .. code-block:: python import board - from adafruit_bme280 import basic + from adafruit_bme280 import basic as adafruit_bme280 Once this is done you can define your `board.I2C` object and define your sensor object .. code-block:: python i2c = board.I2C() # uses board.SCL and board.SDA - bme280 = basic.Adafruit_BME280_I2C(i2c) + bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) You need to setup the pressure at sea level @@ -402,7 +402,7 @@ class Adafruit_BME280_SPI(Adafruit_BME280): import board from digitalio import DigitalInOut - from adafruit_bme280 import basic + from adafruit_bme280 import basic as adafruit_bme280 Once this is done you can define your `board.SPI` object and define your sensor object @@ -410,7 +410,7 @@ class Adafruit_BME280_SPI(Adafruit_BME280): cs = digitalio.DigitalInOut(board.D10) spi = board.SPI() - bme280 = basic.Adafruit_BME280_SPI(spi, cs) + bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, cs) You need to setup the pressure at sea level From d009170c01e9a656535ec94c2f9fdc28b6c1350e Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Thu, 10 Jun 2021 07:59:16 -0400 Subject: [PATCH 064/125] adding_package_folder --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 54753be..29cc976 100644 --- a/setup.py +++ b/setup.py @@ -52,5 +52,5 @@ keywords="adafruit bme280 sensor hardware micropython circuitpython", # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). - py_modules=["adafruit_bme280"], + packages=["adafruit_bme280"], ) From 138efbfdeccb37b650e8e7e2ba7c92ec1355e754 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Thu, 10 Jun 2021 08:06:04 -0400 Subject: [PATCH 065/125] removing_data_references --- README.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index f8f37e4..eecf6e9 100644 --- a/README.rst +++ b/README.rst @@ -71,12 +71,12 @@ Installing the BME280 library could have the following outcomes: * It installs successfully and your code fails to run with a memory allocation error. Try one of the following: - * If your :data:`code.py` is large, especially if it has lots of comments, you - can shrink it into a :data:`.mpy` file instead. See the Adafruit + * If your ``code.py`` is large, especially if it has lots of comments, you + can shrink it into a ``.mpy`` file instead. See the Adafruit `Learn Guide `_ on shrinking your code. * Only use the basic BME280 implementation, and remove the following file: - :data:`/lib/adafruit_bme280/advanced.mpy` where is the + ``/lib/adafruit_bme280/advanced.mpy`` where is the mounted location of your device. Make sure that your code only uses the basic implementation. From 4c70af933c283999e40f593de99bec527314d389 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 23 Sep 2021 17:52:55 -0400 Subject: [PATCH 066/125] Globally disabled consider-using-f-string pylint check Signed-off-by: dherrada --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 354c761..8810708 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,5 +30,5 @@ repos: name: pylint (examples code) description: Run pylint rules on "examples/*.py" files entry: /usr/bin/env bash -c - args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name $example; done)'] + args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name,consider-using-f-string $example; done)'] language: system From a422b11e54defdb4f56acecd90a4d093cc962ebf Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 25 Oct 2021 11:13:47 -0500 Subject: [PATCH 067/125] add docs link to readme --- README.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.rst b/README.rst index eecf6e9..84dbf6c 100644 --- a/README.rst +++ b/README.rst @@ -104,6 +104,11 @@ Usage Example print("Altitude = %0.2f meters" % bme280.altitude) time.sleep(2) +Documentation +============= + +API documentation for this library can be found on `Read the Docs `_. + Contributing ============ From 6f2bc6d52fc89969b74f4b75c85ee1a4c01fee62 Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 3 Nov 2021 14:40:16 -0400 Subject: [PATCH 068/125] PATCH Pylint and readthedocs patch test Signed-off-by: dherrada --- .github/workflows/build.yml | 4 ++-- .pre-commit-config.yaml | 26 +++++++++++++++++--------- .pylintrc | 2 +- .readthedocs.yml | 2 +- docs/requirements.txt | 5 +++++ 5 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 docs/requirements.txt diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c4c975d..ca35544 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,9 +42,9 @@ jobs: # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) run: | source actions-ci/install.sh - - name: Pip install pylint, Sphinx, pre-commit + - name: Pip install Sphinx, pre-commit run: | - pip install --force-reinstall pylint Sphinx sphinx-rtd-theme pre-commit + pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit - name: Library version run: git describe --dirty --always --tags - name: Pre-commit hooks diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8810708..1b9fadc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,17 +18,25 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: pylint-2.7.1 + rev: v2.11.1 hooks: - id: pylint name: pylint (library code) types: [python] - exclude: "^(docs/|examples/|setup.py$)" -- repo: local - hooks: - - id: pylint_examples - name: pylint (examples code) + args: + - --disable=consider-using-f-string + exclude: "^(docs/|examples/|tests/|setup.py$)" + - id: pylint + name: pylint (example code) description: Run pylint rules on "examples/*.py" files - entry: /usr/bin/env bash -c - args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name,consider-using-f-string $example; done)'] - language: system + types: [python] + files: "^examples/" + args: + - --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code + - id: pylint + name: pylint (test code) + description: Run pylint rules on "tests/*.py" files + types: [python] + files: "^tests/" + args: + - --disable=missing-docstring,consider-using-f-string,duplicate-code diff --git a/.pylintrc b/.pylintrc index 0238b90..e78bad2 100644 --- a/.pylintrc +++ b/.pylintrc @@ -252,7 +252,7 @@ ignore-docstrings=yes ignore-imports=yes # Minimum lines number of a similarity. -min-similarity-lines=12 +min-similarity-lines=4 [BASIC] diff --git a/.readthedocs.yml b/.readthedocs.yml index ffa84c4..49dcab3 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -4,4 +4,4 @@ python: version: 3 -requirements_file: requirements.txt +requirements_file: docs/requirements.txt diff --git a/docs/requirements.txt b/docs/requirements.txt new file mode 100644 index 0000000..88e6733 --- /dev/null +++ b/docs/requirements.txt @@ -0,0 +1,5 @@ +# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + +sphinx>=4.0.0 From b02317a3c1076053361af80e65075f938f768299 Mon Sep 17 00:00:00 2001 From: dherrada Date: Fri, 5 Nov 2021 14:49:30 -0400 Subject: [PATCH 069/125] Disabled unspecified-encoding pylint check Signed-off-by: dherrada --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index e78bad2..cfd1c41 100644 --- a/.pylintrc +++ b/.pylintrc @@ -55,7 +55,7 @@ confidence= # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" # disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call -disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation +disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation,unspecified-encoding # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option From 834df8c05a4300f51cb3592e87f9c4b6653efbe5 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Fri, 5 Nov 2021 16:28:01 -0400 Subject: [PATCH 070/125] Linted. --- .pre-commit-config.yaml | 2 +- adafruit_bme280/advanced.py | 8 ++++++-- adafruit_bme280/basic.py | 8 ++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1b9fadc..43d1385 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,7 +24,7 @@ repos: name: pylint (library code) types: [python] args: - - --disable=consider-using-f-string + - --disable=consider-using-f-string,duplicate-code exclude: "^(docs/|examples/|tests/|setup.py$)" - id: pylint name: pylint (example code) diff --git a/adafruit_bme280/advanced.py b/adafruit_bme280/advanced.py index 812d3dc..3e4852a 100644 --- a/adafruit_bme280/advanced.py +++ b/adafruit_bme280/advanced.py @@ -310,7 +310,9 @@ class Adafruit_BME280_I2C(Adafruit_BME280_Advanced): """ def __init__(self, i2c, address=_BME280_ADDRESS): - import adafruit_bus_device.i2c_device as i2c_device # pylint: disable=import-outside-toplevel + from adafruit_bus_device.i2c_device import ( # pylint: disable=import-outside-toplevel + i2c_device, + ) self._i2c = i2c_device.I2CDevice(i2c, address) super().__init__() @@ -378,7 +380,9 @@ class Adafruit_BME280_SPI(Adafruit_BME280_Advanced): """ def __init__(self, spi, cs, baudrate=100000): - import adafruit_bus_device.spi_device as spi_device # pylint: disable=import-outside-toplevel + from adafruit_bus_device.spi_device import ( # pylint: disable=import-outside-toplevel + spi_device, + ) self._spi = spi_device.SPIDevice(spi, cs, baudrate=baudrate) super().__init__() diff --git a/adafruit_bme280/basic.py b/adafruit_bme280/basic.py index 0fd3974..68a5d85 100644 --- a/adafruit_bme280/basic.py +++ b/adafruit_bme280/basic.py @@ -363,7 +363,9 @@ class Adafruit_BME280_I2C(Adafruit_BME280): """ def __init__(self, i2c, address=0x77): # BME280_ADDRESS - import adafruit_bus_device.i2c_device as i2c_device # pylint: disable=import-outside-toplevel + from adafruit_bus_device.i2c_device import ( # pylint: disable=import-outside-toplevel + i2c_device, + ) self._i2c = i2c_device.I2CDevice(i2c, address) super().__init__() @@ -431,7 +433,9 @@ class Adafruit_BME280_SPI(Adafruit_BME280): """ def __init__(self, spi, cs, baudrate=100000): - import adafruit_bus_device.spi_device as spi_device # pylint: disable=import-outside-toplevel + from adafruit_bus_device.spi_device import ( # pylint: disable=import-outside-toplevel + spi_device, + ) self._spi = spi_device.SPIDevice(spi, cs, baudrate=baudrate) super().__init__() From b685903ed289452eb294fc69bf091492ed5a1804 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Mon, 8 Nov 2021 10:38:58 -0500 Subject: [PATCH 071/125] Switch import style. --- adafruit_bme280/advanced.py | 4 ++-- adafruit_bme280/basic.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/adafruit_bme280/advanced.py b/adafruit_bme280/advanced.py index 3e4852a..ef1175a 100644 --- a/adafruit_bme280/advanced.py +++ b/adafruit_bme280/advanced.py @@ -310,7 +310,7 @@ class Adafruit_BME280_I2C(Adafruit_BME280_Advanced): """ def __init__(self, i2c, address=_BME280_ADDRESS): - from adafruit_bus_device.i2c_device import ( # pylint: disable=import-outside-toplevel + from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel i2c_device, ) @@ -380,7 +380,7 @@ class Adafruit_BME280_SPI(Adafruit_BME280_Advanced): """ def __init__(self, spi, cs, baudrate=100000): - from adafruit_bus_device.spi_device import ( # pylint: disable=import-outside-toplevel + from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel spi_device, ) diff --git a/adafruit_bme280/basic.py b/adafruit_bme280/basic.py index 68a5d85..789f45b 100644 --- a/adafruit_bme280/basic.py +++ b/adafruit_bme280/basic.py @@ -363,7 +363,7 @@ class Adafruit_BME280_I2C(Adafruit_BME280): """ def __init__(self, i2c, address=0x77): # BME280_ADDRESS - from adafruit_bus_device.i2c_device import ( # pylint: disable=import-outside-toplevel + from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel i2c_device, ) @@ -433,7 +433,7 @@ class Adafruit_BME280_SPI(Adafruit_BME280): """ def __init__(self, spi, cs, baudrate=100000): - from adafruit_bus_device.spi_device import ( # pylint: disable=import-outside-toplevel + from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel spi_device, ) From df09368ac814391972f3bff40b9da340fde40ccd Mon Sep 17 00:00:00 2001 From: dherrada Date: Tue, 9 Nov 2021 13:31:14 -0500 Subject: [PATCH 072/125] Updated readthedocs file Signed-off-by: dherrada --- .readthedocs.yaml | 15 +++++++++++++++ .readthedocs.yml | 7 ------- 2 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 .readthedocs.yaml delete mode 100644 .readthedocs.yml diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 0000000..95ec218 --- /dev/null +++ b/.readthedocs.yaml @@ -0,0 +1,15 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details + +# Required +version: 2 + +python: + version: "3.6" + install: + - requirements: docs/requirements.txt + - requirements: requirements.txt diff --git a/.readthedocs.yml b/.readthedocs.yml deleted file mode 100644 index 49dcab3..0000000 --- a/.readthedocs.yml +++ /dev/null @@ -1,7 +0,0 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries -# -# SPDX-License-Identifier: Unlicense - -python: - version: 3 -requirements_file: docs/requirements.txt From 4f4d2a45f5ea79a92c53dbffa6969a5fd1a6dd1d Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 23 Nov 2021 12:59:32 -0600 Subject: [PATCH 073/125] update rtd py version --- .readthedocs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 95ec218..1335112 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -9,7 +9,7 @@ version: 2 python: - version: "3.6" + version: "3.7" install: - requirements: docs/requirements.txt - requirements: requirements.txt From 759282503ff009b52b3358a4e5505c0f90e4c32d Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 22 Dec 2021 09:53:00 -0500 Subject: [PATCH 074/125] Update basic.py --- adafruit_bme280/basic.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/adafruit_bme280/basic.py b/adafruit_bme280/basic.py index 789f45b..67d2eb4 100644 --- a/adafruit_bme280/basic.py +++ b/adafruit_bme280/basic.py @@ -30,14 +30,10 @@ """ import math +import struct from time import sleep -from micropython import const - -try: - import struct -except ImportError: - import ustruct as struct +from micropython import const __version__ = "2.6.4" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BME280.git" From 81fbc80de3b52b3351851d51744c185c70d13de5 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 13 Jan 2022 16:27:30 -0500 Subject: [PATCH 075/125] First part of patch Signed-off-by: dherrada --- .../PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md | 2 +- .github/workflows/build.yml | 6 +++--- .github/workflows/release.yml | 8 ++++---- .readthedocs.yaml | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md b/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md index 71ef8f8..8de294e 100644 --- a/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md +++ b/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md @@ -4,7 +4,7 @@ Thank you for contributing! Before you submit a pull request, please read the following. -Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://circuitpython.readthedocs.io/en/latest/docs/design_guide.html +Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://docs.circuitpython.org/en/latest/docs/design_guide.html If your changes are to documentation, please verify that the documentation builds locally by following the steps found here: https://adafru.it/build-docs diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ca35544..474520d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,10 +22,10 @@ jobs: awk -F '\/' '{ print tolower($2) }' | tr '_' '-' ) - - name: Set up Python 3.7 - uses: actions/setup-python@v1 + - name: Set up Python 3.x + uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: "3.x" - name: Versions run: | python3 --version diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6d0015a..a65e5de 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,10 +24,10 @@ jobs: awk -F '\/' '{ print tolower($2) }' | tr '_' '-' ) - - name: Set up Python 3.6 - uses: actions/setup-python@v1 + - name: Set up Python 3.x + uses: actions/setup-python@v2 with: - python-version: 3.6 + python-version: "3.x" - name: Versions run: | python3 --version @@ -67,7 +67,7 @@ jobs: echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) - name: Set up Python if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') - uses: actions/setup-python@v1 + uses: actions/setup-python@v2 with: python-version: '3.x' - name: Install dependencies diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 1335112..f8b2891 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -9,7 +9,7 @@ version: 2 python: - version: "3.7" + version: "3.x" install: - requirements: docs/requirements.txt - requirements: requirements.txt From 911b0d3aa80fc8af0ea0c6b94d017c471e9de0e8 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 24 Jan 2022 16:46:16 -0500 Subject: [PATCH 076/125] Updated docs link, updated python docs link, updated setup.py --- README.rst | 4 ++-- docs/conf.py | 6 +++--- docs/index.rst | 2 +- setup.py | 2 -- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index 84dbf6c..28d389c 100644 --- a/README.rst +++ b/README.rst @@ -2,7 +2,7 @@ Introduction ============ .. image:: https://readthedocs.org/projects/adafruit-circuitpython-bme280/badge/?version=latest - :target: https://circuitpython.readthedocs.io/projects/bme280/en/latest/ + :target: https://docs.circuitpython.org/projects/bme280/en/latest/ :alt: Documentation Status .. image :: https://img.shields.io/discord/327254708534116352.svg @@ -107,7 +107,7 @@ Usage Example Documentation ============= -API documentation for this library can be found on `Read the Docs `_. +API documentation for this library can be found on `Read the Docs `_. Contributing ============ diff --git a/docs/conf.py b/docs/conf.py index f151910..7c8402a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -22,12 +22,12 @@ # API docs fix intersphinx_mapping = { - "python": ("https://docs.python.org/3.4", None), + "python": ("https://docs.python.org/3", None), "BusDevice": ( - "https://circuitpython.readthedocs.io/projects/busdevice/en/latest/", + "https://docs.circuitpython.org/projects/busdevice/en/latest/", None, ), - "CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None), + "CircuitPython": ("https://docs.circuitpython.org/en/latest/", None), } # Add any paths that contain templates here, relative to this directory. diff --git a/docs/index.rst b/docs/index.rst index 62fb9df..273625f 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -34,7 +34,7 @@ Table of Contents :caption: Other Links Download - CircuitPython Reference Documentation + CircuitPython Reference Documentation CircuitPython Support Forum Discord Chat Adafruit Learning System diff --git a/setup.py b/setup.py index 29cc976..f5cd961 100644 --- a/setup.py +++ b/setup.py @@ -45,8 +45,6 @@ "Topic :: System :: Hardware", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.4", - "Programming Language :: Python :: 3.5", ], # What does your project relate to? keywords="adafruit bme280 sensor hardware micropython circuitpython", From e1ca735b034b540821ec4657d90f77d7d49d4d80 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Wed, 9 Feb 2022 12:41:40 -0500 Subject: [PATCH 077/125] Consolidate Documentation sections of README --- README.rst | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 28d389c..b07377e 100644 --- a/README.rst +++ b/README.rst @@ -109,14 +109,11 @@ Documentation API documentation for this library can be found on `Read the Docs `_. +For information on building library documentation, please check out `this guide `_. + Contributing ============ Contributions are welcome! Please read our `Code of Conduct `_ before contributing to help this project stay welcoming. - -Documentation -============= - -For information on building library documentation, please check out `this guide `_. From 62524808fc9429799be4cced89aa7df5ad7604ec Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sun, 13 Feb 2022 16:21:22 -0500 Subject: [PATCH 078/125] Add type annotations for basic.py --- adafruit_bme280/basic.py | 61 ++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/adafruit_bme280/basic.py b/adafruit_bme280/basic.py index 67d2eb4..fffab39 100644 --- a/adafruit_bme280/basic.py +++ b/adafruit_bme280/basic.py @@ -35,6 +35,13 @@ from micropython import const +try: + from typing import Optional + from busio import I2C, SPI + from digitalio import DigitalInOut +except ImportError: + pass + __version__ = "2.6.4" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BME280.git" @@ -81,7 +88,7 @@ class Adafruit_BME280: """ # pylint: disable=too-many-instance-attributes - def __init__(self): + def __init__(self) -> None: """Check the BME280 was found, read the coefficients and enable the sensor""" # Check device ID. chip_id = self._read_byte(_BME280_REGISTER_CHIPID) @@ -102,7 +109,7 @@ def __init__(self): """Pressure in hectoPascals at sea level. Used to calibrate `altitude`.""" self._t_fine = None - def _read_temperature(self): + def _read_temperature(self) -> None: # perform one measurement if self.mode != MODE_NORMAL: self.mode = MODE_FORCE @@ -124,12 +131,12 @@ def _read_temperature(self): self._t_fine = int(var1 + var2) - def _reset(self): + def _reset(self) -> None: """Soft reset the sensor""" self._write_register_byte(_BME280_REGISTER_SOFTRESET, 0xB6) sleep(0.004) # Datasheet says 2ms. Using 4ms just to be safe - def _write_ctrl_meas(self): + def _write_ctrl_meas(self) -> None: """ Write the values to the ctrl_meas and ctrl_hum registers in the device ctrl_meas sets the pressure and temperature data acquisition options @@ -138,15 +145,15 @@ def _write_ctrl_meas(self): self._write_register_byte(_BME280_REGISTER_CTRL_HUM, self.overscan_humidity) self._write_register_byte(_BME280_REGISTER_CTRL_MEAS, self._ctrl_meas) - def _get_status(self): + def _get_status(self) -> int: """Get the value from the status register in the device """ return self._read_byte(_BME280_REGISTER_STATUS) - def _read_config(self): + def _read_config(self) -> int: """Read the value from the config register in the device """ return self._read_byte(_BME280_REGISTER_CONFIG) - def _write_config(self): + def _write_config(self) -> None: """Write the value to the config register in the device """ normal_flag = False if self._mode == MODE_NORMAL: @@ -158,7 +165,7 @@ def _write_config(self): self.mode = MODE_NORMAL @property - def mode(self): + def mode(self) -> int: """ Operation mode Allowed values are the constants MODE_* @@ -166,14 +173,14 @@ def mode(self): return self._mode @mode.setter - def mode(self, value): + def mode(self, value: int) -> None: if not value in _BME280_MODES: raise ValueError("Mode '%s' not supported" % (value)) self._mode = value self._write_ctrl_meas() @property - def _config(self): + def _config(self) -> int: """Value to be written to the device's config register """ config = 0 if self.mode == 0x03: # MODE_NORMAL @@ -183,7 +190,7 @@ def _config(self): return config @property - def _ctrl_meas(self): + def _ctrl_meas(self) -> int: """Value to be written to the device's ctrl_meas register """ ctrl_meas = self.overscan_temperature << 5 ctrl_meas += self.overscan_pressure << 2 @@ -191,13 +198,13 @@ def _ctrl_meas(self): return ctrl_meas @property - def temperature(self): + def temperature(self) -> float: """The compensated temperature in degrees Celsius.""" self._read_temperature() return self._t_fine / 5120.0 @property - def pressure(self): + def pressure(self) -> Optional[float]: """ The compensated pressure in hectoPascals. returns None if pressure measurement is disabled @@ -230,7 +237,7 @@ def pressure(self): return pressure @property - def relative_humidity(self): + def relative_humidity(self) -> Optional[float]: """ The relative humidity in RH % returns None if humidity measurement is disabled @@ -238,7 +245,7 @@ def relative_humidity(self): return self.humidity @property - def humidity(self): + def humidity(self) -> Optional[float]: """ The relative humidity in RH % returns None if humidity measurement is disabled @@ -268,13 +275,13 @@ def humidity(self): return humidity @property - def altitude(self): + def altitude(self) -> float: """The altitude based on current :attr:`pressure` versus the sea level pressure (``sea_level_pressure``) - which you must enter ahead of time)""" pressure = self.pressure # in Si units for hPascal return 44330 * (1.0 - math.pow(pressure / self.sea_level_pressure, 0.1903)) - def _read_coefficients(self): + def _read_coefficients(self) -> None: """Read & save the calibration coefficients""" coeff = self._read_register(0x88, 24) # BME280_REGISTER_DIG_T1 coeff = list(struct.unpack("> 4)) self._humidity_calib[5] = float(coeff[5]) - def _read_byte(self, register): + def _read_byte(self, register: int) -> int: """Read a byte register value and return it""" return self._read_register(register, 1)[0] - def _read24(self, register): + def _read24(self, register: int) -> float: """Read an unsigned 24-bit value as a floating point and return it.""" ret = 0.0 for b in self._read_register(register, 3): @@ -304,10 +311,10 @@ def _read24(self, register): ret += float(b & 0xFF) return ret - def _read_register(self, register, length): + def _read_register(self, register: int, length: int) -> bytearray: raise NotImplementedError() - def _write_register_byte(self, register, value): + def _write_register_byte(self, register: int, value: int) -> None: raise NotImplementedError() @@ -358,7 +365,7 @@ class Adafruit_BME280_I2C(Adafruit_BME280): """ - def __init__(self, i2c, address=0x77): # BME280_ADDRESS + def __init__(self, i2c: I2C, address: int = 0x77) -> None: # BME280_ADDRESS from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel i2c_device, ) @@ -366,14 +373,14 @@ def __init__(self, i2c, address=0x77): # BME280_ADDRESS self._i2c = i2c_device.I2CDevice(i2c, address) super().__init__() - def _read_register(self, register, length): + def _read_register(self, register: int, length: int) -> bytearray: with self._i2c as i2c: i2c.write(bytes([register & 0xFF])) result = bytearray(length) i2c.readinto(result) return result - def _write_register_byte(self, register, value): + def _write_register_byte(self, register: int, value: int) -> None: with self._i2c as i2c: i2c.write(bytes([register & 0xFF, value & 0xFF])) # print("$%02X <= 0x%02X" % (register, value)) @@ -428,7 +435,7 @@ class Adafruit_BME280_SPI(Adafruit_BME280): """ - def __init__(self, spi, cs, baudrate=100000): + def __init__(self, spi: SPI, cs: DigitalInOut, baudrate: int = 100000) -> None: from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel spi_device, ) @@ -436,7 +443,7 @@ def __init__(self, spi, cs, baudrate=100000): self._spi = spi_device.SPIDevice(spi, cs, baudrate=baudrate) super().__init__() - def _read_register(self, register, length): + def _read_register(self, register: int, length: int) -> bytearray: register = (register | 0x80) & 0xFF # Read single, bit 7 high. with self._spi as spi: spi.write(bytearray([register])) # pylint: disable=no-member @@ -444,7 +451,7 @@ def _read_register(self, register, length): spi.readinto(result) # pylint: disable=no-member return result - def _write_register_byte(self, register, value): + def _write_register_byte(self, register: int, value: int) -> None: register &= 0x7F # Write, bit 7 low. with self._spi as spi: spi.write(bytes([register, value & 0xFF])) # pylint: disable=no-member From a824e4978a676c7caec9579944eb0aa252667313 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sun, 13 Feb 2022 16:28:23 -0500 Subject: [PATCH 079/125] Add type annotations for advanced.py --- adafruit_bme280/advanced.py | 49 +++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/adafruit_bme280/advanced.py b/adafruit_bme280/advanced.py index ef1175a..6d39615 100644 --- a/adafruit_bme280/advanced.py +++ b/adafruit_bme280/advanced.py @@ -32,6 +32,13 @@ from micropython import const from adafruit_bme280.basic import Adafruit_BME280 +try: + import typing # pylint: disable=unused-import + from busio import I2C, SPI + from digitalio import DigitalInOut +except ImportError: + pass + __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BME280.git" @@ -134,7 +141,7 @@ class Adafruit_BME280_Advanced(Adafruit_BME280): """ # pylint: disable=too-many-instance-attributes - def __init__(self): + def __init__(self) -> None: """Check the BME280 was found, read the coefficients and enable the sensor""" self._overscan_humidity = OVERSCAN_X1 self._overscan_temperature = OVERSCAN_X1 @@ -144,7 +151,7 @@ def __init__(self): super().__init__() @property - def standby_period(self): + def standby_period(self) -> int: """ Control the inactive period when in Normal mode Allowed standby periods are the constants STANDBY_TC_* @@ -152,7 +159,7 @@ def standby_period(self): return self._t_standby @standby_period.setter - def standby_period(self, value): + def standby_period(self, value: int) -> None: if not value in _BME280_STANDBY_TCS: raise ValueError("Standby Period '%s' not supported" % (value)) if self._t_standby == value: @@ -161,7 +168,7 @@ def standby_period(self, value): self._write_config() @property - def overscan_humidity(self): + def overscan_humidity(self) -> int: """ Humidity Oversampling Allowed values are the constants OVERSCAN_* @@ -169,14 +176,14 @@ def overscan_humidity(self): return self._overscan_humidity @overscan_humidity.setter - def overscan_humidity(self, value): + def overscan_humidity(self, value: int) -> None: if not value in _BME280_OVERSCANS: raise ValueError("Overscan value '%s' not supported" % (value)) self._overscan_humidity = value self._write_ctrl_meas() @property - def overscan_temperature(self): + def overscan_temperature(self) -> int: """ Temperature Oversampling Allowed values are the constants OVERSCAN_* @@ -184,14 +191,14 @@ def overscan_temperature(self): return self._overscan_temperature @overscan_temperature.setter - def overscan_temperature(self, value): + def overscan_temperature(self, value: int) -> None: if not value in _BME280_OVERSCANS: raise ValueError("Overscan value '%s' not supported" % (value)) self._overscan_temperature = value self._write_ctrl_meas() @property - def overscan_pressure(self): + def overscan_pressure(self) -> int: """ Pressure Oversampling Allowed values are the constants OVERSCAN_* @@ -199,14 +206,14 @@ def overscan_pressure(self): return self._overscan_pressure @overscan_pressure.setter - def overscan_pressure(self, value): + def overscan_pressure(self, value: int) -> None: if not value in _BME280_OVERSCANS: raise ValueError("Overscan value '%s' not supported" % (value)) self._overscan_pressure = value self._write_ctrl_meas() @property - def iir_filter(self): + def iir_filter(self) -> int: """ Controls the time constant of the IIR filter Allowed values are the constants IIR_FILTER_* @@ -214,14 +221,14 @@ def iir_filter(self): return self._iir_filter @iir_filter.setter - def iir_filter(self, value): + def iir_filter(self, value: int) -> None: if not value in _BME280_IIR_FILTERS: raise ValueError("IIR Filter '%s' not supported" % (value)) self._iir_filter = value self._write_config() @property - def _config(self): + def _config(self) -> int: """Value to be written to the device's config register """ config = 0 if self.mode == MODE_NORMAL: @@ -231,7 +238,7 @@ def _config(self): return config @property - def _ctrl_meas(self): + def _ctrl_meas(self) -> int: """Value to be written to the device's ctrl_meas register """ ctrl_meas = self.overscan_temperature << 5 ctrl_meas += self.overscan_pressure << 2 @@ -239,7 +246,7 @@ def _ctrl_meas(self): return ctrl_meas @property - def measurement_time_typical(self): + def measurement_time_typical(self) -> float: """Typical time in milliseconds required to complete a measurement in normal mode""" meas_time_ms = 1.0 if self.overscan_temperature != OVERSCAN_DISABLE: @@ -251,7 +258,7 @@ def measurement_time_typical(self): return meas_time_ms @property - def measurement_time_max(self): + def measurement_time_max(self) -> float: """Maximum time in milliseconds required to complete a measurement in normal mode""" meas_time_ms = 1.25 if self.overscan_temperature != OVERSCAN_DISABLE: @@ -309,7 +316,7 @@ class Adafruit_BME280_I2C(Adafruit_BME280_Advanced): """ - def __init__(self, i2c, address=_BME280_ADDRESS): + def __init__(self, i2c: I2C, address: int = _BME280_ADDRESS) -> None: from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel i2c_device, ) @@ -317,7 +324,7 @@ def __init__(self, i2c, address=_BME280_ADDRESS): self._i2c = i2c_device.I2CDevice(i2c, address) super().__init__() - def _read_register(self, register, length): + def _read_register(self, register: int, length: int) -> bytearray: with self._i2c as i2c: i2c.write(bytes([register & 0xFF])) result = bytearray(length) @@ -325,7 +332,7 @@ def _read_register(self, register, length): # print("$%02X => %s" % (register, [hex(i) for i in result])) return result - def _write_register_byte(self, register, value): + def _write_register_byte(self, register: int, value: int) -> None: with self._i2c as i2c: i2c.write(bytes([register & 0xFF, value & 0xFF])) # print("$%02X <= 0x%02X" % (register, value)) @@ -379,7 +386,7 @@ class Adafruit_BME280_SPI(Adafruit_BME280_Advanced): """ - def __init__(self, spi, cs, baudrate=100000): + def __init__(self, spi: SPI, cs: DigitalInOut, baudrate: int = 100000) -> None: from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel spi_device, ) @@ -387,7 +394,7 @@ def __init__(self, spi, cs, baudrate=100000): self._spi = spi_device.SPIDevice(spi, cs, baudrate=baudrate) super().__init__() - def _read_register(self, register, length): + def _read_register(self, register: int, length: int) -> bytearray: register = (register | 0x80) & 0xFF # Read single, bit 7 high. with self._spi as spi: spi.write(bytearray([register])) # pylint: disable=no-member @@ -396,7 +403,7 @@ def _read_register(self, register, length): # print("$%02X => %s" % (register, [hex(i) for i in result])) return result - def _write_register_byte(self, register, value): + def _write_register_byte(self, register: int, value: int) -> None: register &= 0x7F # Write, bit 7 low. with self._spi as spi: spi.write(bytes([register, value & 0xFF])) # pylint: disable=no-member From 75fdee682e989aa4d1b254f20c5966d9f243c1cf Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sun, 13 Feb 2022 16:39:46 -0500 Subject: [PATCH 080/125] Remove Optional typing, comments about returning None It looks to be a holdover from a previous commit that actually did have the ability to return None. --- adafruit_bme280/basic.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/adafruit_bme280/basic.py b/adafruit_bme280/basic.py index fffab39..dd54eba 100644 --- a/adafruit_bme280/basic.py +++ b/adafruit_bme280/basic.py @@ -204,10 +204,9 @@ def temperature(self) -> float: return self._t_fine / 5120.0 @property - def pressure(self) -> Optional[float]: + def pressure(self) -> float: """ The compensated pressure in hectoPascals. - returns None if pressure measurement is disabled """ self._read_temperature() @@ -237,18 +236,16 @@ def pressure(self) -> Optional[float]: return pressure @property - def relative_humidity(self) -> Optional[float]: + def relative_humidity(self) -> float: """ The relative humidity in RH % - returns None if humidity measurement is disabled """ return self.humidity @property - def humidity(self) -> Optional[float]: + def humidity(self) -> float: """ The relative humidity in RH % - returns None if humidity measurement is disabled """ self._read_temperature() hum = self._read_register(0xFD, 2) # BME280_REGISTER_HUMIDDATA From 72c2d68a9f74a48b6f9274e0e5b4067a63df7559 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sun, 13 Feb 2022 16:40:57 -0500 Subject: [PATCH 081/125] Remove Optional import, add pylint disable --- adafruit_bme280/basic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_bme280/basic.py b/adafruit_bme280/basic.py index dd54eba..e57cc9c 100644 --- a/adafruit_bme280/basic.py +++ b/adafruit_bme280/basic.py @@ -36,7 +36,7 @@ from micropython import const try: - from typing import Optional + import typing # pylint: disable=unused-import from busio import I2C, SPI from digitalio import DigitalInOut except ImportError: From 49949f801ef37542ff3f3614b7ceb140672b93d0 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 14 Feb 2022 15:35:02 -0500 Subject: [PATCH 082/125] Fixed readthedocs build Signed-off-by: dherrada --- .readthedocs.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index f8b2891..33c2a61 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -8,8 +8,12 @@ # Required version: 2 +build: + os: ubuntu-20.04 + tools: + python: "3" + python: - version: "3.x" install: - requirements: docs/requirements.txt - requirements: requirements.txt From 0ef34f0a4358d5387dcd173901394c0ee1c1ab22 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Mon, 28 Mar 2022 15:52:04 -0400 Subject: [PATCH 083/125] Update Black to latest. Signed-off-by: Kattni Rembor --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 43d1385..29230db 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ repos: - repo: https://github.com/python/black - rev: 20.8b1 + rev: 22.3.0 hooks: - id: black - repo: https://github.com/fsfe/reuse-tool From a65db9d63fc7fea51b9b4d35b2a6eb78f0720d9a Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 29 Mar 2022 18:16:07 -0400 Subject: [PATCH 084/125] "Reformatted per new black version" --- adafruit_bme280/advanced.py | 4 ++-- adafruit_bme280/basic.py | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/adafruit_bme280/advanced.py b/adafruit_bme280/advanced.py index 6d39615..23b6e16 100644 --- a/adafruit_bme280/advanced.py +++ b/adafruit_bme280/advanced.py @@ -229,7 +229,7 @@ def iir_filter(self, value: int) -> None: @property def _config(self) -> int: - """Value to be written to the device's config register """ + """Value to be written to the device's config register""" config = 0 if self.mode == MODE_NORMAL: config += self._t_standby << 5 @@ -239,7 +239,7 @@ def _config(self) -> int: @property def _ctrl_meas(self) -> int: - """Value to be written to the device's ctrl_meas register """ + """Value to be written to the device's ctrl_meas register""" ctrl_meas = self.overscan_temperature << 5 ctrl_meas += self.overscan_pressure << 2 ctrl_meas += self.mode diff --git a/adafruit_bme280/basic.py b/adafruit_bme280/basic.py index e57cc9c..265aa20 100644 --- a/adafruit_bme280/basic.py +++ b/adafruit_bme280/basic.py @@ -146,15 +146,15 @@ def _write_ctrl_meas(self) -> None: self._write_register_byte(_BME280_REGISTER_CTRL_MEAS, self._ctrl_meas) def _get_status(self) -> int: - """Get the value from the status register in the device """ + """Get the value from the status register in the device""" return self._read_byte(_BME280_REGISTER_STATUS) def _read_config(self) -> int: - """Read the value from the config register in the device """ + """Read the value from the config register in the device""" return self._read_byte(_BME280_REGISTER_CONFIG) def _write_config(self) -> None: - """Write the value to the config register in the device """ + """Write the value to the config register in the device""" normal_flag = False if self._mode == MODE_NORMAL: # Writes to the config register may be ignored while in Normal mode @@ -181,7 +181,7 @@ def mode(self, value: int) -> None: @property def _config(self) -> int: - """Value to be written to the device's config register """ + """Value to be written to the device's config register""" config = 0 if self.mode == 0x03: # MODE_NORMAL config += self._t_standby << 5 @@ -191,7 +191,7 @@ def _config(self) -> int: @property def _ctrl_meas(self) -> int: - """Value to be written to the device's ctrl_meas register """ + """Value to be written to the device's ctrl_meas register""" ctrl_meas = self.overscan_temperature << 5 ctrl_meas += self.overscan_pressure << 2 ctrl_meas += self.mode From 13a18d46e42da4468413929cdcc479fc3fe3a618 Mon Sep 17 00:00:00 2001 From: Eva Herrada <33632497+evaherrada@users.noreply.github.com> Date: Thu, 21 Apr 2022 18:51:32 -0400 Subject: [PATCH 085/125] Update .gitignore --- .gitignore | 49 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index a966824..544ec4a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,18 +1,47 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-FileCopyrightText: 2022 Kattni Rembor, written for Adafruit Industries # -# SPDX-License-Identifier: Unlicense +# SPDX-License-Identifier: MIT +# Do not include files and directories created by your personal work environment, such as the IDE +# you use, except for those already listed here. Pull requests including changes to this file will +# not be accepted. + +# This .gitignore file contains rules for files generated by working with CircuitPython libraries, +# including building Sphinx, testing with pip, and creating a virual environment, as well as the +# MacOS and IDE-specific files generated by using MacOS in general, or the PyCharm or VSCode IDEs. + +# If you find that there are files being generated on your machine that should not be included in +# your git commit, you should create a .gitignore_global file on your computer to include the +# files created by your personal setup. To do so, follow the two steps below. + +# First, create a file called .gitignore_global somewhere convenient for you, and add rules for +# the files you want to exclude from git commits. + +# Second, configure Git to use the exclude file for all Git repositories by running the +# following via commandline, replacing "path/to/your/" with the actual path to your newly created +# .gitignore_global file: +# git config --global core.excludesfile path/to/your/.gitignore_global + +# CircuitPython-specific files *.mpy -.idea + +# Python-specific files __pycache__ -_build *.pyc + +# Sphinx build-specific files +_build + +# This file results from running `pip -e install .` in a local repository +*.egg-info + +# Virtual environment-specific files .env -.python-version -build*/ -bundles + +# MacOS-specific files *.DS_Store -.eggs -dist -**/*.egg-info + +# IDE-specific files +.idea .vscode +*~ From 40f0068cd25f87c9b36d45fb3f7b23034c5e66c9 Mon Sep 17 00:00:00 2001 From: evaherrada Date: Fri, 22 Apr 2022 15:58:27 -0400 Subject: [PATCH 086/125] Patch: Replaced discord badge image --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index b07377e..83f2906 100644 --- a/README.rst +++ b/README.rst @@ -5,7 +5,7 @@ Introduction :target: https://docs.circuitpython.org/projects/bme280/en/latest/ :alt: Documentation Status -.. image :: https://img.shields.io/discord/327254708534116352.svg +.. image:: https://github.com/adafruit/Adafruit_CircuitPython_Bundle/blob/main/badges/adafruit_discord.svg :target: https://adafru.it/discord :alt: Discord From 8ffead23419ce352dd8d8eda2e65557d184d236a Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 24 Apr 2022 13:49:31 -0500 Subject: [PATCH 087/125] change discord badge --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 83f2906..b2bcf18 100644 --- a/README.rst +++ b/README.rst @@ -5,7 +5,7 @@ Introduction :target: https://docs.circuitpython.org/projects/bme280/en/latest/ :alt: Documentation Status -.. image:: https://github.com/adafruit/Adafruit_CircuitPython_Bundle/blob/main/badges/adafruit_discord.svg +.. image:: https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Bundle/main/badges/adafruit_discord.svg :target: https://adafru.it/discord :alt: Discord From f3082899b512b98956d459d146ace9d333051ef8 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sun, 15 May 2022 12:48:14 -0400 Subject: [PATCH 088/125] Patch .pre-commit-config.yaml --- .pre-commit-config.yaml | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 29230db..0a91a11 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,40 +3,40 @@ # SPDX-License-Identifier: Unlicense repos: -- repo: https://github.com/python/black + - repo: https://github.com/python/black rev: 22.3.0 hooks: - - id: black -- repo: https://github.com/fsfe/reuse-tool - rev: v0.12.1 + - id: black + - repo: https://github.com/fsfe/reuse-tool + rev: v0.14.0 hooks: - - id: reuse -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.3.0 + - id: reuse + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.2.0 hooks: - - id: check-yaml - - id: end-of-file-fixer - - id: trailing-whitespace -- repo: https://github.com/pycqa/pylint + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - repo: https://github.com/pycqa/pylint rev: v2.11.1 hooks: - - id: pylint + - id: pylint name: pylint (library code) types: [python] args: - --disable=consider-using-f-string,duplicate-code exclude: "^(docs/|examples/|tests/|setup.py$)" - - id: pylint + - id: pylint name: pylint (example code) description: Run pylint rules on "examples/*.py" files types: [python] files: "^examples/" args: - - --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code - - id: pylint + - --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code + - id: pylint name: pylint (test code) description: Run pylint rules on "tests/*.py" files types: [python] files: "^tests/" args: - - --disable=missing-docstring,consider-using-f-string,duplicate-code + - --disable=missing-docstring,consider-using-f-string,duplicate-code From 497df01daadc1071efdcd8c66c1a7cc72a06d26b Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sun, 22 May 2022 00:18:55 -0400 Subject: [PATCH 089/125] Increase min lines similarity Signed-off-by: Alec Delaney --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index cfd1c41..f006a4a 100644 --- a/.pylintrc +++ b/.pylintrc @@ -252,7 +252,7 @@ ignore-docstrings=yes ignore-imports=yes # Minimum lines number of a similarity. -min-similarity-lines=4 +min-similarity-lines=12 [BASIC] From 9a3ceda62cdfec7fa6b3b4f51e2f14a5fc3952ca Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sun, 22 May 2022 00:18:23 -0400 Subject: [PATCH 090/125] Switch to inclusive terminology Signed-off-by: Alec Delaney --- .pylintrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pylintrc b/.pylintrc index f006a4a..f772971 100644 --- a/.pylintrc +++ b/.pylintrc @@ -9,11 +9,11 @@ # run arbitrary code extension-pkg-whitelist= -# Add files or directories to the blacklist. They should be base names, not +# Add files or directories to the ignore-list. They should be base names, not # paths. ignore=CVS -# Add files or directories matching the regex patterns to the blacklist. The +# Add files or directories matching the regex patterns to the ignore-list. The # regex matches against base names, not paths. ignore-patterns= From 95c360862d8d1720deedf6110b05fdc66c5cd38c Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 30 May 2022 14:25:04 -0400 Subject: [PATCH 091/125] Set language to "en" for documentation Signed-off-by: Alec Delaney --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 7c8402a..126d8a9 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -57,7 +57,7 @@ # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = None +language = "en" # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. From 816def6ec432f83b107e74f4002f53cd712c0fc9 Mon Sep 17 00:00:00 2001 From: evaherrada Date: Tue, 7 Jun 2022 15:34:08 -0400 Subject: [PATCH 092/125] Added cp.org link to index.rst --- docs/index.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/index.rst b/docs/index.rst index 273625f..a2f9957 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -33,7 +33,8 @@ Table of Contents .. toctree:: :caption: Other Links - Download + Download from GitHub + Download Library Bundle CircuitPython Reference Documentation CircuitPython Support Forum Discord Chat From b7765540b4e07e0f49e2c965d4d3defd51f6aa48 Mon Sep 17 00:00:00 2001 From: evaherrada Date: Fri, 22 Jul 2022 13:58:36 -0400 Subject: [PATCH 093/125] Changed .env to .venv in README.rst --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index b2bcf18..d43c44d 100644 --- a/README.rst +++ b/README.rst @@ -54,8 +54,8 @@ To install in a virtual environment in your current project: .. code-block:: shell mkdir project-name && cd project-name - python3 -m venv .env - source .env/bin/activate + python3 -m venv .venv + source .venv/bin/activate pip3 install adafruit-circuitpython-bme280 From 26671743b3c69d2c95a948d31106b38272dee1d8 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 8 Aug 2022 22:05:52 -0400 Subject: [PATCH 094/125] Switched to pyproject.toml --- .github/workflows/build.yml | 18 ++++++------ .github/workflows/release.yml | 17 ++++++----- optional_requirements.txt | 3 ++ pyproject.toml | 44 ++++++++++++++++++++++++++++ requirements.txt | 2 +- setup.py | 54 ----------------------------------- 6 files changed, 68 insertions(+), 70 deletions(-) create mode 100644 optional_requirements.txt create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 474520d..22f6582 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,6 +47,8 @@ jobs: pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit - name: Library version run: git describe --dirty --always --tags + - name: Setup problem matchers + uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1 - name: Pre-commit hooks run: | pre-commit run --all-files @@ -60,16 +62,16 @@ jobs: - name: Build docs working-directory: docs run: sphinx-build -E -W -b html . _build/html - - name: Check For setup.py + - name: Check For pyproject.toml id: need-pypi run: | - echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) + echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' ) - name: Build Python package - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') run: | - pip install --upgrade setuptools wheel twine readme_renderer testresources - python setup.py sdist - python setup.py bdist_wheel --universal + pip install --upgrade build twine + for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do + sed -i -e "s/0.0.0-auto.0/1.2.3/" $file; + done; + python -m build twine check dist/* - - name: Setup problem matchers - uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a65e5de..d1b4f8d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -61,25 +61,28 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - - name: Check For setup.py + - name: Check For pyproject.toml id: need-pypi run: | - echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) + echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' ) - name: Set up Python - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') uses: actions/setup-python@v2 with: python-version: '3.x' - name: Install dependencies - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') run: | python -m pip install --upgrade pip - pip install setuptools wheel twine + pip install --upgrade build twine - name: Build and publish - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') env: TWINE_USERNAME: ${{ secrets.pypi_username }} TWINE_PASSWORD: ${{ secrets.pypi_password }} run: | - python setup.py sdist + for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do + sed -i -e "s/0.0.0-auto.0/${{github.event.release.tag_name}}/" $file; + done; + python -m build twine upload dist/* diff --git a/optional_requirements.txt b/optional_requirements.txt new file mode 100644 index 0000000..d4e27c4 --- /dev/null +++ b/optional_requirements.txt @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b81504d --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,44 @@ +# SPDX-FileCopyrightText: 2022 Alec Delaney for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +[build-system] +requires = [ + "setuptools", + "wheel", +] + +[project] +name = "adafruit-circuitpython-bme280" +description = "CircuitPython library for the Bosch BME280 temperature/humidity/pressure sensor." +version = "0.0.0-auto.0" +readme = "README.rst" +authors = [ + {name = "Adafruit Industries", email = "circuitpython@adafruit.com"} +] +urls = {Homepage = "https://github.com/adafruit/Adafruit_CircuitPython_BME280"} +keywords = [ + "adafruit", + "bme280", + "sensor", + "hardware", + "micropython", + "circuitpython", +] +license = {text = "MIT"} +classifiers = [ + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries", + "Topic :: Software Development :: Embedded Systems", + "Topic :: System :: Hardware", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", +] +dynamic = ["dependencies", "optional-dependencies"] + +[tool.setuptools] +packages = ["adafruit_bme280"] + +[tool.setuptools.dynamic] +dependencies = {file = ["requirements.txt"]} +optional-dependencies = {optional = {file = ["optional_requirements.txt"]}} diff --git a/requirements.txt b/requirements.txt index f675e3b..a45c547 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries # # SPDX-License-Identifier: Unlicense diff --git a/setup.py b/setup.py deleted file mode 100644 index f5cd961..0000000 --- a/setup.py +++ /dev/null @@ -1,54 +0,0 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries -# -# SPDX-License-Identifier: MIT - -"""A setuptools based setup module. - -See: -https://packaging.python.org/en/latest/distributing.html -https://github.com/pypa/sampleproject -""" - -# Always prefer setuptools over distutils -from setuptools import setup, find_packages - -# To use a consistent encoding -from codecs import open -from os import path - -here = path.abspath(path.dirname(__file__)) - -# Get the long description from the README file -with open(path.join(here, "README.rst"), encoding="utf-8") as f: - long_description = f.read() - -setup( - name="adafruit-circuitpython-bme280", - use_scm_version=True, - setup_requires=["setuptools_scm"], - description="CircuitPython library for the Bosch BME280 temperature/humidity/pressure sensor.", - long_description=long_description, - long_description_content_type="text/x-rst", - # The project's main homepage. - url="https://github.com/adafruit/Adafruit_CircuitPython_BME280", - # Author details - author="Adafruit Industries", - author_email="circuitpython@adafruit.com", - install_requires=["Adafruit-Blinka", "adafruit-circuitpython-busdevice"], - # Choose your license - license="MIT", - # See https://pypi.python.org/pypi?%3Aaction=list_classifiers - classifiers=[ - "Development Status :: 3 - Alpha", - "Intended Audience :: Developers", - "Topic :: Software Development :: Libraries", - "Topic :: System :: Hardware", - "License :: OSI Approved :: MIT License", - "Programming Language :: Python :: 3", - ], - # What does your project relate to? - keywords="adafruit bme280 sensor hardware micropython circuitpython", - # You can just specify the packages manually here if your project is - # simple. Or you can use find_packages(). - packages=["adafruit_bme280"], -) From 1f58ab5731b1794042b5cf574390c1142b90181c Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 9 Aug 2022 12:03:54 -0400 Subject: [PATCH 095/125] Add setuptools-scm to build system requirements Signed-off-by: Alec Delaney --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index b81504d..10a963c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,6 +6,7 @@ requires = [ "setuptools", "wheel", + "setuptools-scm", ] [project] From 5b66e5b22aaf318ba197f4915ea81f38ff5be613 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 16 Aug 2022 18:09:12 -0400 Subject: [PATCH 096/125] Update version string --- adafruit_bme280/advanced.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_bme280/advanced.py b/adafruit_bme280/advanced.py index 23b6e16..2604880 100644 --- a/adafruit_bme280/advanced.py +++ b/adafruit_bme280/advanced.py @@ -39,7 +39,7 @@ except ImportError: pass -__version__ = "0.0.0-auto.0" +__version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BME280.git" # I2C ADDRESS/BITS/SETTINGS diff --git a/pyproject.toml b/pyproject.toml index 10a963c..b9bd474 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ requires = [ [project] name = "adafruit-circuitpython-bme280" description = "CircuitPython library for the Bosch BME280 temperature/humidity/pressure sensor." -version = "0.0.0-auto.0" +version = "0.0.0+auto.0" readme = "README.rst" authors = [ {name = "Adafruit Industries", email = "circuitpython@adafruit.com"} From dad6588fb72d50854b16bf637edf05c5cfd77fd5 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 16 Aug 2022 21:09:13 -0400 Subject: [PATCH 097/125] Fix version strings in workflow files --- .github/workflows/build.yml | 2 +- .github/workflows/release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 22f6582..cb2f60e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -71,7 +71,7 @@ jobs: run: | pip install --upgrade build twine for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do - sed -i -e "s/0.0.0-auto.0/1.2.3/" $file; + sed -i -e "s/0.0.0+auto.0/1.2.3/" $file; done; python -m build twine check dist/* diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d1b4f8d..f3a0325 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -82,7 +82,7 @@ jobs: TWINE_PASSWORD: ${{ secrets.pypi_password }} run: | for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do - sed -i -e "s/0.0.0-auto.0/${{github.event.release.tag_name}}/" $file; + sed -i -e "s/0.0.0+auto.0/${{github.event.release.tag_name}}/" $file; done; python -m build twine upload dist/* From 6b3a0a9b2f156a7ee9458caf20b1fde7a7eea654 Mon Sep 17 00:00:00 2001 From: "Randall Bohn (dexter)" Date: Fri, 19 Aug 2022 20:56:45 -0600 Subject: [PATCH 098/125] Provide proxies for I2C and SPI --- adafruit_bme280/advanced.py | 46 ++++-------------------------------- adafruit_bme280/basic.py | 47 ++++++------------------------------- adafruit_bme280/protocol.py | 47 +++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 81 deletions(-) create mode 100644 adafruit_bme280/protocol.py diff --git a/adafruit_bme280/advanced.py b/adafruit_bme280/advanced.py index 2604880..9b0867c 100644 --- a/adafruit_bme280/advanced.py +++ b/adafruit_bme280/advanced.py @@ -31,6 +31,7 @@ """ from micropython import const from adafruit_bme280.basic import Adafruit_BME280 +from adafruit_bme280.protocol import I2C_Impl, SPI_Impl try: import typing # pylint: disable=unused-import @@ -141,14 +142,14 @@ class Adafruit_BME280_Advanced(Adafruit_BME280): """ # pylint: disable=too-many-instance-attributes - def __init__(self) -> None: + def __init__(self, proxy) -> None: """Check the BME280 was found, read the coefficients and enable the sensor""" self._overscan_humidity = OVERSCAN_X1 self._overscan_temperature = OVERSCAN_X1 self._overscan_pressure = OVERSCAN_X16 self._mode = MODE_SLEEP self._t_standby = STANDBY_TC_125 - super().__init__() + super().__init__(proxy) @property def standby_period(self) -> int: @@ -317,25 +318,7 @@ class Adafruit_BME280_I2C(Adafruit_BME280_Advanced): """ def __init__(self, i2c: I2C, address: int = _BME280_ADDRESS) -> None: - from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel - i2c_device, - ) - - self._i2c = i2c_device.I2CDevice(i2c, address) - super().__init__() - - def _read_register(self, register: int, length: int) -> bytearray: - with self._i2c as i2c: - i2c.write(bytes([register & 0xFF])) - result = bytearray(length) - i2c.readinto(result) - # print("$%02X => %s" % (register, [hex(i) for i in result])) - return result - - def _write_register_byte(self, register: int, value: int) -> None: - with self._i2c as i2c: - i2c.write(bytes([register & 0xFF, value & 0xFF])) - # print("$%02X <= 0x%02X" % (register, value)) + super().__init__(I2C_Impl(i2c, address)) class Adafruit_BME280_SPI(Adafruit_BME280_Advanced): @@ -387,23 +370,4 @@ class Adafruit_BME280_SPI(Adafruit_BME280_Advanced): """ def __init__(self, spi: SPI, cs: DigitalInOut, baudrate: int = 100000) -> None: - from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel - spi_device, - ) - - self._spi = spi_device.SPIDevice(spi, cs, baudrate=baudrate) - super().__init__() - - def _read_register(self, register: int, length: int) -> bytearray: - register = (register | 0x80) & 0xFF # Read single, bit 7 high. - with self._spi as spi: - spi.write(bytearray([register])) # pylint: disable=no-member - result = bytearray(length) - spi.readinto(result) # pylint: disable=no-member - # print("$%02X => %s" % (register, [hex(i) for i in result])) - return result - - def _write_register_byte(self, register: int, value: int) -> None: - register &= 0x7F # Write, bit 7 low. - with self._spi as spi: - spi.write(bytes([register, value & 0xFF])) # pylint: disable=no-member + super().__init__(SPI_Impl(spi, cs, baudrate)) diff --git a/adafruit_bme280/basic.py b/adafruit_bme280/basic.py index 265aa20..9fc3f98 100644 --- a/adafruit_bme280/basic.py +++ b/adafruit_bme280/basic.py @@ -34,6 +34,7 @@ from time import sleep from micropython import const +from protocol import I2C_Impl, SPI_Impl try: import typing # pylint: disable=unused-import @@ -88,9 +89,10 @@ class Adafruit_BME280: """ # pylint: disable=too-many-instance-attributes - def __init__(self) -> None: + def __init__(self, proxy: typing.Union[I2C_Impl, SPI_Impl]) -> None: """Check the BME280 was found, read the coefficients and enable the sensor""" # Check device ID. + self._proxy = proxy chip_id = self._read_byte(_BME280_REGISTER_CHIPID) if _BME280_CHIPID != chip_id: raise RuntimeError("Failed to find BME280! Chip ID 0x%x" % chip_id) @@ -309,10 +311,10 @@ def _read24(self, register: int) -> float: return ret def _read_register(self, register: int, length: int) -> bytearray: - raise NotImplementedError() + return self._proxy.read_register(register, length) def _write_register_byte(self, register: int, value: int) -> None: - raise NotImplementedError() + self._proxy.write_register_byte(register, value) class Adafruit_BME280_I2C(Adafruit_BME280): @@ -363,24 +365,7 @@ class Adafruit_BME280_I2C(Adafruit_BME280): """ def __init__(self, i2c: I2C, address: int = 0x77) -> None: # BME280_ADDRESS - from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel - i2c_device, - ) - - self._i2c = i2c_device.I2CDevice(i2c, address) - super().__init__() - - def _read_register(self, register: int, length: int) -> bytearray: - with self._i2c as i2c: - i2c.write(bytes([register & 0xFF])) - result = bytearray(length) - i2c.readinto(result) - return result - - def _write_register_byte(self, register: int, value: int) -> None: - with self._i2c as i2c: - i2c.write(bytes([register & 0xFF, value & 0xFF])) - # print("$%02X <= 0x%02X" % (register, value)) + super().__init__(I2C_Impl(i2c, address)) class Adafruit_BME280_SPI(Adafruit_BME280): @@ -433,22 +418,4 @@ class Adafruit_BME280_SPI(Adafruit_BME280): """ def __init__(self, spi: SPI, cs: DigitalInOut, baudrate: int = 100000) -> None: - from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel - spi_device, - ) - - self._spi = spi_device.SPIDevice(spi, cs, baudrate=baudrate) - super().__init__() - - def _read_register(self, register: int, length: int) -> bytearray: - register = (register | 0x80) & 0xFF # Read single, bit 7 high. - with self._spi as spi: - spi.write(bytearray([register])) # pylint: disable=no-member - result = bytearray(length) - spi.readinto(result) # pylint: disable=no-member - return result - - def _write_register_byte(self, register: int, value: int) -> None: - register &= 0x7F # Write, bit 7 low. - with self._spi as spi: - spi.write(bytes([register, value & 0xFF])) # pylint: disable=no-member + super().__init__(SPI_Impl(spi, cs, baudrate)) diff --git a/adafruit_bme280/protocol.py b/adafruit_bme280/protocol.py new file mode 100644 index 0000000..2fed8da --- /dev/null +++ b/adafruit_bme280/protocol.py @@ -0,0 +1,47 @@ +# SPDX-FileCopyrightText: 2022 Randall Bohn (dexter) +# +# SPDX-License-Identifier: MIT +"Provides the protocol objects for I2C and SPI" + +from busio import I2C, SPI +from digitalio import DigitalInOut + +class I2C_Impl: + def __init__(self, i2c: I2C, address: int) -> None: + from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel + i2c_device, + ) + + self._i2c = i2c_device.I2CDevice(i2c, address) + + def read_register(self, register: int, length: int) -> bytearray: + with self._i2c as i2c: + i2c.write(bytes([register & 0xFF])) + result = bytearray(length) + i2c.readinto(result) + return result + def write_register_byte(self, register: int, value: int) -> None: + with self._i2c as i2c: + i2c.write(bytes([register & 0xFF, value & 0xFF])) + +class SPI_Impl: + def __init__(self, spi: SPI, cs: DigitalInOut, baudrate: int = 100000) -> None: + from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel + spi_device, + ) + + self._spi = spi_device.SPIDevice(spi, cs, baudrate=baudrate) + + def _read_register(self, register: int, length: int) -> bytearray: + register = (register | 0x80) & 0xFF # Read single, bit 7 high. + with self._spi as spi: + spi.write(bytearray([register])) # pylint: disable=no-member + result = bytearray(length) + spi.readinto(result) # pylint: disable=no-member + # print("$%02X => %s" % (register, [hex(i) for i in result])) + return result + + def _write_register_byte(self, register: int, value: int) -> None: + register &= 0x7F # Write, bit 7 low. + with self._spi as spi: + spi.write(bytes([register, value & 0xFF])) # pylint: disable=no-member From 95506f0733eed7cae26bbef48370fa5cf514a729 Mon Sep 17 00:00:00 2001 From: "Randall Bohn (dexter)" Date: Fri, 19 Aug 2022 21:16:05 -0600 Subject: [PATCH 099/125] add type notations, docstrings --- adafruit_bme280/advanced.py | 2 +- adafruit_bme280/protocol.py | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/adafruit_bme280/advanced.py b/adafruit_bme280/advanced.py index 9b0867c..d8da95c 100644 --- a/adafruit_bme280/advanced.py +++ b/adafruit_bme280/advanced.py @@ -142,7 +142,7 @@ class Adafruit_BME280_Advanced(Adafruit_BME280): """ # pylint: disable=too-many-instance-attributes - def __init__(self, proxy) -> None: + def __init__(self, proxy: typing.Union[I2C_Impl, SPI_Impl]) -> None: """Check the BME280 was found, read the coefficients and enable the sensor""" self._overscan_humidity = OVERSCAN_X1 self._overscan_temperature = OVERSCAN_X1 diff --git a/adafruit_bme280/protocol.py b/adafruit_bme280/protocol.py index 2fed8da..679bb9d 100644 --- a/adafruit_bme280/protocol.py +++ b/adafruit_bme280/protocol.py @@ -6,25 +6,34 @@ from busio import I2C, SPI from digitalio import DigitalInOut + class I2C_Impl: + "Protocol implementation for the I2C bus." + def __init__(self, i2c: I2C, address: int) -> None: from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel i2c_device, ) self._i2c = i2c_device.I2CDevice(i2c, address) - + def read_register(self, register: int, length: int) -> bytearray: + "Read from the device register." with self._i2c as i2c: i2c.write(bytes([register & 0xFF])) result = bytearray(length) i2c.readinto(result) return result + def write_register_byte(self, register: int, value: int) -> None: + "Write to the device register." with self._i2c as i2c: i2c.write(bytes([register & 0xFF, value & 0xFF])) + class SPI_Impl: + "Protocol implemenation for the SPI bus." + def __init__(self, spi: SPI, cs: DigitalInOut, baudrate: int = 100000) -> None: from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel spi_device, @@ -32,7 +41,8 @@ def __init__(self, spi: SPI, cs: DigitalInOut, baudrate: int = 100000) -> None: self._spi = spi_device.SPIDevice(spi, cs, baudrate=baudrate) - def _read_register(self, register: int, length: int) -> bytearray: + def read_register(self, register: int, length: int) -> bytearray: + "Read from the device register." register = (register | 0x80) & 0xFF # Read single, bit 7 high. with self._spi as spi: spi.write(bytearray([register])) # pylint: disable=no-member @@ -41,7 +51,8 @@ def _read_register(self, register: int, length: int) -> bytearray: # print("$%02X => %s" % (register, [hex(i) for i in result])) return result - def _write_register_byte(self, register: int, value: int) -> None: + def write_register_byte(self, register: int, value: int) -> None: + "Write value to the device register." register &= 0x7F # Write, bit 7 low. with self._spi as spi: spi.write(bytes([register, value & 0xFF])) # pylint: disable=no-member From 9f0cb1049131b8b73d2a50d26d524164102320eb Mon Sep 17 00:00:00 2001 From: "Randall Bohn (dexter)" Date: Fri, 19 Aug 2022 21:25:47 -0600 Subject: [PATCH 100/125] use the module name for the protocol import --- adafruit_bme280/basic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_bme280/basic.py b/adafruit_bme280/basic.py index 9fc3f98..c653128 100644 --- a/adafruit_bme280/basic.py +++ b/adafruit_bme280/basic.py @@ -34,7 +34,7 @@ from time import sleep from micropython import const -from protocol import I2C_Impl, SPI_Impl +from adafruit_bme280.protocol import I2C_Impl, SPI_Impl try: import typing # pylint: disable=unused-import From 33f5e611ec097bb316fa139329abef39286cbcc3 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 22 Aug 2022 21:36:29 -0400 Subject: [PATCH 101/125] Keep copyright up to date in documentation --- docs/conf.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 126d8a9..9d6508a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -6,6 +6,7 @@ import os import sys +import datetime sys.path.insert(0, os.path.abspath("..")) @@ -40,7 +41,8 @@ # General information about the project. project = "Adafruit BME280 Library" -copyright = "2017 ladyada" +current_year = str(datetime.datetime.now().year) +copyright = current_year + " ladyada" author = "ladyada" # The version info for the project you're documenting, acts as replacement for From 69a07bcb0f648a9333dc546e7fe997ce02bd69f7 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 23 Aug 2022 17:26:20 -0400 Subject: [PATCH 102/125] Use year duration range for copyright attribution --- docs/conf.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 9d6508a..0f87078 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -41,8 +41,14 @@ # General information about the project. project = "Adafruit BME280 Library" +creation_year = "2017" current_year = str(datetime.datetime.now().year) -copyright = current_year + " ladyada" +year_duration = ( + current_year + if current_year == creation_year + else creation_year + " - " + current_year +) +copyright = year_duration + " ladyada" author = "ladyada" # The version info for the project you're documenting, acts as replacement for From e521dfc953c288e259b8e6b05e7bce507202d173 Mon Sep 17 00:00:00 2001 From: Randall Bohn Date: Sat, 27 Aug 2022 09:35:10 -0600 Subject: [PATCH 103/125] rename _proxy to _bus_implementation Based on feedback from @foamyguy. --- adafruit_bme280/basic.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/adafruit_bme280/basic.py b/adafruit_bme280/basic.py index c653128..c4e345a 100644 --- a/adafruit_bme280/basic.py +++ b/adafruit_bme280/basic.py @@ -89,10 +89,10 @@ class Adafruit_BME280: """ # pylint: disable=too-many-instance-attributes - def __init__(self, proxy: typing.Union[I2C_Impl, SPI_Impl]) -> None: + def __init__(self, bus_implementation: typing.Union[I2C_Impl, SPI_Impl]) -> None: """Check the BME280 was found, read the coefficients and enable the sensor""" # Check device ID. - self._proxy = proxy + self._bus_implementation = bus_implementation chip_id = self._read_byte(_BME280_REGISTER_CHIPID) if _BME280_CHIPID != chip_id: raise RuntimeError("Failed to find BME280! Chip ID 0x%x" % chip_id) @@ -311,10 +311,10 @@ def _read24(self, register: int) -> float: return ret def _read_register(self, register: int, length: int) -> bytearray: - return self._proxy.read_register(register, length) + return self._bus_implementation.read_register(register, length) def _write_register_byte(self, register: int, value: int) -> None: - self._proxy.write_register_byte(register, value) + self._bus_implementation.write_register_byte(register, value) class Adafruit_BME280_I2C(Adafruit_BME280): From a166153ca7d323d90880d14d62f19c7cace455f9 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 00:02:49 -0400 Subject: [PATCH 104/125] Switching to composite actions --- .github/workflows/build.yml | 67 +---------------------- .github/workflows/release.yml | 88 ------------------------------ .github/workflows/release_gh.yml | 14 +++++ .github/workflows/release_pypi.yml | 14 +++++ 4 files changed, 30 insertions(+), 153 deletions(-) delete mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/release_gh.yml create mode 100644 .github/workflows/release_pypi.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cb2f60e..041a337 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,68 +10,5 @@ jobs: test: runs-on: ubuntu-latest steps: - - name: Dump GitHub context - env: - GITHUB_CONTEXT: ${{ toJson(github) }} - run: echo "$GITHUB_CONTEXT" - - name: Translate Repo Name For Build Tools filename_prefix - id: repo-name - run: | - echo ::set-output name=repo-name::$( - echo ${{ github.repository }} | - awk -F '\/' '{ print tolower($2) }' | - tr '_' '-' - ) - - name: Set up Python 3.x - uses: actions/setup-python@v2 - with: - python-version: "3.x" - - name: Versions - run: | - python3 --version - - name: Checkout Current Repo - uses: actions/checkout@v1 - with: - submodules: true - - name: Checkout tools repo - uses: actions/checkout@v2 - with: - repository: adafruit/actions-ci-circuitpython-libs - path: actions-ci - - name: Install dependencies - # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) - run: | - source actions-ci/install.sh - - name: Pip install Sphinx, pre-commit - run: | - pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit - - name: Library version - run: git describe --dirty --always --tags - - name: Setup problem matchers - uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1 - - name: Pre-commit hooks - run: | - pre-commit run --all-files - - name: Build assets - run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . - - name: Archive bundles - uses: actions/upload-artifact@v2 - with: - name: bundles - path: ${{ github.workspace }}/bundles/ - - name: Build docs - working-directory: docs - run: sphinx-build -E -W -b html . _build/html - - name: Check For pyproject.toml - id: need-pypi - run: | - echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' ) - - name: Build Python package - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - run: | - pip install --upgrade build twine - for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do - sed -i -e "s/0.0.0+auto.0/1.2.3/" $file; - done; - python -m build - twine check dist/* + - name: Run Build CI workflow + uses: adafruit/workflows-circuitpython-libs/build@main diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index f3a0325..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,88 +0,0 @@ -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -# -# SPDX-License-Identifier: MIT - -name: Release Actions - -on: - release: - types: [published] - -jobs: - upload-release-assets: - runs-on: ubuntu-latest - steps: - - name: Dump GitHub context - env: - GITHUB_CONTEXT: ${{ toJson(github) }} - run: echo "$GITHUB_CONTEXT" - - name: Translate Repo Name For Build Tools filename_prefix - id: repo-name - run: | - echo ::set-output name=repo-name::$( - echo ${{ github.repository }} | - awk -F '\/' '{ print tolower($2) }' | - tr '_' '-' - ) - - name: Set up Python 3.x - uses: actions/setup-python@v2 - with: - python-version: "3.x" - - name: Versions - run: | - python3 --version - - name: Checkout Current Repo - uses: actions/checkout@v1 - with: - submodules: true - - name: Checkout tools repo - uses: actions/checkout@v2 - with: - repository: adafruit/actions-ci-circuitpython-libs - path: actions-ci - - name: Install deps - run: | - source actions-ci/install.sh - - name: Build assets - run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . - - name: Upload Release Assets - # the 'official' actions version does not yet support dynamically - # supplying asset names to upload. @csexton's version chosen based on - # discussion in the issue below, as its the simplest to implement and - # allows for selecting files with a pattern. - # https://github.com/actions/upload-release-asset/issues/4 - #uses: actions/upload-release-asset@v1.0.1 - uses: csexton/release-asset-action@master - with: - pattern: "bundles/*" - github-token: ${{ secrets.GITHUB_TOKEN }} - - upload-pypi: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: Check For pyproject.toml - id: need-pypi - run: | - echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' ) - - name: Set up Python - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - name: Install dependencies - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - run: | - python -m pip install --upgrade pip - pip install --upgrade build twine - - name: Build and publish - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - env: - TWINE_USERNAME: ${{ secrets.pypi_username }} - TWINE_PASSWORD: ${{ secrets.pypi_password }} - run: | - for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do - sed -i -e "s/0.0.0+auto.0/${{github.event.release.tag_name}}/" $file; - done; - python -m build - twine upload dist/* diff --git a/.github/workflows/release_gh.yml b/.github/workflows/release_gh.yml new file mode 100644 index 0000000..041a337 --- /dev/null +++ b/.github/workflows/release_gh.yml @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: Build CI + +on: [pull_request, push] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Run Build CI workflow + uses: adafruit/workflows-circuitpython-libs/build@main diff --git a/.github/workflows/release_pypi.yml b/.github/workflows/release_pypi.yml new file mode 100644 index 0000000..041a337 --- /dev/null +++ b/.github/workflows/release_pypi.yml @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: Build CI + +on: [pull_request, push] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Run Build CI workflow + uses: adafruit/workflows-circuitpython-libs/build@main From 6685b91d17052794e3addc96337e7064186db827 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 00:46:59 -0400 Subject: [PATCH 105/125] Updated pylint version to 2.13.0 --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0a91a11..e6ddf7c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,7 +18,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: v2.11.1 + rev: v2.13.0 hooks: - id: pylint name: pylint (library code) From bfc44b524b71091b3d0d97e22faff469d5f2f09f Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 08:15:19 -0400 Subject: [PATCH 106/125] Update pylint to 2.15.5 --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e6ddf7c..6996f9c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,7 +18,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: v2.13.0 + rev: v2.15.5 hooks: - id: pylint name: pylint (library code) From e80c357c4cad357e669d1613df16f457e62f3ca8 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 09:12:43 -0400 Subject: [PATCH 107/125] Fix release CI files --- .github/workflows/release_gh.yml | 14 +++++++++----- .github/workflows/release_pypi.yml | 15 ++++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/.github/workflows/release_gh.yml b/.github/workflows/release_gh.yml index 041a337..b8aa8d6 100644 --- a/.github/workflows/release_gh.yml +++ b/.github/workflows/release_gh.yml @@ -2,13 +2,17 @@ # # SPDX-License-Identifier: MIT -name: Build CI +name: GitHub Release Actions -on: [pull_request, push] +on: + release: + types: [published] jobs: - test: + upload-release-assets: runs-on: ubuntu-latest steps: - - name: Run Build CI workflow - uses: adafruit/workflows-circuitpython-libs/build@main + - name: Run GitHub Release CI workflow + uses: adafruit/workflows-circuitpython-libs/release-gh@main + with: + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release_pypi.yml b/.github/workflows/release_pypi.yml index 041a337..65775b7 100644 --- a/.github/workflows/release_pypi.yml +++ b/.github/workflows/release_pypi.yml @@ -2,13 +2,18 @@ # # SPDX-License-Identifier: MIT -name: Build CI +name: PyPI Release Actions -on: [pull_request, push] +on: + release: + types: [published] jobs: - test: + upload-release-assets: runs-on: ubuntu-latest steps: - - name: Run Build CI workflow - uses: adafruit/workflows-circuitpython-libs/build@main + - name: Run PyPI Release CI workflow + uses: adafruit/workflows-circuitpython-libs/release-pypi@main + with: + pypi-username: ${{ secrets.pypi_username }} + pypi-password: ${{ secrets.pypi_password }} From bec68c2132e083c87023b20fcc533a67e06847dc Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 18:34:32 -0400 Subject: [PATCH 108/125] Update .pylintrc for v2.15.5 --- .pylintrc | 45 ++++----------------------------------------- 1 file changed, 4 insertions(+), 41 deletions(-) diff --git a/.pylintrc b/.pylintrc index f772971..40208c3 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries # # SPDX-License-Identifier: Unlicense @@ -26,7 +26,7 @@ jobs=1 # List of plugins (as comma separated values of python modules names) to load, # usually to register additional checkers. -load-plugins= +load-plugins=pylint.extensions.no_self_use # Pickle collected data for later comparisons. persistent=yes @@ -54,8 +54,8 @@ confidence= # --enable=similarities". If you want to run only the classes checker, but have # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" -# disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call -disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation,unspecified-encoding +# disable=import-error,raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,deprecated-str-translate-call +disable=raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,import-error,pointless-string-statement,unspecified-encoding # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option @@ -225,12 +225,6 @@ max-line-length=100 # Maximum number of lines in a module max-module-lines=1000 -# List of optional constructs for which whitespace checking is disabled. `dict- -# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. -# `trailing-comma` allows a space between comma and closing bracket: (a, ). -# `empty-line` allows space-only lines. -no-space-check=trailing-comma,dict-separator - # Allow the body of a class to be on the same line as the declaration if body # contains single statement. single-line-class-stmt=no @@ -257,38 +251,22 @@ min-similarity-lines=12 [BASIC] -# Naming hint for argument names -argument-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct argument names argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ -# Naming hint for attribute names -attr-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct attribute names attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ # Bad variable names which should always be refused, separated by a comma bad-names=foo,bar,baz,toto,tutu,tata -# Naming hint for class attribute names -class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ - # Regular expression matching correct class attribute names class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ -# Naming hint for class names -# class-name-hint=[A-Z_][a-zA-Z0-9]+$ -class-name-hint=[A-Z_][a-zA-Z0-9_]+$ - # Regular expression matching correct class names # class-rgx=[A-Z_][a-zA-Z0-9]+$ class-rgx=[A-Z_][a-zA-Z0-9_]+$ -# Naming hint for constant names -const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$ - # Regular expression matching correct constant names const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ @@ -296,9 +274,6 @@ const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ # ones are exempt. docstring-min-length=-1 -# Naming hint for function names -function-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct function names function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ @@ -309,21 +284,12 @@ good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_ # Include a hint for the correct naming format with invalid-name include-naming-hint=no -# Naming hint for inline iteration names -inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$ - # Regular expression matching correct inline iteration names inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ -# Naming hint for method names -method-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct method names method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ -# Naming hint for module names -module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ - # Regular expression matching correct module names module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ @@ -339,9 +305,6 @@ no-docstring-rgx=^_ # to this list to register other decorators that produce valid properties. property-classes=abc.abstractproperty -# Naming hint for variable names -variable-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct variable names variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ From 4709166d70f48e98b2b20d0c82e9dce44836bbf0 Mon Sep 17 00:00:00 2001 From: evaherrada Date: Thu, 10 Nov 2022 15:03:54 -0500 Subject: [PATCH 109/125] Fixed linting --- adafruit_bme280/protocol.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/adafruit_bme280/protocol.py b/adafruit_bme280/protocol.py index 679bb9d..b24a397 100644 --- a/adafruit_bme280/protocol.py +++ b/adafruit_bme280/protocol.py @@ -34,7 +34,12 @@ def write_register_byte(self, register: int, value: int) -> None: class SPI_Impl: "Protocol implemenation for the SPI bus." - def __init__(self, spi: SPI, cs: DigitalInOut, baudrate: int = 100000) -> None: + def __init__( + self, + spi: SPI, + cs: DigitalInOut, # pylint: disable=invalid-name + baudrate: int = 100000, + ) -> None: from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel spi_device, ) From dd135f05dfab7e2b618b2384c2c72cf5fe29af32 Mon Sep 17 00:00:00 2001 From: dherrada Date: Fri, 18 Nov 2022 13:05:21 -0500 Subject: [PATCH 110/125] Added commented out board.STEMMA_I2C with explanation --- examples/bme280_normal_mode.py | 1 + examples/bme280_simpletest.py | 1 + 2 files changed, 2 insertions(+) diff --git a/examples/bme280_normal_mode.py b/examples/bme280_normal_mode.py index 85dd156..65505a4 100644 --- a/examples/bme280_normal_mode.py +++ b/examples/bme280_normal_mode.py @@ -12,6 +12,7 @@ # Create sensor object, using the board's default I2C bus. i2c = board.I2C() # uses board.SCL and board.SDA +# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) # OR create sensor object, using the board's default SPI bus. diff --git a/examples/bme280_simpletest.py b/examples/bme280_simpletest.py index 2f1c39a..5b06be0 100644 --- a/examples/bme280_simpletest.py +++ b/examples/bme280_simpletest.py @@ -7,6 +7,7 @@ # Create sensor object, using the board's default I2C bus. i2c = board.I2C() # uses board.SCL and board.SDA +# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) # OR create sensor object, using the board's default SPI bus. From d390b3ae9298abbe3655816dc048426d007bd7dc Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Thu, 1 Sep 2022 20:16:31 -0400 Subject: [PATCH 111/125] Add .venv to .gitignore Signed-off-by: Alec Delaney <89490472+tekktrik@users.noreply.github.com> --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 544ec4a..db3d538 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,7 @@ _build # Virtual environment-specific files .env +.venv # MacOS-specific files *.DS_Store From 5dee063efbbdab5ffde21570ca572a0b21d1be56 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Thu, 19 Jan 2023 23:39:55 -0500 Subject: [PATCH 112/125] Add upload url to release action Signed-off-by: Alec Delaney <89490472+tekktrik@users.noreply.github.com> --- .github/workflows/release_gh.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release_gh.yml b/.github/workflows/release_gh.yml index b8aa8d6..9acec60 100644 --- a/.github/workflows/release_gh.yml +++ b/.github/workflows/release_gh.yml @@ -16,3 +16,4 @@ jobs: uses: adafruit/workflows-circuitpython-libs/release-gh@main with: github-token: ${{ secrets.GITHUB_TOKEN }} + upload-url: ${{ github.event.release.upload_url }} From aa0e2079adf978322c4497e56fb6fb724f540b8f Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Mon, 27 Mar 2023 17:57:43 -0400 Subject: [PATCH 113/125] Fixing Pylint Short Namnes --- adafruit_bme280/advanced.py | 88 +++++++++++++++++++------------------ adafruit_bme280/basic.py | 50 +++++++++++---------- adafruit_bme280/protocol.py | 8 ++-- docs/api.rst | 3 ++ 4 files changed, 78 insertions(+), 71 deletions(-) diff --git a/adafruit_bme280/advanced.py b/adafruit_bme280/advanced.py index d8da95c..f6e9865 100644 --- a/adafruit_bme280/advanced.py +++ b/adafruit_bme280/advanced.py @@ -284,36 +284,36 @@ class Adafruit_BME280_I2C(Adafruit_BME280_Advanced): **Quickstart: Importing and using the BME280** - Here is an example of using the :class:`Adafruit_BME280_I2C`. - First you will need to import the libraries to use the sensor + Here is an example of using the :class:`Adafruit_BME280_I2C`. + First you will need to import the libraries to use the sensor - .. code-block:: python + .. code-block:: python - import board - import adafruit_bme280.advanced as adafruit_bme280 + import board + import adafruit_bme280.advanced as adafruit_bme280 - Once this is done you can define your `board.I2C` object and define your sensor object + Once this is done you can define your `board.I2C` object and define your sensor object - .. code-block:: python + .. code-block:: python - i2c = board.I2C() # uses board.SCL and board.SDA - bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) + i2c = board.I2C() # uses board.SCL and board.SDA + bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) - You need to setup the pressure at sea level + You need to setup the pressure at sea level - .. code-block:: python + .. code-block:: python - bme280.sea_level_pressure = 1013.25 + bme280.sea_level_pressure = 1013.25 - Now you have access to the :attr:`temperature`, :attr:`relative_humidity` - :attr:`pressure` and :attr:`altitude` attributes + Now you have access to the :attr:`temperature`, :attr:`relative_humidity` + :attr:`pressure` and :attr:`altitude` attributes - .. code-block:: python + .. code-block:: python - temperature = bme280.temperature - relative_humidity = bme280.relative_humidity - pressure = bme280.pressure - altitude = bme280.altitude + temperature = bme280.temperature + relative_humidity = bme280.relative_humidity + pressure = bme280.pressure + altitude = bme280.altitude """ @@ -325,7 +325,7 @@ class Adafruit_BME280_SPI(Adafruit_BME280_Advanced): """Driver for BME280 connected over SPI :param ~busio.SPI spi: SPI device - :param ~digitalio.DigitalInOut cs: Chip Select + :param ~digitalio.DigitalInOut chip_select: Chip Select :param int baudrate: Clock rate, default is 100000. Can be changed with :meth:`baudrate` .. note:: @@ -334,40 +334,42 @@ class Adafruit_BME280_SPI(Adafruit_BME280_Advanced): **Quickstart: Importing and using the BME280** - Here is an example of using the :class:`Adafruit_BME280_SPI` class. - First you will need to import the libraries to use the sensor + Here is an example of using the :class:`Adafruit_BME280_SPI` class. + First you will need to import the libraries to use the sensor - .. code-block:: python + .. code-block:: python - import board - from digitalio import DigitalInOut - import adafruit_bme280.advanced as adafruit_bme280 + import board + from digitalio import DigitalInOut + import adafruit_bme280.advanced as adafruit_bme280 - Once this is done you can define your `board.SPI` object and define your sensor object + Once this is done you can define your `board.SPI` object and define your sensor object - .. code-block:: python + .. code-block:: python - cs = digitalio.DigitalInOut(board.D10) - spi = board.SPI() - bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, cs) + chip_select = digitalio.DigitalInOut(board.D10) + spi = board.SPI() + bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, chip_select) - You need to setup the pressure at sea level + You need to setup the pressure at sea level - .. code-block:: python + .. code-block:: python - bme280.sea_level_pressure = 1013.25 + bme280.sea_level_pressure = 1013.25 - Now you have access to the :attr:`temperature`, :attr:`relative_humidity` - :attr:`pressure` and :attr:`altitude` attributes + Now you have access to the :attr:`temperature`, :attr:`relative_humidity` + :attr:`pressure` and :attr:`altitude` attributes - .. code-block:: python + .. code-block:: python - temperature = bme280.temperature - relative_humidity = bme280.relative_humidity - pressure = bme280.pressure - altitude = bme280.altitude + temperature = bme280.temperature + relative_humidity = bme280.relative_humidity + pressure = bme280.pressure + altitude = bme280.altitude """ - def __init__(self, spi: SPI, cs: DigitalInOut, baudrate: int = 100000) -> None: - super().__init__(SPI_Impl(spi, cs, baudrate)) + def __init__( + self, spi: SPI, chip_select: DigitalInOut, baudrate: int = 100000 + ) -> None: + super().__init__(SPI_Impl(spi, chip_select, baudrate)) diff --git a/adafruit_bme280/basic.py b/adafruit_bme280/basic.py index c4e345a..af105a7 100644 --- a/adafruit_bme280/basic.py +++ b/adafruit_bme280/basic.py @@ -331,36 +331,36 @@ class Adafruit_BME280_I2C(Adafruit_BME280): **Quickstart: Importing and using the BME280** - Here is an example of using the :class:`Adafruit_BME280_I2C`. - First you will need to import the libraries to use the sensor + Here is an example of using the :class:`Adafruit_BME280_I2C`. + First you will need to import the libraries to use the sensor - .. code-block:: python + .. code-block:: python - import board - from adafruit_bme280 import basic as adafruit_bme280 + import board + from adafruit_bme280 import basic as adafruit_bme280 - Once this is done you can define your `board.I2C` object and define your sensor object + Once this is done you can define your `board.I2C` object and define your sensor object - .. code-block:: python + .. code-block:: python - i2c = board.I2C() # uses board.SCL and board.SDA - bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) + i2c = board.I2C() # uses board.SCL and board.SDA + bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) - You need to setup the pressure at sea level + You need to setup the pressure at sea level - .. code-block:: python + .. code-block:: python - bme280.sea_level_pressure = 1013.25 + bme280.sea_level_pressure = 1013.25 - Now you have access to the :attr:`temperature`, :attr:`relative_humidity` - :attr:`pressure` and :attr:`altitude` attributes + Now you have access to the :attr:`temperature`, :attr:`relative_humidity` + :attr:`pressure` and :attr:`altitude` attributes - .. code-block:: python + .. code-block:: python - temperature = bme280.temperature - relative_humidity = bme280.relative_humidity - pressure = bme280.pressure - altitude = bme280.altitude + temperature = bme280.temperature + relative_humidity = bme280.relative_humidity + pressure = bme280.pressure + altitude = bme280.altitude """ @@ -373,7 +373,7 @@ class Adafruit_BME280_SPI(Adafruit_BME280): """Driver for BME280 connected over SPI :param ~busio.SPI spi: SPI device - :param ~digitalio.DigitalInOut cs: Chip Select + :param ~digitalio.DigitalInOut chip_select: Chip Select :param int baudrate: Clock rate, default is 100000. Can be changed with :meth:`baudrate` .. note:: @@ -395,9 +395,9 @@ class Adafruit_BME280_SPI(Adafruit_BME280): .. code-block:: python - cs = digitalio.DigitalInOut(board.D10) + chip_select = digitalio.DigitalInOut(board.D10) spi = board.SPI() - bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, cs) + bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, chip_select) You need to setup the pressure at sea level @@ -417,5 +417,7 @@ class Adafruit_BME280_SPI(Adafruit_BME280): """ - def __init__(self, spi: SPI, cs: DigitalInOut, baudrate: int = 100000) -> None: - super().__init__(SPI_Impl(spi, cs, baudrate)) + def __init__( + self, spi: SPI, chip_select: DigitalInOut, baudrate: int = 100000 + ) -> None: + super().__init__(SPI_Impl(spi, chip_select, baudrate)) diff --git a/adafruit_bme280/protocol.py b/adafruit_bme280/protocol.py index b24a397..71be771 100644 --- a/adafruit_bme280/protocol.py +++ b/adafruit_bme280/protocol.py @@ -26,25 +26,25 @@ def read_register(self, register: int, length: int) -> bytearray: return result def write_register_byte(self, register: int, value: int) -> None: - "Write to the device register." + """Write to the device register""" with self._i2c as i2c: i2c.write(bytes([register & 0xFF, value & 0xFF])) class SPI_Impl: - "Protocol implemenation for the SPI bus." + """Protocol implemenation for the SPI bus.""" def __init__( self, spi: SPI, - cs: DigitalInOut, # pylint: disable=invalid-name + chip_select: DigitalInOut, baudrate: int = 100000, ) -> None: from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel spi_device, ) - self._spi = spi_device.SPIDevice(spi, cs, baudrate=baudrate) + self._spi = spi_device.SPIDevice(spi, chip_select, baudrate=baudrate) def read_register(self, register: int, length: int) -> bytearray: "Read from the device register." diff --git a/docs/api.rst b/docs/api.rst index 8818b61..ffdfd9a 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -9,3 +9,6 @@ .. automodule:: adafruit_bme280.advanced :members: + +.. automodule:: adafruit_bme280.protocol + :members: From ed8aec49128748eead3234935068ad6725a664b5 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Mon, 27 Mar 2023 19:32:40 -0400 Subject: [PATCH 114/125] fixing short names --- .pylintrc | 2 +- adafruit_bme280/advanced.py | 12 +++++------- adafruit_bme280/basic.py | 12 +++++------- adafruit_bme280/protocol.py | 4 ++-- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/.pylintrc b/.pylintrc index 40208c3..6eea82f 100644 --- a/.pylintrc +++ b/.pylintrc @@ -279,7 +279,7 @@ function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ # Good variable names which should always be accepted, separated by a comma # good-names=i,j,k,ex,Run,_ -good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_ +good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_,cs # Include a hint for the correct naming format with invalid-name include-naming-hint=no diff --git a/adafruit_bme280/advanced.py b/adafruit_bme280/advanced.py index f6e9865..98ed180 100644 --- a/adafruit_bme280/advanced.py +++ b/adafruit_bme280/advanced.py @@ -325,7 +325,7 @@ class Adafruit_BME280_SPI(Adafruit_BME280_Advanced): """Driver for BME280 connected over SPI :param ~busio.SPI spi: SPI device - :param ~digitalio.DigitalInOut chip_select: Chip Select + :param ~digitalio.DigitalInOut cs: Chip Select :param int baudrate: Clock rate, default is 100000. Can be changed with :meth:`baudrate` .. note:: @@ -347,9 +347,9 @@ class Adafruit_BME280_SPI(Adafruit_BME280_Advanced): .. code-block:: python - chip_select = digitalio.DigitalInOut(board.D10) + cs = digitalio.DigitalInOut(board.D10) spi = board.SPI() - bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, chip_select) + bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, cs) You need to setup the pressure at sea level @@ -369,7 +369,5 @@ class Adafruit_BME280_SPI(Adafruit_BME280_Advanced): """ - def __init__( - self, spi: SPI, chip_select: DigitalInOut, baudrate: int = 100000 - ) -> None: - super().__init__(SPI_Impl(spi, chip_select, baudrate)) + def __init__(self, spi: SPI, cs: DigitalInOut, baudrate: int = 100000) -> None: + super().__init__(SPI_Impl(spi, cs, baudrate)) diff --git a/adafruit_bme280/basic.py b/adafruit_bme280/basic.py index af105a7..958da93 100644 --- a/adafruit_bme280/basic.py +++ b/adafruit_bme280/basic.py @@ -373,7 +373,7 @@ class Adafruit_BME280_SPI(Adafruit_BME280): """Driver for BME280 connected over SPI :param ~busio.SPI spi: SPI device - :param ~digitalio.DigitalInOut chip_select: Chip Select + :param ~digitalio.DigitalInOut cs: Chip Select :param int baudrate: Clock rate, default is 100000. Can be changed with :meth:`baudrate` .. note:: @@ -395,9 +395,9 @@ class Adafruit_BME280_SPI(Adafruit_BME280): .. code-block:: python - chip_select = digitalio.DigitalInOut(board.D10) + cs = digitalio.DigitalInOut(board.D10) spi = board.SPI() - bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, chip_select) + bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, cs) You need to setup the pressure at sea level @@ -417,7 +417,5 @@ class Adafruit_BME280_SPI(Adafruit_BME280): """ - def __init__( - self, spi: SPI, chip_select: DigitalInOut, baudrate: int = 100000 - ) -> None: - super().__init__(SPI_Impl(spi, chip_select, baudrate)) + def __init__(self, spi: SPI, cs: DigitalInOut, baudrate: int = 100000) -> None: + super().__init__(SPI_Impl(spi, cs, baudrate)) diff --git a/adafruit_bme280/protocol.py b/adafruit_bme280/protocol.py index 71be771..8cb7058 100644 --- a/adafruit_bme280/protocol.py +++ b/adafruit_bme280/protocol.py @@ -37,14 +37,14 @@ class SPI_Impl: def __init__( self, spi: SPI, - chip_select: DigitalInOut, + cs: DigitalInOut, baudrate: int = 100000, ) -> None: from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel spi_device, ) - self._spi = spi_device.SPIDevice(spi, chip_select, baudrate=baudrate) + self._spi = spi_device.SPIDevice(spi, cs, baudrate=baudrate) def read_register(self, register: int, length: int) -> bytearray: "Read from the device register." From 6c8152a89f2247d316be38917a8595c0cac49f9f Mon Sep 17 00:00:00 2001 From: Tekktrik Date: Tue, 9 May 2023 20:26:25 -0400 Subject: [PATCH 115/125] Update pre-commit hooks Signed-off-by: Tekktrik --- .pre-commit-config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6996f9c..179cf07 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,21 +4,21 @@ repos: - repo: https://github.com/python/black - rev: 22.3.0 + rev: 23.3.0 hooks: - id: black - repo: https://github.com/fsfe/reuse-tool - rev: v0.14.0 + rev: v1.1.2 hooks: - id: reuse - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.2.0 + rev: v4.4.0 hooks: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: v2.15.5 + rev: v2.17.4 hooks: - id: pylint name: pylint (library code) From 8ed50099523a4f990091e78ce3d37f127a0a00e1 Mon Sep 17 00:00:00 2001 From: Tekktrik Date: Wed, 10 May 2023 22:28:38 -0400 Subject: [PATCH 116/125] Run pre-commit --- adafruit_bme280/advanced.py | 1 + 1 file changed, 1 insertion(+) diff --git a/adafruit_bme280/advanced.py b/adafruit_bme280/advanced.py index 98ed180..30e0589 100644 --- a/adafruit_bme280/advanced.py +++ b/adafruit_bme280/advanced.py @@ -131,6 +131,7 @@ STANDBY_TC_1000, ) + # pylint: disable=abstract-method class Adafruit_BME280_Advanced(Adafruit_BME280): """Driver from BME280 Temperature, Humidity and Barometric Pressure sensor From cffb535ac7ee663ccc77ea8ebca3cbef62c91f29 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Tue, 23 May 2023 22:29:00 -0400 Subject: [PATCH 117/125] Update .pylintrc, fix jQuery for docs --- .pylintrc | 2 +- docs/conf.py | 1 + docs/requirements.txt | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index 6eea82f..fd97a01 100644 --- a/.pylintrc +++ b/.pylintrc @@ -396,4 +396,4 @@ min-public-methods=1 # Exceptions that will emit a warning when being caught. Defaults to # "Exception" -overgeneral-exceptions=Exception +overgeneral-exceptions=builtins.Exception diff --git a/docs/conf.py b/docs/conf.py index 0f87078..8a10f85 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -17,6 +17,7 @@ # ones. extensions = [ "sphinx.ext.autodoc", + "sphinxcontrib.jquery", "sphinx.ext.intersphinx", "sphinx.ext.viewcode", ] diff --git a/docs/requirements.txt b/docs/requirements.txt index 88e6733..797aa04 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -3,3 +3,4 @@ # SPDX-License-Identifier: Unlicense sphinx>=4.0.0 +sphinxcontrib-jquery From cde05a9dca5bf0839df91d92741c01caecb506f7 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 18 Sep 2023 16:21:39 -0500 Subject: [PATCH 118/125] "fix rtd theme " --- docs/conf.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 8a10f85..c1d3086 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -97,19 +97,10 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -on_rtd = os.environ.get("READTHEDOCS", None) == "True" - -if not on_rtd: # only import and set the theme if we're building docs locally - try: - import sphinx_rtd_theme - - html_theme = "sphinx_rtd_theme" - html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] - except: - html_theme = "default" - html_theme_path = ["."] -else: - html_theme_path = ["."] +import sphinx_rtd_theme + +html_theme = "sphinx_rtd_theme" +html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, From 0baf6d0373b94974793b4c34dec7f7e4279ed9ab Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 16 Oct 2023 14:30:31 -0500 Subject: [PATCH 119/125] unpin sphinx and add sphinx-rtd-theme to docs reqs Signed-off-by: foamyguy --- docs/requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 797aa04..979f568 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -2,5 +2,6 @@ # # SPDX-License-Identifier: Unlicense -sphinx>=4.0.0 +sphinx sphinxcontrib-jquery +sphinx-rtd-theme From 6aab3b0b8ecf357bc87094201aac0a9372db0566 Mon Sep 17 00:00:00 2001 From: Romanos Dodopoulos Date: Wed, 24 Jul 2024 19:25:26 +0200 Subject: [PATCH 120/125] Fix SPI commented example bme280_normal_mode.py --- examples/bme280_normal_mode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/bme280_normal_mode.py b/examples/bme280_normal_mode.py index 65505a4..62fffd5 100644 --- a/examples/bme280_normal_mode.py +++ b/examples/bme280_normal_mode.py @@ -17,7 +17,7 @@ # OR create sensor object, using the board's default SPI bus. # SPI setup -# from digitalio import DigitalInOut +# import digitalio # spi = board.SPI() # bme_cs = digitalio.DigitalInOut(board.D10) # bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs) From 1b462224034a81557f3522ad90c4ed1e7e91d8b8 Mon Sep 17 00:00:00 2001 From: Romanos Dodopoulos Date: Wed, 24 Jul 2024 19:28:03 +0200 Subject: [PATCH 121/125] Fix SPI commented example bme280_simpletest.py --- examples/bme280_simpletest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/bme280_simpletest.py b/examples/bme280_simpletest.py index 5b06be0..76c0dfc 100644 --- a/examples/bme280_simpletest.py +++ b/examples/bme280_simpletest.py @@ -11,6 +11,7 @@ bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) # OR create sensor object, using the board's default SPI bus. +# import digitalio # spi = board.SPI() # bme_cs = digitalio.DigitalInOut(board.D10) # bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs) From 563e650003f1328907b361e2810f85057622a16c Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 7 Oct 2024 09:24:05 -0500 Subject: [PATCH 122/125] remove deprecated get_html_theme_path() call Signed-off-by: foamyguy --- docs/conf.py | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index c1d3086..6f2c02b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -100,7 +100,6 @@ import sphinx_rtd_theme html_theme = "sphinx_rtd_theme" -html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, From 67ae1c2bb11a59c1244d2d1ddda41452635034f4 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 14 Jan 2025 11:32:34 -0600 Subject: [PATCH 123/125] add sphinx configuration to rtd.yaml Signed-off-by: foamyguy --- .readthedocs.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 33c2a61..88bca9f 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -8,6 +8,9 @@ # Required version: 2 +sphinx: + configuration: docs/conf.py + build: os: ubuntu-20.04 tools: From 8fe6286f3dfbb08c3e282a13749c7e9d8f4ee23d Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 13 May 2025 19:33:33 +0000 Subject: [PATCH 124/125] change to ruff --- .gitattributes | 11 + .pre-commit-config.yaml | 43 +--- .pylintrc | 399 ----------------------------- README.rst | 6 +- adafruit_bme280/advanced.py | 7 +- adafruit_bme280/basic.py | 20 +- adafruit_bme280/protocol.py | 10 +- docs/api.rst | 3 + docs/conf.py | 8 +- examples/bme280_normal_mode.py | 3 + examples/bme280_simpletest.py | 2 + examples/bme280_simpletest_pico.py | 2 + ruff.toml | 105 ++++++++ 13 files changed, 158 insertions(+), 461 deletions(-) create mode 100644 .gitattributes delete mode 100644 .pylintrc create mode 100644 ruff.toml diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..21c125c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,11 @@ +# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + +.py text eol=lf +.rst text eol=lf +.txt text eol=lf +.yaml text eol=lf +.toml text eol=lf +.license text eol=lf +.md text eol=lf diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 179cf07..ff19dde 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,42 +1,21 @@ -# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò +# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries # # SPDX-License-Identifier: Unlicense repos: - - repo: https://github.com/python/black - rev: 23.3.0 - hooks: - - id: black - - repo: https://github.com/fsfe/reuse-tool - rev: v1.1.2 - hooks: - - id: reuse - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - - repo: https://github.com/pycqa/pylint - rev: v2.17.4 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.3.4 hooks: - - id: pylint - name: pylint (library code) - types: [python] - args: - - --disable=consider-using-f-string,duplicate-code - exclude: "^(docs/|examples/|tests/|setup.py$)" - - id: pylint - name: pylint (example code) - description: Run pylint rules on "examples/*.py" files - types: [python] - files: "^examples/" - args: - - --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code - - id: pylint - name: pylint (test code) - description: Run pylint rules on "tests/*.py" files - types: [python] - files: "^tests/" - args: - - --disable=missing-docstring,consider-using-f-string,duplicate-code + - id: ruff-format + - id: ruff + args: ["--fix"] + - repo: https://github.com/fsfe/reuse-tool + rev: v3.0.1 + hooks: + - id: reuse diff --git a/.pylintrc b/.pylintrc deleted file mode 100644 index fd97a01..0000000 --- a/.pylintrc +++ /dev/null @@ -1,399 +0,0 @@ -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -# -# SPDX-License-Identifier: Unlicense - -[MASTER] - -# A comma-separated list of package or module names from where C extensions may -# be loaded. Extensions are loading into the active Python interpreter and may -# run arbitrary code -extension-pkg-whitelist= - -# Add files or directories to the ignore-list. They should be base names, not -# paths. -ignore=CVS - -# Add files or directories matching the regex patterns to the ignore-list. The -# regex matches against base names, not paths. -ignore-patterns= - -# Python code to execute, usually for sys.path manipulation such as -# pygtk.require(). -#init-hook= - -# Use multiple processes to speed up Pylint. -jobs=1 - -# List of plugins (as comma separated values of python modules names) to load, -# usually to register additional checkers. -load-plugins=pylint.extensions.no_self_use - -# Pickle collected data for later comparisons. -persistent=yes - -# Specify a configuration file. -#rcfile= - -# Allow loading of arbitrary C extensions. Extensions are imported into the -# active Python interpreter and may run arbitrary code. -unsafe-load-any-extension=no - - -[MESSAGES CONTROL] - -# Only show warnings with the listed confidence levels. Leave empty to show -# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED -confidence= - -# Disable the message, report, category or checker with the given id(s). You -# can either give multiple identifiers separated by comma (,) or put this -# option multiple times (only on the command line, not in the configuration -# file where it should appear only once).You can also use "--disable=all" to -# disable everything first and then reenable specific checks. For example, if -# you want to run only the similarities checker, you can use "--disable=all -# --enable=similarities". If you want to run only the classes checker, but have -# no Warning level messages displayed, use"--disable=all --enable=classes -# --disable=W" -# disable=import-error,raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,deprecated-str-translate-call -disable=raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,import-error,pointless-string-statement,unspecified-encoding - -# Enable the message, report, category or checker with the given id(s). You can -# either give multiple identifier separated by comma (,) or put this option -# multiple time (only on the command line, not in the configuration file where -# it should appear only once). See also the "--disable" option for examples. -enable= - - -[REPORTS] - -# Python expression which should return a note less than 10 (10 is the highest -# note). You have access to the variables errors warning, statement which -# respectively contain the number of errors / warnings messages and the total -# number of statements analyzed. This is used by the global evaluation report -# (RP0004). -evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) - -# Template used to display messages. This is a python new-style format string -# used to format the message information. See doc for all details -#msg-template= - -# Set the output format. Available formats are text, parseable, colorized, json -# and msvs (visual studio).You can also give a reporter class, eg -# mypackage.mymodule.MyReporterClass. -output-format=text - -# Tells whether to display a full report or only the messages -reports=no - -# Activate the evaluation score. -score=yes - - -[REFACTORING] - -# Maximum number of nested blocks for function / method body -max-nested-blocks=5 - - -[LOGGING] - -# Logging modules to check that the string format arguments are in logging -# function parameter format -logging-modules=logging - - -[SPELLING] - -# Spelling dictionary name. Available dictionaries: none. To make it working -# install python-enchant package. -spelling-dict= - -# List of comma separated words that should not be checked. -spelling-ignore-words= - -# A path to a file that contains private dictionary; one word per line. -spelling-private-dict-file= - -# Tells whether to store unknown words to indicated private dictionary in -# --spelling-private-dict-file option instead of raising a message. -spelling-store-unknown-words=no - - -[MISCELLANEOUS] - -# List of note tags to take in consideration, separated by a comma. -# notes=FIXME,XXX,TODO -notes=FIXME,XXX - - -[TYPECHECK] - -# List of decorators that produce context managers, such as -# contextlib.contextmanager. Add to this list to register other decorators that -# produce valid context managers. -contextmanager-decorators=contextlib.contextmanager - -# List of members which are set dynamically and missed by pylint inference -# system, and so shouldn't trigger E1101 when accessed. Python regular -# expressions are accepted. -generated-members= - -# Tells whether missing members accessed in mixin class should be ignored. A -# mixin class is detected if its name ends with "mixin" (case insensitive). -ignore-mixin-members=yes - -# This flag controls whether pylint should warn about no-member and similar -# checks whenever an opaque object is returned when inferring. The inference -# can return multiple potential results while evaluating a Python object, but -# some branches might not be evaluated, which results in partial inference. In -# that case, it might be useful to still emit no-member and other checks for -# the rest of the inferred objects. -ignore-on-opaque-inference=yes - -# List of class names for which member attributes should not be checked (useful -# for classes with dynamically set attributes). This supports the use of -# qualified names. -ignored-classes=optparse.Values,thread._local,_thread._local - -# List of module names for which member attributes should not be checked -# (useful for modules/projects where namespaces are manipulated during runtime -# and thus existing member attributes cannot be deduced by static analysis. It -# supports qualified module names, as well as Unix pattern matching. -ignored-modules=board - -# Show a hint with possible names when a member name was not found. The aspect -# of finding the hint is based on edit distance. -missing-member-hint=yes - -# The minimum edit distance a name should have in order to be considered a -# similar match for a missing member name. -missing-member-hint-distance=1 - -# The total number of similar names that should be taken in consideration when -# showing a hint for a missing member. -missing-member-max-choices=1 - - -[VARIABLES] - -# List of additional names supposed to be defined in builtins. Remember that -# you should avoid to define new builtins when possible. -additional-builtins= - -# Tells whether unused global variables should be treated as a violation. -allow-global-unused-variables=yes - -# List of strings which can identify a callback function by name. A callback -# name must start or end with one of those strings. -callbacks=cb_,_cb - -# A regular expression matching the name of dummy variables (i.e. expectedly -# not used). -dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ - -# Argument names that match this expression will be ignored. Default to name -# with leading underscore -ignored-argument-names=_.*|^ignored_|^unused_ - -# Tells whether we should check for unused import in __init__ files. -init-import=no - -# List of qualified module names which can have objects that can redefine -# builtins. -redefining-builtins-modules=six.moves,future.builtins - - -[FORMAT] - -# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. -# expected-line-ending-format= -expected-line-ending-format=LF - -# Regexp for a line that is allowed to be longer than the limit. -ignore-long-lines=^\s*(# )??$ - -# Number of spaces of indent required inside a hanging or continued line. -indent-after-paren=4 - -# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 -# tab). -indent-string=' ' - -# Maximum number of characters on a single line. -max-line-length=100 - -# Maximum number of lines in a module -max-module-lines=1000 - -# Allow the body of a class to be on the same line as the declaration if body -# contains single statement. -single-line-class-stmt=no - -# Allow the body of an if to be on the same line as the test if there is no -# else. -single-line-if-stmt=no - - -[SIMILARITIES] - -# Ignore comments when computing similarities. -ignore-comments=yes - -# Ignore docstrings when computing similarities. -ignore-docstrings=yes - -# Ignore imports when computing similarities. -ignore-imports=yes - -# Minimum lines number of a similarity. -min-similarity-lines=12 - - -[BASIC] - -# Regular expression matching correct argument names -argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Regular expression matching correct attribute names -attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Bad variable names which should always be refused, separated by a comma -bad-names=foo,bar,baz,toto,tutu,tata - -# Regular expression matching correct class attribute names -class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ - -# Regular expression matching correct class names -# class-rgx=[A-Z_][a-zA-Z0-9]+$ -class-rgx=[A-Z_][a-zA-Z0-9_]+$ - -# Regular expression matching correct constant names -const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ - -# Minimum line length for functions/classes that require docstrings, shorter -# ones are exempt. -docstring-min-length=-1 - -# Regular expression matching correct function names -function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Good variable names which should always be accepted, separated by a comma -# good-names=i,j,k,ex,Run,_ -good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_,cs - -# Include a hint for the correct naming format with invalid-name -include-naming-hint=no - -# Regular expression matching correct inline iteration names -inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ - -# Regular expression matching correct method names -method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Regular expression matching correct module names -module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ - -# Colon-delimited sets of names that determine each other's naming style when -# the name regexes allow several styles. -name-group= - -# Regular expression which should only match function or class names that do -# not require a docstring. -no-docstring-rgx=^_ - -# List of decorators that produce properties, such as abc.abstractproperty. Add -# to this list to register other decorators that produce valid properties. -property-classes=abc.abstractproperty - -# Regular expression matching correct variable names -variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - - -[IMPORTS] - -# Allow wildcard imports from modules that define __all__. -allow-wildcard-with-all=no - -# Analyse import fallback blocks. This can be used to support both Python 2 and -# 3 compatible code, which means that the block might have code that exists -# only in one or another interpreter, leading to false positives when analysed. -analyse-fallback-blocks=no - -# Deprecated modules which should not be used, separated by a comma -deprecated-modules=optparse,tkinter.tix - -# Create a graph of external dependencies in the given file (report RP0402 must -# not be disabled) -ext-import-graph= - -# Create a graph of every (i.e. internal and external) dependencies in the -# given file (report RP0402 must not be disabled) -import-graph= - -# Create a graph of internal dependencies in the given file (report RP0402 must -# not be disabled) -int-import-graph= - -# Force import order to recognize a module as part of the standard -# compatibility libraries. -known-standard-library= - -# Force import order to recognize a module as part of a third party library. -known-third-party=enchant - - -[CLASSES] - -# List of method names used to declare (i.e. assign) instance attributes. -defining-attr-methods=__init__,__new__,setUp - -# List of member names, which should be excluded from the protected access -# warning. -exclude-protected=_asdict,_fields,_replace,_source,_make - -# List of valid names for the first argument in a class method. -valid-classmethod-first-arg=cls - -# List of valid names for the first argument in a metaclass class method. -valid-metaclass-classmethod-first-arg=mcs - - -[DESIGN] - -# Maximum number of arguments for function / method -max-args=5 - -# Maximum number of attributes for a class (see R0902). -# max-attributes=7 -max-attributes=11 - -# Maximum number of boolean expressions in a if statement -max-bool-expr=5 - -# Maximum number of branch for function / method body -max-branches=12 - -# Maximum number of locals for function / method body -max-locals=15 - -# Maximum number of parents for a class (see R0901). -max-parents=7 - -# Maximum number of public methods for a class (see R0904). -max-public-methods=20 - -# Maximum number of return / yield for function / method body -max-returns=6 - -# Maximum number of statements in function / method body -max-statements=50 - -# Minimum number of public methods for a class (see R0903). -min-public-methods=1 - - -[EXCEPTIONS] - -# Exceptions that will emit a warning when being caught. Defaults to -# "Exception" -overgeneral-exceptions=builtins.Exception diff --git a/README.rst b/README.rst index d43c44d..d5b17eb 100644 --- a/README.rst +++ b/README.rst @@ -13,9 +13,9 @@ Introduction :target: https://github.com/adafruit/Adafruit_CircuitPython_BME280/actions/ :alt: Build Status -.. image:: https://img.shields.io/badge/code%20style-black-000000.svg - :target: https://github.com/psf/black - :alt: Code Style: Black +.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json + :target: https://github.com/astral-sh/ruff + :alt: Code Style: Ruff I2C and SPI driver for the Bosch BME280 Temperature, Humidity, and Barometric Pressure sensor diff --git a/adafruit_bme280/advanced.py b/adafruit_bme280/advanced.py index 30e0589..6e773d1 100644 --- a/adafruit_bme280/advanced.py +++ b/adafruit_bme280/advanced.py @@ -29,12 +29,15 @@ https://github.com/adafruit/Adafruit_CircuitPython_BusDevice """ + from micropython import const + from adafruit_bme280.basic import Adafruit_BME280 from adafruit_bme280.protocol import I2C_Impl, SPI_Impl try: - import typing # pylint: disable=unused-import + import typing + from busio import I2C, SPI from digitalio import DigitalInOut except ImportError: @@ -132,7 +135,6 @@ ) -# pylint: disable=abstract-method class Adafruit_BME280_Advanced(Adafruit_BME280): """Driver from BME280 Temperature, Humidity and Barometric Pressure sensor @@ -142,7 +144,6 @@ class Adafruit_BME280_Advanced(Adafruit_BME280): """ - # pylint: disable=too-many-instance-attributes def __init__(self, proxy: typing.Union[I2C_Impl, SPI_Impl]) -> None: """Check the BME280 was found, read the coefficients and enable the sensor""" self._overscan_humidity = OVERSCAN_X1 diff --git a/adafruit_bme280/basic.py b/adafruit_bme280/basic.py index 958da93..1ff5c0a 100644 --- a/adafruit_bme280/basic.py +++ b/adafruit_bme280/basic.py @@ -29,15 +29,18 @@ https://github.com/adafruit/Adafruit_CircuitPython_BusDevice """ + import math import struct from time import sleep from micropython import const + from adafruit_bme280.protocol import I2C_Impl, SPI_Impl try: - import typing # pylint: disable=unused-import + import typing + from busio import I2C, SPI from digitalio import DigitalInOut except ImportError: @@ -88,7 +91,6 @@ class Adafruit_BME280: """ - # pylint: disable=too-many-instance-attributes def __init__(self, bus_implementation: typing.Union[I2C_Impl, SPI_Impl]) -> None: """Check the BME280 was found, read the coefficients and enable the sensor""" # Check device ID. @@ -118,13 +120,9 @@ def _read_temperature(self) -> None: # Wait for conversion to complete while self._get_status() & 0x08: sleep(0.002) - raw_temperature = ( - self._read24(_BME280_REGISTER_TEMPDATA) / 16 - ) # lowest 4 bits get dropped + raw_temperature = self._read24(_BME280_REGISTER_TEMPDATA) / 16 # lowest 4 bits get dropped - var1 = ( - raw_temperature / 16384.0 - self._temp_calib[0] / 1024.0 - ) * self._temp_calib[1] + var1 = (raw_temperature / 16384.0 - self._temp_calib[0] / 1024.0) * self._temp_calib[1] var2 = ( (raw_temperature / 131072.0 - self._temp_calib[0] / 8192.0) @@ -256,9 +254,7 @@ def humidity(self) -> float: # Algorithm from the BME280 driver # https://github.com/BoschSensortec/BME280_driver/blob/master/bme280.c var1 = float(self._t_fine) - 76800.0 - var2 = ( - self._humidity_calib[3] * 64.0 + (self._humidity_calib[4] / 16384.0) * var1 - ) + var2 = self._humidity_calib[3] * 64.0 + (self._humidity_calib[4] / 16384.0) * var1 var3 = adc - var2 var4 = self._humidity_calib[1] / 65536.0 var5 = 1.0 + (self._humidity_calib[2] / 67108864.0) * var1 @@ -318,7 +314,6 @@ def _write_register_byte(self, register: int, value: int) -> None: class Adafruit_BME280_I2C(Adafruit_BME280): - """Driver for BME280 connected over I2C :param ~busio.I2C i2c: The I2C bus the BME280 is connected to. @@ -369,7 +364,6 @@ def __init__(self, i2c: I2C, address: int = 0x77) -> None: # BME280_ADDRESS class Adafruit_BME280_SPI(Adafruit_BME280): - """Driver for BME280 connected over SPI :param ~busio.SPI spi: SPI device diff --git a/adafruit_bme280/protocol.py b/adafruit_bme280/protocol.py index 8cb7058..5ec5d32 100644 --- a/adafruit_bme280/protocol.py +++ b/adafruit_bme280/protocol.py @@ -11,7 +11,7 @@ class I2C_Impl: "Protocol implementation for the I2C bus." def __init__(self, i2c: I2C, address: int) -> None: - from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel + from adafruit_bus_device import ( # noqa: PLC0415 i2c_device, ) @@ -40,7 +40,7 @@ def __init__( cs: DigitalInOut, baudrate: int = 100000, ) -> None: - from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel + from adafruit_bus_device import ( # noqa: PLC0415 spi_device, ) @@ -50,9 +50,9 @@ def read_register(self, register: int, length: int) -> bytearray: "Read from the device register." register = (register | 0x80) & 0xFF # Read single, bit 7 high. with self._spi as spi: - spi.write(bytearray([register])) # pylint: disable=no-member + spi.write(bytearray([register])) result = bytearray(length) - spi.readinto(result) # pylint: disable=no-member + spi.readinto(result) # print("$%02X => %s" % (register, [hex(i) for i in result])) return result @@ -60,4 +60,4 @@ def write_register_byte(self, register: int, value: int) -> None: "Write value to the device register." register &= 0x7F # Write, bit 7 low. with self._spi as spi: - spi.write(bytes([register, value & 0xFF])) # pylint: disable=no-member + spi.write(bytes([register, value & 0xFF])) diff --git a/docs/api.rst b/docs/api.rst index ffdfd9a..698a1a3 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -1,6 +1,9 @@ .. If you created a package, create one automodule per module in the package. +API Reference +############# + .. automodule:: adafruit_bme280 :members: diff --git a/docs/conf.py b/docs/conf.py index 6f2c02b..6a17d36 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,12 +1,10 @@ -# -*- coding: utf-8 -*- - # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # # SPDX-License-Identifier: MIT +import datetime import os import sys -import datetime sys.path.insert(0, os.path.abspath("..")) @@ -45,9 +43,7 @@ creation_year = "2017" current_year = str(datetime.datetime.now().year) year_duration = ( - current_year - if current_year == creation_year - else creation_year + " - " + current_year + current_year if current_year == creation_year else creation_year + " - " + current_year ) copyright = year_duration + " ladyada" author = "ladyada" diff --git a/examples/bme280_normal_mode.py b/examples/bme280_normal_mode.py index 62fffd5..f69ca88 100644 --- a/examples/bme280_normal_mode.py +++ b/examples/bme280_normal_mode.py @@ -6,8 +6,11 @@ parameters supported by the sensor. Refer to the BME280 datasheet to understand what these parameters do """ + import time + import board + import adafruit_bme280.advanced as adafruit_bme280 # Create sensor object, using the board's default I2C bus. diff --git a/examples/bme280_simpletest.py b/examples/bme280_simpletest.py index 76c0dfc..21712ec 100644 --- a/examples/bme280_simpletest.py +++ b/examples/bme280_simpletest.py @@ -2,7 +2,9 @@ # SPDX-License-Identifier: MIT import time + import board + from adafruit_bme280 import basic as adafruit_bme280 # Create sensor object, using the board's default I2C bus. diff --git a/examples/bme280_simpletest_pico.py b/examples/bme280_simpletest_pico.py index 435e41a..a1444d4 100644 --- a/examples/bme280_simpletest_pico.py +++ b/examples/bme280_simpletest_pico.py @@ -2,8 +2,10 @@ # SPDX-License-Identifier: MIT import time + import board import busio + from adafruit_bme280 import basic as adafruit_bme280 # Create sensor object, using the board's default I2C bus. diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..36332ff --- /dev/null +++ b/ruff.toml @@ -0,0 +1,105 @@ +# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +target-version = "py38" +line-length = 100 + +[lint] +preview = true +select = ["I", "PL", "UP"] + +extend-select = [ + "D419", # empty-docstring + "E501", # line-too-long + "W291", # trailing-whitespace + "PLC0414", # useless-import-alias + "PLC2401", # non-ascii-name + "PLC2801", # unnecessary-dunder-call + "PLC3002", # unnecessary-direct-lambda-call + "E999", # syntax-error + "PLE0101", # return-in-init + "F706", # return-outside-function + "F704", # yield-outside-function + "PLE0116", # continue-in-finally + "PLE0117", # nonlocal-without-binding + "PLE0241", # duplicate-bases + "PLE0302", # unexpected-special-method-signature + "PLE0604", # invalid-all-object + "PLE0605", # invalid-all-format + "PLE0643", # potential-index-error + "PLE0704", # misplaced-bare-raise + "PLE1141", # dict-iter-missing-items + "PLE1142", # await-outside-async + "PLE1205", # logging-too-many-args + "PLE1206", # logging-too-few-args + "PLE1307", # bad-string-format-type + "PLE1310", # bad-str-strip-call + "PLE1507", # invalid-envvar-value + "PLE2502", # bidirectional-unicode + "PLE2510", # invalid-character-backspace + "PLE2512", # invalid-character-sub + "PLE2513", # invalid-character-esc + "PLE2514", # invalid-character-nul + "PLE2515", # invalid-character-zero-width-space + "PLR0124", # comparison-with-itself + "PLR0202", # no-classmethod-decorator + "PLR0203", # no-staticmethod-decorator + "UP004", # useless-object-inheritance + "PLR0206", # property-with-parameters + "PLR0904", # too-many-public-methods + "PLR0911", # too-many-return-statements + "PLR0912", # too-many-branches + "PLR0913", # too-many-arguments + "PLR0914", # too-many-locals + "PLR0915", # too-many-statements + "PLR0916", # too-many-boolean-expressions + "PLR1702", # too-many-nested-blocks + "PLR1704", # redefined-argument-from-local + "PLR1711", # useless-return + "C416", # unnecessary-comprehension + "PLR1733", # unnecessary-dict-index-lookup + "PLR1736", # unnecessary-list-index-lookup + + # ruff reports this rule is unstable + #"PLR6301", # no-self-use + + "PLW0108", # unnecessary-lambda + "PLW0120", # useless-else-on-loop + "PLW0127", # self-assigning-variable + "PLW0129", # assert-on-string-literal + "B033", # duplicate-value + "PLW0131", # named-expr-without-context + "PLW0245", # super-without-brackets + "PLW0406", # import-self + "PLW0602", # global-variable-not-assigned + "PLW0603", # global-statement + "PLW0604", # global-at-module-level + + # fails on the try: import typing used by libraries + #"F401", # unused-import + + "F841", # unused-variable + "E722", # bare-except + "PLW0711", # binary-op-exception + "PLW1501", # bad-open-mode + "PLW1508", # invalid-envvar-default + "PLW1509", # subprocess-popen-preexec-fn + "PLW2101", # useless-with-lock + "PLW3301", # nested-min-max +] + +ignore = [ + "PLR2004", # magic-value-comparison + "UP030", # format literals + "PLW1514", # unspecified-encoding + "PLR0913", # too-many-arguments + "PLR0915", # too-many-statements + "PLR0917", # too-many-positional-arguments + "PLR0904", # too-many-public-methods + "PLR0912", # too-many-branches + "PLR0916", # too-many-boolean-expressions +] + +[format] +line-ending = "lf" From cd260c0ddffa14fa175e54cb45ccb94becfaa102 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 4 Jun 2025 10:00:20 -0500 Subject: [PATCH 125/125] update rtd.yml file Signed-off-by: foamyguy --- .readthedocs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 88bca9f..255dafd 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -12,7 +12,7 @@ sphinx: configuration: docs/conf.py build: - os: ubuntu-20.04 + os: ubuntu-lts-latest tools: python: "3" pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy