Skip to content

Conversation

@agners
Copy link
Member

@agners agners commented Apr 17, 2025

Proposed change

Similar to timezone also add country information to the Supervisor info. This is useful to set country specific configurations such as Wireless radio regulatory setting. This is also useful for add-ons which need country information but only have hassio API access.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (which adds functionality to the supervisor)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Ruff (ruff format supervisor tests)
  • Tests have been added to verify that the new code works.

If API endpoints or add-on configuration are added/changed:

Summary by CodeRabbit

  • New Features
    • Added support for configuring and retrieving the country setting via the supervisor API.
  • Bug Fixes
    • None.
  • Tests
    • Introduced tests to verify setting and retrieving the country configuration through the API.

Similar to timezone also add country information to the Supervisor
info. This is useful to set country specific configurations such as
Wireless radio regulatory setting. This is also useful for add-ons
which need country information but only have hassio API access.
@agners agners added the new-feature A new feature label Apr 17, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 17, 2025

📝 Walkthrough

Walkthrough

The changes introduce support for a "country" configuration parameter within the supervisor component. A new constant, ATTR_COUNTRY, is defined and integrated into relevant validation schemas and the supervisor's configuration model. The supervisor API is updated to allow clients to set and retrieve the country via the /supervisor/options and /supervisor/info endpoints. A corresponding test is added to verify the correct handling of the country parameter through the API.

Changes

File(s) Change Summary
supervisor/const.py Added the constant ATTR_COUNTRY = "country".
supervisor/validate.py Added optional ATTR_COUNTRY string field to the SCHEMA_SUPERVISOR_CONFIG schema.
supervisor/config.py Added a country property (getter and setter) to the CoreConfig class to manage the country code.
supervisor/api/supervisor.py Integrated ATTR_COUNTRY into API: added to imports, schemas, info and options endpoints for country support.
tests/api/test_supervisor.py Added test test_api_supervisor_options_country to verify API country set/get functionality.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API (supervisor.py)
    participant Config (config.py)

    Client->>API (supervisor.py): POST /supervisor/options {"country": "CH"}
    API (supervisor.py)->>Config (config.py): set country = "CH"
    Config (config.py)-->>API (supervisor.py): country updated
    API (supervisor.py)-->>Client: 200 OK

    Client->>API (supervisor.py): GET /supervisor/info
    API (supervisor.py)->>Config (config.py): get country
    Config (config.py)-->>API (supervisor.py): return country ("CH")
    API (supervisor.py)-->>Client: {"data": {"country": "CH", ...}}
Loading

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
  • @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 (1)
supervisor/api/supervisor.py (1)

80-80: Schema update looks good, but consider adding validation.

Adding country as an optional parameter to the SCHEMA_OPTIONS is appropriate. However, unlike timezone which has a specific validation function, there's no validation to ensure the country follows the ISO 3166-1 alpha-2 format mentioned in the country property documentation in supervisor/config.py.

Consider adding a validation function for country codes similar to how timezone is validated:

-        vol.Optional(ATTR_COUNTRY): str,
+        vol.Optional(ATTR_COUNTRY): validate_country_code,

And add a validation function to utils/validate.py:

def validate_country_code(country: str) -> str:
    """Validate that a country is valid."""
    # ISO 3166-1 alpha-2 codes are always 2 uppercase letters
    if not country or len(country) != 2 or not country.isalpha() or not country.isupper():
        raise vol.Invalid(f"Invalid country code {country}")
    return country
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6fad7d1 and cfa042c.

📒 Files selected for processing (5)
  • supervisor/api/supervisor.py (4 hunks)
  • supervisor/config.py (2 hunks)
  • supervisor/const.py (1 hunks)
  • supervisor/validate.py (2 hunks)
  • tests/api/test_supervisor.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
`*/**(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 t...

*/**(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'
  • supervisor/const.py
  • supervisor/validate.py
  • supervisor/config.py
`*/**(html|markdown|md)`: - Use bold to mark UI strings. - If "" are used to mark UI strings, replace them by bold.

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

  • If "" are used to mark UI strings, replace them by bold.
  • supervisor/const.py
  • supervisor/validate.py
  • supervisor/config.py
`*/**(html|markdown|md)`: - Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"

*/**(html|markdown|md): - Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"

  • supervisor/const.py
  • supervisor/validate.py
  • supervisor/config.py
`*/**(html|markdown|md)`: - Use sentence-style capitalization also in headings.

*/**(html|markdown|md): - Use sentence-style capitalization also in headings.

  • supervisor/const.py
  • supervisor/validate.py
  • supervisor/config.py
`*/**(html|markdown|md)`: do not comment on HTML used for icons

*/**(html|markdown|md): do not comment on HTML used for icons

  • supervisor/const.py
  • supervisor/validate.py
  • supervisor/config.py
`*/**(html|markdown|md)`: Avoid flagging inline HTML for embedding videos in future reviews for this repository.

*/**(html|markdown|md): Avoid flagging inline HTML for embedding videos in future reviews for this repository.

  • supervisor/const.py
  • supervisor/validate.py
  • supervisor/config.py
🧬 Code Graph Analysis (1)
supervisor/api/supervisor.py (2)
supervisor/coresys.py (1)
  • sys_config (671-673)
supervisor/config.py (2)
  • country (98-104)
  • country (107-109)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Build armv7 supervisor
  • GitHub Check: Build armhf supervisor
  • GitHub Check: Build aarch64 supervisor
  • GitHub Check: Run tests Python 3.13.3
🔇 Additional comments (9)
supervisor/const.py (1)

143-143: LGTM: Addition of ATTR_COUNTRY constant

The new country attribute constant is appropriately placed in alphabetical order among other attribute constants.

supervisor/validate.py (2)

16-16: LGTM: ATTR_COUNTRY import added

The import is correctly placed in alphabetical order.


168-168: LGTM: Country field added to validation schema

The country field is properly added as an optional string field in the SCHEMA_SUPERVISOR_CONFIG.

supervisor/config.py (2)

13-13: LGTM: ATTR_COUNTRY import added

The import is correctly placed in alphabetical order.


97-110: LGTM: Country property implementation

The country property getter and setter methods are well-implemented with descriptive docstrings clarifying the ISO 3166-1 alpha-2 format. The implementation follows the same pattern as other configuration properties.

tests/api/test_supervisor.py (1)

255-268: LGTM: Test coverage for country setting

The test properly verifies:

  1. Initial state (country is None)
  2. Setting country through API
  3. Retrieving country through supervisor info endpoint

This provides good test coverage for the new functionality.

supervisor/api/supervisor.py (3)

20-20: Appropriate import addition.

The ATTR_COUNTRY constant is properly added to the import list in alphabetical order, consistent with the codebase style.


114-114: Good addition to the info response.

The country attribute is properly added to the info response dictionary, following the same pattern as the existing timezone attribute and placed in a logical position.


153-155: Options handling implementation is good.

The implementation to handle the country attribute in the options method is straightforward and follows the established pattern in the codebase. The changes will be properly saved when self.sys_config.save_data() is called at line 194.

@agners agners requested a review from sairon April 17, 2025 16:04
@agners agners added the needs-client-library Pull requests needs client library changes but none is linked label Apr 17, 2025
@agners agners merged commit 5d07dd2 into main Apr 22, 2025
24 checks passed
@agners agners deleted the add-country-to-supervisor-info branch April 22, 2025 14:18
@github-actions github-actions bot locked and limited conversation to collaborators Apr 24, 2025
@agners agners removed the needs-client-library Pull requests needs client library changes but none is linked label Aug 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants