Skip to content

Add ha core reload command to reload YAML configuration#640

Closed
paulczar wants to merge 4 commits into
home-assistant:masterfrom
paulczar:add-core-reload-command
Closed

Add ha core reload command to reload YAML configuration#640
paulczar wants to merge 4 commits into
home-assistant:masterfrom
paulczar:add-core-reload-command

Conversation

@paulczar
Copy link
Copy Markdown

@paulczar paulczar commented Mar 16, 2026

Summary

Adds a new ha core reload command that reloads Home Assistant Core YAML
configuration without a full restart.

  • Without flags, calls homeassistant/reload_all to reload all YAML-configurable components
  • With --component / -c, reloads a specific component (e.g., automation, script, scene)
  • Provides shell completions for common reloadable components
  • Returns a clear error message for invalid component names

Usage

# Reload all YAML configuration
ha core reload

# Reload a specific component
ha core reload --component automation
ha core reload -c script

Test plan

  • ha core reload reloads all YAML config and changes are reflected in the UI
  • ha core reload -c automation reloads only automations
  • ha core reload -c invalid returns a helpful error message
  • go test ./... passes
  • go build succeeds

Summary by CodeRabbit

  • New Features
    • Added a CLI command to reload Home Assistant Core (alias: refresh) with an optional component flag, input validation, clear success/error messages, and shell completion for supported components.
  • Tests
    • Expanded URL helper tests to cover component-specific reloads and full-core reload scenarios.
  • Chores
    • Added security-linter suppression comments in a couple of helper entries (no behavioral changes).

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>
Copy link
Copy Markdown

@home-assistant home-assistant Bot left a comment

Choose a reason for hiding this comment

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

Hi @paulczar

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant home-assistant Bot marked this pull request as draft March 16, 2026 04:36
@home-assistant
Copy link
Copy Markdown

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.

@paulczar paulczar marked this pull request as ready for review March 17, 2026 00:35
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 822b3ec5-b29c-472a-bdff-6738f1a68259

📥 Commits

Reviewing files that changed from the base of the PR and between 1fe1a38 and a25af2a.

📒 Files selected for processing (2)
  • client/helper.go
  • cmd/network_update.go
✅ Files skipped from review due to trivial changes (2)
  • client/helper.go
  • cmd/network_update.go

📝 Walkthrough

Walkthrough

Adds a new CLI command ha core reload (alias refresh) with an optional validated --component flag that builds a supervisor URL, issues a POST to trigger reloads, and reports results. Also adds two URL helper tests for supervisor endpoints.

Changes

Cohort / File(s) Summary
Tests
client/helper_test.go
Added two URL helper test cases for supervisor endpoints: core/api/services/automation/reload and core/api/services/homeassistant/reload_all.
New CLI Command
cmd/core_reload.go
Introduced ha core reload (alias refresh) with --component/-c flag, strict regex validation, URL construction via helper.URLHelper, POST via helper.GetRequest().Post, response handling (200 OK, 4xx → component not found, other errors), shell completion, and registration under coreCmd.
Static-analysis suppression (helper)
client/helper.go
Added // #nosec G115 comment to the terminal check call; no behavioral changes.
Static-analysis suppression (network)
cmd/network_update.go
Added // #nosec G101 comment to addr-gen-mode NetworkArg entry; no behavioral changes.

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add ha core reload command to reload YAML configuration' accurately summarizes the main change: introducing a new CLI command for reloading Core YAML configuration.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Tip

You can disable the changed files summary in the walkthrough.

Disable the reviews.changed_files_summary setting to disable the changed files summary in the walkthrough.

Copy link
Copy Markdown
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

🧹 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

📥 Commits

Reviewing files that changed from the base of the PR and between 507d2c0 and a185048.

📒 Files selected for processing (2)
  • client/helper_test.go
  • cmd/core_reload.go

Comment thread cmd/core_reload.go
paulczar and others added 3 commits March 19, 2026 13:00
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>
Copy link
Copy Markdown
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

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

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

@frenck frenck closed this Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants