Add ha core reload command to reload YAML configuration#640
Conversation
Add a new core reload command that reloads Home Assistant Core YAML configuration without a full restart. Supports an optional --component flag to reload a specific component (e.g., automation, script, scene) via the Supervisor's Core API proxy. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Paul Czarkowski <username.taken@gmail.com>
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (2)
📝 WalkthroughWalkthroughAdds a new CLI command Changes
Sequence DiagramsequenceDiagram
actor User
participant CLI as CLI Command Handler
participant URLHelper as URL Helper
participant HTTPClient as HTTP Client
participant Server as Supervisor API
User->>CLI: Run `ha core reload [--component X]`
CLI->>CLI: Read and validate `--component` (regex)
CLI->>URLHelper: Build URL for reload endpoint
URLHelper-->>CLI: Return URL
CLI->>HTTPClient: POST URL
HTTPClient->>Server: Send POST request
Server-->>HTTPClient: Return HTTP response (200 / 4xx / other)
HTTPClient-->>CLI: Return status
CLI->>User: Print result and set exit state if error
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment Tip You can disable the changed files summary in the walkthrough.Disable the |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
cmd/core_reload.go (1)
56-62: Broaden invalid-component messaging beyond only 400.If upstream returns a different client error (for example 404/422), users get the generic “unexpected response” text. Treat component-related 4xx responses uniformly to keep the invalid-name error clear.
Proposed fix
- if resp.StatusCode() != http.StatusOK { - if component != "" && resp.StatusCode() == http.StatusBadRequest { + if resp.StatusCode() != http.StatusOK { + if component != "" && resp.StatusCode() >= 400 && resp.StatusCode() < 500 { helper.PrintErrorString(fmt.Sprintf( "component %q not found or does not support reload", component)) } else { helper.PrintErrorString(fmt.Sprintf("unexpected response (status: %d)", resp.StatusCode())) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@cmd/core_reload.go` around lines 56 - 62, The current logic only treats a 400 as "component not found", but any 4xx should yield the same invalid-component message; inside the block that checks resp.StatusCode() != http.StatusOK update the inner condition to detect any client error range (resp.StatusCode() >= http.StatusBadRequest && resp.StatusCode() < http.StatusInternalServerError) when component != "" and call helper.PrintErrorString(fmt.Sprintf("component %q not found or does not support reload", component)); otherwise keep the generic helper.PrintErrorString for non-4xx unexpected responses — use the existing resp, component and helper.PrintErrorString identifiers to locate and change the conditional.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@cmd/core_reload.go`:
- Around line 31-40: Validate the user-supplied component value before
interpolating it into the service path: in cmd/core_reload.go, before
constructing section and command (where component is read via
cmd.Flags().GetString("component")), check that component is non-empty (when
provided) and matches a strict allowlist (e.g., only [A-Za-z0-9_-]+), and reject
inputs containing path separators or traversal tokens like "/", "\", "." or
".."; on invalid input return an error (or print and exit) rather than building
"core/api/services/"+component so that only safe component names are used to
form the section path.
---
Nitpick comments:
In `@cmd/core_reload.go`:
- Around line 56-62: The current logic only treats a 400 as "component not
found", but any 4xx should yield the same invalid-component message; inside the
block that checks resp.StatusCode() != http.StatusOK update the inner condition
to detect any client error range (resp.StatusCode() >= http.StatusBadRequest &&
resp.StatusCode() < http.StatusInternalServerError) when component != "" and
call helper.PrintErrorString(fmt.Sprintf("component %q not found or does not
support reload", component)); otherwise keep the generic helper.PrintErrorString
for non-4xx unexpected responses — use the existing resp, component and
helper.PrintErrorString identifiers to locate and change the conditional.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 061f22fa-66c4-498d-a7d6-23cd9aae3a91
📒 Files selected for processing (2)
client/helper_test.gocmd/core_reload.go
Signed-off-by: Paul Czarkowski <username.taken@gmail.com>
Signed-off-by: Paul Czarkowski <username.taken@gmail.com>
Add #nosec comments for G115 (uintptr->int for file descriptor) and G101 (ApiKey field name misidentified as hardcoded credentials). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
frenck
left a comment
There was a problem hiding this comment.
Oh hi there @paulczar 👋
Thanks for opening a pull request. HOwever, this CLI is currently limited to operating the Supervisor and not internals of Home Assistant itself.
Nevertheless, thanks for being willing to contribute 👍
../Frenck
Blogging my personal ramblings at frenck.dev
Summary
Adds a new
ha core reloadcommand that reloads Home Assistant Core YAMLconfiguration without a full restart.
homeassistant/reload_allto reload all YAML-configurable components--component/-c, reloads a specific component (e.g.,automation,script,scene)Usage
Test plan
Summary by CodeRabbit