-
Notifications
You must be signed in to change notification settings - Fork 751
Add country to Supervisor info #5826
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
Conversation
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.
📝 WalkthroughWalkthroughThe changes introduce support for a "country" configuration parameter within the supervisor component. A new constant, Changes
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", ...}}
Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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_OPTIONSis 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 thecountryproperty documentation insupervisor/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
📒 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.pysupervisor/validate.pysupervisor/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.pysupervisor/validate.pysupervisor/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.pysupervisor/validate.pysupervisor/config.py
`*/**(html|markdown|md)`: - Use sentence-style capitalization also in headings.
*/**(html|markdown|md): - Use sentence-style capitalization also in headings.
supervisor/const.pysupervisor/validate.pysupervisor/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.pysupervisor/validate.pysupervisor/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.pysupervisor/validate.pysupervisor/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 constantThe new country attribute constant is appropriately placed in alphabetical order among other attribute constants.
supervisor/validate.py (2)
16-16: LGTM: ATTR_COUNTRY import addedThe import is correctly placed in alphabetical order.
168-168: LGTM: Country field added to validation schemaThe 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 addedThe import is correctly placed in alphabetical order.
97-110: LGTM: Country property implementationThe 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 settingThe test properly verifies:
- Initial state (country is None)
- Setting country through API
- 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_COUNTRYconstant 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.
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
Additional information
Checklist
ruff format supervisor tests)If API endpoints or add-on configuration are added/changed:
Summary by CodeRabbit