Skip to content

Commit 837c3f3

Browse files
filip-jaksicpre-commit-ci[bot]Filip Jaksic
authored
Add usage example for WoCurtain (Curtain 3) (#313)
* Add usage example for WoCurtain (Curtain 3) * chore(pre-commit.ci): auto fixes * Refactor BLE address as variable and fix formatting --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Filip Jaksic <[email protected]>
1 parent 8698281 commit 837c3f3

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

README.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Library to control Switchbot IoT devices https://www.switch-bot.com/bot
44

5-
## Obtaining locks encryption key
5+
## Obtaining encryption key for Switchbot Locks
66

77
Using the script `scripts/get_encryption_key.py` you can manually obtain locks encryption key.
88

@@ -17,9 +17,9 @@ Encryption key: xxxxxxxxxxxxxxxx
1717
Where `MAC` is MAC address of the lock and `USERNAME` is your SwitchBot account username, after that script will ask for your password.
1818
If authentication succeeds then script should output your key id and encryption key.
1919

20-
Examples:
20+
## Examples:
2121

22-
- WoLock
22+
#### WoLock
2323

2424
```python
2525
import asyncio
@@ -33,5 +33,36 @@ async def main():
3333

3434

3535
asyncio.run(main())
36+
```
37+
38+
#### WoCurtain (Curtain 3)
39+
40+
```python
41+
import asyncio
42+
from pprint import pprint
43+
from switchbot import GetSwitchbotDevices
44+
from switchbot.devices import curtain
45+
46+
47+
async def main():
48+
# get the BLE advertisement data of all switchbot devices in the vicinity
49+
advertisement_data = await GetSwitchbotDevices().discover()
50+
51+
for i in advertisement_data.values():
52+
pprint(i)
53+
print() # print newline so that devices' data is separated visually
54+
55+
# find your device's BLE address by inspecting the above printed debug logs, example below
56+
ble_address = "9915077C-C6FD-5FF6-27D3-45087898790B"
57+
# get the BLE device (via its address) and construct a curtain device
58+
ble_device = advertisement_data[ble_address].device
59+
curtain_device = curtain.SwitchbotCurtain(ble_device, reverse_mode=False)
60+
61+
pprint(await curtain_device.get_device_data())
62+
pprint(await curtain_device.get_basic_info())
63+
await curtain_device.set_position(100)
64+
3665

66+
if __name__ == "__main__":
67+
asyncio.run(main())
3768
```

0 commit comments

Comments
 (0)