Skip to content

Conversation

@jbouwh
Copy link
Contributor

@jbouwh jbouwh commented Sep 25, 2025

Proposed change

Blog post for new MQTT subscribe subscribe status callback option

Type of change

  • Document existing features within Home Assistant
  • Document new or changing features for which there is an existing pull request elsewhere
  • Spelling or grammatical corrections, or rewording for improved clarity
  • Changes to the backend of this documentation
  • Remove stale or deprecated documentation

Checklist

  • I have read and followed the documentation guidelines.
  • I have verified that my changes render correctly in the documentation.

Additional information

Summary by CodeRabbit

Release Notes

  • New Features

    • Added callback option to wait for broker confirmation on MQTT subscriptions before proceeding
    • New helper function for monitoring subscription status with synchronized post-subscription actions
  • Documentation

    • Added usage examples for new subscription status monitoring capabilities

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 25, 2025

📝 Walkthrough

Walkthrough

A blog post documents new MQTT subscription features: an on_subscribe_status callback parameter for the async_subscribe method enabling subscription confirmation awaiting, and a new mqtt.async_on_subscribe_done helper function for monitoring and reacting to subscription state changes.

Changes

Cohort / File(s) Summary
MQTT Subscribe Status Documentation
blog/2025-10-29-mqtt-subscribe-wait.md
Introduces on_subscribe_status callback parameter added to async_subscribe API signature, enabling callers to await broker subscription confirmation. Documents new mqtt.async_on_subscribe_done helper function for monitoring pending or existing subscriptions. Includes usage examples demonstrating awaiting subscription readiness before publishing and monitoring ongoing subscriptions.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant async_subscribe
    participant Broker
    participant on_subscribe_status

    Caller->>async_subscribe: subscribe(topic, on_subscribe_status=callback)
    async_subscribe->>Broker: SUBSCRIBE message
    Broker-->>async_subscribe: SUBACK
    async_subscribe->>on_subscribe_status: invoke callback(status)
    on_subscribe_status-->>Caller: subscription ready
    Caller->>Caller: proceed with operations
Loading
sequenceDiagram
    participant Caller
    participant async_on_subscribe_done
    participant async_subscribe
    participant Broker

    Caller->>async_on_subscribe_done: monitor subscription
    alt Subscription exists
        async_on_subscribe_done-->>Caller: immediate readiness
    else Subscription pending
        async_on_subscribe_done->>async_subscribe: wait for confirmation
        async_subscribe->>Broker: SUBSCRIBE
        Broker-->>async_subscribe: SUBACK
        async_on_subscribe_done-->>Caller: ready after confirmation
    end
    Caller->>Caller: perform post-subscription actions
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • API signature changes: The on_subscribe_status parameter addition to async_subscribe requires verification that it maintains backward compatibility and is correctly implemented across callers.
  • New public function: Review of mqtt.async_on_subscribe_done implementation for correctness in handling both existing and pending subscriptions, ensuring QoS consistency.
  • Documentation accuracy: Cross-check that examples accurately reflect the new control flow and that callback semantics are properly documented.

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description uses the required template structure and correctly selects the type of change (documenting new or changing features) and provides a link to the related core pull request. However, the description is largely incomplete in critical sections. The "Proposed change" section merely repeats the title without explaining the big picture or justifying why this PR should be accepted. Additionally, both required checklist items—verifying compliance with documentation guidelines and render verification—are unchecked rather than completed, which undermines the quality and thoroughness of the submission. The author should expand the "Proposed change" section to explain the purpose and scope of the blog post in meaningful detail, rather than just restating the title. Additionally, the checklist items should be verified and checked off by the author before merge, confirming they have reviewed the documentation guidelines and tested that their changes render correctly. The link to the related core PR is helpful and should be retained.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "Blog post for new MQTT subscribe status callback option" is a single, concise sentence that accurately reflects the main change in the pull request. According to the raw_summary, the changeset introduces documentation for a new on_subscribe_status callback option in the MQTT subscribe API, which is exactly what the title conveys. The title is clear, specific enough for teammates to understand the primary change, and does not use vague terms or misleading language.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch mqtt-subscribe-wait

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
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.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 94701a2 and 2db8b0f.

📒 Files selected for processing (1)
  • blog/2025-09-26-mqtt-subscribe-wait.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
*/**(html|markdown|md)

⚙️ CodeRabbit configuration file

*/**(html|markdown|md): - For instructional content in documentation, use a direct and authoritative tone. Avoid expressions of politeness such as 'may' or 'please', and ensure the goal of the instruction is fronted.

  • Apply the Microsoft Style Guide to ensure documentation maintains clarity and conciseness.
  • In step-by-step instructions, front the location phrase in the instructional sentence.
  • In step-by-step instructions, front the 'goal' in the instructional sentence.
  • In step-by-step instructions, if in doubt what to front, front the 'goal' before the location phrase in the instructional sentence.
  • do not hyphenate terms like 'top-right' or 'bottom-left' with 'corner'

