Skip to content

fix: typing for message_handler - #5

Merged
Lash-L merged 1 commit into
mainfrom
typing_fix
Jul 9, 2026
Merged

fix: typing for message_handler#5
Lash-L merged 1 commit into
mainfrom
typing_fix

Conversation

@Lash-L

@Lash-L Lash-L commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Same typing fix so that mypy passes for HA

Summary by CodeRabbit

  • Bug Fixes

    • Improved compatibility for MQTT message handlers that may return an event object or no result.
    • Preserved existing message handling behavior while broadening supported handler annotations.
  • Tests

    • Added coverage to confirm message handlers returning an optional event type are handled correctly.

@Lash-L
Lash-L requested a review from afgarcia86 July 9, 2026 02:05
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Free

Run ID: b239462b-e57a-40fe-8379-a7c06a25d296

📥 Commits

Reviewing files that changed from the base of the PR and between cd50a98 and f8e81ae.

📒 Files selected for processing (2)
  • harbor/mqtt.py
  • tests/test_mqtt.py

📝 Walkthrough

Walkthrough

The change updates type hints in harbor/mqtt.py to allow the message_handler callback to return HarborEvent | None instead of None, using postponed annotation evaluation and a TYPE_CHECKING import. A corresponding test is added to verify compatibility.

Changes

MQTT Message Handler Type Update

Layer / File(s) Summary
Widen message_handler return type
harbor/mqtt.py
Adds from __future__ import annotations, a TYPE_CHECKING-guarded import of HarborEvent, and updates the constructor's message_handler parameter type from Awaitable[None] to Awaitable[HarborEvent | None].
Test for widened return type
tests/test_mqtt.py
Imports HarborEvent and adds test_message_handler_may_return_event, confirming _handle_message works with a handler annotated to return HarborEvent | None.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Poem

A type hint hops, both light and free,
HarborEvent joins the None, you see!
No runtime change, just clearer signs,
Tests confirm the handler's fine.
Thump-thump goes this rabbit's heart with glee! 🐇✨


Note

🎁 Summarized by CodeRabbit Free

Your organization has reached its limit of developer seats under the Pro Plan. For new users, CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please add seats to your subscription by visiting https://app.coderabbit.ai/login.If you believe this is a mistake and have available seats, please assign one to the pull request author through the subscription management page using the link above.

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

@Lash-L
Lash-L merged commit a7f50f4 into main Jul 9, 2026
8 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.

2 participants