From feb2217dc5c90180fa55d42200e4fe98d148e10d Mon Sep 17 00:00:00 2001 From: Maciej Bieniek Date: Sat, 5 Oct 2024 11:59:45 +0200 Subject: [PATCH 1/2] Get all pages of paginated response to GetComponents --- aioshelly/rpc_device/device.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/aioshelly/rpc_device/device.py b/aioshelly/rpc_device/device.py index 64759ec8..25f657db 100644 --- a/aioshelly/rpc_device/device.py +++ b/aioshelly/rpc_device/device.py @@ -309,7 +309,19 @@ async def _init_calls(self) -> None: if fetch_status: self._status = results.pop(0) if fetch_dynamic: - self._parse_dynamic_components(results.pop(0)) + all_pages = await self.get_all_pages(results.pop(0)) + self._parse_dynamic_components(all_pages) + + async def get_all_pages(self, first_page: dict[str, Any]) -> dict[str, Any]: + """Get all pages of paginated response to GetComponents.""" + total = first_page["total"] + while len(first_page["components"]) < total: + offset = len(first_page["components"]) + next_page = await self.call_rpc( + "Shelly.GetComponents", {"dynamic_only": True, "offset": offset} + ) + first_page["components"].extend(next_page["components"]) + return first_page async def script_list(self) -> list[ShellyScript]: """Get a list of scripts from 'Script.List'.""" @@ -507,8 +519,9 @@ async def get_dynamic_components(self) -> None: """Return a list of dynamic components.""" if not self._supports_dynamic_components(): return - components = await self.call_rpc("Shelly.GetComponents", {"dynamic_only": True}) - self._parse_dynamic_components(components) + first_page = await self.call_rpc("Shelly.GetComponents", {"dynamic_only": True}) + all_pages = await self.get_all_pages(first_page) + self._parse_dynamic_components(all_pages) def _supports_dynamic_components(self) -> bool: """Return True if device supports dynamic components.""" From 351f0f70e35a01c8d310f409f91cecbfe3db98c7 Mon Sep 17 00:00:00 2001 From: Maciej Bieniek Date: Mon, 25 Nov 2024 14:21:17 +0100 Subject: [PATCH 2/2] Allow up to 10 iterations --- aioshelly/rpc_device/device.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/aioshelly/rpc_device/device.py b/aioshelly/rpc_device/device.py index 25f657db..11f9db4a 100644 --- a/aioshelly/rpc_device/device.py +++ b/aioshelly/rpc_device/device.py @@ -46,6 +46,8 @@ ) from .wsrpc import RPCSource, WsRPC, WsServer +MAX_ITERATIONS = 10 + _LOGGER = logging.getLogger(__name__) @@ -315,7 +317,9 @@ async def _init_calls(self) -> None: async def get_all_pages(self, first_page: dict[str, Any]) -> dict[str, Any]: """Get all pages of paginated response to GetComponents.""" total = first_page["total"] - while len(first_page["components"]) < total: + counter = 0 + while len(first_page["components"]) < total and counter < MAX_ITERATIONS: + counter += 1 offset = len(first_page["components"]) next_page = await self.call_rpc( "Shelly.GetComponents", {"dynamic_only": True, "offset": offset}