Skip to content

Split numeric field renderers out of config-entry primitives#849

Merged
bdraco merged 1 commit into
esphome:mainfrom
esphbot:koan/split-config-entry-primitives
Jun 15, 2026
Merged

Split numeric field renderers out of config-entry primitives#849
bdraco merged 1 commit into
esphome:mainfrom
esphbot:koan/split-config-entry-primitives

Conversation

@esphbot

@esphbot esphbot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

What does this implement/fix?

Split the numeric/magnitude field renderers out of
config-entry-renderers/primitives.ts into a sibling
primitives-numeric.ts, bringing both files under the 600-line cap.

primitives.ts had regrown to 624 lines, over the repo's file-size cap.
The file is a collection of independent field-renderer functions, so it
splits cleanly by field shape — the same pattern already used by the
sibling lists.ts / nested.ts / registry-list.ts modules in this
folder.

  • Moved the numeric cluster — renderNumberField (and its private
    renderIntField / renderHexIntField / hexDisplayOrFallback
    helpers), renderTimePeriodField, and renderFloatWithUnitField
    into primitives-numeric.ts.
  • primitives.ts re-exports the three public renderers from the new
    module, so every consumer (the config-entry-renderers barrel,
    config-entry-pin-renderer, and the test suite) keeps importing from
    the same path — zero consumer churn.
  • The numeric cluster shares no private helpers with the remaining
    selection/boolean/text renderers, so there's no circular import.
  • Result: primitives.ts 298 lines, primitives-numeric.ts 342 lines.
    No behaviour change; public surface unchanged.

Related issue or feature (if applicable):

  • N/A

Types of changes

  • Bugfix (non-breaking change which fixes an issue) — bugfix
  • New feature (non-breaking change which adds functionality) — new-feature
  • Enhancement to an existing feature — enhancement
  • Breaking change (fix or feature that would cause existing functionality to not work as expected) — breaking-change
  • Refactor (no behaviour change) — refactor
  • Documentation only — docs
  • Maintenance / chore — maintenance
  • CI / workflow change — ci
  • Dependencies bump — dependencies

Checklist

  • The code change is tested and works locally.
  • npm run lint passes.
  • npm run test passes.
  • Tests have been added to verify that the new code works (where applicable).

@bdraco bdraco left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You must use the pr template, do not mangle it

@bdraco

bdraco commented Jun 15, 2026

Copy link
Copy Markdown
Member

@esphbot rr

@esphbot

esphbot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

PR Review — Split numeric field renderers out of config-entry primitives

Clean, verifiable refactor — the code is merge-ready, but the PR body still needs to use the repo template per @bdraco's CHANGES_REQUESTED.

What's solid (verified locally on the PR branch):

  • The moved cluster (renderNumberField + private renderIntField/renderHexIntField/hexDisplayOrFallback, renderTimePeriodField, renderFloatWithUnitField) is byte-identical to the original — diffing old lines 58–377 against the new file's bodies shows zero changes (only the trailing renderBooleanField comment, which correctly stays behind).
  • Zero consumer churn: primitives.ts re-exports the three public renderers via export { … } from "./primitives-numeric.js", so the barrel, config-entry-pin-renderer, and ~8 test files keep their ./primitives.js import path.
  • No circular import — the numeric cluster shares no private helpers with the selection/boolean/text renderers; primitives.ts correctly sheds ifDefined, ConfigEntryType, the float-with-unit/hex-int/int-input/time-period imports, and renderFieldShell/renderStringField.
  • Both files land under the 600-line cap (298 / 342). npx tsc --noEmit clean on both, prettier --check clean.

On the failing-tests line in the quality report: I ran npx vitest run test/components/device on the branch — 802 tests pass. The reported "18 failed, 0 test" is a transient collection/install-drift artifact, not a regression from this PR.

  • Blocker is process, not code: the PR description replaces the repo template (# What does this implement/fix?, full ## Types of changes list, ## Checklist) with a custom What/Why/How/Testing layout and a single bare [x] Refactor line. Restore the template and tick the Refactor (no behaviour change) box so the pr-labels workflow derives the refactor label.
  • No code-level findings — the move is verbatim and behavior-preserving.


Checklist

  • No behaviour change (verbatim move)
  • Public surface / consumer import paths preserved
  • No circular import introduced
  • Files under 600-line cap
  • tsc / prettier / vitest green
  • PR uses required template — @bdraco CHANGES_REQUESTED

Automated review by Kōan (Claude) HEAD=ca34ea1 3 min 35s

primitives.ts had grown to 624 lines, over the repo's 600-line cap.
Move the numeric/magnitude renderers (renderNumberField + its private
hex/int helpers, renderTimePeriodField, renderFloatWithUnitField) into a
sibling primitives-numeric.ts and re-export them from primitives.ts so
every consumer and test keeps importing from the same path.

The numeric cluster shares no private helpers with the remaining
selection/boolean/text renderers, so the cut is clean with no circular
imports. primitives.ts drops to 298 lines, primitives-numeric.ts is 342.
No behaviour change; public surface unchanged.
@github-actions github-actions Bot added the refactor Code refactor with no user-visible behaviour change label Jun 15, 2026
@esphbot

esphbot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

Simple rebase

Branch koan/split-config-entry-primitives was rebased onto main — no additional changes were needed.

Stats

2 files changed, 347 insertions(+), 331 deletions(-)
Actions performed
  • Already-solved check: negative (confidence=high, reasoning=No commit on main splits config-entry-renderers/primitives.ts into primitives-numeric.ts; the only r)
  • Rebased koan/split-config-entry-primitives onto upstream/main
  • Pre-push CI check: previous run #27527019354 failed
  • Pre-push CI fix: no changes needed or Claude found nothing to fix
  • Force-pushed koan/split-config-entry-primitives to origin
  • CI check enqueued in ## CI (async)

CI status

CI will be checked asynchronously.


Automated by Kōan

@esphbot esphbot force-pushed the koan/split-config-entry-primitives branch from ca34ea1 to a8ccac9 Compare June 15, 2026 12:49
@bdraco bdraco marked this pull request as ready for review June 15, 2026 13:39
Copilot AI review requested due to automatic review settings June 15, 2026 13:39
@bdraco bdraco merged commit b84ce9c into esphome:main Jun 15, 2026
4 checks passed

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 device config-entry primitive renderers by extracting the numeric/magnitude-related field renderers into a dedicated sibling module, keeping primitives.ts under the repo’s 500–600 line file-size policy while preserving the existing public import surface.

Changes:

  • Moved numeric renderers (renderNumberField, renderTimePeriodField, renderFloatWithUnitField) and their private helpers into primitives-numeric.ts.
  • Updated primitives.ts to re-export the numeric renderers from the new module (no consumer import churn).

Reviewed changes

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

File Description
src/components/device/config-entry-renderers/primitives.ts Removes inlined numeric renderer implementations and re-exports them from the new numeric module.
src/components/device/config-entry-renderers/primitives-numeric.ts New module containing the extracted numeric/time-period/float-with-unit renderers and helper functions.

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