Skip to content

Slugify enum select and sensor option values for translation#805

Open
foXaCe wants to merge 3 commits into
zigpy:devfrom
foXaCe:feat/translate-enum-selects
Open

Slugify enum select and sensor option values for translation#805
foXaCe wants to merge 3 commits into
zigpy:devfrom
foXaCe:feat/translate-enum-selects

Conversation

@foXaCe

@foXaCe foXaCe commented Jul 1, 2026

Copy link
Copy Markdown

Summary

Enum-based select (ZCLEnumSelectEntity, SirenDefaultSelectEntity) and sensor
(EnumSensor) entities currently expose their options/states as spaced,
title-cased strings derived from the enum member names (e.g. "Police Panic",
"Previous value"). Home Assistant cannot translate these, because entity state
translation keys must be slugs.

This makes the option values and enum sensor states the slugified enum member
names (e.g. "police_panic"), so they can be translated through the entity's
translation_key.

This revives #86 (which stalled). It's the blocker referenced by
home-assistant/core#165493, which was closed with a pointer to that PR.

Details

  • ZCLEnumSelectEntity: options are now entry.name.lower(); a
    _enum_member_by_option map resolves the selected option back to the enum member.
  • SirenDefaultSelectEntity: same slugification, via a _member_for_option helper.
  • EnumSensor: _attr_options and formatter return the slugified member name.
  • Backwards compatibility: async_select_option and the siren-default restore
    path fall back to the previous spaced names, so existing automations and restored
    state keep working.
  • Device diagnostic snapshots (tests/data/devices/*.json) and the affected tests
    are regenerated / updated accordingly.

Breaking change

Select option values and enum sensor states change from spaced/title-cased strings
(e.g. Police Panic) to slugs (e.g. police_panic). Automations that reference the
old values keep working through the compatibility fallback, but the displayed/stored
state changes (and is now translatable in Home Assistant).

Companion PR

The matching Home Assistant strings.json translations (the state blocks for the
39 affected translation_keys) will be submitted to home-assistant/core once a
release including this change is available, since the state keys must match the new
slug options.

Tests

Full suite passes (1337 passed).

Enum-based select (ZCLEnumSelectEntity, SirenDefaultSelectEntity) and sensor
(EnumSensor) entities exposed their options/states as spaced, title-cased
strings derived from the enum member names (e.g. "Police Panic", "Previous
value"). Home Assistant cannot translate these, because entity state
translation keys must be slugs.

Option values and enum sensor states are now the slugified enum member names
(e.g. "police_panic"), so they can be translated through the entity's
translation_key. async_select_option and the siren-default restore path keep
backwards compatibility with the previous spaced option names.

Device diagnostic snapshots and affected tests are updated accordingly.
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.29%. Comparing base (a0e3195) to head (eca6216).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev     #805   +/-   ##
=======================================
  Coverage   97.29%   97.29%           
=======================================
  Files          55       55           
  Lines       10933    10943   +10     
=======================================
+ Hits        10637    10647   +10     
  Misses        296      296           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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