Add entity translations to Govee BLE - #177644
Conversation
|
Hey there @bdraco, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
Pull request overview
Adds translatable sensor and binary sensor names to Govee BLE.
Changes:
- Uses device-class translations instead of library names.
- Adds translation keys for grill probes.
- Adds probe-name tests and fixtures.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
homeassistant/components/govee_ble/sensor.py |
Adds translated sensor descriptions. |
homeassistant/components/govee_ble/binary_sensor.py |
Removes library-provided names. |
homeassistant/components/govee_ble/strings.json |
Adds probe translations. |
tests/components/govee_ble/test_sensor.py |
Tests translated names. |
tests/components/govee_ble/__init__.py |
Adds probe advertisements. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
homeassistant/components/govee_ble/binary_sensor.py:71
- Clear or version the persisted binary-sensor names before relying on translated names.
PassiveBluetoothDataUpdate.update()only merges incomingentity_names, so this empty mapping never removes the English names restored bypassive_update_processor.py:212-216; restored entities then set_attr_namefrom that cache at lines 676-677 and existing installations keep the untranslated library names.
entity_names={},
homeassistant/components/govee_ble/sensor.py:123
- Invalidate or version the persisted sensor processor data before switching names and descriptions. On upgrade,
async_register_coordinator()reconstructs entities from the old restore data first: the old English name is still applied, and probe entities retain the restored generic description without these translation keys; subsequent merge-only updates replace the mappings but not the descriptions already attached to entity instances.
device_key_to_bluetooth_entity_key(device_key): (
PROBE_SENSOR_DESCRIPTIONS.get(device_key.key)
or SENSOR_DESCRIPTIONS[
(description.device_class, description.native_unit_of_measurement)
]
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (5)
homeassistant/components/govee_ble/binary_sensor.py:71
- Add an assertion that binary sensors now receive device-class translated names. The sensor-side translation behavior is tested, but this separate conversion path also drops all library names and currently has no friendly-name coverage, so regressions in the binary-sensor naming path would pass unnoticed.
entity_names={},
homeassistant/components/bluetooth/passive_update_processor.py:176
- Preserve omission as “no update” and use explicit
Noneto clear a name.PassiveBluetoothDataUpdateis a merge-style API, andtest_namingalready establishesentity_names={key: None}as the unnamed representation; treating every value/description update without a name as deletion can silently erase names supplied by parsers that send partial updates.
for key in new_data.entity_data.keys() | new_data.entity_descriptions.keys():
if (
key not in new_data.entity_names
and self.entity_names.get(key) is not None
):
changed_entity_keys.add(key)
self.entity_names[key] = None
homeassistant/components/bluetooth/passive_update_processor.py:176
- Clear restored names before constructing entities, or synchronize the entity’s cached name here. Restore data is dispatched during processor registration, and
PassiveBluetoothProcessorEntity.__init__copies the restored value into_attr_name; changing onlyself.entity_namesafter the first advertisement never resets that attribute, so upgraded Govee entities retain the old English name until another restart.
for key in new_data.entity_data.keys() | new_data.entity_descriptions.keys():
if (
key not in new_data.entity_names
and self.entity_names.get(key) is not None
):
changed_entity_keys.add(key)
self.entity_names[key] = None
homeassistant/components/govee_ble/sensor.py:105
- Add coverage for the dedicated humidity-probe description. Unlike the generated temperature entries, this hand-written branch has different class, unit, key, and placeholder values, but neither new service-info case exercises it.
"humidity_probe_1": SensorEntityDescription(
key="humidity_probe_1",
translation_key="humidity_probe",
translation_placeholders={"probe_id": "1"},
device_class=SensorDeviceClass.HUMIDITY,
native_unit_of_measurement=UnitOfRatio.PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
)
homeassistant/components/govee_ble/sensor.py:124
- Invalidate or migrate restored sensor descriptions when introducing these probe translations. Existing probe entities are constructed from the serialized pre-change generic temperature description before the first advertisement, and later replacing the processor’s description mapping does not replace each entity’s cached
entity_description; consequently upgraded probe entities do not adopt these translation keys/placeholders until a subsequent restart.
device_key_to_bluetooth_entity_key(device_key): (
PROBE_SENSOR_DESCRIPTIONS.get(device_key.key)
or SENSOR_DESCRIPTIONS[
(description.device_class, description.native_unit_of_measurement)
]
)
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (5)
homeassistant/components/govee_ble/binary_sensor.py:71
- Add a test assertion for the translated binary-sensor friendly name. The existing binary-sensor tests only verify state, so this separate conversion path can keep or regain a library-provided English name without any test failing.
entity_names={},
homeassistant/components/bluetooth/passive_update_processor.py:178
- Clear restored names before restored entities are instantiated.
async_register_coordinator()dispatches restore data first, soPassiveBluetoothProcessorEntity.__init__()copies the old name into_attr_name; this later mapping update only writes state and cannot switch an existing Govee entity to its translated name during that session. The restore data needs migration/versioning before the initial dispatch, or entities need an explicit name-change path.
if not new_data.entity_names:
for key in (
new_data.entity_data.keys() | new_data.entity_descriptions.keys()
):
if self.entity_names.get(key) is not None:
changed_entity_keys.add(key)
self.entity_names[key] = None
homeassistant/components/govee_ble/sensor.py:124
- Migrate restored probe descriptions before entities are created. Existing installations restore the previous generic temperature description and instantiate the entity before the first advertisement reaches this mapping; later replacing
processor.entity_descriptionsdoes not replace the entity's boundentity_description, so these probes do not receive the new translation key until a subsequent restart after storage is rewritten.
device_key_to_bluetooth_entity_key(device_key): (
PROBE_SENSOR_DESCRIPTIONS.get(device_key.key)
or SENSOR_DESCRIPTIONS[
(description.device_class, description.native_unit_of_measurement)
]
)
homeassistant/components/bluetooth/passive_update_processor.py:178
- Keep an empty
entity_namesmapping as “no name updates.”PassiveBluetoothDataUpdateis explicitly designed for partial advertisements, andNoneis already the deletion value for an individual key; treating the default empty mapping as deletion makes an ordinary data-only partial update erase names supplied by an earlier update. Emit{key: None}explicitly from integrations that are dropping names instead.
if not new_data.entity_names:
for key in (
new_data.entity_data.keys() | new_data.entity_descriptions.keys()
):
if self.entity_names.get(key) is not None:
changed_entity_keys.add(key)
self.entity_names[key] = None
homeassistant/components/govee_ble/sensor.py:105
- Add coverage for the dedicated humidity-probe description. The new advertisements exercise only the generated temperature descriptions, leaving this hand-written key, humidity class/unit, translation key, and placeholder branch unverified.
"humidity_probe_1": SensorEntityDescription(
key="humidity_probe_1",
translation_key="humidity_probe",
translation_placeholders={"probe_id": "1"},
device_class=SensorDeviceClass.HUMIDITY,
native_unit_of_measurement=UnitOfRatio.PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
)
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
homeassistant/components/govee_ble/binary_sensor.py:71
- Add coverage showing that binary sensors now use translated device-class names. Existing
test_binary_sensor.pycases only assert state, so the binary-sensor half of this change could keep or regain the library-provided English name without failing any test; use a non-English language so the translated name differs from the library string.
entity_names={},
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (3)
homeassistant/components/govee_ble/binary_sensor.py:74
- Add an upgrade-path test that seeds a restored English binary-sensor name and verifies this
Noneentry replaces it. Existing binary-sensor tests assert only state values, so neither translated naming nor the persisted-name clearing behavior is currently exercised.
# None overrides names restored from storage, {} would keep them
entity_names={
device_key_to_bluetooth_entity_key(device_key): None
for device_key in sensor_update.binary_entity_values
homeassistant/components/govee_ble/sensor.py:135
- Add an upgrade-path test that seeds a restored English sensor name and verifies this
Noneentry replaces it. The current tests only exercise fresh entities, where omittingentity_namesentirely would produce the same translated result, so the persistence behavior added for existing installations can regress unnoticed.
# None overrides names restored from storage, {} would keep them
entity_names={
device_key_to_bluetooth_entity_key(device_key): None
for device_key in sensor_update.entity_values
homeassistant/components/govee_ble/sensor.py:102
- Add coverage for the dedicated humidity-probe description. The new probe tests cover only the temperature and alarm variants, leaving this separately constructed translation key, placeholder, device class, and unit unverified.
"humidity_probe_1": SensorEntityDescription(
key="humidity_probe_1",
translation_key="humidity_probe",
translation_placeholders={"probe_id": "1"},
device_class=SensorDeviceClass.HUMIDITY,
* upstream/dev: (361 commits) Improve Z-Wave heat alarm binary sensors discovery (home-assistant#177486) Use entity attribute enums in logbook (home-assistant#178254) Import DOMAIN constants in Google Assistant (home-assistant#178262) Import DOMAIN constants in Alexa (home-assistant#178260) Raise ServiceValidationError for invalid vizio source and sound mode (home-assistant#177588) Fixes home-assistant#173399 Seerr webhook registration (home-assistant#177201) Adapt mqtt to set via_device_id in DeviceInfo (home-assistant#178234) Use base entity attribute enums in MQTT base blocked attributes (home-assistant#178231) ProxmoxVE component change Hibernate button to Suspend and fix API call path (home-assistant#177205) Fix via_device in fritz linking to itself (home-assistant#178226) Fix via_device in tplink linking to itself (home-assistant#178228) Adapt hortimax to set via_device_id in DeviceInfo (home-assistant#178233) Add entity translations to Govee BLE (home-assistant#177644) Add FireAvert (home-assistant#178224) Bump plugwise to v1.14.4 (home-assistant#177957) Do not probe Pi-hole v6 API version with a wrong password (home-assistant#178143) Bump ttls to 1.10.0 (home-assistant#177418) Add Reolink anti-flicker entity (home-assistant#177411) Add Reolink time synchronization button (home-assistant#177352) Add input_button support to button.pressed trigger (home-assistant#178161) ... # Conflicts: # homeassistant/components/vizio/config_flow.py # tests/components/vizio/conftest.py
Proposed change
Sensor and binary sensor names come from the govee-ble library as hardcoded English strings, so they are never translated. Stop passing the library names and rely on the translated device class names instead, following what was done for OralB (#97402), Bluemaestro (#102424) and BTHome (#156060). The grill thermometer probe sensors cannot be distinguished by device class alone, so they get dedicated entity descriptions with translation keys.
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: