Skip to content

Commit 58a37a6

Browse files
0xAHAclaude
andcommitted
feat: translatable sensor names (169 entities)
Sensor names were hardcoded English regardless of the user's Home Assistant language. The integration already ships 22 languages, but they only covered the config and options flows -- there was no entity section at all. Names now come from entity.sensor.<key>.name via _attr_translation_key. The English text was generated from sensor_def['name'], so what users see is unchanged; other languages can now be contributed without touching Python. The strings were generated in CI rather than locally. sensor.py imports homeassistant.components.sensor and cannot be imported on the Windows dev machine, so doing this locally would have meant parsing source -- and many definitions are built by _pv_string_sensors() and _phase_sensors() with f-strings, which is where that would have gone wrong. The throwaway workflow imported the module properly on Linux and uploaded the real 169 definitions; it is removed again in this commit. The failure mode for a missing key is quiet: Home Assistant does not fall back to anything readable, so the entity simply has no label while continuing to work. tests_ha asserts every key has text, that no orphaned entries remain, and that the English matches SENSOR_DEFINITIONS exactly -- the last of which is what proves this changed nothing visible. number/select/time names stay in Python for now; those platforms were only just moved onto GrowattEntity and their naming should settle first. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 2a17d06 commit 58a37a6

5 files changed

Lines changed: 1096 additions & 61 deletions

File tree

.github/workflows/dump-entity-names.yaml

Lines changed: 0 additions & 60 deletions
This file was deleted.

custom_components/growatt_modbus/sensor.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,13 @@ def __init__(
13881388

13891389
self._sensor_key = sensor_key
13901390
self._sensor_def = sensor_def
1391-
self._attr_name = sensor_def['name']
1391+
1392+
# Name comes from strings.json / translations/*.json under entity.sensor.<key>.name
1393+
# rather than from sensor_def['name'], so the 22 shipped languages can translate it.
1394+
# The English text there was generated from sensor_def['name'], so what users see is
1395+
# unchanged; tests_ha asserts every key has an entry, because a missing one leaves
1396+
# the entity with no name at all rather than falling back.
1397+
self._attr_translation_key = sensor_key
13921398

13931399
# Set entity category (None for main sensors, "diagnostic" for technical details)
13941400
entity_category = get_entity_category(sensor_key)

0 commit comments

Comments
 (0)