Skip to content

Commit d7a3af2

Browse files
authored
chore: add example (#269)
1 parent b669117 commit d7a3af2

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,50 @@ Install this via pip (or your favourite package manager):
2020

2121
You can see all of the commands supported [here]("https://python-roborock.readthedocs.io/en/latest/api_commands.html")
2222

23+
## Sending Commands
24+
25+
Here is an example that requires no manual intervention and can be done all automatically. You can skip some steps by
26+
caching values or looking at them and grabbing them manually.
27+
```python
28+
import asyncio
29+
30+
from roborock import HomeDataProduct, DeviceData, RoborockCommand
31+
from roborock.version_1_apis import RoborockMqttClientV1, RoborockLocalClientV1
32+
from roborock.web_api import RoborockApiClient
33+
34+
async def main():
35+
web_api = RoborockApiClient(username="youremailhere")
36+
# Login via your password
37+
user_data = await web_api.pass_login(password="pass_here")
38+
# Or login via a code
39+
await web_api.request_code()
40+
code = input("What is the code?")
41+
user_data = await web_api.code_login(code)
42+
43+
# Get home data
44+
home_data = await web_api.get_home_data_v2(user_data)
45+
46+
# Get the device you want
47+
device = home_data.devices[0]
48+
49+
# Get product ids:
50+
product_info: dict[str, HomeDataProduct] = {
51+
product.id: product for product in home_data.products
52+
}
53+
# Create the Mqtt(aka cloud required) Client
54+
device_data = DeviceData(device, product_info[device.product_id].model)
55+
mqtt_client = RoborockMqttClientV1(user_data, device_data)
56+
networking = await mqtt_client.get_networking()
57+
local_device_data = DeviceData(device, product_info[device.product_id].model, networking)
58+
local_client = RoborockLocalClientV1(local_device_data)
59+
# You can use the send_command to send any command to the device
60+
status = await local_client.send_command(RoborockCommand.GET_STATUS)
61+
# Or use existing functions that will give you data classes
62+
status = await local_client.get_status()
63+
64+
asyncio.run(main())
65+
```
66+
2367
## Supported devices
2468

2569
You can find what devices are supported

0 commit comments

Comments
 (0)