Skip to content

Next release#1589

Merged
jokob-sk merged 2 commits intomainfrom
next_release
Apr 4, 2026
Merged

Next release#1589
jokob-sk merged 2 commits intomainfrom
next_release

Conversation

@jokob-sk
Copy link
Copy Markdown
Collaborator

@jokob-sk jokob-sk commented Apr 4, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Updated device connection timestamp formatting to ensure consistent ISO 8601 datetime representation.
  • Tests

    • Added test coverage for timestamp formatting functionality to validate correct datetime conversion and handling of edge cases.

jokob-sk added 2 commits April 5, 2026 08:51
…timestamp formatting and add regression tests for format_date_iso function Events have wrong time in HA

Fixes #1587
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 4, 2026

📝 Walkthrough

Walkthrough

This pull request refactors timestamp formatting by extracting the local prepTimeStamp() function from the MQTT plugin module and consolidating it into a centralized format_date_iso() utility function. The MQTT module now uses this shared utility for device timestamp fields, while new test coverage validates the utility's behavior with various input scenarios.

Changes

Cohort / File(s) Summary
MQTT Plugin Refactoring
front/plugins/_publisher_mqtt/mqtt.py
Removed local prepTimeStamp() function and replaced its usage with format_date_iso() for last_connection and first_connection device JSON fields. Removed unused datetime import; added format_date_iso import from utils.datetime_utils.
Datetime Utility Testing
test/server/test_datetime_utils.py
Added import of format_date_iso and introduced TestFormatDateIso test class validating ISO 8601 compliance, timezone awareness, UTC timestamp accuracy, and error handling for None and empty string inputs.

Poem

🐰 A timestamp's journey, once tangled and local,
Now dances with shared utilities—so focal!
From MQTT's depths to the commons it flew,
ISO 8601 shines in everything true.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Next release' is vague and generic, providing no meaningful information about the actual changes in the pull request, which involve refactoring timestamp formatting utilities and updating tests. Replace with a descriptive title that summarizes the main change, such as 'Refactor timestamp formatting to use centralized format_date_iso utility' or similar.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch next_release

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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
test/server/test_datetime_utils.py (1)

150-155: Consider adding a test for malformed input strings.

The format_date_iso() function has a fallback that returns str(date_val) on parse exceptions. Adding a test to verify this behavior would improve coverage:

Optional test case
def test_malformed_input_returns_original_string(self):
    """Malformed date strings should fall back to returning the original value."""
    result = format_date_iso("not-a-date")
    assert result == "not-a-date"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/server/test_datetime_utils.py` around lines 150 - 155, Add a test that
verifies format_date_iso's fallback behavior for malformed input: create a new
test (e.g., test_malformed_input_returns_original_string) alongside
test_output_is_valid_iso8601 that calls format_date_iso("not-a-date") and
asserts the result equals the original string; reference the format_date_iso
function to ensure the test covers the parse-exception branch that returns
str(date_val).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@test/server/test_datetime_utils.py`:
- Around line 150-155: Add a test that verifies format_date_iso's fallback
behavior for malformed input: create a new test (e.g.,
test_malformed_input_returns_original_string) alongside
test_output_is_valid_iso8601 that calls format_date_iso("not-a-date") and
asserts the result equals the original string; reference the format_date_iso
function to ensure the test covers the parse-exception branch that returns
str(date_val).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0914d912-0c27-43ab-856a-e86b151e6c36

📥 Commits

Reviewing files that changed from the base of the PR and between a8131a6 and 36e606e.

📒 Files selected for processing (2)
  • front/plugins/_publisher_mqtt/mqtt.py
  • test/server/test_datetime_utils.py

@jokob-sk jokob-sk merged commit c687507 into main Apr 4, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant