Skip to content

Commit 321bcde

Browse files
committed
add scenes support
1 parent 2118a93 commit 321bcde

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

roborock/web_api.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,7 @@ async def get_scenes(self, user_data: UserData, device_id: int) -> list[HomeData
372372
raise RoborockException(scenes_response)
373373
scenes = scenes_response.get("result")
374374
if isinstance(scenes, list):
375-
output_list = []
376-
for scene in scenes:
377-
output_list.append(HomeDataScene.from_dict(scene))
378-
return output_list
375+
return [HomeDataScene.from_dict(scene) for scene in scenes]
379376
else:
380377
raise RoborockException("home_response result was an unexpected type")
381378

tests/conftest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,15 @@ def mock_rest() -> aioresponses:
252252
},
253253
)
254254
mocked.get(
255-
re.compile(r"https://api-.*\.roborock\.com/user/scene/device/123456"),
255+
re.compile(r"https://api-.*\.roborock\.com/user/scene/device/.*"),
256256
status=200,
257257
payload={"api": None, "code": 200, "result": HOME_DATA_SCENES_RAW, "status": "ok", "success": True},
258258
)
259+
mocked.post(
260+
re.compile(r"https://api-.*\.roborock\.com/user/scene/.*/execute"),
261+
status=200,
262+
payload={"api": None, "code": 200, "result": None, "status": "ok", "success": True},
263+
)
259264
yield mocked
260265

261266

tests/test_web_api.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from yarl import URL
2+
13
from roborock import HomeData, HomeDataScene, UserData
24
from roborock.web_api import RoborockApiClient
35
from tests.mock_data import HOME_DATA_RAW, USER_DATA
@@ -51,3 +53,11 @@ async def test_get_scenes():
5153
}
5254
)
5355
]
56+
57+
58+
async def test_execute_scene(mock_rest):
59+
"""Test that we can execute a scene"""
60+
api = RoborockApiClient(username="test_user@gmail.com")
61+
ud = await api.pass_login("password")
62+
await api.execute_scene(ud, 123456)
63+
assert ("post", URL("https://api-us.roborock.com/user/scene/123456/execute")) in mock_rest.requests

0 commit comments

Comments
 (0)