1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
import aiohttp
from roborock import HomeData, HomeDataScene, UserData
from roborock.web_api import RoborockApiClient
from tests.mock_data import HOME_DATA_RAW, USER_DATA
async def test_pass_login_flow() -> None:
"""Test that we can login with a password and we get back the correct userdata object."""
my_session = aiohttp.ClientSession()
api = RoborockApiClient(username="test_user@gmail.com", session=my_session)
ud = await api.pass_login("password")
assert ud == UserData.from_dict(USER_DATA)
assert not my_session.closed
async def test_code_login_flow() -> None:
"""Test that we can login with a code and we get back the correct userdata object."""
api = RoborockApiClient(username="test_user@gmail.com")
await api.request_code()
ud = await api.code_login(4123)
assert ud == UserData.from_dict(USER_DATA)
async def test_get_home_data_v2():
"""Test a full standard flow where we get the home data to end it off.
This matches what HA does"""
api = RoborockApiClient(username="test_user@gmail.com")
await api.request_code()
ud = await api.code_login(4123)
hd = await api.get_home_data_v2(ud)
assert hd == HomeData.from_dict(HOME_DATA_RAW)
async def test_nc_prepare():
"""Test adding a device and that nothing breaks"""
api = RoborockApiClient(username="test_user@gmail.com")
await api.request_code()
ud = await api.code_login(4123)
prepare = await api.nc_prepare(ud, "America/New_York")
new_device = await api.add_device(ud, prepare["s"], prepare["t"])
assert new_device["duid"] == "rand_duid"
async def test_get_scenes():
"""Test that we can get scenes"""
api = RoborockApiClient(username="test_user@gmail.com")
ud = await api.pass_login("password")
sc = await api.get_scenes(ud, "123456")
assert sc == [
HomeDataScene.from_dict(
{
"id": 1234567,
"name": "My plan",
}
)
]
async def test_execute_scene(mock_rest):
"""Test that we can execute a scene"""
api = RoborockApiClient(username="test_user@gmail.com")
ud = await api.pass_login("password")
await api.execute_scene(ud, 123456)
mock_rest.assert_any_call("https://api-us.roborock.com/user/scene/123456/execute", "post")
|