*/**(html|markdown|md): - Use bold to mark UI strings.

  • If "" are used to mark UI strings, replace them by bold.

  • Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"

  • Use sentence-style capitalization also in headings.

do not comment on HTML used for icons

Avoid flagging inline HTML for embedding videos in future reviews for this repository.

Files:

  • blog/2025-09-26-mqtt-subscribe-wait.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Redirect rules - developers-home-assistant
  • GitHub Check: Header rules - developers-home-assistant
  • GitHub Check: Pages changed - developers-home-assistant

@jbouwh jbouwh marked this pull request as draft September 26, 2025 07:29
@jbouwh jbouwh changed the title Blog post for new MQTT subscribe wait option Blog post for new MQTT subscribe status callback option Oct 29, 2025
@jbouwh jbouwh marked this pull request as ready for review October 29, 2025 07:45
Copy link
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.

Actionable comments posted: 4

🧹 Nitpick comments (1)
blog/2025-10-29-mqtt-subscribe-wait.md (1)

67-67: Improve clarity of description and grammar.

"to allow doing additional task" should be "to perform additional tasks". Also, rewrite for directness per documentation guidelines.

- In case a subscription is already pending, or when we want to keep monitoring, the  `mqtt.async_on_subscribe_done` helper can be used to monitor its subscription, to allow doing additional task. Make sure the same QoS is used.
+ Use the `mqtt.async_on_subscribe_done` helper to monitor an existing or pending subscription and perform additional tasks. Ensure you use the same QoS value.

As per coding guidelines, use direct language, avoid passive constructions, and front goals.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 2db8b0f and b44731e.

📒 Files selected for processing (1)
  • blog/2025-10-29-mqtt-subscribe-wait.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
*/**(html|markdown|md)

⚙️ CodeRabbit configuration file

*/**(html|markdown|md): - For instructional content in documentation, use a direct and authoritative tone. Avoid expressions of politeness such as 'may' or 'please', and ensure the goal of the instruction is fronted.

  • Apply the Microsoft Style Guide to ensure documentation maintains clarity and conciseness.
  • In step-by-step instructions, front the location phrase in the instructional sentence.
  • In step-by-step instructions, front the 'goal' in the instructional sentence.
  • In step-by-step instructions, if in doubt what to front, front the 'goal' before the location phrase in the instructional sentence.
  • do not hyphenate terms like 'top-right' or 'bottom-left' with 'corner'

*/**(html|markdown|md): - Use bold to mark UI strings.

  • If "" are used to mark UI strings, replace them by bold.

  • Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"

  • Use sentence-style capitalization also in headings.

do not comment on HTML used for icons

Avoid flagging inline HTML for embedding videos in future reviews for this repository.

Files:

  • blog/2025-10-29-mqtt-subscribe-wait.md

author: Jan Bouwhuis
authorURL: https://github.com/jbouwh
authorImageURL: https://avatars.githubusercontent.com/u/7188918?s=96&v=4
title: Option added to add a callback for status updates on an MQTT subscription
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Improve title and heading phrasing.

Both the title (line 5) and heading (line 8) use awkward phrasing with "add to add" and "add a callback on". Use more concise language.

- title: Option added to add a callback for status updates on an MQTT subscription
+ title: Add a status callback for MQTT subscriptions

- ## Option added to add a callback on an MQTT subscription
+ ## Add a status callback for MQTT subscriptions

As per coding guidelines, prefer direct, authoritative language and front the goal.

Also applies to: 8-8

🤖 Prompt for AI Agents
In blog/2025-10-29-mqtt-subscribe-wait.md around lines 5 and 8, the title and
heading use awkward duplicate phrasing ("add to add" and "add a callback on");
update both to concise, authoritative language that fronts the goal. Replace the
title with something like "Option to receive status updates for MQTT
subscriptions" and the heading with "Add status-update callback for MQTT
subscriptions" (or similar short, active variants) so they are clear, direct,
and free of duplicated words.

"""Callback example."""
# Do stuff

def _on_subscribe() -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix function name mismatch in code example.

Line 44 defines the callback as _on_subscribe(), but line 58 references it as _on_subscribe_status. These must match.

-    def _on_subscribe() -> None:
+    def _on_subscribe_status() -> None:
         """Publish an online state when we are ready to receive updates."""
         hass.async_create_task(
             mqtt.async_publish(

Also applies to: 58-58

🤖 Prompt for AI Agents
In blog/2025-10-29-mqtt-subscribe-wait.md around lines 44 and 58, the callback
name is inconsistent: the function is defined as `_on_subscribe()` at line 44
but referenced as `_on_subscribe_status` at line 58; rename the definition to
`_on_subscribe_status()` (or update the reference to `_on_subscribe`) so both
the definition and call use the same identifier, and ensure any other references
in the example are updated accordingly.

...
```

## Receive status updates on for as specific MQTT subscription
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix heading grammar.

"Receive status updates on for as specific MQTT subscription" is grammatically incorrect.

- ## Receive status updates on for as specific MQTT subscription
+ ## Monitor subscription status with the helper function
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
## Receive status updates on for as specific MQTT subscription
## Monitor subscription status with the helper function
🤖 Prompt for AI Agents
In blog/2025-10-29-mqtt-subscribe-wait.md around line 65, the heading "Receive
status updates on for as specific MQTT subscription" is grammatically incorrect;
replace it with a corrected heading such as "Receive status updates for a
specific MQTT subscription" (or "Receive status updates on a specific MQTT
subscription") so the sentence reads properly.

Comment on lines +78 to +79
"""Integration ."""
# Do stuff
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Complete the callback docstring.

Line 78 contains an incomplete comment that reads only "Integration ."

     def _on_subscribe_status() -> None:
-        """Integration ."""
+        """Handle subscription ready signal."""
         # Do stuff
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"""Integration ."""
# Do stuff
"""Handle subscription ready signal."""
# Do stuff
🤖 Prompt for AI Agents
In blog/2025-10-29-mqtt-subscribe-wait.md around lines 78 to 79, the callback
docstring is incomplete ("Integration ."); replace it with a complete,
self-contained docstring describing the callback's purpose (e.g., what
integration it performs), its parameters (names, types, and meanings), return
value (if any), and any side effects or exceptions raised — keep it concise and
use conventional docstring style consistent with the project.

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