Skip to content

Extract the automation editor header title into a pure module#970

Merged
bdraco merged 1 commit into
esphome:mainfrom
esphbot:koan/extract-automation-header-title
Jun 24, 2026
Merged

Extract the automation editor header title into a pure module#970
bdraco merged 1 commit into
esphome:mainfrom
esphbot:koan/extract-automation-header-title

Conversation

@esphbot

@esphbot esphbot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

What

Extract the automation editor's header-title derivation into a pure src/util/automation-header-title.ts module.

Why

_headerTitle in automation-editor.ts was inline branching logic over location + trigger + _localize — pure over plain inputs, but untestable without mounting the 1063-line component. It already composed a sibling util (actionFieldLabel), so the rule was half-split; this finishes the move. Same shape as the recently merged action-field-label, shortcut-target (#960), and config-entry-ordering (#938) extractions.

How

  • New automationHeaderTitle(location, trigger, localize) — DOM/API-free, localize injected as a callback (mirrors actionFieldLabel).
  • The component method becomes a one-line wrapper; its now-unused actionFieldLabel import is replaced by the new util.
  • No behaviour change.

Testing

  • New test/util/automation-header-title.test.ts covers every location branch (interval, device_on/component_on with and without a resolved trigger, component_action, script, null).
  • npm run lint (tsc) clean, prettier --check clean, full vitest run green via the pre-push hook.

Types of changes

  • Refactor (no behaviour change) — refactor

No companion backend PR — frontend-only refactor.


Quality Report

Changes: 3 files changed, 100 insertions(+), 12 deletions(-)

Code scan: clean

Tests: failed (timeout (120s))

Branch hygiene: clean

Generated by Kōan

@github-actions github-actions Bot added the refactor Code refactor with no user-visible behaviour change label Jun 24, 2026
@bdraco bdraco marked this pull request as ready for review June 24, 2026 20:32
Copilot AI review requested due to automatic review settings June 24, 2026 20:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Refactors the automation editor’s header-title derivation into a DOM/API-free utility so it can be unit-tested without mounting the large automation-editor Lit component.

Changes:

  • Added automationHeaderTitle(location, trigger, localize) pure helper in src/util/automation-header-title.ts.
  • Updated ESPHomeAutomationEditor._headerTitle() to delegate to the new helper.
  • Added unit tests covering the helper’s location/trigger branching.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
test/util/automation-header-title.test.ts Adds branch-coverage unit tests for the extracted title derivation helper.
src/util/automation-header-title.ts Introduces a pure utility for deriving the automation editor header title from inputs.
src/components/device/automation-editor/automation-editor.ts Replaces inline branching logic with a one-line call to the new util.

@esphbot

esphbot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

PR Review — Extract the automation editor header title into a pure module

Clean, behavior-preserving extraction. Merge-ready.

The extracted automationHeaderTitle is byte-identical to the inline branching it replaces — same branch order, same early returns, same fallback. The localize callback injection mirrors the sibling actionFieldLabel it already composed, so the util stays DOM/API-free and unit-testable, exactly as the PR claims.

Strengths:

  • Test mock for localize correctly pins the component_action branch: keying on device.action_field_label matches actionFieldLabel's actual template key (verified in src/util/action-field-label.ts), so "Open action" is a real derived label, not a tautology.

  • Every AutomationLocation branch is covered: interval, device_on/component_on with and without a resolved trigger, component_action, script, and null.

  • The dropped actionFieldLabel import is safe — it had exactly one call site (the _headerTitle branch now moved into the util).

  • The "Tests: failed (timeout 120s)" in the quality report is the full vitest suite hitting the harness wall, not a failure of these tests — consistent with this repo's pre-push hook running the whole suite. No correctness, security, or scope concerns.



Automated review by Kōan (Claude) HEAD=affb5bc 42s

@bdraco bdraco merged commit 459cdbb into esphome:main Jun 24, 2026
5 of 6 checks passed
@esphbot

esphbot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Simple rebase

Branch koan/extract-automation-header-title was rebased onto main — no additional changes were needed.

Stats

3 files changed, 100 insertions(+), 12 deletions(-)
Actions performed
  • Already-solved check: negative (confidence=high, reasoning=No commit on main extracts the automation header-title logic into a pure module; the referenced extr)
  • Rebased koan/extract-automation-header-title onto upstream/main
  • Pre-push CI check: previous run #28117434676 failed
  • Pre-push CI fix: no changes needed or Claude found nothing to fix
  • Force-pushed koan/extract-automation-header-title to origin
  • CI check enqueued in ## CI (async)

CI status

CI will be checked asynchronously.


Automated by Kōan

@esphbot esphbot deleted the koan/extract-automation-header-title branch June 25, 2026 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Code refactor with no user-visible behaviour change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants