Remove sync interface, add asyncio discovery (#14)

* do not update inside __repr__

* Convert discovery to asyncio

* Use asyncio.DatagramProtocol
* Cleanup parameters, no more positional arguments

Closes #7

* Remove sync interface

* This requires #13 to be merged. Closes #12.
* Converts cli to use asyncio.run() where needed.
* The children from smartstrips is being initialized during the first update call.

* Convert on and off commands to use asyncio.run

* conftest: do the initial update automatically for the device, cleans up tests a bit

* return subdevices alias for strip plugs, remove sync from docstrings

* Make tests pass using pytest-asyncio

* Simplify tests and use pytest-asyncio.
* Removed the emeter tests for child devices, as this information do not seem to exist (based on the dummy sysinfo data). Can be added again if needed.
* Remove sync from docstrings.

* Fix incorrect type hint

* Add type hints and some docstrings to discovery
This commit is contained in:
Teemu R
2020-01-12 22:44:19 +01:00
committed by GitHub
parent 3c68d295da
commit 524d28abbc
9 changed files with 386 additions and 341 deletions

View File

@@ -27,46 +27,45 @@ class SmartBulb(SmartDevice):
Usage example when used as library:
```python
p = SmartBulb("192.168.1.105")
await p.update()
# print the devices alias
print(p.sync.alias)
print(p.alias)
# change state of bulb
p.sync.turn_on()
p.sync.turn_off()
await p.turn_on()
await p.turn_off()
# query and print current state of plug
print(p.sync.state_information())
print(p.state_information)
# check whether the bulb supports color changes
if p.sync.is_color():
if p.is_color:
# set the color to an HSV tuple
p.sync.set_hsv(180, 100, 100)
await p.set_hsv(180, 100, 100)
# get the current HSV value
print(p.sync.hsv())
print(p.hsv)
# check whether the bulb supports setting color temperature
if p.sync.is_variable_color_temp():
if p.is_variable_color_temp:
# set the color temperature in Kelvin
p.sync.set_color_temp(3000)
await p.set_color_temp(3000)
# get the current color temperature
print(p.sync.color_temp)
print(p.color_temp)
# check whether the bulb is dimmable
if p.is_dimmable:
# set the bulb to 50% brightness
p.sync.set_brightness(50)
await p.set_brightness(50)
# check the current brightness
print(p.brightness)
```
Omit the `sync` attribute to get coroutines.
Errors reported by the device are raised as SmartDeviceExceptions,
and should be handled by the user of the library.
"""