Slugify enum select and sensor option values for translation#805
Open
foXaCe wants to merge 3 commits into
Open
Slugify enum select and sensor option values for translation#805foXaCe wants to merge 3 commits into
foXaCe wants to merge 3 commits into
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 statetranslation 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'stranslation_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 nowentry.name.lower(); a_enum_member_by_optionmap resolves the selected option back to the enum member.SirenDefaultSelectEntity: same slugification, via a_member_for_optionhelper.EnumSensor:_attr_optionsandformatterreturn the slugified member name.async_select_optionand the siren-default restorepath fall back to the previous spaced names, so existing automations and restored
state keep working.
tests/data/devices/*.json) and the affected testsare 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 theold 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.jsontranslations (thestateblocks for the39 affected
translation_keys) will be submitted tohome-assistant/coreonce arelease including this change is available, since the
statekeys must match the newslug options.
Tests
Full suite passes (
1337 passed).