Skip to content

Commit 51399e6

Browse files
committed
fix regression with main entities translation
1 parent 8c5c42f commit 51399e6

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

custom_components/victron_mqtt/entity.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ def __init__(
4545
self.entity_id = entity_id
4646
self._attr_unique_id = entity_id
4747
self._attr_suggested_display_precision = metric.precision
48-
# When main_topic is set, omit translation_key/name so HA uses the device name (via _attr_has_entity_name).
48+
# Always set translation_key so HA can resolve state/option translations (e.g. select options).
49+
self._attr_translation_key = metric.generic_short_id.replace(
50+
"{", ""
51+
).replace("}", "")
52+
self._attr_translation_placeholders = metric.key_values
53+
# When main_topic is set, override name to None so HA uses the device name (via _attr_has_entity_name).
4954
if metric.main_topic:
5055
self._attr_name = None
51-
else:
52-
self._attr_translation_key = metric.generic_short_id.replace(
53-
"{", ""
54-
).replace("}", "")
55-
self._attr_translation_placeholders = metric.key_values
5656

5757
# Special case for "%" as it should not be coming from the localization file
5858
self._attr_native_unit_of_measurement = (

tests/test_hub.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,13 @@ async def test_device_tracker(
447447
"""Test device tracker entity creation from GPS location."""
448448
victron_hub, mock_config_entry = init_integration
449449

450-
# Inject GPS coordinates (latitude and longitude)
450+
# Inject all GPS metrics required by the gps_location formula
451451
await inject_message(victron_hub, "N/123/gps/0/Position/Latitude", '{"value": 52.3676}')
452452
await inject_message(victron_hub, "N/123/gps/0/Position/Longitude", '{"value": 4.9041}')
453+
await inject_message(victron_hub, "N/123/gps/0/Fix", '{"value": 1}')
454+
await inject_message(victron_hub, "N/123/gps/0/Altitude", '{"value": 10.0}')
455+
await inject_message(victron_hub, "N/123/gps/0/Course", '{"value": 0.0}')
456+
await inject_message(victron_hub, "N/123/gps/0/Speed", '{"value": 0.0}')
453457
await finalize_injection(victron_hub)
454458

455459
# Verify entity was created by checking entity registry
@@ -472,6 +476,10 @@ async def test_device_tracker_update(
472476

473477
await inject_message(victron_hub, "N/123/gps/0/Position/Latitude", '{"value": 52.3676}')
474478
await inject_message(victron_hub, "N/123/gps/0/Position/Longitude", '{"value": 4.9041}')
479+
await inject_message(victron_hub, "N/123/gps/0/Fix", '{"value": 1}')
480+
await inject_message(victron_hub, "N/123/gps/0/Altitude", '{"value": 10.0}')
481+
await inject_message(victron_hub, "N/123/gps/0/Course", '{"value": 0.0}')
482+
await inject_message(victron_hub, "N/123/gps/0/Speed", '{"value": 0.0}')
475483
await finalize_injection(victron_hub, disconnect=False)
476484
await hass.async_block_till_done()
477485

0 commit comments

Comments
 (0)