Skip to content

Support alternate Speedtest plugins - #80

Merged
Snuffy2 merged 5 commits into
mainfrom
Handle-alt-speedtest-plugin
Jul 19, 2026
Merged

Support alternate Speedtest plugins#80
Snuffy2 merged 5 commits into
mainfrom
Handle-alt-speedtest-plugin

Conversation

@Snuffy2

@Snuffy2 Snuffy2 commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Summary

Supports Speedtest plugin variants that omit the showrecent endpoint while preserving the existing normalized client response.

Allows for support of 2 Speedtest plugins using the existing aiopnsense endpoints:

What Changed

  • Uses the shared showlog endpoint as the source for the latest Speedtest result
  • Normalizes the newest history row into the existing download, upload, latency, server, date, and URL fields
  • Uses the shared endpoint when checking whether manual Speedtest runs are available
  • Retains showstat for full-history averages
  • Adds coverage for shared endpoint selection and malformed history payloads

Why

The supported Speedtest plugins expose the same showlog and showstat endpoints, but only one exposes showrecent. Using the common endpoint avoids plugin-specific detection and keeps the public aiopnsense response contract unchanged.

Fixes travisghansen/hass-opnsense#654

Summary by CodeRabbit

  • Bug Fixes
    • Improved speed test retrieval by switching to the latest log entry for “last” results and related server/date/link details.
    • More consistently derives server identifiers, timestamps, and URLs across varying response shapes.
    • Preserves download/upload/latency averages when stats are available, with safer fallbacks when not.
    • Enhanced robustness against missing or malformed payloads, with updated validations and coverage in tests.

Greptile Summary

This PR switches the Speedtest integration from the showrecent endpoint (only present in some plugin variants) to the universally-available showlog endpoint, normalising the newest history row into the same public response shape that callers already expect.

  • _parse_showlog_latest extracts index-addressed fields from the structured list rows returned by showlog, with correct bool/type guards for the server-ID field and an early-return for missing or short rows.
  • get_speedtest and run_speedtest now gate on showlog availability instead of showrecent; showstat remains an optional secondary fetch.
  • Tests are updated to mock _safe_list_get, and new parametrised cases cover malformed rows and server-field edge cases.

Confidence Score: 5/5

This PR is safe to merge; the change is well-scoped and all edge cases are guarded.

The logic is straightforward — swap one endpoint for another, add a small row-parsing helper with proper type guards — and the tests cover normal, missing, and malformed payloads. No data-loss paths, no silent coercions, and the public response contract is preserved.

No files require special attention.

Important Files Changed

Filename Overview
aiopnsense/speedtest.py Replaces showrecent endpoint with showlog; adds _parse_showlog_latest to normalize the newest row from the structured list response; type guards and fallback logic are correct.
tests/test_speedtest.py Tests updated to mock _safe_list_get instead of _safe_dict_get; new parametrized tests for malformed rows and server-field edge cases provide good coverage.

Reviews (3): Last reviewed commit: "Harden Speedtest log parsing" | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Speedtest retrieval now uses showlog for latest results, normalizes history rows, and retains showstat averages. Execution checks and tests were updated for the new endpoint and payload handling.

Changes

Speedtest showlog integration

Layer / File(s) Summary
Latest-result retrieval and normalization
aiopnsense/speedtest.py, tests/test_speedtest.py
get_speedtest() reads and normalizes the newest showlog row, uses showstat for averages, and validates malformed payloads and server fields.
Speedtest execution endpoint checks
aiopnsense/speedtest.py, tests/test_speedtest.py
run_speedtest() checks showlog availability before fetching results, with updated endpoint assertions.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is clear and aligned with the main change: supporting Speedtest plugin variants that use showlog instead of showrecent.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  aiopnsense
  speedtest.py 60, 128
Project Total  

This report was generated by python-coverage-comment-action

@read-the-docs-community

read-the-docs-community Bot commented Jul 19, 2026

Copy link
Copy Markdown

Documentation build overview

📚 aiopnsense | 🛠️ Build #33654685 | 📁 Comparing dfd37f9 against latest (790e2fa)

  🔍 Preview build  

1 file changed
± _modules/aiopnsense/speedtest.html

@Snuffy2 Snuffy2 added the enhancement Enhance an existing feature or functionality label Jul 19, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
aiopnsense/speedtest.py (1)

1-1: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Replace Any with object to resolve static analysis warnings.

The Any type hint triggers the Ruff ANN401 rule for dynamically typed expressions and violates the repository guideline to minimize Any usage. Since the code safely verifies these arguments at runtime using isinstance, object is the standard, strict type hint for this scenario.

  • aiopnsense/speedtest.py#L96-96: replace show_log: Any with show_log: object.
  • aiopnsense/speedtest.py#L124-124: replace server_text: Any with server_text: object.
  • tests/test_speedtest.py#L226-228: replace show_log: Any with show_log: object.
  • tests/test_speedtest.py#L4-4: remove the from typing import Any import if it is no longer used elsewhere in the file.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@aiopnsense/speedtest.py` at line 1, Replace the Any annotations with object
for the show_log and server_text parameters in the speedtest methods and the
test helper, preserving their existing isinstance validation. Remove the
typing.Any import from the test module if no other references remain.

Sources: Coding guidelines, Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@aiopnsense/speedtest.py`:
- Line 1: Replace the Any annotations with object for the show_log and
server_text parameters in the speedtest methods and the test helper, preserving
their existing isinstance validation. Remove the typing.Any import from the test
module if no other references remain.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: fafd34f4-25c9-41a9-a638-320f18629d67

📥 Commits

Reviewing files that changed from the base of the PR and between 790e2fa and 2a8c604.

📒 Files selected for processing (2)
  • aiopnsense/speedtest.py
  • tests/test_speedtest.py

Comment thread aiopnsense/speedtest.py
Comment thread aiopnsense/speedtest.py Outdated
Snuffy2 added 4 commits July 19, 2026 00:38
Keep server IDs and names separate while normalizing showlog rows. Add regressions for digit-leading names and empty server names.
Delete the unused combined server-field parser after showlog normalization began preserving server IDs and names separately.
Avoid stripping server identifiers and names twice while preserving existing type and empty-value handling.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@aiopnsense/speedtest.py`:
- Around line 55-60: In the latest-result handling, remove the redundant
isinstance checks and assign server_id and server_name directly from
latest_result.get("server_id") and latest_result.get("server"). Preserve the
existing field mappings and rely on _parse_showlog_latest’s str-or-None
contract.
- Around line 119-130: The server ID and server name normalization in the
latest-result parsing block is unnecessarily verbose. Replace the conditional
assignments for server_id and server with concise inline expressions that
preserve the existing behavior: reject booleans and non-integer/string IDs,
stringify valid IDs, and convert empty or invalid server names to None.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: e0b20fea-8aa2-4baf-9bc4-aca523dce230

📥 Commits

Reviewing files that changed from the base of the PR and between 2a8c604 and dfd37f9.

📒 Files selected for processing (2)
  • aiopnsense/speedtest.py
  • tests/test_speedtest.py

Comment thread aiopnsense/speedtest.py
Comment thread aiopnsense/speedtest.py
@Snuffy2
Snuffy2 merged commit 9db7b70 into main Jul 19, 2026
16 checks passed
@Snuffy2
Snuffy2 deleted the Handle-alt-speedtest-plugin branch July 19, 2026 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Enhance an existing feature or functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Speedtest sensors permanently unavailable with the os-speedtest-guru plugin (no showrecent endpoint)

1 participant