From 5aa6cd8459c36bf4c46f0a7f401cd3ca684aa73d Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Wed, 25 Dec 2024 10:38:40 +0100 Subject: [PATCH 01/10] Update install action --- .github/workflows/pythonpackage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index fabd5ab..78a0557 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -25,7 +25,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - python -m pip install --upgrade pip + python -m pip install --upgrade pip setuptools wheel pip install -r requirements.txt - name: Lint with flake8 run: | From cc290bda2f359b71f5a87e8771ee5312ab705838 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Wed, 18 Jun 2025 01:16:01 +0200 Subject: [PATCH 02/10] Migrate to poetry-core --- examples/example-bulb.py | 5 ++-- pyproject.toml | 27 ++++++++++++++++++++++ requirements.txt | 2 -- setup.py | 49 ---------------------------------------- 4 files changed, 29 insertions(+), 54 deletions(-) create mode 100644 pyproject.toml delete mode 100644 requirements.txt delete mode 100644 setup.py diff --git a/examples/example-bulb.py b/examples/example-bulb.py index e771423..7476c68 100644 --- a/examples/example-bulb.py +++ b/examples/example-bulb.py @@ -5,9 +5,8 @@ from pymystrom.bulb import MyStromBulb from pymystrom.discovery import discover_devices -IP_ADDRESS = "192.168.0.51" -MAC_ADDRESS = "5CCF7FA0AFB0" - +IP_ADDRESS = "192.168.1.25" +MAC_ADDRESS = "5CCF7FA0C27C" async def main(): """Sample code to work with a myStrom bulb.""" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..c80f3a7 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,27 @@ +[tool.poetry] +name = "python-mystrom" +version = "2.4.0" +description = "Asynchronous Python API client for interacting with myStrom devices" +authors = ["Fabian Affolter "] +license = "MIT" +readme = "README.rst" +homepage = "https://github.com/home-assistant-ecosystem/python-mystrom" +repository = "https://github.com/home-assistant-ecosystem/python-mystrom" +keywords = ["myStrom", "API", "client", "asynchronous"] +packages = [ + { include = "pymystrom" } +] + +[tool.poetry.dependencies] +python = ">=3.9" +aiohttp = "*" +click = "*" +requests = "*" + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" + +[tool.poetry.scripts] +pymystrom = "pymystrom.cli:main" + diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index bd1170e..0000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -# python-mystrom requirements. Use setup.py for the dependencies. -. diff --git a/setup.py b/setup.py deleted file mode 100644 index b3d7b59..0000000 --- a/setup.py +++ /dev/null @@ -1,49 +0,0 @@ -"""Set up the Python API for myStrom devices.""" -import os - -import sys - -from setuptools import setup, find_packages - -here = os.path.abspath(os.path.dirname(__file__)) - -with open(os.path.join(here, "README.rst"), encoding="utf-8") as readme: - long_description = readme.read() - -setup( - name="python-mystrom", - version="2.3.0", - description="Asynchronous Python API client for interacting with myStrom devices", - long_description=long_description, - url="https://github.com/home-assistant-ecosystem/python-mystrom", - author="Fabian Affolter", - author_email="fabian@affolter-engineering.ch", - license="MIT", - install_requires=[ - "requests", - "click", - "aiohttp", - "setuptools", - "async_timeout", - ], - packages=find_packages(), - python_requires=">=3.9", - zip_safe=True, - include_package_data=True, - entry_points=""" - [console_scripts] - mystrom=pymystrom.cli:main -""", - classifiers=[ - "Development Status :: 3 - Alpha", - "Environment :: Console", - "Intended Audience :: Developers", - "License :: OSI Approved :: MIT License", - "Operating System :: MacOS :: MacOS X", - "Operating System :: Microsoft :: Windows", - "Operating System :: POSIX", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Topic :: Utilities", - ], -) From 82c5dbc773e69e10b13a92bd04f640ab668dbc22 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Wed, 18 Jun 2025 08:13:44 +0200 Subject: [PATCH 03/10] Sort imports --- pymystrom/bulb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymystrom/bulb.py b/pymystrom/bulb.py index 7934485..a263384 100644 --- a/pymystrom/bulb.py +++ b/pymystrom/bulb.py @@ -1,10 +1,10 @@ """Support for communicating with myStrom bulbs.""" import asyncio import logging +from typing import Optional import aiohttp from yarl import URL -from typing import Optional from . import _request as request From d17ca7c9434f985b14287adba4c41c60b6123c91 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Wed, 18 Jun 2025 08:14:23 +0200 Subject: [PATCH 04/10] Sort imports --- pymystrom/discovery.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymystrom/discovery.py b/pymystrom/discovery.py index e9956f9..ad01cc8 100644 --- a/pymystrom/discovery.py +++ b/pymystrom/discovery.py @@ -1,7 +1,7 @@ """Support for discovering myStrom devices.""" import asyncio import logging -from typing import Optional, List +from typing import List, Optional from .device_types import DEVICE_MAPPING_NUMERIC From 4cdb2b987878e5a9391b2f4bc414ad24f753729b Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Wed, 18 Jun 2025 08:14:54 +0200 Subject: [PATCH 05/10] Sort imports --- pymystrom/pir.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pymystrom/pir.py b/pymystrom/pir.py index de66b29..c727b77 100644 --- a/pymystrom/pir.py +++ b/pymystrom/pir.py @@ -1,7 +1,8 @@ """Support for communicating with myStrom PIRs.""" +from typing import Any, Dict, Iterable, List, Optional, Union + import aiohttp from yarl import URL -from typing import Any, Dict, Iterable, List, Optional, Union from . import _request as request From d9efede8510420fe2d8a9c5bdca44148ec863258 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Wed, 18 Jun 2025 08:15:23 +0200 Subject: [PATCH 06/10] Sort imports --- pymystrom/switch.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pymystrom/switch.py b/pymystrom/switch.py index 30303a7..75e0e46 100644 --- a/pymystrom/switch.py +++ b/pymystrom/switch.py @@ -1,10 +1,11 @@ """Support for communicating with myStrom plugs/switches.""" +from typing import Optional, Union + import aiohttp from yarl import URL -from typing import Optional, Union from . import _request as request -from .device_types import DEVICE_MAPPING_NUMERIC, DEVICE_MAPPING_LITERAL +from .device_types import DEVICE_MAPPING_LITERAL, DEVICE_MAPPING_NUMERIC class MyStromSwitch: From 8f937ab349f57e6148e961d2d2b014447b5e883d Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Fri, 20 Jun 2025 08:26:47 +0200 Subject: [PATCH 07/10] Remove async_timeout --- pymystrom/__init__.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/pymystrom/__init__.py b/pymystrom/__init__.py index 80cc054..ccbe22b 100644 --- a/pymystrom/__init__.py +++ b/pymystrom/__init__.py @@ -1,18 +1,15 @@ """Base details for the myStrom Python bindings.""" import asyncio -import aiohttp -import async_timeout -from yarl import URL -from typing import Any, Mapping, Optional import socket -from .exceptions import MyStromConnectionError +from typing import Any, Mapping, Optional -import pkg_resources +import aiohttp +from yarl import URL -__version__ = pkg_resources.get_distribution("setuptools").version +from .exceptions import MyStromConnectionError TIMEOUT = 10 -USER_AGENT = f"PythonMyStrom/{__version__}" +USER_AGENT = "PythonMyStrom/1.0" async def _request( @@ -34,15 +31,17 @@ async def _request( self._close_session = True try: - with async_timeout.timeout(TIMEOUT): - response = await self._session.request( + response = await asyncio.wait_for( + self._session.request( method, uri, data=data, json=json_data, params=params, headers=headers, - ) + ), + timeout=TIMEOUT, + ) except asyncio.TimeoutError as exception: raise MyStromConnectionError( "Timeout occurred while connecting to myStrom device." From 6b1e29b189868862173b22234c351ec26e8130d9 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Fri, 20 Jun 2025 08:36:49 +0200 Subject: [PATCH 08/10] Set to later Python release --- pyproject.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c80f3a7..97eee23 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ packages = [ ] [tool.poetry.dependencies] -python = ">=3.9" +python = ">=3.11" aiohttp = "*" click = "*" requests = "*" @@ -24,4 +24,3 @@ build-backend = "poetry.core.masonry.api" [tool.poetry.scripts] pymystrom = "pymystrom.cli:main" - From 25f8df9547cc06a2bf5dffdca41bf0c4c2c42c51 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Fri, 20 Jun 2025 08:39:06 +0200 Subject: [PATCH 09/10] Add example for discovery --- examples/example-bulb-hsv.py | 1 + examples/example-bulb.py | 2 ++ examples/example-discovery.py | 15 +++++++++++++++ examples/example-get-data-bulb.py | 1 + examples/example-pir.py | 1 + examples/example-switch.py | 1 + 6 files changed, 21 insertions(+) create mode 100644 examples/example-discovery.py diff --git a/examples/example-bulb-hsv.py b/examples/example-bulb-hsv.py index 171368c..5b7e702 100644 --- a/examples/example-bulb-hsv.py +++ b/examples/example-bulb-hsv.py @@ -1,4 +1,5 @@ """Example code for communicating with a myStrom bulb and HSV values.""" + import time from pymystrom import bulb diff --git a/examples/example-bulb.py b/examples/example-bulb.py index 7476c68..84c5a92 100644 --- a/examples/example-bulb.py +++ b/examples/example-bulb.py @@ -1,4 +1,5 @@ """Example code for communicating with a myStrom bulb.""" + import asyncio import logging @@ -8,6 +9,7 @@ IP_ADDRESS = "192.168.1.25" MAC_ADDRESS = "5CCF7FA0C27C" + async def main(): """Sample code to work with a myStrom bulb.""" # Discover myStrom bulbs devices diff --git a/examples/example-discovery.py b/examples/example-discovery.py new file mode 100644 index 0000000..76e94df --- /dev/null +++ b/examples/example-discovery.py @@ -0,0 +1,15 @@ +import asyncio + +from pymystrom import discovery + + +async def main(): + """Sample code to work with discovery.""" + # Discover all bulbs in the network via broadcast datagram (UDP) + bulbs = await discovery.discover_devices() + print(f"Number of detected bulbs: {len(bulbs)}") + + +if __name__ == "__main__": + loop = asyncio.get_event_loop() + loop.run_until_complete(main()) diff --git a/examples/example-get-data-bulb.py b/examples/example-get-data-bulb.py index c6f03ac..c0b07d3 100644 --- a/examples/example-get-data-bulb.py +++ b/examples/example-get-data-bulb.py @@ -1,4 +1,5 @@ """Example code for getting the data from a myStrom bulb.""" + from pymystrom import bulb bulb = bulb.MyStromBulb("192.168.0.51", "5CCF7FA0AFB0") diff --git a/examples/example-pir.py b/examples/example-pir.py index 7596a5a..c884e20 100644 --- a/examples/example-pir.py +++ b/examples/example-pir.py @@ -1,4 +1,5 @@ """Example code for communicating with a myStrom PIR unit.""" + import asyncio from pymystrom.pir import MyStromPir diff --git a/examples/example-switch.py b/examples/example-switch.py index 8e78c04..1287379 100644 --- a/examples/example-switch.py +++ b/examples/example-switch.py @@ -1,4 +1,5 @@ """Example code for communicating with a myStrom plug/switch.""" + import asyncio from pymystrom.switch import MyStromSwitch From 6707256a2fd4d646c8d1e562432e4579f0ba9989 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Fri, 20 Jun 2025 08:39:59 +0200 Subject: [PATCH 10/10] Update formatting --- pymystrom/__init__.py | 1 + pymystrom/bulb.py | 1 + pymystrom/cli.py | 1 + pymystrom/discovery.py | 1 + pymystrom/pir.py | 1 + pymystrom/switch.py | 1 + 6 files changed, 6 insertions(+) diff --git a/pymystrom/__init__.py b/pymystrom/__init__.py index ccbe22b..e81c6a8 100644 --- a/pymystrom/__init__.py +++ b/pymystrom/__init__.py @@ -1,4 +1,5 @@ """Base details for the myStrom Python bindings.""" + import asyncio import socket from typing import Any, Mapping, Optional diff --git a/pymystrom/bulb.py b/pymystrom/bulb.py index a263384..adfa70f 100644 --- a/pymystrom/bulb.py +++ b/pymystrom/bulb.py @@ -1,4 +1,5 @@ """Support for communicating with myStrom bulbs.""" + import asyncio import logging from typing import Optional diff --git a/pymystrom/cli.py b/pymystrom/cli.py index 3ebd1d0..b76d034 100644 --- a/pymystrom/cli.py +++ b/pymystrom/cli.py @@ -1,4 +1,5 @@ """Command-line tool for working with myStrom devices.""" + import click import requests import asyncio diff --git a/pymystrom/discovery.py b/pymystrom/discovery.py index ad01cc8..5389062 100644 --- a/pymystrom/discovery.py +++ b/pymystrom/discovery.py @@ -1,4 +1,5 @@ """Support for discovering myStrom devices.""" + import asyncio import logging from typing import List, Optional diff --git a/pymystrom/pir.py b/pymystrom/pir.py index c727b77..dc68441 100644 --- a/pymystrom/pir.py +++ b/pymystrom/pir.py @@ -1,4 +1,5 @@ """Support for communicating with myStrom PIRs.""" + from typing import Any, Dict, Iterable, List, Optional, Union import aiohttp diff --git a/pymystrom/switch.py b/pymystrom/switch.py index 75e0e46..d83b088 100644 --- a/pymystrom/switch.py +++ b/pymystrom/switch.py @@ -1,4 +1,5 @@ """Support for communicating with myStrom plugs/switches.""" + from typing import Optional, Union import aiohttp