diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml index 8582f42..d990a98 100644 --- a/.github/workflows/build-and-publish.yml +++ b/.github/workflows/build-and-publish.yml @@ -1,13 +1,11 @@ on: push: branches: - - master + - main tags: - "[0-9]+.[0-9]+.[0-9]+" jobs: build_and_deploy: uses: sensirion/.github/.github/workflows/driver.python.pypi_publish.yml@main - secrets: - PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }} - + secrets: inherit diff --git a/.github/workflows/build-docs.yml b/.github/workflows/build-docs.yml index b331793..d2d0f78 100644 --- a/.github/workflows/build-docs.yml +++ b/.github/workflows/build-docs.yml @@ -3,10 +3,10 @@ on: workflow_dispatch: push: branches: - - master + - main jobs: documentation: uses: sensirion/.github/.github/workflows/driver.python.documentation.yml@main with: - build-python-version: 3.8 + use-project-requirements: true diff --git a/.github/workflows/gh_workflow_metadata_update.yml b/.github/workflows/gh_workflow_metadata_update.yml new file mode 100644 index 0000000..7dd70ed --- /dev/null +++ b/.github/workflows/gh_workflow_metadata_update.yml @@ -0,0 +1,11 @@ +name: Driver Index Metadata Update + +on: + push: + branches: + - main + +jobs: + driver-index-metadata-update: + uses: sensirion/.github/.github/workflows/driver.common.di_metadata_update.yml@main + secrets: inherit diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 615fdfb..c15f72f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,11 +2,15 @@ name: Validate and Test Python Package on: pull_request: branches: - - master + - main push: branches: - - master + - main jobs: + dg-metadata-validation: + if: github.event_name == 'push' && github.ref != 'refs/head/main' + uses: sensirion/.github/.github/workflows/driver.generated.metadata_check.yml@main + test: uses: sensirion/.github/.github/workflows/driver.python.test.yml@main diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..34210ea --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,32 @@ +# CHANGELOG + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + + +## [2.0.3] - 2023-11-15 + + +### Added + +- function get_product_type_as_int as get_product_type has no longer a parameter as_int + +### Changed + +- Renamed from svm41 to svm4x + +### ### Removed + +- SetNoxState and GetNoxState are not supported in newer firmware + + +## [0.1.0] - 2023-10-23 + +### Added + +- Initial release + +[Unreleased]: https://github.com/Sensirion/python-uart-svm4x/compare/2.0.3...HEAD +[2.0.3]: https://github.com/Sensirion/python-uart-svm4x/releases/tag/2.0.3 \ No newline at end of file diff --git a/LICENSE b/LICENSE index f95f5fe..8fe04ed 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ BSD 3-Clause License -Copyright (c) 2023, Sensirion AG +Copyright (c) 2026, Sensirion AG All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/README.md b/README.md index 040c20c..3170f4b 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Click [here](https://www.sensirion.com/my-sgp-ek/) to learn more about the Sensi The SVM4x evaluation kit covers evaluation of the SGP40 and SGP41 sensors. +This driver supports SVM4x firmware version 3.1.0 and above. @@ -45,12 +46,6 @@ See the [documentation page](https://sensirion.github.io/python-uart-svm4x) for ## Contributing -We develop and test this driver using our company internal tools (version -control, continuous integration, code review etc.) and automatically -synchronize the `master` branch with GitHub. But this doesn't mean that we -don't respond to issues or don't accept pull requests on GitHub. In fact, -you're very welcome to open issues or create pull requests :-) - ### Check coding style The coding style can be checked with [`flake8`](http://flake8.pycqa.org/): diff --git a/README.rst b/README.rst deleted file mode 100644 index 1ea673b..0000000 --- a/README.rst +++ /dev/null @@ -1,10 +0,0 @@ -sensirion_shdlc_svm41 -===================== - -This package contains the driver to communicate with a Sensirion SVM41 sensor over uart. - -Installation and Usage ----------------------- - -The user manual is available at -https://sensirion.github.io/python-uart-svm41 diff --git a/docs/build-documentation.rst b/docs/build-documentation.rst index 8653cf1..a188010 100644 --- a/docs/build-documentation.rst +++ b/docs/build-documentation.rst @@ -5,10 +5,5 @@ The documentation is built with `Sphinx `_: .. code-block:: bash - python setup.py install # Install package - pip install -r docs/requirements.txt # Install requirements - cd docs # Change to docs folder - make html # Build documentation - - -The generated documentation is located in docs/_build/html. \ No newline at end of file + python -m pip install .[docs] # Install doc requirements + sphinx-build -b html docs docs/_build/html # Build documentation diff --git a/docs/conf.py b/docs/conf.py index 8930438..b52e756 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -4,11 +4,14 @@ # list see the documentation: # https://www.sphinx-doc.org/en/master/usage/configuration.html + import os import sys from datetime import datetime -import pkg_resources +import importlib.metadata as metadata +import sphinx_tabs.tabs + import sphinx.ext.autodoc import sensirion_uart_svm4x @@ -17,16 +20,16 @@ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) # -- Project information ----------------------------------------------------- -distribution = pkg_resources.get_distribution('sensirion_uart_svm4x') +distribution = metadata.distribution("sensirion_uart_svm4x") -project = u'sensirion_uart_svm4x' +project = distribution.name copyright = u'{} Sensirion AG, Switzerland'.format(datetime.now().year) author = 'Sensirion AG' # The short X.Y version -version = sensirion_uart_svm4x.__version__ +version = distribution.version # The full version, including alpha/beta/rc tags -release = sensirion_uart_svm4x.__version__ +release = distribution.version # -- General configuration --------------------------------------------------- @@ -36,6 +39,7 @@ extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.viewcode', + 'sphinx_tabs.tabs', 'sphinx.ext.inheritance_diagram', 'sphinx.ext.githubpages', 'sphinx.ext.intersphinx', diff --git a/docs/dev-setup.rst b/docs/dev-setup.rst new file mode 100644 index 0000000..3e2a3e5 --- /dev/null +++ b/docs/dev-setup.rst @@ -0,0 +1,45 @@ +To prepare your development environment, check out the repository, +create a Python virtual environment, and activate it. +Then install the driver in editable mode using `pip`. + +Check out the Git repository to your local machine: + +.. code-block:: console + + git clone + cd + +Create a Python virtual environment: + +.. code-block:: console + + python -m venv .venv + +Activate the virtual environment: + +.. tabs:: + + .. group-tab:: Bash + + .. code-block:: console + + source .venv/bin/activate + + .. group-tab:: PowerShell + + .. code-block:: console + + .venv\Scripts\Activate.ps1 + + .. group-tab:: Command Prompt + + .. code-block:: console + + .venv\Scripts\activate.bat + +Install the driver in editable mode together with the development dependencies: + +.. code-block:: console + + python -m pip install -e . + diff --git a/docs/development.rst b/docs/development.rst index d169708..dddb742 100644 --- a/docs/development.rst +++ b/docs/development.rst @@ -1,6 +1,10 @@ Development =========== +For development, you first need to prepare your setup. + +.. include:: dev-setup.rst + .. toctree:: run-tests diff --git a/docs/driver-installation.rst b/docs/driver-installation.rst new file mode 100644 index 0000000..b23531c --- /dev/null +++ b/docs/driver-installation.rst @@ -0,0 +1,37 @@ +The driver installation consists of creating a Python virtual environment, +activating it, and installing the driver using `pip`. + +Create a Python virtual environment: + +.. code-block:: console + + python -m venv .venv + +Activate the virtual environment: + +.. tabs:: + + .. group-tab:: Bash + + + .. code-block:: console + + source .venv/bin/activate + + .. group-tab:: PowerShell + + .. code-block:: console + + .venv\Scripts\Activate.ps1 + + .. group-tab:: Command Prompt + + .. code-block:: console + + .venv\Scripts\activate.bat + +Install the driver: + +.. code-block:: console + + python -m pip install sensirion_uart_svm4x diff --git a/docs/execute-measurements.rst b/docs/execute-measurements.rst index 92250bd..3b1d76b 100644 --- a/docs/execute-measurements.rst +++ b/docs/execute-measurements.rst @@ -1,11 +1,13 @@ -Execute measurements -==================== +Install the SVM4X Driver +------------------------ -The following steps show how to use this driver to execute a simple measurement on a Windows system. +.. include:: driver-installation.rst -1. Install the SVM4X sensor driver and all required packages as described in :ref:`Installation`. -2. Connect the SVM4X sensor to your system with the serial USB cable. -3. Run the example script from the root of the repository. +Run Usage-Example +----------------- + +1. Connect the SVM4X sensor to your system with the serial USB cable. +2. Run the example script from the root of the repository. By default the script assumes the sensor is connected to COM1 serial port. If this is different on your system, pass the port in use with the :code:`--serial-port` parameter as outlined below. @@ -15,7 +17,7 @@ The following steps show how to use this driver to execute a simple measurement python examples/example_usage_uart_svm4x.py --serial-port Example script --------------- +~~~~~~~~~~~~~~ .. literalinclude:: ../examples/example_usage_uart_svm4x.py :language: python \ No newline at end of file diff --git a/docs/installation.rst b/docs/installation.rst index 40ba2f8..dcec370 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -3,10 +3,7 @@ Installation ============ -The package can be installed with pip: +It is assumed that you have a working Python installation on your system. +If not, please install Python first including `pip `_. -.. sourcecode:: bash - - pip install sensirion_uart_svm4x - -Recommended usage is within a virtualenv. +.. include:: driver-installation.rst \ No newline at end of file diff --git a/docs/quickstart.rst b/docs/quickstart.rst index 5dce52d..8399634 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -1,6 +1,10 @@ Quick Start =========== +Learn how to quickly get started with the SVM4X and perform your first measurements using +the provided usage examples. + + .. toctree:: execute-measurements diff --git a/docs/requirements.txt b/docs/requirements.txt index 0c69c37..bd93639 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,4 +1,5 @@ click==8.0.4 -jinja2==3.0.1 -sphinx~=4.2.0 -sphinx_rtd_theme~=1.0.0 +jinja2~=3.1.0 +sphinx~=7.1.0 +sphinx-tabs~=3.5.0 +sphinx_rtd_theme~=1.3.0 diff --git a/examples/algorithm_tuning_example_uart_svm4x.py b/examples/algorithm_tuning_example_uart_svm4x.py index c5cdd3e..5a9ee2e 100644 --- a/examples/algorithm_tuning_example_uart_svm4x.py +++ b/examples/algorithm_tuning_example_uart_svm4x.py @@ -20,7 +20,7 @@ parser.add_argument('--serial-port', '-p', default='COM1') args = parser.parse_args() -with ShdlcSerialPort(port=args.serial_port, baudrate=115200) as port: +with ShdlcSerialPort(port=args.serial_port, baudrate=115200, additional_response_time=0.02) as port: channel = ShdlcChannel(port) sensor = Svm4xDevice(channel) sensor.device_reset() diff --git a/examples/example_usage_uart_svm4x.py b/examples/example_usage_uart_svm4x.py index b7776be..6c9bead 100644 --- a/examples/example_usage_uart_svm4x.py +++ b/examples/example_usage_uart_svm4x.py @@ -20,7 +20,7 @@ parser.add_argument('--serial-port', '-p', default='COM1') args = parser.parse_args() -with ShdlcSerialPort(port=args.serial_port, baudrate=115200) as port: +with ShdlcSerialPort(port=args.serial_port, baudrate=115200, additional_response_time=0.02) as port: channel = ShdlcChannel(port) sensor = Svm4xDevice(channel) sensor.device_reset() @@ -44,8 +44,8 @@ f"protocol_major: {protocol_major}; " f"protocol_minor: {protocol_minor}; " ) - t_offset = sensor.get_temperature_offset_for_rht_measurements() - print(f"t_offset: {t_offset}; " + temperature_offset = sensor.get_temperature_offset_for_rht_measurements() + print(f"temperature_offset: {temperature_offset}; " ) sensor.set_temperature_offset_for_rht_measurements(0) sensor.start_measurement() diff --git a/metadata.yml b/metadata.yml index c217de8..34c0196 100644 --- a/metadata.yml +++ b/metadata.yml @@ -1,8 +1,7 @@ # driver generation metadata -generator_version: 0.33.0 -model_version: 2.0.3 -dg_status: -- released +generator_version: 1.7.0 +model_version: 2.0.4 +dg_status: released is_manually_modified: true -first_generated: '2022-09-27 17:04' -last_generated: '2023-11-14 09:35' +first_generated: '2026-10-19 11:14' +last_generated: '2026-10-19 11:14' diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b70b6fa --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,68 @@ +[build-system] +requires = ["hatchling >= 1.26", "wheel >= 0.45.0"] +build-backend = "hatchling.build" + +[project] +name = "sensirion_uart_svm4x" +description = "I2C driver for the Sensirion SVM4X sensor family" + +readme = "README.md" +version = "0.2.0" + +requires-python = ">=3.8.4,<4.0" + +authors = [ + { name = "Sensirion", email = "info@sensirion.com" }, +] + +license = "BSD-3-Clause" +license-files = ["LICENSE"] + +keywords = [ + "Sensirion SVM4X", + "SHDLC", + "SVM4x", + ] + +classifiers = [ + "Intended Audience :: Developers", + "Topic :: System :: Hardware :: Hardware Drivers", + "Topic :: Software Development :: Libraries :: Python Modules", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", +] + +dependencies = [ + "sensirion-driver-adapters>=2.3.0,<3.0", + "sensirion-driver-support-types>=1.2.0,<2.0", + "sensirion-shdlc-driver", + ] + +[project.optional-dependencies] + +docs=[ + "jinja2~=3.1.6", + "sphinx-rtd-theme==3.0.2", + "sphinx>=7.0,<8.0;python_version < '3.11'", + "sphinx==8.2.3;python_version >= '3.11'", + "lazy-object-proxy ~=1.7.1", + "sphinx-tabs~=3.5.0", + "sphinx-autoapi~=3.0.0", +] + +test= [ + "flake8>=7.1.0", + "mock~=5.2.0", + "pytest>=8.3.5", + "pytest-cov>=5.0.0", + "mypy~=1.13.0", + "setuptools>=73.2.0" +] + +[project.urls] +Changelog = "https://github.com/Sensirion/python-uart-svm4x/blob/master/CHANGELOG.md" +Repository = "https://github.com/Sensirion/python-uart-svm4x" +Documentation = "https://sensirion.github.io/python-uart-svm4x" + diff --git a/sensirion_uart_svm4x/commands.py b/sensirion_uart_svm4x/commands.py index 7fe0635..baaf2b0 100644 --- a/sensirion_uart_svm4x/commands.py +++ b/sensirion_uart_svm4x/commands.py @@ -1,13 +1,13 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # -# (c) Copyright 2023 Sensirion AG, Switzerland +# (c) Copyright 2026 Sensirion AG, Switzerland # # THIS FILE IS AUTOMATICALLY GENERATED! # -# Generator: sensirion-driver-generator 0.33.0 +# Generator: sensirion-driver-generator 1.7.0 # Product: svm4x -# Model-Version: 2.0.3 +# Model-Version: 2.0.4 # """ The transfer classes specify the data that is transferred between host and sensor. The generated transfer classes diff --git a/sensirion_uart_svm4x/device.py b/sensirion_uart_svm4x/device.py index 08bd08c..45dbb9a 100644 --- a/sensirion_uart_svm4x/device.py +++ b/sensirion_uart_svm4x/device.py @@ -1,13 +1,13 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # -# (c) Copyright 2023 Sensirion AG, Switzerland +# (c) Copyright 2026 Sensirion AG, Switzerland # # THIS FILE IS AUTOMATICALLY GENERATED! # -# Generator: sensirion-driver-generator 0.33.0 +# Generator: sensirion-driver-generator 1.7.0 # Product: svm4x -# Model-Version: 2.0.3 +# Model-Version: 2.0.4 # """ The class Svm4xDeviceBase implements the low level interface of the sensor. @@ -95,7 +95,7 @@ def device_reset(self): Executs a reset on the device. .. note:: - The device will reply before executing the reset. If the command is send with + The device will reply before executing the reset. If the command is sent with broadcast, the reset is done directly after the reception of the command. """ transfer = DeviceReset() @@ -419,7 +419,7 @@ def get_temperature_offset_for_rht_measurements(self): """ Gets the T-Offset for the temperature compensation of the RHT algorithm. - :return arg_0: + :return temperature_offset: """ t_offset_int = self.svm4x.get_temperature_offset_for_rht_measurements() @@ -432,7 +432,7 @@ def set_temperature_offset_for_rht_measurements(self, t_offset): :param t_offset: Temperature offset as float in degrees celsius. """ - t_offset_int = round(t_offset * 200) + t_offset_int = round(t_offset * 200.0) self.svm4x.set_temperature_offset_for_rht_measurements(t_offset_int) return diff --git a/sensirion_uart_svm4x/result_types.py b/sensirion_uart_svm4x/result_types.py index b5cfeea..2730e2f 100644 --- a/sensirion_uart_svm4x/result_types.py +++ b/sensirion_uart_svm4x/result_types.py @@ -1,13 +1,13 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # -# (c) Copyright 2023 Sensirion AG, Switzerland +# (c) Copyright 2026 Sensirion AG, Switzerland # # THIS FILE IS AUTOMATICALLY GENERATED! # -# Generator: sensirion-driver-generator 0.33.0 +# Generator: sensirion-driver-generator 1.7.0 # Product: svm4x -# Model-Version: 2.0.3 +# Model-Version: 2.0.4 # """ The signal classes specify transformations of the raw sensor signals into a meaningful units. diff --git a/sensirion_uart_svm4x/version.py b/sensirion_uart_svm4x/version.py index 3548b22..b7d6e6c 100644 --- a/sensirion_uart_svm4x/version.py +++ b/sensirion_uart_svm4x/version.py @@ -1,5 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import absolute_import, division, print_function +import importlib.metadata as metadata +from typing import Final -version = "2.0.3" +version: Final[str] = metadata.version("sensirion_uart_svm4x") diff --git a/setup.py b/setup.py index 2e97434..bfae448 100644 --- a/setup.py +++ b/setup.py @@ -1,75 +1,5 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +from setuptools import setup -import os -import re - -from setuptools import setup, find_packages - -# Python versions this package is compatible with -python_requires = '>=3.6, <4' - -# Packages that this package imports. List everything apart from standard lib packages. -install_requires = [ - 'sensirion-shdlc-driver~=0.1.5', - 'sensirion-driver-adapters>=2.1.8,<3.0', - 'sensirion-driver-support-types>=1.1.0,<2.0', -] - -# Packages required for tests and docs -extras_require = { - 'test': [ - 'flake8~=3.7.8', - 'pytest~=6.2.5', - 'pytest-cov~=3.0.0', - ], - 'docs': [ - 'click==8.0.4', - 'jinja2==3.0.1', - 'sphinx~=2.2.1', - 'sphinx-rtd-theme~=0.4.3', - ] -} - -# Read version number from version.py -version_line = open("sensirion_uart_svm4x/version.py", "rt").read() -result = re.search(r"^version = ['\"]([^'\"]*)['\"]", version_line, re.M) -if result: - version_string = result.group(1) -else: - raise RuntimeError("Unable to find version string") - -# Use README.rst and CHANGELOG.rst as package description -root_path = os.path.dirname(__file__) -long_description = open(os.path.join(root_path, 'README.md')).read() - -setup( - name='sensirion_uart_svm4x', - version=version_string, - author='Sensirion', - author_email='info@sensirion.com', - description='SHDLC driver for the Sensirion SVM4X sensor family', - license='BSD', - keywords="""Sensirion SVM4X - SHDLC - UART - SVM4x""", - project_urls={ - "Documentation": "https://sensirion.github.io/python-uart-svm4x", - "Repository": "https://github.com/Sensirion/python-uart-svm4x", - "Changelog": "https://github.com/Sensirion/python-uart-svm4x/blob/master/CHANGELOG.rst", - }, - packages=find_packages(exclude=['tests', 'tests.*']), - long_description=long_description, - long_description_content_type='text/markdown', - python_requires=python_requires, - install_requires=install_requires, - extras_require=extras_require, - classifiers=[ - 'Intended Audience :: Developers', - 'License :: Other/Proprietary License', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.8', - 'Topic :: Software Development :: Libraries :: Python Modules' - ] -) +setup() \ No newline at end of file diff --git a/conftest.py b/tests/conftest.py similarity index 100% rename from conftest.py rename to tests/conftest.py diff --git a/tests/test_svm4x.py b/tests/test_svm4x.py index 1e815a3..59dacc5 100644 --- a/tests/test_svm4x.py +++ b/tests/test_svm4x.py @@ -1,13 +1,13 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # -# (c) Copyright 2023 Sensirion AG, Switzerland +# (c) Copyright 2026 Sensirion AG, Switzerland # # THIS FILE IS AUTOMATICALLY GENERATED! # -# Generator: sensirion-driver-generator 0.33.0 +# Generator: sensirion-driver-generator 1.7.0 # Product: svm4x -# Model-Version: 2.0.3 +# Model-Version: 2.0.4 # import pytest @@ -65,8 +65,8 @@ def test_get_system_up_time1(sensor): def test_get_temperature_offset_for_rht_measurements1(sensor): - arg_0 = sensor.get_temperature_offset_for_rht_measurements() - print(f"arg_0: {arg_0}; " + temperature_offset = sensor.get_temperature_offset_for_rht_measurements() + print(f"temperature_offset: {temperature_offset}; " ) @@ -139,8 +139,8 @@ def test_start_measurement1(sensor): f"raw_voc_ticks: {raw_voc_ticks}; " f"raw_nox_ticks: {raw_nox_ticks}; " ) - arg_0 = sensor.get_temperature_offset_for_rht_measurements() - print(f"arg_0: {arg_0}; " + temperature_offset = sensor.get_temperature_offset_for_rht_measurements() + print(f"temperature_offset: {temperature_offset}; " ) (voc_index_offset, learning_time_offset_hours, learning_time_gain_hours, gating_max_duration_minutes, std_initial, gain_factor