Skip to content

Resolve entity name via hass.formatEntityName - #93

Open
bramkragten wants to merge 3 commits into
custom-cards:mainfrom
bramkragten:ha-entity-names
Open

bramkragten wants to merge 3 commits into
custom-cards:mainfrom
bramkragten:ha-entity-names

Conversation

@bramkragten

@bramkragten bramkragten commented Sep 14, 2026 •

Copy link
Copy Markdown

What

Resolve the name option through hass.formatEntityName instead of reading attributes.friendly_name directly, and offer the entity_name selector in the visual editor.

Why

Home Assistant is moving from a single friendly_name string to a name composed from the entity's registry context (entity, device, area, floor). Under that model the device name becomes part of the composed name, so a button reads "Kitchen Ceiling light" where the built-in cards next to it show "Ceiling light" — and on a slider button, where the name shares the tile with the slider, that extra length wraps. Cards reading the attribute directly also can't follow the default when HA changes it.

Routing through the helper fixes both, and users can compose the name:

type: custom:slider-button-card
entity: light.kitchen_ceiling
name:
  - type: area
  - type: entity

Context: home-assistant/frontend#51686, which tracks bringing the most-used custom cards along with the new naming model.

Changes

  • Controller.name goes through computeEntityName in the new src/entity-name.ts.
  • SliderButtonCardConfig.name widens from string to a new EntityName type.
  • The editor's name field becomes an ha-selector with entity_name on HA 2025.11+, falling back to the existing mwc-textfield below that, so the visual editor keeps working on older versions. It needs its own handler because ha-selector reports through ev.detail rather than target.value.
  • shouldUpdate also returns true when the naming inputs change. formatEntityName resolves against the registries and HA swaps the real formatter in asynchronously once translations load — neither changes an entity state, so hasConfigOrEntityChanged misses both.

Compatibility

Two version gates, both in src/entity-name.ts: 2026.4 for formatEntityName (it has existed since 2025.10 but with an incompatible signature — bare type strings then, structured items only in 2025.11–2026.3 — so feature detection isn't safe), and 2025.11 for the editor selector. Below 2026.4 behaviour is unchanged.

Verification

npm run lint and npm run rollup both pass. The build is what caught the editor: widening the config type surfaced TS2322 on the _name getter, which is why the field was upgraded rather than left as a text input that would have shown an empty box for a structured name.

dist/ and package-lock.json are untouched by this branch.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
bramkragten and others added 2 commits September 15, 2026 12:33
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
formatEntityName returns any string it is given verbatim, the empty one
included, so `name: ''` blanked the label where it previously fell through
to the friendly name. It now reaches the formatter as undefined.

Also drops `parent_device` from the accepted name parts. It only landed in
the frontend on 2026-09-10 and is in no release yet, so under the 2026.4
gate it was silently ignored.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant