|
15 | 15 | from pyrate_limiter import Duration, Limiter, Rate |
16 | 16 |
|
17 | 17 | from roborock import HomeDataSchedule |
18 | | -from roborock.data import HomeData, HomeDataRoom, HomeDataScene, ProductResponse, RRiot, UserData |
| 18 | +from roborock.data import HomeData, HomeDataRoom, HomeDataScene, InboxMessage, ProductResponse, RRiot, UserData |
19 | 19 | from roborock.exceptions import ( |
20 | 20 | RoborockAccountDoesNotExist, |
21 | 21 | RoborockException, |
@@ -608,6 +608,42 @@ async def get_scenes(self, user_data: UserData, device_id: str) -> list[HomeData |
608 | 608 | else: |
609 | 609 | raise RoborockException("scene_response result was an unexpected type") |
610 | 610 |
|
| 611 | + async def get_inbox_messages( |
| 612 | + self, |
| 613 | + user_data: UserData, |
| 614 | + message_type: str = "NOTIFICATION", |
| 615 | + device_id: str | None = None, |
| 616 | + offset: int = 0, |
| 617 | + limit: int = 20, |
| 618 | + ) -> list[InboxMessage]: |
| 619 | + """Get inbox messages of a given type, newest first. |
| 620 | +
|
| 621 | + ``message_type`` is one of NOTIFICATION/WARNING (device-scoped, require |
| 622 | + ``device_id``) or SYSTEM/MARKETING/SHARE (account-scoped). rriot API host with |
| 623 | + Hawk auth. |
| 624 | + """ |
| 625 | + rriot = user_data.rriot |
| 626 | + if rriot is None: |
| 627 | + raise RoborockException("rriot is none") |
| 628 | + if rriot.r.a is None: |
| 629 | + raise RoborockException("Missing field 'a' in rriot reference") |
| 630 | + path = "/user/inbox" |
| 631 | + params = {"offset": str(offset), "limit": str(limit), "type": message_type} |
| 632 | + if device_id is not None: |
| 633 | + params["duid"] = device_id |
| 634 | + inbox_request = PreparedRequest( |
| 635 | + rriot.r.a, |
| 636 | + self.session, |
| 637 | + { |
| 638 | + "Authorization": _get_hawk_authentication(rriot, path, params=params), |
| 639 | + }, |
| 640 | + ) |
| 641 | + inbox_response = await inbox_request.request("get", path, params=params) |
| 642 | + if not inbox_response or not inbox_response.get("success"): |
| 643 | + raise RoborockException(inbox_response) |
| 644 | + result = inbox_response.get("result") or {} |
| 645 | + return [InboxMessage.from_dict(message) for message in result.get("list", [])] |
| 646 | + |
611 | 647 | async def execute_scene(self, user_data: UserData, scene_id: int) -> None: |
612 | 648 | rriot = user_data.rriot |
613 | 649 | if rriot is None: |
|
0 commit comments