Skip to content

Commit

Permalink
chore: fix examples in readme (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
vanstinator authored Aug 29, 2022
1 parent d183236 commit d1f690d
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,52 @@ The python API has been designed to be as easy to use as possible. A few example
```python
import asyncio

from melnor_bluetooth.constants import BATTERY_UUID
from bleak import BleakScanner # type: ignore - bleak has bad export types

from melnor_bluetooth.device import Device

address = '00:00:00:00:00' # fill with your device mac address
ADDRESS = "00:00:00:00:00" # fill with your device mac address


async def main():
device = Device(address)
await device.connect()

print(device.battery_life);
ble_device = await BleakScanner.find_device_by_address(ADDRESS)
if ble_device is not None:
device = Device(ble_device)
await device.connect()
await device.fetch_state()

print(device.battery_level)

await device.disconnect()

await device.disconnect();

asyncio.run(main())

```

#### Turn on a zone
```python
import asyncio

from bleak import BleakScanner # type: ignore - bleak has bad export types

from melnor_bluetooth.device import Device

address = "00:00:00:00:00" # fill with your device mac address


async def main():
device = Device(address)
await device.connect()
ble_device = await BleakScanner.find_device_by_address(ADDRESS)
if ble_device is not None:
device = Device(ble_device)
await device.connect()
await device.fetch_state()

device.zone1.is_watering = True
device.zone1.is_watering = True

await device.push_state()
await device.disconnect()
await device.push_state()
await device.disconnect()


asyncio.run(main())
Expand Down

0 comments on commit d1f690d

Please sign in to comment.