Skip to content

Commit da65579

Browse files
committed
add scenes support
1 parent 512dffc commit da65579

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

roborock/web_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ async def get_rooms(self, user_data: UserData, home_id: int | None = None) -> li
269269
else:
270270
raise RoborockException("home_response result was an unexpected type")
271271

272-
async def get_scenes(self, user_data: UserData, home_id: int) -> list[HomeDataRoom]:
272+
async def get_scenes(self, user_data: UserData, home_id: int) -> list[HomeDataScene]:
273273
rriot = user_data.rriot
274274
if rriot is None:
275275
raise RoborockException("rriot is none")

tests/conftest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from roborock.containers import DeviceData
1616
from roborock.version_1_apis.roborock_local_client_v1 import RoborockLocalClientV1
1717
from roborock.version_1_apis.roborock_mqtt_client_v1 import RoborockMqttClientV1
18-
from tests.mock_data import HOME_DATA_RAW, TEST_LOCAL_API_HOST, USER_DATA
18+
from tests.mock_data import HOME_DATA_RAW, HOME_DATA_SCENES_RAW, TEST_LOCAL_API_HOST, USER_DATA
1919

2020
_LOGGER = logging.getLogger(__name__)
2121

@@ -200,6 +200,11 @@ def mock_rest() -> aioresponses:
200200
status=200,
201201
payload={"api": None, "code": 200, "result": HOME_DATA_RAW, "status": "ok", "success": True},
202202
)
203+
mocked.get(
204+
re.compile(r"https://api-.*\.roborock\.com/user/scene/device/123456"),
205+
status=200,
206+
payload={"api": None, "code": 200, "result": HOME_DATA_SCENES_RAW, "status": "ok", "success": True},
207+
)
203208
yield mocked
204209

205210

tests/mock_data.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@
3535
}
3636
LOCAL_KEY = "key123key123key1" # 16 bytes / 128 bits
3737
PRODUCT_ID = "product-id-123"
38+
HOME_DATA_SCENES_RAW = [
39+
{
40+
"id": 5925425,
41+
"name": "My plan",
42+
"param": "not used",
43+
"enabled": True,
44+
"extra": None,
45+
"type": "WORKFLOW",
46+
}
47+
]
3848
HOME_DATA_RAW = {
3949
"id": 123456,
4050
"name": "My Home",

tests/test_web_api.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from roborock import HomeData, UserData
1+
from roborock import HomeData, HomeDataScene, UserData
22
from roborock.web_api import RoborockApiClient
33
from tests.mock_data import HOME_DATA_RAW, USER_DATA
44

@@ -26,3 +26,18 @@ async def test_get_home_data_v2():
2626
ud = await api.code_login(4123)
2727
hd = await api.get_home_data_v2(ud)
2828
assert hd == HomeData.from_dict(HOME_DATA_RAW)
29+
30+
31+
async def test_get_scenes():
32+
"""Test that we can get scenes"""
33+
api = RoborockApiClient(username="[email protected]")
34+
ud = await api.pass_login("password")
35+
sc = await api.get_scenes(ud, 123456)
36+
assert sc == [
37+
HomeDataScene.from_dict(
38+
{
39+
"id": 5925425,
40+
"name": "My plan",
41+
}
42+
)
43+
]

0 commit comments

Comments
 (0)