From 66c0f577f05686c8ee51adfee1205e1286b455d7 Mon Sep 17 00:00:00 2001 From: CrakeNotSnowman Date: Fri, 27 Aug 2021 11:06:38 -0500 Subject: [PATCH 01/71] Added single shot co2 measurements and single shot humidity and temp measurement for the SCD41 --- adafruit_scd4x.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index d64d701..bf0097a 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -54,6 +54,8 @@ _SCD4X_PERSISTSETTINGS = const(0x3615) _SCD4X_GETASCE = const(0x2313) _SCD4X_SETASCE = const(0x2416) +_SCD4X_MEASURESINGLESHOT = const(0x219D) +_SCD4X_MEASURESINGLESHOTRHTONLY = const(0x2196) class SCD4X: @@ -142,6 +144,16 @@ def relative_humidity(self): self._read_data() return self._relative_humidity + def measure_single_shot(self): + """On-demand measurement of CO2 concentration, relative humidity, and + temperature for SCD41 only""" + self._send_command(_SCD4X_MEASURESINGLESHOT, cmd_delay=5) + + def measure_single_shot_rht_only(self): + """On-demand measurement of relative humidity and temperature for + SCD41 only""" + self._send_command(_SCD4X_MEASURESINGLESHOTRHTONLY, cmd_delay=0.05) + def reinit(self): """Reinitializes the sensor by reloading user settings from EEPROM.""" self.stop_periodic_measurement() From d44b6bf3174681fdd61b95984dab87949824f36c Mon Sep 17 00:00:00 2001 From: CrakeNotSnowman Date: Fri, 27 Aug 2021 11:16:14 -0500 Subject: [PATCH 02/71] Adjusted code for precommit --- adafruit_scd4x.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index bf0097a..15ea601 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -145,12 +145,12 @@ def relative_humidity(self): return self._relative_humidity def measure_single_shot(self): - """On-demand measurement of CO2 concentration, relative humidity, and + """On-demand measurement of CO2 concentration, relative humidity, and temperature for SCD41 only""" self._send_command(_SCD4X_MEASURESINGLESHOT, cmd_delay=5) def measure_single_shot_rht_only(self): - """On-demand measurement of relative humidity and temperature for + """On-demand measurement of relative humidity and temperature for SCD41 only""" self._send_command(_SCD4X_MEASURESINGLESHOTRHTONLY, cmd_delay=0.05) From 5e11fbf4c385aa2ecfbce65ec0e9fe0a4793bbdd Mon Sep 17 00:00:00 2001 From: CrakeNotSnowman Date: Fri, 27 Aug 2021 11:42:42 -0500 Subject: [PATCH 03/71] Adding an example for the SCD41 which uses the single shot on demand measurement --- examples/scd41_single_shot_example.py | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 examples/scd41_single_shot_example.py diff --git a/examples/scd41_single_shot_example.py b/examples/scd41_single_shot_example.py new file mode 100644 index 0000000..d0ba9e3 --- /dev/null +++ b/examples/scd41_single_shot_example.py @@ -0,0 +1,41 @@ +# SPDX-FileCopyrightText: 2021 by Keith Murray, written for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense +import time +import board +import adafruit_scd4x + +i2c = board.I2C() +scd4x = adafruit_scd4x.SCD4X(i2c) +print("Serial number:", [hex(i) for i in scd4x.serial_number]) + +scd4x.measure_single_shot() +print("Waiting for single show CO2 measurement from SCD41....") + +sample_counter = 0 +while sample_counter < 3: + if scd4x.data_ready: + print("CO2: %d ppm" % scd4x.CO2) + print("Temperature: %0.1f *C" % scd4x.temperature) + print("Humidity: %0.1f %%" % scd4x.relative_humidity) + print() + sample_counter += 1 + else: + print("Waiting...") + time.sleep(1) + + +scd4x.measure_single_shot_rht_only() +print("Waiting for single show Humidity and Temperature measurement from SCD41....") + +sample_counter = 0 +while sample_counter < 3: + if scd4x.data_ready: + print("CO2: %d ppm" % scd4x.CO2) # Should be 0 ppm + print("Temperature: %0.1f *C" % scd4x.temperature) + print("Humidity: %0.1f %%" % scd4x.relative_humidity) + print() + sample_counter += 1 + else: + print("Waiting...") + time.sleep(1) \ No newline at end of file From 7d6aaff18b716438fb7115b2d7d29d787947901e Mon Sep 17 00:00:00 2001 From: CrakeNotSnowman Date: Fri, 27 Aug 2021 14:19:54 -0500 Subject: [PATCH 04/71] Fixed spelling and adjusted example design to more closely match the scd4x datasheet --- examples/scd41_single_shot_example.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/scd41_single_shot_example.py b/examples/scd41_single_shot_example.py index d0ba9e3..6b04d0d 100644 --- a/examples/scd41_single_shot_example.py +++ b/examples/scd41_single_shot_example.py @@ -9,8 +9,8 @@ scd4x = adafruit_scd4x.SCD4X(i2c) print("Serial number:", [hex(i) for i in scd4x.serial_number]) +print("Waiting for single shot CO2 measurement from SCD41....") scd4x.measure_single_shot() -print("Waiting for single show CO2 measurement from SCD41....") sample_counter = 0 while sample_counter < 3: @@ -19,23 +19,25 @@ print("Temperature: %0.1f *C" % scd4x.temperature) print("Humidity: %0.1f %%" % scd4x.relative_humidity) print() + scd4x.measure_single_shot() sample_counter += 1 else: print("Waiting...") time.sleep(1) +print("Waiting for single shot Humidity and Temperature measurement from SCD41....") scd4x.measure_single_shot_rht_only() -print("Waiting for single show Humidity and Temperature measurement from SCD41....") sample_counter = 0 while sample_counter < 3: if scd4x.data_ready: - print("CO2: %d ppm" % scd4x.CO2) # Should be 0 ppm + print("CO2: %d ppm" % scd4x.CO2) # Should be 0 ppm print("Temperature: %0.1f *C" % scd4x.temperature) print("Humidity: %0.1f %%" % scd4x.relative_humidity) print() + scd4x.measure_single_shot_rht_only() sample_counter += 1 else: print("Waiting...") - time.sleep(1) \ No newline at end of file + time.sleep(1) From 00d3781f0331827c2e0f4ab6d6fbee5e6f007eea Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 23 Nov 2021 13:07:24 -0600 Subject: [PATCH 05/71] 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 ea17ea7cddccf7452ce98f6628147bf06c4cf351 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 13 Jan 2022 16:27:30 -0500 Subject: [PATCH 06/71] 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 bfee82d..5a2a203 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 89f86fd..cbf8ab7 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 9ecae754e5ce8fad45b6ace7ca9966c8034a546d Mon Sep 17 00:00:00 2001 From: CrakeNotSnowman Date: Thu, 20 Jan 2022 23:40:09 -0600 Subject: [PATCH 07/71] corrected data ready to check to check 11 least significant bits instead of 7 --- adafruit_scd4x.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index 3f5bc32..22ed6b8 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -208,7 +208,7 @@ def data_ready(self): """Check the sensor to see if new data is available""" self._send_command(_SCD4X_DATAREADY, cmd_delay=0.001) self._read_reply(self._buffer, 3) - return not ((self._buffer[0] & 0x03 == 0) and (self._buffer[1] == 0)) + return not ((self._buffer[0] & 0x07 == 0) and (self._buffer[1] == 0)) @property def serial_number(self): From 494c7fd39438559946c9bd34d1e45f37a55c80cb Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 24 Jan 2022 16:46:17 -0500 Subject: [PATCH 08/71] 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 8a114d2..6653559 100644 --- a/README.rst +++ b/README.rst @@ -3,7 +3,7 @@ Introduction .. image:: https://readthedocs.org/projects/adafruit-circuitpython-scd4x/badge/?version=latest - :target: https://circuitpython.readthedocs.io/projects/scd4x/en/latest/ + :target: https://docs.circuitpython.org/projects/scd4x/en/latest/ :alt: Documentation Status @@ -119,7 +119,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 981ebc2..d27fe23 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -29,12 +29,12 @@ 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), } # Show the docstring from both the class and its __init__() method. diff --git a/docs/index.rst b/docs/index.rst index 643aa05..06ddc0b 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -32,7 +32,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 5fb0a3a..45c2945 100644 --- a/setup.py +++ b/setup.py @@ -49,8 +49,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 blinka circuitpython micropython scd4x CO2 humidity temperature sensor " From 15b24c1b8e229c4d60d5a0be420ad2921549f49e Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Wed, 9 Feb 2022 13:05:41 -0500 Subject: [PATCH 09/71] Consolidate Documentation sections of README --- README.rst | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index 6653559..ccf30bc 100644 --- a/README.rst +++ b/README.rst @@ -121,15 +121,11 @@ Documentation API documentation for this library can be found on `Read the Docs `_. +For information on building library documentation, please check out + 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 4f7ac1d74dfbd8245a7193e3e7e713524b2d24a2 Mon Sep 17 00:00:00 2001 From: tekktrik <89490472+tekktrik@users.noreply.github.com> Date: Wed, 9 Feb 2022 13:09:21 -0500 Subject: [PATCH 10/71] Post-patch cleanup Manual cleanup for patch consolidating Documentation sections of READMEs --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index ccf30bc..e0e05f8 100644 --- a/README.rst +++ b/README.rst @@ -121,7 +121,7 @@ Documentation API documentation for this library can be found on `Read the Docs `_. -For information on building library documentation, please check out +For information on building library documentation, please check out `this guide `_. Contributing ============ From 96cdd6d289a17b2a58939c72c242a0ca684cc16e Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 14 Feb 2022 15:35:02 -0500 Subject: [PATCH 11/71] 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 503ed5187a133bcbcb2b16b4d8f50f3b968f7b43 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 8 Mar 2022 12:44:14 -0500 Subject: [PATCH 12/71] Add information that some commands unavailable in working mode --- adafruit_scd4x.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index 22ed6b8..70a3844 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -229,11 +229,28 @@ def stop_periodic_measurement(self): self._send_command(_SCD4X_STOPPERIODICMEASUREMENT, cmd_delay=0.5) def start_periodic_measurement(self): - """Put sensor into working mode, about 5s per measurement""" + """Put sensor into working mode, about 5s per measurement + + .. note:: + Only the following commands will work once in working mode: + + * `SCD4X.CO2` + * `SCD4X.temperature` + * `SCD4X.relative_humidity` + * `SCD4x.data_ready()` + * `SCD4X.reinit()` + * `SCD4X.factory_reset()` + * `SCD4X.force_calibration()` + * `SCD4X.self_test()` + * `SCD4X.set_ambient_pressure()` + + """ self._send_command(_SCD4X_STARTPERIODICMEASUREMENT) def start_low_periodic_measurement(self): - """Put sensor into low power working mode, about 30s per measurement""" + """Put sensor into low power working mode, about 30s per measurement. See + `SCD4X.start_perodic_measurement` for more details. + """ self._send_command(_SCD4X_STARTLOWPOWERPERIODICMEASUREMENT) def persist_settings(self): @@ -303,8 +320,14 @@ def _send_command(self, cmd: int, cmd_delay: float = 0) -> None: self._cmd[0] = (cmd >> 8) & 0xFF self._cmd[1] = cmd & 0xFF - with self.i2c_device as i2c: - i2c.write(self._cmd, end=2) + try: + with self.i2c_device as i2c: + i2c.write(self._cmd, end=2) + except OSError as err: + raise RuntimeError( + "Could not communicate via I2C, some commands/settings \ + unavailable while in working mode" + ) from err time.sleep(cmd_delay) def _set_command_value(self, cmd, value, cmd_delay=0): From 4cad155730741231872e15881e6a81df4c1786e3 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 8 Mar 2022 12:52:45 -0500 Subject: [PATCH 13/71] Modify references --- adafruit_scd4x.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index 70a3844..a4e9542 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -234,15 +234,15 @@ def start_periodic_measurement(self): .. note:: Only the following commands will work once in working mode: - * `SCD4X.CO2` - * `SCD4X.temperature` - * `SCD4X.relative_humidity` - * `SCD4x.data_ready()` - * `SCD4X.reinit()` - * `SCD4X.factory_reset()` - * `SCD4X.force_calibration()` - * `SCD4X.self_test()` - * `SCD4X.set_ambient_pressure()` + * :attr:`CO2 ` + * :attr:`temperature ` + * :attr:`relative_humidity ` + * :meth:`data_ready() ` + * :meth:`reinit() ` + * :meth:`factory_reset() ` + * :meth:`force_calibration() ` + * :meth:`self_test() ` + * :meth:`set_ambient_pressure() ` """ self._send_command(_SCD4X_STARTPERIODICMEASUREMENT) From d71ac1b2b699c24fd0441725a85c1a9600cb55d1 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 8 Mar 2022 13:04:52 -0500 Subject: [PATCH 14/71] Fix docstring of start_low_periodic_measurement() --- adafruit_scd4x.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index a4e9542..7c21a67 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -249,7 +249,8 @@ def start_periodic_measurement(self): def start_low_periodic_measurement(self): """Put sensor into low power working mode, about 30s per measurement. See - `SCD4X.start_perodic_measurement` for more details. + :meth:`start_periodic_measurement() ` + for more details. """ self._send_command(_SCD4X_STARTLOWPOWERPERIODICMEASUREMENT) From 149a0ef3d07765e7fc5f9b187b50eb5f0b243e23 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 8 Mar 2022 16:01:51 -0500 Subject: [PATCH 15/71] Correct multiline error string --- adafruit_scd4x.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index 7c21a67..fc770b3 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -326,8 +326,8 @@ def _send_command(self, cmd: int, cmd_delay: float = 0) -> None: i2c.write(self._cmd, end=2) except OSError as err: raise RuntimeError( - "Could not communicate via I2C, some commands/settings \ - unavailable while in working mode" + "Could not communicate via I2C, some commands/settings " + "unavailable while in working mode" ) from err time.sleep(cmd_delay) From cbd1e24fb01a566e70fc3c1cabd658517d3d4ce3 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Mon, 28 Mar 2022 15:52:04 -0400 Subject: [PATCH 16/71] 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 1b9fadc..7467c1d 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 6735dbc74e9352532d314fd9c5b88e95a4fb750d Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 29 Mar 2022 18:17:01 -0400 Subject: [PATCH 17/71] "Reformatted per new black version" --- adafruit_scd4x.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index fc770b3..5283650 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -199,9 +199,9 @@ def _read_data(self): self._read_reply(self._buffer, 9) self._co2 = (self._buffer[0] << 8) | self._buffer[1] temp = (self._buffer[3] << 8) | self._buffer[4] - self._temperature = -45 + 175 * (temp / 2 ** 16) + self._temperature = -45 + 175 * (temp / 2**16) humi = (self._buffer[6] << 8) | self._buffer[7] - self._relative_humidity = 100 * (humi / 2 ** 16) + self._relative_humidity = 100 * (humi / 2**16) @property def data_ready(self): @@ -278,7 +278,7 @@ def temperature_offset(self): self._send_command(_SCD4X_GETTEMPOFFSET, cmd_delay=0.001) self._read_reply(self._buffer, 3) temp = (self._buffer[0] << 8) | self._buffer[1] - return 175.0 * temp / 2 ** 16 + return 175.0 * temp / 2**16 @temperature_offset.setter def temperature_offset(self, offset): @@ -286,7 +286,7 @@ def temperature_offset(self, offset): raise AttributeError( "Offset value must be less than or equal to 374 degrees Celsius" ) - temp = int(offset * 2 ** 16 / 175) + temp = int(offset * 2**16 / 175) self._set_command_value(_SCD4X_SETTEMPOFFSET, temp) @property From 0fd04f5ced614ffad91aa3d1d15ebd8044abe839 Mon Sep 17 00:00:00 2001 From: evaherrada Date: Thu, 21 Apr 2022 15:45:16 -0400 Subject: [PATCH 18/71] Updated gitignore Signed-off-by: evaherrada --- .gitignore | 49 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 2c6ddfd..544ec4a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,18 +1,47 @@ -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written 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 59bf98825f35d8c2a6236b37af521cc098bb8578 Mon Sep 17 00:00:00 2001 From: evaherrada Date: Fri, 22 Apr 2022 15:59:15 -0400 Subject: [PATCH 19/71] Patch: Replaced discord badge image --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index e0e05f8..8430ef0 100644 --- a/README.rst +++ b/README.rst @@ -7,7 +7,7 @@ Introduction :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 9eb6dc9e32aa9d3b33168072a3f69321c4283084 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 24 Apr 2022 13:57:04 -0500 Subject: [PATCH 20/71] change discord badge --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 8430ef0..dce3669 100644 --- a/README.rst +++ b/README.rst @@ -7,7 +7,7 @@ Introduction :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 54df9b03a07d6577d9ee450bbe39103e1584c9e9 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sun, 15 May 2022 12:21:32 -0400 Subject: [PATCH 21/71] 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 7467c1d..3343606 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 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 850dc5ff743471478391b8bc1a61d0b6e97245e6 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sun, 22 May 2022 00:18:55 -0400 Subject: [PATCH 22/71] 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 08e12bf..1f42e5d 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 e29eb40cc7a156d5d554672785a71f16a468f864 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 30 May 2022 14:25:04 -0400 Subject: [PATCH 23/71] 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 d27fe23..4075181 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -67,7 +67,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 e4dba358a4e8a11c7e191c6ec8fdb143102ca91f Mon Sep 17 00:00:00 2001 From: evaherrada Date: Tue, 7 Jun 2022 15:34:55 -0400 Subject: [PATCH 24/71] 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 06ddc0b..81ec897 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -31,7 +31,8 @@ Table of Contents .. toctree:: :caption: Other Links - Download + Download from GitHub + Download Library Bundle CircuitPython Reference Documentation CircuitPython Support Forum Discord Chat From cb9ff901db9c7656b7ac2e49ae528392bf5e5f4f Mon Sep 17 00:00:00 2001 From: evaherrada Date: Fri, 22 Jul 2022 13:59:16 -0400 Subject: [PATCH 25/71] 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 dce3669..608274a 100644 --- a/README.rst +++ b/README.rst @@ -63,8 +63,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-scd4x From 7aceb2f72e17b00b18939581ea8bfdbd09905749 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 8 Aug 2022 22:05:53 -0400 Subject: [PATCH 26/71] Switched to pyproject.toml --- .github/workflows/build.yml | 21 +++++------- .github/workflows/release.yml | 27 +++++----------- optional_requirements.txt | 3 ++ pyproject.toml | 51 ++++++++++++++++++++++++++--- requirements.txt | 5 ++- setup.py | 61 ----------------------------------- 6 files changed, 68 insertions(+), 100 deletions(-) create mode 100644 optional_requirements.txt delete mode 100644 setup.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5a2a203..22f6582 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -59,24 +59,19 @@ jobs: with: name: bundles path: ${{ github.workspace }}/bundles/ - - name: Check For docs folder - id: need-docs - run: | - echo ::set-output name=docs::$( find . -wholename './docs' ) - name: Build docs - if: contains(steps.need-docs.outputs.docs, '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 cbf8ab7..d1b4f8d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -61,39 +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 - # After the dist file is packaged, extract it, update the __version__ - # lines and repackage it. - cd dist - ZIP_FILE=`ls | sed -e "s/\.tar\.gz$//"` - echo "ZIP FILE = ${ZIP_FILE}" - tar xzf "${ZIP_FILE}.tar.gz" - echo The latest release version is \"${{github.event.release.tag_name}}\". - # Don't descend into ./.env, ./.eggs, or ./docs - for file in $(find -not -path "./.*" -not -path "./docs*" -name "*.py"); do + 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; - tar czf "${ZIP_FILE}.tar.gz" "${ZIP_FILE}" - rm -rf "${ZIP_FILE}" - cd .. + 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 index f3c35ae..44ab924 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,49 @@ -# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò +# SPDX-FileCopyrightText: 2022 Alec Delaney for Adafruit Industries # -# SPDX-License-Identifier: Unlicense +# SPDX-License-Identifier: MIT -[tool.black] -target-version = ['py35'] +[build-system] +requires = [ + "setuptools", + "wheel", +] + +[project] +name = "adafruit-circuitpython-scd4x" +description = "Driver for Sensirion SCD4X CO2 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_SCD4X.git"} +keywords = [ + "adafruit", + "blinka", + "circuitpython", + "micropython", + "scd4x", + "CO2", + "humidity", + "temperature", + "sensor", + "SCD40", + "SCD41", +] +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] +py-modules = ["adafruit_scd4x"] + +[tool.setuptools.dynamic] +dependencies = {file = ["requirements.txt"]} +optional-dependencies = {optional = {file = ["optional_requirements.txt"]}} diff --git a/requirements.txt b/requirements.txt index 22ba3bd..a45c547 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,6 @@ -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -# SPDX-FileCopyrightText: Copyright (c) 2021 ladyada for Adafruit Industries +# SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries # -# SPDX-License-Identifier: MIT +# SPDX-License-Identifier: Unlicense Adafruit-Blinka adafruit-circuitpython-busdevice diff --git a/setup.py b/setup.py deleted file mode 100644 index 45c2945..0000000 --- a/setup.py +++ /dev/null @@ -1,61 +0,0 @@ -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -# SPDX-FileCopyrightText: Copyright (c) 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 -""" - -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( - # Adafruit Bundle Information - name="adafruit-circuitpython-scd4x", - use_scm_version=True, - setup_requires=["setuptools_scm"], - description="Driver for Sensirion SCD4X CO2 sensor", - long_description=long_description, - long_description_content_type="text/x-rst", - # The project's main homepage. - url="https://github.com/adafruit/Adafruit_CircuitPython_SCD4X.git", - # 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 blinka circuitpython micropython scd4x CO2 humidity temperature sensor " - "SCD40 SCD41", - # You can just specify the packages manually here if your project is - # simple. Or you can use find_packages(). - # TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER, - # CHANGE `py_modules=['...']` TO `packages=['...']` - py_modules=["adafruit_scd4x"], -) From 77473671c28c644529c42ebd376e134a3f06c5a5 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 9 Aug 2022 12:03:54 -0400 Subject: [PATCH 27/71] 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 44ab924..23cd216 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,6 +6,7 @@ requires = [ "setuptools", "wheel", + "setuptools-scm", ] [project] From 7cb7743a73bae48c7b0c80edae8442e81e3cdd73 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 16 Aug 2022 18:09:14 -0400 Subject: [PATCH 28/71] Update version string --- adafruit_scd4x.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index 5283650..f4d7f3f 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -32,7 +32,7 @@ from micropython import const -__version__ = "0.0.0-auto.0" +__version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_SCD4X.git" SCD4X_DEFAULT_ADDR = 0x62 diff --git a/pyproject.toml b/pyproject.toml index 23cd216..a66524e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ requires = [ [project] name = "adafruit-circuitpython-scd4x" description = "Driver for Sensirion SCD4X CO2 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 7308537287ba4bff08ced41136c379cab7e98cf1 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 16 Aug 2022 21:09:14 -0400 Subject: [PATCH 29/71] 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 e728f7a6c3baaaff720a27a1a5e0826aa293105a Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 22 Aug 2022 21:36:31 -0400 Subject: [PATCH 30/71] 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 4075181..7da0cdb 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("..")) @@ -50,7 +51,8 @@ # General information about the project. project = "Adafruit CircuitPython SCD4X Library" -copyright = "2021 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 6e0a8dc4b789973b2113208496e1f27e1b711162 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 23 Aug 2022 17:26:21 -0400 Subject: [PATCH 31/71] 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 7da0cdb..fb43d1c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -51,8 +51,14 @@ # General information about the project. project = "Adafruit CircuitPython SCD4X Library" +creation_year = "2021" 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 be5934191b50443a750c10315392ea6f5bf9b4a8 Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Fri, 26 Aug 2022 13:58:10 -0400 Subject: [PATCH 32/71] Add Missing Type Annotations --- adafruit_scd4x.py | 53 ++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index f4d7f3f..408d044 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -31,6 +31,11 @@ from adafruit_bus_device import i2c_device from micropython import const +try: + from typing import Optional, Union # pylint: disable=unused-import + from busio import I2C +except ImportError: + pass __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_SCD4X.git" @@ -93,7 +98,7 @@ class SCD4X: """ - def __init__(self, i2c_bus, address=SCD4X_DEFAULT_ADDR): + def __init__(self, i2c_bus: I2C, address: int = SCD4X_DEFAULT_ADDR) -> None: self.i2c_device = i2c_device.I2CDevice(i2c_bus, address) self._buffer = bytearray(18) self._cmd = bytearray(2) @@ -107,7 +112,7 @@ def __init__(self, i2c_bus, address=SCD4X_DEFAULT_ADDR): self.stop_periodic_measurement() @property - def CO2(self): # pylint:disable=invalid-name + def CO2(self) -> int: # pylint:disable=invalid-name """Returns the CO2 concentration in PPM (parts per million) .. note:: @@ -119,7 +124,7 @@ def CO2(self): # pylint:disable=invalid-name return self._co2 @property - def temperature(self): + def temperature(self) -> float: """Returns the current temperature in degrees Celsius .. note:: @@ -131,7 +136,7 @@ def temperature(self): return self._temperature @property - def relative_humidity(self): + def relative_humidity(self) -> float: """Returns the current relative humidity in %rH. .. note:: @@ -142,18 +147,18 @@ def relative_humidity(self): self._read_data() return self._relative_humidity - def reinit(self): + def reinit(self) -> None: """Reinitializes the sensor by reloading user settings from EEPROM.""" self.stop_periodic_measurement() self._send_command(_SCD4X_REINIT, cmd_delay=0.02) - def factory_reset(self): + def factory_reset(self) -> None: """Resets all configuration settings stored in the EEPROM and erases the FRC and ASC algorithm history.""" self.stop_periodic_measurement() self._send_command(_SCD4X_FACTORYRESET, cmd_delay=1.2) - def force_calibration(self, target_co2): + def force_calibration(self, target_co2: int) -> None: """Forces the sensor to recalibrate with a given current CO2""" self.stop_periodic_measurement() self._set_command_value(_SCD4X_FORCEDRECAL, target_co2) @@ -167,7 +172,7 @@ def force_calibration(self, target_co2): ) @property - def self_calibration_enabled(self): + def self_calibration_enabled(self) -> bool: """Enables or disables automatic self calibration (ASC). To work correctly, the sensor must be on and active for 7 days after enabling ASC, and exposed to fresh air for at least 1 hour per day. Consult the manufacturer's documentation for more information. @@ -182,10 +187,10 @@ def self_calibration_enabled(self): return self._buffer[1] == 1 @self_calibration_enabled.setter - def self_calibration_enabled(self, enabled): + def self_calibration_enabled(self, enabled: bool) -> None: self._set_command_value(_SCD4X_SETASCE, enabled) - def self_test(self): + def self_test(self) -> None: """Performs a self test, takes up to 10 seconds""" self.stop_periodic_measurement() self._send_command(_SCD4X_SELFTEST, cmd_delay=10) @@ -193,7 +198,7 @@ def self_test(self): if (self._buffer[0] != 0) or (self._buffer[1] != 0): raise RuntimeError("Self test failed") - def _read_data(self): + def _read_data(self) -> None: """Reads the temp/hum/co2 from the sensor and caches it""" self._send_command(_SCD4X_READMEASUREMENT, cmd_delay=0.001) self._read_reply(self._buffer, 9) @@ -204,14 +209,14 @@ def _read_data(self): self._relative_humidity = 100 * (humi / 2**16) @property - def data_ready(self): + def data_ready(self) -> bool: """Check the sensor to see if new data is available""" self._send_command(_SCD4X_DATAREADY, cmd_delay=0.001) self._read_reply(self._buffer, 3) return not ((self._buffer[0] & 0x07 == 0) and (self._buffer[1] == 0)) @property - def serial_number(self): + def serial_number(self) -> bytearray: """Request a 6-tuple containing the unique serial number for this sensor""" self._send_command(_SCD4X_SERIALNUMBER, cmd_delay=0.001) self._read_reply(self._buffer, 9) @@ -224,11 +229,11 @@ def serial_number(self): self._buffer[7], ) - def stop_periodic_measurement(self): + def stop_periodic_measurement(self) -> None: """Stop measurement mode""" self._send_command(_SCD4X_STOPPERIODICMEASUREMENT, cmd_delay=0.5) - def start_periodic_measurement(self): + def start_periodic_measurement(self) -> None: """Put sensor into working mode, about 5s per measurement .. note:: @@ -247,25 +252,25 @@ def start_periodic_measurement(self): """ self._send_command(_SCD4X_STARTPERIODICMEASUREMENT) - def start_low_periodic_measurement(self): + def start_low_periodic_measurement(self) -> None: """Put sensor into low power working mode, about 30s per measurement. See :meth:`start_periodic_measurement() ` for more details. """ self._send_command(_SCD4X_STARTLOWPOWERPERIODICMEASUREMENT) - def persist_settings(self): + def persist_settings(self) -> None: """Save temperature offset, altitude offset, and selfcal enable settings to EEPROM""" self._send_command(_SCD4X_PERSISTSETTINGS, cmd_delay=0.8) - def set_ambient_pressure(self, ambient_pressure): + def set_ambient_pressure(self, ambient_pressure: int) -> None: """Set the ambient pressure in hPa at any time to adjust CO2 calculations""" if ambient_pressure < 0 or ambient_pressure > 65535: raise AttributeError("`ambient_pressure` must be from 0~65535 hPascals") self._set_command_value(_SCD4X_SETPRESSURE, ambient_pressure) @property - def temperature_offset(self): + def temperature_offset(self) -> float: """Specifies the offset to be added to the reported measurements to account for a bias in the measured signal. Value is in degrees Celsius with a resolution of 0.01 degrees and a maximum value of 374 C @@ -281,7 +286,7 @@ def temperature_offset(self): return 175.0 * temp / 2**16 @temperature_offset.setter - def temperature_offset(self, offset): + def temperature_offset(self, offset: Union[int, float]) -> None: if offset > 374: raise AttributeError( "Offset value must be less than or equal to 374 degrees Celsius" @@ -290,7 +295,7 @@ def temperature_offset(self, offset): self._set_command_value(_SCD4X_SETTEMPOFFSET, temp) @property - def altitude(self): + def altitude(self) -> int: """Specifies the altitude at the measurement location in meters above sea level. Setting this value adjusts the CO2 measurement calculations to account for the air pressure's effect on readings. @@ -304,12 +309,12 @@ def altitude(self): return (self._buffer[0] << 8) | self._buffer[1] @altitude.setter - def altitude(self, height): + def altitude(self, height: int) -> None: if height > 65535: raise AttributeError("Height must be less than or equal to 65535 meters") self._set_command_value(_SCD4X_SETALTITUDE, height) - def _check_buffer_crc(self, buf): + def _check_buffer_crc(self, buf: bytearray) -> bool: for i in range(0, len(buf), 3): self._crc_buffer[0] = buf[i] self._crc_buffer[1] = buf[i + 1] @@ -347,7 +352,7 @@ def _read_reply(self, buff, num): self._check_buffer_crc(self._buffer[0:num]) @staticmethod - def _crc8(buffer): + def _crc8(buffer: bytearray) -> int: crc = 0xFF for byte in buffer: crc ^= byte From 1339a4f78fb3e791f1833f9a71b53188ee8c14d1 Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Thu, 1 Sep 2022 17:43:26 -0400 Subject: [PATCH 33/71] Add Missing Type Annotations --- adafruit_scd4x.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index 408d044..274c1c9 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -32,7 +32,7 @@ from micropython import const try: - from typing import Optional, Union # pylint: disable=unused-import + from typing import Optional, Union, Tuple # pylint: disable=unused-import from busio import I2C except ImportError: pass @@ -216,7 +216,7 @@ def data_ready(self) -> bool: return not ((self._buffer[0] & 0x07 == 0) and (self._buffer[1] == 0)) @property - def serial_number(self) -> bytearray: + def serial_number(self) -> Tuple(int, int, int, int, int, int): """Request a 6-tuple containing the unique serial number for this sensor""" self._send_command(_SCD4X_SERIALNUMBER, cmd_delay=0.001) self._read_reply(self._buffer, 9) From f93de492ab140a80186f2f76d4823283f673e4e6 Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Thu, 1 Sep 2022 17:48:15 -0400 Subject: [PATCH 34/71] Add Missing Type Annotations --- adafruit_scd4x.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index 274c1c9..82c906d 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -216,7 +216,7 @@ def data_ready(self) -> bool: return not ((self._buffer[0] & 0x07 == 0) and (self._buffer[1] == 0)) @property - def serial_number(self) -> Tuple(int, int, int, int, int, int): + def serial_number(self) -> tuple(int, int, int, int, int, int): """Request a 6-tuple containing the unique serial number for this sensor""" self._send_command(_SCD4X_SERIALNUMBER, cmd_delay=0.001) self._read_reply(self._buffer, 9) From 128415bb91a84652b71d543269938be56b3101e9 Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Thu, 1 Sep 2022 17:53:09 -0400 Subject: [PATCH 35/71] Add Missing Type Annotations --- adafruit_scd4x.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index 82c906d..92c5fca 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -216,7 +216,7 @@ def data_ready(self) -> bool: return not ((self._buffer[0] & 0x07 == 0) and (self._buffer[1] == 0)) @property - def serial_number(self) -> tuple(int, int, int, int, int, int): + def serial_number(self) -> tuple(int): """Request a 6-tuple containing the unique serial number for this sensor""" self._send_command(_SCD4X_SERIALNUMBER, cmd_delay=0.001) self._read_reply(self._buffer, 9) From 8de97d87014ec4ad495d8c34db187eba3d4f02cd Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Thu, 1 Sep 2022 17:59:35 -0400 Subject: [PATCH 36/71] Add Missing Type Annotations --- adafruit_scd4x.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index 92c5fca..c1025e5 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -216,7 +216,7 @@ def data_ready(self) -> bool: return not ((self._buffer[0] & 0x07 == 0) and (self._buffer[1] == 0)) @property - def serial_number(self) -> tuple(int): + def serial_number(self) -> Tuple(int, int): """Request a 6-tuple containing the unique serial number for this sensor""" self._send_command(_SCD4X_SERIALNUMBER, cmd_delay=0.001) self._read_reply(self._buffer, 9) From eef1d8e1ae621b07fd29d59feb4634223a21acad Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Thu, 1 Sep 2022 18:04:15 -0400 Subject: [PATCH 37/71] Add Missing Type Annotations --- adafruit_scd4x.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index c1025e5..c375fed 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -216,7 +216,7 @@ def data_ready(self) -> bool: return not ((self._buffer[0] & 0x07 == 0) and (self._buffer[1] == 0)) @property - def serial_number(self) -> Tuple(int, int): + def serial_number(self) -> tuple(int, int): """Request a 6-tuple containing the unique serial number for this sensor""" self._send_command(_SCD4X_SERIALNUMBER, cmd_delay=0.001) self._read_reply(self._buffer, 9) From 26c2107348ef01654511f4251080849229c7fbd8 Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Thu, 1 Sep 2022 18:07:29 -0400 Subject: [PATCH 38/71] Add Missing Type Annotations --- adafruit_scd4x.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index c375fed..82c906d 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -216,7 +216,7 @@ def data_ready(self) -> bool: return not ((self._buffer[0] & 0x07 == 0) and (self._buffer[1] == 0)) @property - def serial_number(self) -> tuple(int, int): + def serial_number(self) -> tuple(int, int, int, int, int, int): """Request a 6-tuple containing the unique serial number for this sensor""" self._send_command(_SCD4X_SERIALNUMBER, cmd_delay=0.001) self._read_reply(self._buffer, 9) From 92c79f2fa4acfbce51efa3e08e6ce6be06cfe966 Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Thu, 1 Sep 2022 18:38:24 -0400 Subject: [PATCH 39/71] Add Missing Type Annotations --- adafruit_scd4x.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index 82c906d..f132792 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -216,7 +216,7 @@ def data_ready(self) -> bool: return not ((self._buffer[0] & 0x07 == 0) and (self._buffer[1] == 0)) @property - def serial_number(self) -> tuple(int, int, int, int, int, int): + def serial_number(self) -> Tuple[int, int, int, int, int, int]: """Request a 6-tuple containing the unique serial number for this sensor""" self._send_command(_SCD4X_SERIALNUMBER, cmd_delay=0.001) self._read_reply(self._buffer, 9) From c5fd275741181e73bf444114942a35abaf17a968 Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Thu, 1 Sep 2022 18:39:23 -0400 Subject: [PATCH 40/71] Add Missing Type Annotations --- adafruit_scd4x.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index f132792..f2e84f3 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -32,7 +32,7 @@ from micropython import const try: - from typing import Optional, Union, Tuple # pylint: disable=unused-import + from typing import Optional, Union, Tuple from busio import I2C except ImportError: pass From 8adef63dc48d452d35ff42783c38e2fbca56baec Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Thu, 1 Sep 2022 18:42:33 -0400 Subject: [PATCH 41/71] Add Missing Type Annotations --- adafruit_scd4x.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index f2e84f3..2a70f0f 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -32,7 +32,7 @@ from micropython import const try: - from typing import Optional, Union, Tuple + from typing import Union, Tuple from busio import I2C except ImportError: pass From 9ab17bc387f93ccc59fcdfb4c0fac38be223fa7e Mon Sep 17 00:00:00 2001 From: Thomas Franks Date: Thu, 1 Sep 2022 18:47:13 -0400 Subject: [PATCH 42/71] Add Missing Type Annotations --- adafruit_scd4x.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index 2a70f0f..5fc3f95 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -32,7 +32,7 @@ from micropython import const try: - from typing import Union, Tuple + from typing import Tuple, Union from busio import I2C except ImportError: pass From b94b6587421fb78ba417b5807d2af88efb5abf39 Mon Sep 17 00:00:00 2001 From: mopore Date: Sun, 16 Oct 2022 11:48:44 +0200 Subject: [PATCH 43/71] Add 'adafruit' in circup install command to find library. --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 608274a..ad213c1 100644 --- a/README.rst +++ b/README.rst @@ -84,7 +84,7 @@ following command to install: .. code-block:: shell - circup install scd4x + circup install adafruit_scd4x Or the following command to update an existing version: From 8e533a6ea5016af2969d574882dd87bde01ca3c6 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 44/71] 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 21c00a563fb08d835ebda507b2573c7e5cb99327 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 45/71] 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 3343606..4c43710 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 327ee7378d6f9c1a467b637e967a2a5b2dc81148 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 08:15:20 -0400 Subject: [PATCH 46/71] 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 4c43710..0e5fccc 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 4d40faad1cfc30bdaeda505ca2cf6b39a0d9850d Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 09:12:44 -0400 Subject: [PATCH 47/71] 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 c7f08fa321c8a60894ae0afaf36faa24a1744e19 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 18:34:33 -0400 Subject: [PATCH 48/71] Update .pylintrc for v2.15.5 --- .pylintrc | 43 +++---------------------------------------- 1 file changed, 3 insertions(+), 40 deletions(-) diff --git a/.pylintrc b/.pylintrc index 1f42e5d..40208c3 100644 --- a/.pylintrc +++ b/.pylintrc @@ -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,pointless-string-statement,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 bf447cfe3526e8193905aac950e50deaab46f058 Mon Sep 17 00:00:00 2001 From: dherrada Date: Fri, 18 Nov 2022 13:05:29 -0500 Subject: [PATCH 49/71] Added commented out board.STEMMA_I2C with explanation --- examples/scd4x_simpletest.py | 3 ++- examples/scd4x_tuning_knobs.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/scd4x_simpletest.py b/examples/scd4x_simpletest.py index c4f035d..62b071a 100644 --- a/examples/scd4x_simpletest.py +++ b/examples/scd4x_simpletest.py @@ -5,7 +5,8 @@ import board import adafruit_scd4x -i2c = board.I2C() +i2c = board.I2C() # uses board.SCL and board.SDA +# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller scd4x = adafruit_scd4x.SCD4X(i2c) print("Serial number:", [hex(i) for i in scd4x.serial_number]) diff --git a/examples/scd4x_tuning_knobs.py b/examples/scd4x_tuning_knobs.py index cb2495c..9c6e90b 100644 --- a/examples/scd4x_tuning_knobs.py +++ b/examples/scd4x_tuning_knobs.py @@ -5,7 +5,8 @@ import board import adafruit_scd4x -i2c = board.I2C() +i2c = board.I2C() # uses board.SCL and board.SDA +# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller scd4x = adafruit_scd4x.SCD4X(i2c) print("Serial number:", [hex(i) for i in scd4x.serial_number]) From b6438856f6d1df27336aa6a34d6fab1ce0249f7c 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 50/71] 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 5767608f2153aa53280183558065f496eb70590a 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 51/71] 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 0446246d95eeb78b661e15a3154c1f3c79459b8b Mon Sep 17 00:00:00 2001 From: Tekktrik Date: Tue, 9 May 2023 20:26:25 -0400 Subject: [PATCH 52/71] 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 0e5fccc..70ade69 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 ad1dbd32c9371fb2c6699549addec6de41a873e6 Mon Sep 17 00:00:00 2001 From: Tekktrik Date: Sun, 14 May 2023 13:00:32 -0400 Subject: [PATCH 53/71] Update .pylintrc, fix jQuery for docs Signed-off-by: Tekktrik --- .pylintrc | 2 +- docs/conf.py | 1 + docs/requirements.txt | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index 40208c3..f945e92 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 fb43d1c..2b939a8 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.napoleon", "sphinx.ext.todo", 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 ed8180c63783629b6ca75ce81e2575db8ea23a9a Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 30 Jul 2023 14:19:34 -0500 Subject: [PATCH 54/71] merge main, add type info on new functions --- adafruit_scd4x.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index b331af7..6d33c87 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -149,12 +149,12 @@ def relative_humidity(self) -> float: self._read_data() return self._relative_humidity - def measure_single_shot(self): + def measure_single_shot(self) -> None: """On-demand measurement of CO2 concentration, relative humidity, and temperature for SCD41 only""" self._send_command(_SCD4X_MEASURESINGLESHOT, cmd_delay=5) - def measure_single_shot_rht_only(self): + def measure_single_shot_rht_only(self) -> None: """On-demand measurement of relative humidity and temperature for SCD41 only""" self._send_command(_SCD4X_MEASURESINGLESHOTRHTONLY, cmd_delay=0.05) From ed1ea8c97a974c984f02c43d4770888169f58cf6 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 18 Sep 2023 16:23:32 -0500 Subject: [PATCH 55/71] "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 2b939a8..3e161fe 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -114,19 +114,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 7a05843702ae883f43c331915f941017d63e2b51 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 16 Oct 2023 14:30:31 -0500 Subject: [PATCH 56/71] 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 51c1fd32774bb432595c717ceda7f00850f150c2 Mon Sep 17 00:00:00 2001 From: kolcz Date: Wed, 3 Apr 2024 14:40:48 +0200 Subject: [PATCH 57/71] Subtract 1 from demominator --- adafruit_scd4x.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index 6d33c87..846a6f1 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -216,9 +216,9 @@ def _read_data(self) -> None: self._read_reply(self._buffer, 9) self._co2 = (self._buffer[0] << 8) | self._buffer[1] temp = (self._buffer[3] << 8) | self._buffer[4] - self._temperature = -45 + 175 * (temp / 2**16) + self._temperature = -45 + 175 * (temp / (2**16 - 1)) humi = (self._buffer[6] << 8) | self._buffer[7] - self._relative_humidity = 100 * (humi / 2**16) + self._relative_humidity = 100 * (humi / (2**16 - 1)) @property def data_ready(self) -> bool: From 8d67b789b615fdda14f383dff567b6265a574a09 Mon Sep 17 00:00:00 2001 From: kolcz <17905157+kolcz@users.noreply.github.com> Date: Thu, 15 Aug 2024 20:49:31 +0200 Subject: [PATCH 58/71] Change calculation 2**16 - 1 to exact value and add equations to docstring --- adafruit_scd4x.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index 846a6f1..4f988bd 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -211,14 +211,18 @@ def self_test(self) -> None: raise RuntimeError("Self test failed") def _read_data(self) -> None: - """Reads the temp/hum/co2 from the sensor and caches it""" + """Reads the temp/hum/co2 from the sensor and caches it. + Equations used for calculation: + CO2 = word[0] + T = -45 + 175 * (word[1] / (2**16 - 1)) + RH = 100 * (word[2] / (2**16 - 1))""" self._send_command(_SCD4X_READMEASUREMENT, cmd_delay=0.001) self._read_reply(self._buffer, 9) self._co2 = (self._buffer[0] << 8) | self._buffer[1] temp = (self._buffer[3] << 8) | self._buffer[4] - self._temperature = -45 + 175 * (temp / (2**16 - 1)) + self._temperature = -45 + 175 * (temp / 65535) humi = (self._buffer[6] << 8) | self._buffer[7] - self._relative_humidity = 100 * (humi / (2**16 - 1)) + self._relative_humidity = 100 * (humi / 65535) @property def data_ready(self) -> bool: @@ -285,7 +289,9 @@ def set_ambient_pressure(self, ambient_pressure: int) -> None: def temperature_offset(self) -> float: """Specifies the offset to be added to the reported measurements to account for a bias in the measured signal. Value is in degrees Celsius with a resolution of 0.01 degrees and a - maximum value of 374 C + maximum value of 374 C. + Equation used for calculation: + T_offset = word[0] * (175 / (2**16 - 1)) .. note:: This value will NOT be saved and will be reset on boot unless saved with @@ -295,15 +301,17 @@ def temperature_offset(self) -> float: self._send_command(_SCD4X_GETTEMPOFFSET, cmd_delay=0.001) self._read_reply(self._buffer, 3) temp = (self._buffer[0] << 8) | self._buffer[1] - return 175.0 * temp / 2**16 + return temp * 175.0 / 65535 @temperature_offset.setter def temperature_offset(self, offset: Union[int, float]) -> None: + """Equation used for calculation: + word[0] = T_offset * ((2**16 -1) / 175)""" if offset > 374: raise AttributeError( "Offset value must be less than or equal to 374 degrees Celsius" ) - temp = int(offset * 2**16 / 175) + temp = int(offset * 65535 / 175) self._set_command_value(_SCD4X_SETTEMPOFFSET, temp) @property From 7159f2cffa23887f3718c5c7b21a03b2bf3ff8f5 Mon Sep 17 00:00:00 2001 From: kolcz <17905157+kolcz@users.noreply.github.com> Date: Thu, 15 Aug 2024 21:08:20 +0200 Subject: [PATCH 59/71] Remove docstring in setter --- adafruit_scd4x.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index 4f988bd..36f7a7a 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -305,8 +305,6 @@ def temperature_offset(self) -> float: @temperature_offset.setter def temperature_offset(self, offset: Union[int, float]) -> None: - """Equation used for calculation: - word[0] = T_offset * ((2**16 -1) / 175)""" if offset > 374: raise AttributeError( "Offset value must be less than or equal to 374 degrees Celsius" From 64e117681f8a38245d6c1482a1e2d5d73d93b816 Mon Sep 17 00:00:00 2001 From: kolcz <17905157+kolcz@users.noreply.github.com> Date: Thu, 15 Aug 2024 21:14:23 +0200 Subject: [PATCH 60/71] Remove docstring equations --- adafruit_scd4x.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index 36f7a7a..5238a8b 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -211,11 +211,7 @@ def self_test(self) -> None: raise RuntimeError("Self test failed") def _read_data(self) -> None: - """Reads the temp/hum/co2 from the sensor and caches it. - Equations used for calculation: - CO2 = word[0] - T = -45 + 175 * (word[1] / (2**16 - 1)) - RH = 100 * (word[2] / (2**16 - 1))""" + """Reads the temp/hum/co2 from the sensor and caches it""" self._send_command(_SCD4X_READMEASUREMENT, cmd_delay=0.001) self._read_reply(self._buffer, 9) self._co2 = (self._buffer[0] << 8) | self._buffer[1] @@ -290,8 +286,6 @@ def temperature_offset(self) -> float: """Specifies the offset to be added to the reported measurements to account for a bias in the measured signal. Value is in degrees Celsius with a resolution of 0.01 degrees and a maximum value of 374 C. - Equation used for calculation: - T_offset = word[0] * (175 / (2**16 - 1)) .. note:: This value will NOT be saved and will be reset on boot unless saved with From 75b6f1597abcff059153142286cc315c9ec2be64 Mon Sep 17 00:00:00 2001 From: kolcz <17905157+kolcz@users.noreply.github.com> Date: Thu, 15 Aug 2024 21:24:50 +0200 Subject: [PATCH 61/71] Insert equation in line comments --- adafruit_scd4x.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index 5238a8b..3ba182a 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -214,11 +214,11 @@ def _read_data(self) -> None: """Reads the temp/hum/co2 from the sensor and caches it""" self._send_command(_SCD4X_READMEASUREMENT, cmd_delay=0.001) self._read_reply(self._buffer, 9) - self._co2 = (self._buffer[0] << 8) | self._buffer[1] + self._co2 = (self._buffer[0] << 8) | self._buffer[1] # CO2 = word[0] temp = (self._buffer[3] << 8) | self._buffer[4] - self._temperature = -45 + 175 * (temp / 65535) + self._temperature = -45 + 175 * (temp / 65535) # T = -45 + 175 * (word[1] / 2**16 - 1) humi = (self._buffer[6] << 8) | self._buffer[7] - self._relative_humidity = 100 * (humi / 65535) + self._relative_humidity = 100 * (humi / 65535) # RH = 100 * (word[2] / (2**16 - 1)) @property def data_ready(self) -> bool: @@ -295,7 +295,7 @@ def temperature_offset(self) -> float: self._send_command(_SCD4X_GETTEMPOFFSET, cmd_delay=0.001) self._read_reply(self._buffer, 3) temp = (self._buffer[0] << 8) | self._buffer[1] - return temp * 175.0 / 65535 + return temp * 175.0 / 65535 # T_offset = word[0] * (175 / (2**16 - 1)) @temperature_offset.setter def temperature_offset(self, offset: Union[int, float]) -> None: @@ -303,7 +303,7 @@ def temperature_offset(self, offset: Union[int, float]) -> None: raise AttributeError( "Offset value must be less than or equal to 374 degrees Celsius" ) - temp = int(offset * 65535 / 175) + temp = int(offset * 65535 / 175) # word[0] = T_offset * ((2**16 - 1) / 175) self._set_command_value(_SCD4X_SETTEMPOFFSET, temp) @property From a2f56c025f49d515512c219cd9f7920c97a1ed0d Mon Sep 17 00:00:00 2001 From: kolcz <17905157+kolcz@users.noreply.github.com> Date: Thu, 15 Aug 2024 21:46:36 +0200 Subject: [PATCH 62/71] Unify intedation --- adafruit_scd4x.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index 3ba182a..ff50a3c 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -214,11 +214,11 @@ def _read_data(self) -> None: """Reads the temp/hum/co2 from the sensor and caches it""" self._send_command(_SCD4X_READMEASUREMENT, cmd_delay=0.001) self._read_reply(self._buffer, 9) - self._co2 = (self._buffer[0] << 8) | self._buffer[1] # CO2 = word[0] + self._co2 = (self._buffer[0] << 8) | self._buffer[1] # CO2 = word[0] temp = (self._buffer[3] << 8) | self._buffer[4] - self._temperature = -45 + 175 * (temp / 65535) # T = -45 + 175 * (word[1] / 2**16 - 1) + self._temperature = -45 + 175 * (temp / 65535) # T = -45 + 175 * (word[1] / 2**16 - 1) humi = (self._buffer[6] << 8) | self._buffer[7] - self._relative_humidity = 100 * (humi / 65535) # RH = 100 * (word[2] / (2**16 - 1)) + self._relative_humidity = 100 * (humi / 65535) # RH = 100 * (word[2] / (2**16 - 1)) @property def data_ready(self) -> bool: @@ -295,7 +295,7 @@ def temperature_offset(self) -> float: self._send_command(_SCD4X_GETTEMPOFFSET, cmd_delay=0.001) self._read_reply(self._buffer, 3) temp = (self._buffer[0] << 8) | self._buffer[1] - return temp * 175.0 / 65535 # T_offset = word[0] * (175 / (2**16 - 1)) + return temp * 175.0 / 65535 # T_offset = word[0] * (175 / (2**16 - 1)) @temperature_offset.setter def temperature_offset(self, offset: Union[int, float]) -> None: @@ -303,7 +303,7 @@ def temperature_offset(self, offset: Union[int, float]) -> None: raise AttributeError( "Offset value must be less than or equal to 374 degrees Celsius" ) - temp = int(offset * 65535 / 175) # word[0] = T_offset * ((2**16 - 1) / 175) + temp = int(offset * 65535 / 175) # word[0] = T_offset * ((2**16 - 1) / 175) self._set_command_value(_SCD4X_SETTEMPOFFSET, temp) @property From 556109d42569c938dc603f331445cb30ec0ca529 Mon Sep 17 00:00:00 2001 From: kolcz <17905157+kolcz@users.noreply.github.com> Date: Thu, 15 Aug 2024 22:01:49 +0200 Subject: [PATCH 63/71] Reformat by black --- adafruit_scd4x.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index ff50a3c..8bfabd1 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -214,11 +214,15 @@ def _read_data(self) -> None: """Reads the temp/hum/co2 from the sensor and caches it""" self._send_command(_SCD4X_READMEASUREMENT, cmd_delay=0.001) self._read_reply(self._buffer, 9) - self._co2 = (self._buffer[0] << 8) | self._buffer[1] # CO2 = word[0] + self._co2 = (self._buffer[0] << 8) | self._buffer[1] # CO2 = word[0] temp = (self._buffer[3] << 8) | self._buffer[4] - self._temperature = -45 + 175 * (temp / 65535) # T = -45 + 175 * (word[1] / 2**16 - 1) + self._temperature = -45 + 175 * ( + temp / 65535 + ) # T = -45 + 175 * (word[1] / 2**16 - 1) humi = (self._buffer[6] << 8) | self._buffer[7] - self._relative_humidity = 100 * (humi / 65535) # RH = 100 * (word[2] / (2**16 - 1)) + self._relative_humidity = 100 * ( + humi / 65535 + ) # RH = 100 * (word[2] / (2**16 - 1)) @property def data_ready(self) -> bool: @@ -295,7 +299,7 @@ def temperature_offset(self) -> float: self._send_command(_SCD4X_GETTEMPOFFSET, cmd_delay=0.001) self._read_reply(self._buffer, 3) temp = (self._buffer[0] << 8) | self._buffer[1] - return temp * 175.0 / 65535 # T_offset = word[0] * (175 / (2**16 - 1)) + return temp * 175.0 / 65535 # T_offset = word[0] * (175 / (2**16 - 1)) @temperature_offset.setter def temperature_offset(self, offset: Union[int, float]) -> None: @@ -303,7 +307,7 @@ def temperature_offset(self, offset: Union[int, float]) -> None: raise AttributeError( "Offset value must be less than or equal to 374 degrees Celsius" ) - temp = int(offset * 65535 / 175) # word[0] = T_offset * ((2**16 - 1) / 175) + temp = int(offset * 65535 / 175) # word[0] = T_offset * ((2**16 - 1) / 175) self._set_command_value(_SCD4X_SETTEMPOFFSET, temp) @property From b7c46bc52a86278fac6238d4a7834e3032f5a46c Mon Sep 17 00:00:00 2001 From: kolcz <17905157+kolcz@users.noreply.github.com> Date: Thu, 15 Aug 2024 22:12:36 +0200 Subject: [PATCH 64/71] Move equation comment to line above --- adafruit_scd4x.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index 8bfabd1..aa62a88 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -214,15 +214,14 @@ def _read_data(self) -> None: """Reads the temp/hum/co2 from the sensor and caches it""" self._send_command(_SCD4X_READMEASUREMENT, cmd_delay=0.001) self._read_reply(self._buffer, 9) - self._co2 = (self._buffer[0] << 8) | self._buffer[1] # CO2 = word[0] + # CO2 = word[0] + self._co2 = (self._buffer[0] << 8) | self._buffer[1] temp = (self._buffer[3] << 8) | self._buffer[4] - self._temperature = -45 + 175 * ( - temp / 65535 - ) # T = -45 + 175 * (word[1] / 2**16 - 1) + # T = -45 + 175 * (word[1] / 2**16 - 1) + self._temperature = -45 + 175 * (temp / 65535) humi = (self._buffer[6] << 8) | self._buffer[7] - self._relative_humidity = 100 * ( - humi / 65535 - ) # RH = 100 * (word[2] / (2**16 - 1)) + # RH = 100 * (word[2] / (2**16 - 1)) + self._relative_humidity = 100 * (humi / 65535) @property def data_ready(self) -> bool: From 35fbd67bb40f8f86b8825afa00719b983440cee9 Mon Sep 17 00:00:00 2001 From: snkYmkrct Date: Wed, 2 Oct 2024 17:17:54 +0200 Subject: [PATCH 65/71] Add displayio example --- examples/scd4x_displayio_simpletest.py | 50 ++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 examples/scd4x_displayio_simpletest.py diff --git a/examples/scd4x_displayio_simpletest.py b/examples/scd4x_displayio_simpletest.py new file mode 100644 index 0000000..4a6b5d6 --- /dev/null +++ b/examples/scd4x_displayio_simpletest.py @@ -0,0 +1,50 @@ +# SPDX-FileCopyrightText: 2024 +# SPDX-License-Identifier: MIT + +import time +import board +from adafruit_display_text.bitmap_label import Label +from displayio import Group +from terminalio import FONT + +import adafruit_scd4x + +# Create sensor object, communicating over 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 +scd4x = adafruit_scd4x.SCD4X(i2c) + +print("Serial number:", [hex(i) for i in scd4x.serial_number]) + +# Put sensor into working mode, one measurement every 5s +scd4x.start_periodic_measurement() + + +# Example written for boards with built-in displays +display = board.DISPLAY + +# Create a main_group to hold anything we want to show on the display. +main_group = Group() + +# Create a Label to show the readings. If you have a very small +# display you may need to change to scale=1. +display_output_label = Label(FONT, text="", scale=2) + +# Place the label near the top left corner with anchored positioning +display_output_label.anchor_point = (0, 0) +display_output_label.anchored_position = (4, 4) + +# Add the label to the main_group +main_group.append(display_output_label) + +# Set the main_group as the root_group of the display +display.root_group = main_group + +# Begin main loop +while True: + if scd4x.data_ready: + # Update the label.text property to change the text on the display + # one sensor value per line + display_output_label.text = f"CO2: {scd4x.CO2} ppm \ + \nTemperature: {scd4x.temperature:.1f} C \ + \nHumidity: {scd4x.relative_humidity:.1f} %" From e9a819eeefeadbe44645379a34575e70bba5fcea Mon Sep 17 00:00:00 2001 From: snkYmkrct Date: Wed, 2 Oct 2024 17:19:37 +0200 Subject: [PATCH 66/71] black error fix --- examples/scd4x_displayio_simpletest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/scd4x_displayio_simpletest.py b/examples/scd4x_displayio_simpletest.py index 4a6b5d6..efbd9f4 100644 --- a/examples/scd4x_displayio_simpletest.py +++ b/examples/scd4x_displayio_simpletest.py @@ -18,8 +18,8 @@ # Put sensor into working mode, one measurement every 5s scd4x.start_periodic_measurement() - - + + # Example written for boards with built-in displays display = board.DISPLAY From 3a96e59e9a6bd42302f729683886ba37a26093d3 Mon Sep 17 00:00:00 2001 From: snkYmkrct Date: Wed, 2 Oct 2024 17:29:48 +0200 Subject: [PATCH 67/71] pylint error fix --- examples/scd4x_displayio_simpletest.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/scd4x_displayio_simpletest.py b/examples/scd4x_displayio_simpletest.py index efbd9f4..a2c727f 100644 --- a/examples/scd4x_displayio_simpletest.py +++ b/examples/scd4x_displayio_simpletest.py @@ -1,7 +1,6 @@ # SPDX-FileCopyrightText: 2024 # SPDX-License-Identifier: MIT -import time import board from adafruit_display_text.bitmap_label import Label from displayio import Group From f3ea11f84ccaec007958d5b7ae9d30fb0eda3b8a Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 7 Oct 2024 09:24:05 -0500 Subject: [PATCH 68/71] 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 3e161fe..da52c65 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -117,7 +117,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 11a95ec15102b9cc8a400515a037ec4d99de792b Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 14 Jan 2025 11:32:34 -0600 Subject: [PATCH 69/71] 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 f294dbae7795e52c7d9e9aa6bc33f1a7ee543788 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 15 May 2025 14:45:04 +0000 Subject: [PATCH 70/71] change to ruff --- .gitattributes | 11 + .pre-commit-config.yaml | 43 +-- .pylintrc | 399 -------------------------- README.rst | 6 +- adafruit_scd4x.py | 8 +- docs/api.rst | 3 + docs/conf.py | 8 +- examples/scd41_single_shot_example.py | 2 + examples/scd4x_simpletest.py | 2 + examples/scd4x_tuning_knobs.py | 2 + ruff.toml | 105 +++++++ 11 files changed, 145 insertions(+), 444 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 70ade69..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 - 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 f945e92..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,_ - -# 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 ad213c1..22b9b45 100644 --- a/README.rst +++ b/README.rst @@ -17,9 +17,9 @@ Introduction :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 Driver for Sensirion SCD4X CO2 sensor diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index aa62a88..a073a1c 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -26,13 +26,15 @@ * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice """ -import time import struct +import time + from adafruit_bus_device import i2c_device from micropython import const try: from typing import Tuple, Union + from busio import I2C except ImportError: pass @@ -303,9 +305,7 @@ def temperature_offset(self) -> float: @temperature_offset.setter def temperature_offset(self, offset: Union[int, float]) -> None: if offset > 374: - raise AttributeError( - "Offset value must be less than or equal to 374 degrees Celsius" - ) + raise AttributeError("Offset value must be less than or equal to 374 degrees Celsius") temp = int(offset * 65535 / 175) # word[0] = T_offset * ((2**16 - 1) / 175) self._set_command_value(_SCD4X_SETTEMPOFFSET, temp) diff --git a/docs/api.rst b/docs/api.rst index 332dc26..fa13bea 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -4,5 +4,8 @@ .. If your library file(s) are nested in a directory (e.g. /adafruit_foo/foo.py) .. use this format as the module name: "adafruit_foo.foo" +API Reference +############# + .. automodule:: adafruit_scd4x :members: diff --git a/docs/conf.py b/docs/conf.py index da52c65..6d669e1 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,12 +1,10 @@ -# -*- coding: utf-8 -*- - # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries # # SPDX-License-Identifier: MIT +import datetime import os import sys -import datetime sys.path.insert(0, os.path.abspath("..")) @@ -55,9 +53,7 @@ creation_year = "2021" 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/scd41_single_shot_example.py b/examples/scd41_single_shot_example.py index 6b04d0d..9a7dab1 100644 --- a/examples/scd41_single_shot_example.py +++ b/examples/scd41_single_shot_example.py @@ -2,7 +2,9 @@ # # SPDX-License-Identifier: Unlicense import time + import board + import adafruit_scd4x i2c = board.I2C() diff --git a/examples/scd4x_simpletest.py b/examples/scd4x_simpletest.py index 62b071a..fbf6f6a 100644 --- a/examples/scd4x_simpletest.py +++ b/examples/scd4x_simpletest.py @@ -2,7 +2,9 @@ # # SPDX-License-Identifier: Unlicense import time + import board + import adafruit_scd4x i2c = board.I2C() # uses board.SCL and board.SDA diff --git a/examples/scd4x_tuning_knobs.py b/examples/scd4x_tuning_knobs.py index 9c6e90b..372502b 100644 --- a/examples/scd4x_tuning_knobs.py +++ b/examples/scd4x_tuning_knobs.py @@ -2,7 +2,9 @@ # # SPDX-License-Identifier: Unlicense import time + import board + import adafruit_scd4x i2c = board.I2C() # uses board.SCL and board.SDA 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 2e8a3204ff1fd01f921718cf7e4c9db79c7c0910 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 4 Jun 2025 10:00:20 -0500 Subject: [PATCH 71/71] 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"