Skip to content

Commit

Permalink
Merge pull request #61 from MarkGodwin/iterate_fix
Browse files Browse the repository at this point in the history
Fix #59 - Iterating result pages misses last page
  • Loading branch information
MarkGodwin authored Jan 12, 2025
2 parents dd04542 + 0c69252 commit db5aba4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "tplink_omada_client"
version = "1.4.3"
version = "1.4.4"
authors = [
{ name="Mark Godwin", email="[email protected]" },
]
Expand Down
2 changes: 1 addition & 1 deletion src/tplink_omada_client/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def display_uptime(self) -> str | None:
def cpu_usage(self) -> int:
"""Currenct CPU usage of the device."""
if self._data["statusCategory"] == DeviceStatusCategory.CONNECTED:
return self._data["cpuUtil"]
return self._data.get("cpuUtil", 0)
else:
return 0

Expand Down
9 changes: 5 additions & 4 deletions src/tplink_omada_client/omadaapiconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,20 @@ async def iterate_pages(self, url: str, params: dict[str, Any] | None = None) ->
request_params = {}
if params is not None:
request_params.update(params)
request_params["currentPageSize"] = _PAGE_SIZE
actual_page_size = _PAGE_SIZE

current_page = 1
has_next = True
while has_next:
request_params["currentPageSize"] = actual_page_size
request_params["currentPage"] = current_page
response = await self.request("get", url, request_params)

# Setup next page request
current_page = int(response["currentPage"]) + 1
current_size = int(response["currentSize"])
actual_page_size = int(response["currentSize"])
total_rows = int(response["totalRows"])
has_next = total_rows > current_page * current_size
has_next = total_rows > current_page * actual_page_size
current_page += 1

data: list[dict[str, Any]] = response["data"]
for item in data:
Expand Down

0 comments on commit db5aba4

Please sign in to comment.