Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
1 change: 1 addition & 0 deletions examples/example-bulb-hsv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Example code for communicating with a myStrom bulb and HSV values."""

import time

from pymystrom import bulb
Expand Down
5 changes: 3 additions & 2 deletions examples/example-bulb.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""Example code for communicating with a myStrom bulb."""

import asyncio
import logging

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():
Expand Down
15 changes: 15 additions & 0 deletions examples/example-discovery.py
Original file line number Diff line number Diff line change
@@ -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())
1 change: 1 addition & 0 deletions examples/example-get-data-bulb.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
1 change: 1 addition & 0 deletions examples/example-pir.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Example code for communicating with a myStrom PIR unit."""

import asyncio

from pymystrom.pir import MyStromPir
Expand Down
1 change: 1 addition & 0 deletions examples/example-switch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Example code for communicating with a myStrom plug/switch."""

import asyncio

from pymystrom.switch import MyStromSwitch
Expand Down
22 changes: 11 additions & 11 deletions pymystrom/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
"""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(
Expand All @@ -34,15 +32,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."
Expand Down
3 changes: 2 additions & 1 deletion pymystrom/bulb.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""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

Expand Down
1 change: 1 addition & 0 deletions pymystrom/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Command-line tool for working with myStrom devices."""

import click
import requests
import asyncio
Expand Down
3 changes: 2 additions & 1 deletion pymystrom/discovery.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""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

Expand Down
4 changes: 3 additions & 1 deletion pymystrom/pir.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""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

Expand Down
6 changes: 4 additions & 2 deletions pymystrom/switch.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""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:
Expand Down
26 changes: 26 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[tool.poetry]
name = "python-mystrom"
version = "2.4.0"
description = "Asynchronous Python API client for interacting with myStrom devices"
authors = ["Fabian Affolter <fabian@affolter-engineering.ch>"]
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.11"
aiohttp = "*"
click = "*"
requests = "*"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.scripts]
pymystrom = "pymystrom.cli:main"
2 changes: 0 additions & 2 deletions requirements.txt

This file was deleted.

49 changes: 0 additions & 49 deletions setup.py

This file was deleted.

Loading