Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration system health documentation page #2549

Merged
merged 5 commits into from
Feb 5, 2025

Conversation

abmantis
Copy link
Contributor

@abmantis abmantis commented Jan 30, 2025

Proposed change

Add system health docs since they were missing.

Type of change

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

Additional information

  • This PR fixes or closes issue: fixes #
  • Link to relevant existing code or pull request:

Summary by CodeRabbit

  • Documentation
    • Added comprehensive documentation for the integration system health platform.
    • Explained how integrations can report operational status.
    • Provided guidance on implementing system health information reporting.
    • Included details on localization and health metric tracking.
    • Introduced a new entry in the "Core" category of the documentation for easy access to system health resources.

Copy link
Contributor

coderabbitai bot commented Jan 30, 2025

Warning

Rate limit exceeded

@abmantis has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 12 minutes and 33 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 0b00766 and bd1017b.

📒 Files selected for processing (1)
  • docs/core/integration_system_health.md (1 hunks)
📝 Walkthrough

Walkthrough

The pull request introduces a new documentation file integration_system_health.md in the docs/core/ directory, which provides comprehensive guidance on implementing system health reporting for integrations. The documentation explains how integrations can register and report their operational status, including endpoint availability, server connections, and request quota information. It details the implementation of the async_register function and provides examples of how to create system health information callbacks. Additionally, a new entry is added to the sidebar for easy access to this documentation.

Changes

File Change Summary
docs/core/integration_system_health.md New documentation file added explaining system health integration reporting mechanism
sidebars.js Added new documentation entry "core/integration_system_health" under the "Core" category

Sequence Diagram

sequenceDiagram
    participant Integration
    participant SystemHealthFramework
    participant Frontend

    Integration->>SystemHealthFramework: Implement async_register()
    Integration->>SystemHealthFramework: Define system_health_info callback
    SystemHealthFramework->>Integration: Request health information
    Integration-->>SystemHealthFramework: Return health metrics dictionary
    SystemHealthFramework->>Frontend: Transmit health data
    Frontend->>Frontend: Display system health information
Loading

The sequence diagram illustrates the process of registering and retrieving system health information, showing how an integration provides health metrics to the system health framework, which then makes these details available to the frontend.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 0

🧹 Nitpick comments (5)
docs/core/integration_system_health.md (5)

8-8: Enhance navigation instructions for clarity.

Consider adding more specific navigation details to help users locate the system information more easily.

-Users can find the aggregated system health by going to **Settings** > **Repairs** and selecting **System information** in the three dots menu.
+Users can find the aggregated system health by going to **Settings** > **Repairs**, clicking the three dots (⋮) menu in the top right, and selecting **System information**.

12-17: Add required import statements.

The code example would be more complete with the necessary import statements.

+from __future__ import annotations
+
+from homeassistant.core import HomeAssistant, callback
+from homeassistant.components import system_health
+
 @callback
 def async_register(hass: HomeAssistant, register: system_health.SystemHealthRegistration) -> None:
     """Register system health callbacks."""
     register.async_register_info(system_health_info)

22-24: Add type definition and error handling.

The example uses undefined types and assumes the config entry exists.

+from typing import Any
+
+from homeassistant.config_entries import ConfigEntry
+
+DOMAIN = "example"
+ENDPOINT = "https://api.example.com"
+
 async def system_health_info(hass: HomeAssistant) -> dict[str, Any]:
     """Get info for the info page."""
-    config_entry: ExampleConfigEntry = hass.config_entries.async_entries(DOMAIN)[0]
+    config_entries = hass.config_entries.async_entries(DOMAIN)
+    if not config_entries:
+        return {
+            "can_reach_server": system_health.async_check_can_reach_url(hass, ENDPOINT),
+            "remaining_requests": "No config entry found",
+        }
+    config_entry: ConfigEntry = config_entries[0]

37-37: Specify the strings.json file location.

Add information about where to place the strings.json file.

-In order to provide good descriptions, each key on the info dictionary can be translated using the `system_health` section on `strings.json`:
+In order to provide good descriptions, each key on the info dictionary can be translated using the `system_health` section in the integration's `strings.json` file (located in the `translations/en.json` directory):

10-10: Fix grammatical and style issues.

Several minor language improvements can be made:

-In order to provide system health information, the integration should implement `async_register`
+To provide system health information, the integration should implement `async_register`

-checking the availability of an URL
+checking the availability of a URL

-In order to provide good descriptions
+To provide good descriptions

Also applies to: 33-33, 37-37

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2b2b3f5 and 6343dbf.

