1212
1313from aioresponses import CallbackResult , aioresponses
1414
15- from roborock .data import HomeData
15+ from roborock .data import HomeData , Reference , RRiot , UserData
1616from roborock .devices .rpc .v1_channel import create_v1_channel as original_create_v1_channel
1717from roborock .devices .transport .mqtt_channel import create_mqtt_channel as original_create_mqtt_channel
18- from roborock .testing .simulator import DEFAULT_KEY_T , RoborockDeviceSimulator
18+ from roborock .testing .simulator import RoborockDeviceSimulator
1919from roborock .testing .v1_simulator import V1VacuumSimulator
2020
2121# EAPI Base URL pattern constants
2222IOT_API_BASE_URL = r"https://.*iot\.roborock\.com/api/v1"
2323REST_API_BASE_URL = r"https://api-.*\.roborock\.com"
2424
25-
26- class FakeUserState :
27- """Holds the fake user account details in the cloud environment."""
28-
29- def __init__ (self ):
30- self .username = "test_user@gmail.com"
31- self .nickname = "user_nickname"
32- self .country = "US"
33- self .country_code = "1"
34- self .region = "us"
35- self .home_id = 123456
36- self .home_name = "Fake Home"
37- self .uid = 123456
38- self .rruid = "abc123"
39- self .token = "abc123"
40- self .rriot_u = "user123"
41- self .rriot_s = "pass123"
42- self .rriot_h = "unknown123"
25+ DEFAULT_USER_DATA = UserData (
26+ uid = 123456 ,
27+ tokentype = "token_type" ,
28+ token = "abc123" ,
29+ rruid = "abc123" ,
30+ region = "us" ,
31+ countrycode = "1" ,
32+ country = "US" ,
33+ nickname = "user_nickname" ,
34+ rriot = RRiot (
35+ u = "user123" ,
36+ s = "pass123" ,
37+ h = "unknown123" ,
38+ k = "qiCNieZa" ,
39+ r = Reference (
40+ r = "US" ,
41+ a = "https://api-us.roborock.com" ,
42+ l = "https://wood-us.roborock.com" ,
43+ m = "tcp://mqtt-us.roborock.com:8883" ,
44+ ),
45+ ),
46+ )
4347
4448
4549class FakeWebApiClient :
@@ -67,9 +71,9 @@ def get_url_by_email_payload(self) -> dict[str, Any]:
6771 return {
6872 "code" : 200 ,
6973 "data" : {
70- "country" : self .cloud .user .country ,
71- "countrycode" : self .cloud .user . country_code ,
72- "url" : f"https://{ self .cloud .user .region } iot.roborock.com" ,
74+ "country" : self .cloud .user_data .country ,
75+ "countrycode" : self .cloud .user_data . countrycode ,
76+ "url" : f"https://{ self .cloud .user_data .region } iot.roborock.com" ,
7377 },
7478 "msg" : "success" ,
7579 }
@@ -80,30 +84,7 @@ def get_login_payload(self) -> dict[str, Any]:
8084 return self .login_payload
8185 return {
8286 "code" : 200 ,
83- "data" : {
84- "uid" : self .cloud .user .uid ,
85- "tokentype" : "token_type" ,
86- "token" : self .cloud .user .token ,
87- "rruid" : self .cloud .user .rruid ,
88- "region" : self .cloud .user .region ,
89- "countrycode" : self .cloud .user .country_code ,
90- "country" : self .cloud .user .country ,
91- "nickname" : self .cloud .user .nickname ,
92- "rriot" : {
93- "u" : self .cloud .user .rriot_u ,
94- "s" : self .cloud .user .rriot_s ,
95- "h" : self .cloud .user .rriot_h ,
96- "k" : DEFAULT_KEY_T ,
97- "r" : {
98- "r" : self .cloud .user .country ,
99- "a" : f"https://api-{ self .cloud .user .region } .roborock.com" ,
100- "l" : f"https://wood-{ self .cloud .user .region } .roborock.com" ,
101- "m" : f"tcp://mqtt-{ self .cloud .user .region } .roborock.com:8883" ,
102- },
103- },
104- "tuyaDeviceState" : 2 ,
105- "avatarurl" : "https://files.roborock.com/iottest/default_avatar.png" ,
106- },
87+ "data" : self .cloud .user_data .as_dict (),
10788 "msg" : "success" ,
10889 }
10990
@@ -115,9 +96,9 @@ def get_home_detail_payload(self) -> dict[str, Any]:
11596 "code" : 200 ,
11697 "data" : {
11798 "deviceListOrder" : None ,
118- "id" : self .cloud .user . home_id ,
119- "name" : self .cloud .user . home_name ,
120- "rrHomeId" : self .cloud .user . home_id ,
99+ "id" : self .cloud .home_id ,
100+ "name" : self .cloud .home_name ,
101+ "rrHomeId" : self .cloud .home_id ,
121102 "tuyaHomeId" : 0 ,
122103 },
123104 "msg" : "success" ,
@@ -166,8 +147,8 @@ def get_homes_callback(url, **kwargs):
166147 products .append (server .product )
167148
168149 home_data = HomeData (
169- id = self .cloud .user . home_id ,
170- name = self .cloud .user . home_name ,
150+ id = self .cloud .home_id ,
151+ name = self .cloud .home_name ,
171152 devices = devices ,
172153 products = products ,
173154 )
@@ -184,21 +165,28 @@ def get_homes_callback(url, **kwargs):
184165
185166 # getHomeDetail v2 & v3 callbacks routing
186167 mocked .get (
187- re .compile (rf"{ REST_API_BASE_URL } /v2/user/homes/{ self .cloud .user . home_id } " ),
168+ re .compile (rf"{ REST_API_BASE_URL } /v2/user/homes/{ self .cloud .home_id } " ),
188169 callback = get_homes_callback ,
189170 )
190171 mocked .get (
191- re .compile (rf"{ REST_API_BASE_URL } /v3/user/homes/{ self .cloud .user . home_id } " ),
172+ re .compile (rf"{ REST_API_BASE_URL } /v3/user/homes/{ self .cloud .home_id } " ),
192173 callback = get_homes_callback ,
193174 )
194175
195176
196177class FakeRoborockCloud :
197178 """A central state object representing the Roborock Cloud environment under test."""
198179
199- def __init__ (self ):
180+ def __init__ (
181+ self ,
182+ user_data : UserData | None = None ,
183+ home_id : int = 123456 ,
184+ home_name : str = "Fake Home" ,
185+ ):
200186 self .servers : dict [str , RoborockDeviceSimulator ] = {}
201- self .user = FakeUserState ()
187+ self .user_data = user_data or DEFAULT_USER_DATA
188+ self .home_id = home_id
189+ self .home_name = home_name
202190 self .web_api = FakeWebApiClient (self )
203191
204192 def add_device (self , server : RoborockDeviceSimulator ) -> None :
0 commit comments