diff --git a/aioshelly/rpc_device/device.py b/aioshelly/rpc_device/device.py index 64759ec8..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__) @@ -309,7 +311,21 @@ 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"] + 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} + ) + 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 +523,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."""