📒 Files selected for processing (2)
  • docs/core/integration_system_health.md (1 hunks)
  • sidebars.js (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/core/integration_system_health.md

[style] ~9-~9: Consider a shorter alternative to avoid wordiness.
Context: ... information** in the three dots menu. In order to provide system health information, the ...

(IN_ORDER_TO_PREMIUM)


[misspelling] ~33-~33: Use “a” instead of ‘an’ if the following word doesn’t start with a vowel sound, e.g. ‘a sentence’, ‘a university’.
Context: ... implement checking the availability of an URL. ::: In order to provide good des...

(EN_A_VS_AN)


[style] ~36-~36: Consider a shorter alternative to avoid wordiness.
Context: ...cking the availability of an URL. ::: In order to provide good descriptions, each key on ...

(IN_ORDER_TO_PREMIUM)

🔇 Additional comments (1)
sidebars.js (1)

121-121: LGTM! Documentation entry properly placed.

The new system health documentation entry is correctly positioned within the "Building Integrations" section, maintaining a logical grouping with related integration documentation.

@abmantis abmantis force-pushed the system_health_integrations branch from 6343dbf to f277d87 Compare January 30, 2025 17:31
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: 0

🧹 Nitpick comments (5)
docs/core/integration_system_health.md (5)

8-8: Consider adding a screenshot of the menu path.

Adding a screenshot showing the path to Settings > Repairs > System information would help users locate this feature more easily.


22-30: Add guidance on error handling and common pitfalls.

The example would be more robust with additional guidance on:

  1. Error handling for when no config entries exist
  2. Handling multiple config entries
  3. Exception handling for network failures

Here's a more comprehensive example:

async def system_health_info(hass: HomeAssistant) -> dict[str, Any]:
    """Get info for the info page."""
    entries = hass.config_entries.async_entries(DOMAIN)
    
    if not entries:
        return {
            "setup_state": "no_entries",
            "documentation": "https://www.home-assistant.io/integrations/example"
        }
        
    # Use the primary entry if multiple exist
    config_entry = entries[0]
    
    try:
        can_reach = await system_health.async_check_can_reach_url(
            hass, 
            ENDPOINT,
            timeout=3
        )
    except Exception as err:  # pylint: disable=broad-except
        can_reach = f"Failed to connect: {err}"

    return {
        "can_reach_server": can_reach,
        "remaining_requests": config_entry.runtime_data.requests_remaining,
        "setup_state": "configured"
    }

32-34: Enhance the helper function documentation.

Consider adding more details about async_check_can_reach_url:

  • Available parameters (e.g., timeout)
  • Return type
  • Exception handling

37-46: Add translation naming conventions.

Consider adding guidelines for:

  • Key naming conventions (e.g., using snake_case)
  • Best practices for writing clear, translatable descriptions
  • How to handle dynamic values in translations

37-37: Simplify wording.

Replace "In order to provide" with "To provide" for better conciseness.

-In order to provide good descriptions, each key on the info dictionary can be translated using the `system_health` section on `strings.json`:
+To provide good descriptions, each key on the info dictionary can be translated using the `system_health` section on `strings.json`:
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6343dbf and f277d87.

📒 Files selected for processing (2)
  • docs/core/integration_system_health.md (1 hunks)
  • sidebars.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • sidebars.js
🧰 Additional context used
🪛 LanguageTool
docs/core/integration_system_health.md

[style] ~36-~36: Consider a shorter alternative to avoid wordiness.
Context: ...ecking the availability of a URL. ::: In order to provide good descriptions, each key on ...

(IN_ORDER_TO_PREMIUM)

@home-assistant home-assistant bot marked this pull request as draft February 5, 2025 12:04
@home-assistant
Copy link

home-assistant bot commented Feb 5, 2025

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@abmantis abmantis marked this pull request as ready for review February 5, 2025 15:14
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: 0

🧹 Nitpick comments (1)
docs/core/integration_system_health.md (1)

47-56: Localization JSON Snippet & Wording Improvement
The JSON snippet (lines 49–56) properly demonstrates how to map info dictionary keys for localization using the system_health section in strings.json.

Suggestion: Revise the sentence on line 47 for conciseness. Instead of:

-In order to provide good descriptions, each key on the info dictionary can be translated using the `system_health` section on `strings.json`:
+For better descriptions, translate each info dictionary key using the `system_health` section in `strings.json`:

This revision adheres to the static analysis suggestion for brevity.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f277d87 and 60d8571.

📒 Files selected for processing (1)
  • docs/core/integration_system_health.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/core/integration_system_health.md

[style] ~46-~46: Consider a shorter alternative to avoid wordiness.
Context: ...ecking the availability of a URL. ::: In order to provide good descriptions, each key on ...

(IN_ORDER_TO_PREMIUM)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Redirect rules - developers-home-assistant
  • GitHub Check: Header rules - developers-home-assistant
  • GitHub Check: Pages changed - developers-home-assistant
🔇 Additional comments (6)
docs/core/integration_system_health.md (6)

1-4: YAML Front Matter is Correctly Formatted
The front matter (lines 1–4) is well-formed with a proper title and sidebar label. This matches the convention used elsewhere in the documentation.


6-9: Introduction Clarity & Module Reference
The introduction (lines 6–9) clearly explains the purpose of the system health platform. However, as suggested in previous reviews, consider clarifying that the referenced file, system_health.py, is the specific platform module responsible for handling these callbacks.


10-13: Instruction on Adding the system_health.py File
The instruction at lines 10–13 correctly directs users to add a system_health.py file and implement the async_register method. To further improve clarity, you might include a brief note on the role or location of this file within the integration structure (as per earlier feedback).


14-24: async_register Snippet is Well-Structured
The Python code snippet (lines 14–24) for the async_register function is concise and follows best practices (e.g., proper import order and use of the @callback decorator). The inline documentation is helpful.


28-40: Async Info Callback Implementation
The system_health_info function (lines 28–40) demonstrates clear asynchronous behavior and accurately returns a mixed-type dictionary. The inline comment on line 37 about setting a coroutine (instead of awaiting it) is useful for readers to understand that the frontend handles pending results. You might consider a brief note explaining when an explicit await might be necessary in different contexts, although this design is intentional here.


42-45: Helpful Tip on the async_check_can_reach_url Helper
The tip block (lines 42–45) effectively highlights the purpose of the async_check_can_reach_url helper. It reinforces its non-blocking nature and guides users on how to integrate it into their system health callbacks.

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: 0

🧹 Nitpick comments (4)
docs/core/integration_system_health.md (4)

6-8: Clarify Platform Module Naming.
While the instructions mention adding a system_health.py file in line 12, it may be beneficial to reiterate at the introduction that the file must be named exactly system_health.py to avoid any ambiguity for the integrator.


14-24: Include Additional Import Guidance in Code Snippet.
The async_register code snippet is well presented. However, since later examples use types such as Any (in the return type) or refer to placeholders like ExampleConfigEntry, it might help to include a comment or additional import (e.g., from typing import Any) to ensure completeness for integrators who copy these snippets.


26-40: Clarify Placeholder Identifiers in the Callback Example.
The system_health_info function example is clear; however, identifiers like ExampleConfigEntry, DOMAIN, and ENDPOINT are used without explanation. Consider adding inline comments or notes indicating these are placeholders that should be replaced with the actual integration-specific values.


47-57: Improve Language Consistency in Translation Instructions.
The instruction "Translate each key on the info dictionary using the system_health section on strings.json file" can be reworded for clarity. Consider revising it to "Translate each key on the info dictionary using the system_health section in the strings.json file" to improve grammatical precision.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~47-~47: The preposition “in” seems more likely in this position than the preposition “on”.
Context: ...lity of a URL. ::: Translate each key on the info dictionary using the `system_h...

(AI_EN_LECTOR_REPLACEMENT_PREPOSITION_ON_IN)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 60d8571 and 0b00766.

📒 Files selected for processing (1)
  • docs/core/integration_system_health.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/core/integration_system_health.md

[uncategorized] ~47-~47: The preposition “in” seems more likely in this position than the preposition “on”.
Context: ...lity of a URL. ::: Translate each key on the info dictionary using the `system_h...

(AI_EN_LECTOR_REPLACEMENT_PREPOSITION_ON_IN)

🔇 Additional comments (3)
docs/core/integration_system_health.md (3)

1-4: Front Matter is Correct but Consider Additional Metadata.
The YAML front matter is structured correctly. You may consider adding extra metadata (e.g., a description or authors field) to provide more context if required by the project guidelines.


10-12: Introduction Clarity and Importance of Naming.
The introduction clearly explains the purpose of the system health platform. Consider briefly explaining why the precise naming (i.e. system_health.py) is critical, or linking to further guidelines, to reinforce best practices.


42-44: Tip Block is Informative.
The tip block effectively explains the purpose of async_check_can_reach_url. It aids in understanding and requires no change.

MartinHjelmare
MartinHjelmare previously approved these changes Feb 5, 2025
Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Thanks!

docs/core/integration_system_health.md Outdated Show resolved Hide resolved
@abmantis abmantis merged commit 3afcff2 into master Feb 5, 2025
5 checks passed
@abmantis abmantis deleted the system_health_integrations branch February 5, 2025 16:40
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