File tree Expand file tree Collapse file tree 4 files changed +65
-9
lines changed
Expand file tree Collapse file tree 4 files changed +65
-9
lines changed Original file line number Diff line number Diff line change @@ -4,10 +4,10 @@ Changelog
440.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
12120.2.0 (2020-05-20)
1313------------------
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ You need to have `Python 3 <https://www.python.org>`_ installed.
3535- Devices connected to your network
3636
3737You 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
4040Installation
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-------
Original file line number Diff line number Diff line change 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 ()
Original file line number Diff line number Diff line change 2323 author = "Fabian Affolter" ,
2424 author_email = "fabian@affolter-engineering.ch" ,
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" ,
You can’t perform that action at this time.
0 commit comments