|
49 | 49 | ) |
50 | 50 | from .wsrpc import RPCSource, WsRPC, WsServer |
51 | 51 |
|
| 52 | +MAX_ITERATIONS = 10 |
| 53 | + |
52 | 54 | _LOGGER = logging.getLogger(__name__) |
53 | 55 |
|
54 | 56 |
|
@@ -317,9 +319,22 @@ async def _init_calls(self) -> None: |
317 | 319 | if fetch_status: |
318 | 320 | self._status = results.pop(0) |
319 | 321 | if fetch_dynamic: |
320 | | - components = results.pop(0) |
321 | | - self._parse_dynamic_components(components) |
322 | | - await self._retrieve_blutrv_components(components) |
| 322 | + all_pages = await self.get_all_pages(results.pop(0)) |
| 323 | + self._parse_dynamic_components(all_pages) |
| 324 | + await self._retrieve_blutrv_components(all_pages) |
| 325 | + |
| 326 | + async def get_all_pages(self, first_page: dict[str, Any]) -> dict[str, Any]: |
| 327 | + """Get all pages of paginated response to GetComponents.""" |
| 328 | + total = first_page["total"] |
| 329 | + counter = 0 |
| 330 | + while len(first_page["components"]) < total and counter < MAX_ITERATIONS: |
| 331 | + counter += 1 |
| 332 | + offset = len(first_page["components"]) |
| 333 | + next_page = await self.call_rpc( |
| 334 | + "Shelly.GetComponents", {"dynamic_only": True, "offset": offset} |
| 335 | + ) |
| 336 | + first_page["components"].extend(next_page["components"]) |
| 337 | + return first_page |
323 | 338 |
|
324 | 339 | async def script_list(self) -> list[ShellyScript]: |
325 | 340 | """Get a list of scripts from 'Script.List'.""" |
@@ -511,9 +526,10 @@ async def get_dynamic_components(self) -> None: |
511 | 526 | """Return a list of dynamic components.""" |
512 | 527 | if not self._supports_dynamic_components(): |
513 | 528 | return |
514 | | - components = await self.call_rpc("Shelly.GetComponents", {"dynamic_only": True}) |
515 | | - self._parse_dynamic_components(components) |
516 | | - await self._retrieve_blutrv_components(components) |
| 529 | + first_page = await self.call_rpc("Shelly.GetComponents", {"dynamic_only": True}) |
| 530 | + all_pages = await self.get_all_pages(first_page) |
| 531 | + self._parse_dynamic_components(all_pages) |
| 532 | + await self._retrieve_blutrv_components(all_pages) |
517 | 533 |
|
518 | 534 | def _supports_dynamic_components(self) -> bool: |
519 | 535 | """Return True if device supports dynamic components.""" |
|
0 commit comments