Skip to content

Commit e4a03dc

Browse files
authored
Migrate to pyproject (#57)
* Update install action * Migrate to poetry-core * Sort imports * Sort imports * Sort imports * Sort imports * Remove async_timeout * Set to later Python release * Add example for discovery * Update formatting
1 parent 4590c24 commit e4a03dc

File tree

15 files changed

+71
-69
lines changed

15 files changed

+71
-69
lines changed

examples/example-bulb-hsv.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Example code for communicating with a myStrom bulb and HSV values."""
2+
23
import time
34

45
from pymystrom import bulb

examples/example-bulb.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
"""Example code for communicating with a myStrom bulb."""
2+
23
import asyncio
34
import logging
45

56
from pymystrom.bulb import MyStromBulb
67
from pymystrom.discovery import discover_devices
78

8-
IP_ADDRESS = "192.168.0.51"
9-
MAC_ADDRESS = "5CCF7FA0AFB0"
9+
IP_ADDRESS = "192.168.1.25"
10+
MAC_ADDRESS = "5CCF7FA0C27C"
1011

1112

1213
async def main():

examples/example-discovery.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import asyncio
2+
3+
from pymystrom import discovery
4+
5+
6+
async def main():
7+
"""Sample code to work with discovery."""
8+
# Discover all bulbs in the network via broadcast datagram (UDP)
9+
bulbs = await discovery.discover_devices()
10+
print(f"Number of detected bulbs: {len(bulbs)}")
11+
12+
13+
if __name__ == "__main__":
14+
loop = asyncio.get_event_loop()
15+
loop.run_until_complete(main())

examples/example-get-data-bulb.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Example code for getting the data from a myStrom bulb."""
2+
23
from pymystrom import bulb
34

45
bulb = bulb.MyStromBulb("192.168.0.51", "5CCF7FA0AFB0")

examples/example-pir.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Example code for communicating with a myStrom PIR unit."""
2+
23
import asyncio
34

45
from pymystrom.pir import MyStromPir

examples/example-switch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Example code for communicating with a myStrom plug/switch."""
2+
23
import asyncio
34

45
from pymystrom.switch import MyStromSwitch

pymystrom/__init__.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
"""Base details for the myStrom Python bindings."""
2+
23
import asyncio
3-
import aiohttp
4-
import async_timeout
5-
from yarl import URL
6-
from typing import Any, Mapping, Optional
74
import socket
8-
from .exceptions import MyStromConnectionError
5+
from typing import Any, Mapping, Optional
96

10-
import pkg_resources
7+
import aiohttp
8+
from yarl import URL
119

12-
__version__ = pkg_resources.get_distribution("setuptools").version
10+
from .exceptions import MyStromConnectionError
1311

1412
TIMEOUT = 10
15-
USER_AGENT = f"PythonMyStrom/{__version__}"
13+
USER_AGENT = "PythonMyStrom/1.0"
1614

1715

1816
async def _request(
@@ -34,15 +32,17 @@ async def _request(
3432
self._close_session = True
3533

3634
try:
37-
with async_timeout.timeout(TIMEOUT):
38-
response = await self._session.request(
35+
response = await asyncio.wait_for(
36+
self._session.request(
3937
method,
4038
uri,
4139
data=data,
4240
json=json_data,
4341
params=params,
4442
headers=headers,
45-
)
43+
),
44+
timeout=TIMEOUT,
45+
)
4646
except asyncio.TimeoutError as exception:
4747
raise MyStromConnectionError(
4848
"Timeout occurred while connecting to myStrom device."

pymystrom/bulb.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""Support for communicating with myStrom bulbs."""
2+
23
import asyncio
34
import logging
5+
from typing import Optional
46

57
import aiohttp
68
from yarl import URL
7-
from typing import Optional
89

910
from . import _request as request
1011

pymystrom/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Command-line tool for working with myStrom devices."""
2+
23
import click
34
import requests
45
import asyncio

pymystrom/discovery.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""Support for discovering myStrom devices."""
2+
23
import asyncio
34
import logging
4-
from typing import Optional, List
5+
from typing import List, Optional
56

67
from .device_types import DEVICE_MAPPING_NUMERIC
78

0 commit comments

Comments
 (0)