Skip to content

Commit 5ef2be1

Browse files
authored
Add CLI tool for device discovery (#3)
* Add CLI tool for device discover * Add new requirement click * Add changelog entry * Fix typo * Add new details about the CLI tool
1 parent b62741e commit 5ef2be1

File tree

4 files changed

+65
-9
lines changed

4 files changed

+65
-9
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ Changelog
44
0.3.0 (--)
55
----------
66

7-
- Support for Shades/Blinds (@retoo)
8-
- Access to more parts of the Dingz API
9-
(Blind Config, System Config and others) (@retoo)
10-
- Automatic discovery for Dingz units in the local network (@retoo)
7+
- Add CLI tool
8+
- Support for shades/blinds (@retoo)
9+
- Access to more parts of the dingz API (blind config, system config and others) (@retoo)
10+
- Automatic discovery for dingz units in the local network (@retoo)
1111

1212
0.2.0 (2020-05-20)
1313
------------------

README.rst

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ You need to have `Python 3 <https://www.python.org>`_ installed.
3535
- Devices connected to your network
3636

3737
You need to know the IP address of the devices. Please consult your router
38-
documentation to get this information.
38+
documentation to get this information or use the `dingz` CLI tool.
3939

4040
Installation
4141
------------
@@ -46,10 +46,22 @@ The package is available in the `Python Package Index <https://pypi.python.org/>
4646
4747
$ pip install dingz
4848
49-
Usage
50-
-----
49+
Module usage
50+
------------
51+
52+
Every unit has its own web interface: `http://IP_ADDRESS <http://IP_ADDRESS>`_ .
53+
54+
See `example.py` for detail about module.
55+
56+
CLI usage
57+
---------
58+
59+
The package contains a command-line tool which support some basic tasks.
60+
61+
.. code:: bash
62+
63+
$ dingz discover
5164
52-
Every unit has its own web interface: `http://IP_ADDRESS <http://IP_ADDRESS>`_
5365
5466
License
5567
-------

dingz/cli.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""Command-line interface to interact with dingz devices."""
2+
import click
3+
from .discovery import discover_dingz_devices
4+
import asyncio
5+
6+
7+
import asyncio
8+
from functools import wraps
9+
10+
11+
def coro(f):
12+
"""Allow to use async in click."""
13+
14+
@wraps(f)
15+
def wrapper(*args, **kwargs):
16+
"""Async wrapper."""
17+
return asyncio.run(f(*args, **kwargs))
18+
19+
return wrapper
20+
21+
22+
@click.group()
23+
@click.version_option()
24+
def main():
25+
"""Simple command-line tool to interact with dingz devices."""
26+
27+
28+
@main.command("discover")
29+
@coro
30+
async def discover():
31+
"""Read the current configuration of a myStrom device."""
32+
click.echo("Waiting for UDP broadcast packages...")
33+
devices = await discover_dingz_devices()
34+
35+
print(f"Found {len(devices)} devices")
36+
for device in devices:
37+
print(
38+
f" MAC address: {device.mac}, IP address: {device.host}, HW: {device.hardware}"
39+
)
40+
41+
42+
if __name__ == "__main__":
43+
main()

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
author="Fabian Affolter",
2424
author_email="[email protected]",
2525
license="Apache License 2.0",
26-
install_requires=["aiohttp<4", "async_timeout<4"],
26+
install_requires=["aiohttp<4", "async_timeout<4", "click"],
2727
packages=find_packages(),
2828
zip_safe=True,
2929
include_package_data=True,
30+
entry_points={"console_scripts": ["dingz = dingz.cli:main"]},
3031
classifiers=[
3132
"Development Status :: 3 - Alpha",
3233
"Environment :: Console",

0 commit comments

Comments
 (0)