Skip to content

Commit 1325fda

Browse files
authored
feat: add home_data_v3 (#347)
* feat: add home_data_v3 * fix: address comments
1 parent 522ab8a commit 1325fda

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

roborock/containers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ class RRiot(RoborockBase):
226226

227227
@dataclass
228228
class UserData(RoborockBase):
229+
rriot: RRiot
229230
uid: int | None = None
230231
tokentype: str | None = None
231232
token: str | None = None
@@ -234,7 +235,6 @@ class UserData(RoborockBase):
234235
countrycode: str | None = None
235236
country: str | None = None
236237
nickname: str | None = None
237-
rriot: RRiot | None = None
238238
tuya_device_state: int | None = None
239239
avatarurl: str | None = None
240240

roborock/web_api.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ async def _get_home_id(self, user_data: UserData):
285285
)
286286
raise RoborockException(f"{home_id_response.get('msg')} - response code: {home_id_response.get('code')}")
287287

288-
return home_id_response["data"].get("rrHomeId")
288+
return home_id_response["data"]["rrHomeId"]
289289

290290
async def get_home_data(self, user_data: UserData) -> HomeData:
291291
rriot = user_data.rriot
@@ -332,6 +332,26 @@ async def get_home_data_v2(self, user_data: UserData) -> HomeData:
332332
else:
333333
raise RoborockException("home_response result was an unexpected type")
334334

335+
async def get_home_data_v3(self, user_data: UserData) -> HomeData:
336+
"""This is the same as get_home_data, but uses a different endpoint and includes non-robotic vacuums."""
337+
rriot = user_data.rriot
338+
home_id = await self._get_home_id(user_data)
339+
if rriot.r.a is None:
340+
raise RoborockException("Missing field 'a' in rriot reference")
341+
home_request = PreparedRequest(
342+
rriot.r.a,
343+
{
344+
"Authorization": self._get_hawk_authentication(rriot, "/v3/user/homes/" + home_id),
345+
},
346+
)
347+
home_response = await home_request.request("get", "/v3/user/homes/" + home_id)
348+
if not home_response.get("success"):
349+
raise RoborockException(home_response)
350+
home_data = home_response.get("result")
351+
if isinstance(home_data, dict):
352+
return HomeData.from_dict(home_data)
353+
raise RoborockException(f"home_response result was an unexpected type: {home_data}")
354+
335355
async def get_rooms(self, user_data: UserData, home_id: int | None = None) -> list[HomeDataRoom]:
336356
rriot = user_data.rriot
337357
if rriot is None:

0 commit comments

Comments
 (0)