Skip to content

Add timezone to Speedtest dates - #83

Merged
Snuffy2 merged 5 commits into
mainfrom
fix-speedtest-date-timezone
Jul 21, 2026
Merged

Add timezone to Speedtest dates#83
Snuffy2 merged 5 commits into
mainfrom
fix-speedtest-date-timezone

Conversation

@Snuffy2

@Snuffy2 Snuffy2 commented Jul 21, 2026

Copy link
Copy Markdown
Owner

Summary

Normalizes Speedtest result timestamps as timezone-aware ISO 8601 values so consumers such as Home Assistant can render the result date in the configured local timezone.

What Changed

  • Add the OPNsense timezone to naive Speedtest result dates
  • Preserve timestamps that already include a UTC offset
  • Omit malformed date values instead of exposing ambiguous timestamps
  • Add regression coverage for naive, timezone-aware, and malformed dates

Why

The Speedtest plugin returns local wall-clock timestamps without timezone information. Home Assistant cannot reliably convert those naive values for display.

Normalizing the date at the aiopnsense boundary keeps the existing hass-opnsense sensor contract intact while giving Home Assistant the offset it needs for correct local-time rendering.

Summary by CodeRabbit

  • Bug Fixes
    • Normalized Speedtest timestamps into timezone-aware ISO 8601 format.
    • Preserved timestamps that already include timezone information.
    • Gracefully excluded malformed date values instead of returning invalid data.

Greptile Summary

This PR makes Speedtest timestamps timezone-aware for downstream consumers. The main changes are:

  • Resolves the timezone from OPNsense system time.
  • Adds offsets to naive Speedtest result and period dates.
  • Preserves timestamps that already contain an offset.
  • Omits malformed dates and naive dates when the firewall timezone is unavailable.
  • Adds tests for timezone resolution and date normalization.

Confidence Score: 5/5

This looks safe to merge.

  • The Speedtest path no longer substitutes the client process timezone when the firewall timezone cannot be resolved.
  • Aware timestamps remain intact, while unresolved naive timestamps are omitted instead of receiving an incorrect offset.
  • Tests cover the updated success and failure paths.

Important Files Changed

Filename Overview
aiopnsense/_typing.py Adds the resolved-timezone method to the client protocol.
aiopnsense/helpers.py Adds date normalization that preserves offsets and handles malformed or unresolved values.
aiopnsense/speedtest.py Normalizes the latest and aggregate Speedtest dates with the resolved firewall timezone.
aiopnsense/system.py Separates resolved timezone lookup from the existing local-timezone fallback behavior.
tests/test_helpers.py Covers normalization of naive, aware, malformed, and non-string date values.
tests/test_speedtest.py Covers timezone-aware results, seasonal offsets, malformed dates, and unavailable timezone data.
tests/test_system.py Covers unavailable endpoints, request failures, and malformed system-time responses.

Reviews (4): Last reviewed commit: "Keep Speedtest timezone lookup optional" | Re-trigger Greptile

Context used (3)

  • Rule used - In Python 3.14+, except ExcTypeA, ExcTypeB: (com... (source)
  • Rule used - Always check the project's minimum Python version ... (source)
  • Context used - AGENTS.md (source)

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Speedtest date normalization

Layer / File(s) Summary
Normalize speedtest dates
aiopnsense/speedtest.py
get_speedtest() now parses ISO 8601 dates, applies the OPNsense timezone to naive timestamps, preserves existing offsets, and returns None for malformed values.
Validate normalized date behavior
tests/test_speedtest.py
Tests cover timezone conversion, existing timezone preservation, malformed dates, and timezone lookup calls.

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

Suggested labels: enhancement

🚥 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 clearly matches the main change: Speedtest dates are now normalized to include timezone information.

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 21, 2026

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  aiopnsense
  _typing.py
  helpers.py
  speedtest.py
  system.py
Project Total  

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

@read-the-docs-community

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

Copy link
Copy Markdown

Documentation build overview

📚 aiopnsense | 🛠️ Build #33678649 | 📁 Comparing 36997db against latest (035db7b)

  🔍 Preview build  

2 files changed
± _modules/aiopnsense/speedtest.html
± _modules/aiopnsense/system.html

Comment thread aiopnsense/speedtest.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 19a6266f4e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread aiopnsense/speedtest.py Outdated
@Snuffy2 Snuffy2 added the bugfix label Jul 21, 2026

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b11d35718d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread aiopnsense/speedtest.py Outdated
Comment thread aiopnsense/system.py

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 71384a2983

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread aiopnsense/speedtest.py

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 36997db8c3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread aiopnsense/speedtest.py
@Snuffy2
Snuffy2 merged commit d73cde0 into main Jul 21, 2026
12 of 13 checks passed
@Snuffy2
Snuffy2 deleted the fix-speedtest-date-timezone branch July 21, 2026 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant