From aa371b9039bff3033ad12844769a91a553c02ddc Mon Sep 17 00:00:00 2001 From: Jason Rumney Date: Thu, 29 Feb 2024 22:16:11 +0900 Subject: [PATCH] Translations: fix using translated entity names. At some unadvertised point, HA removed the deprecation notices for defaulting to device names, and in the process changed the behaviour. Most of the internal components that support translations seem to be using EntityDescriptor.name, so our overriding of name is not well looked after as a stable API. Now there is a new function use_device_name, which tries to figure out by complex logic, but doesn't get the same result as the old inline code. If we override that function to act as we expect, then it works but the special meaning of UNDEFINED seems to have been removed except for the self._attr_name case. --- custom_components/tuya_local/helpers/mixin.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/custom_components/tuya_local/helpers/mixin.py b/custom_components/tuya_local/helpers/mixin.py index 2b264fe75d..bc0dfda1b4 100644 --- a/custom_components/tuya_local/helpers/mixin.py +++ b/custom_components/tuya_local/helpers/mixin.py @@ -46,13 +46,17 @@ def has_entity_name(self): @property def name(self): """Return the name for the UI.""" - # Super has the logic to get default names from device class. - super_name = getattr(super(), "name") - # If we don't have a name, and super also doesn't, we explicitly want to use - # the device name - avoid the HA warning about implicitly using it. - if super_name is UNDEFINED: - super_name = None - return self._config.name or super_name + own_name = self._config.name + if not own_name and not self.use_device_name: + # super has the translation logic + own_name = getattr(super(), "name") + return own_name + + @property + def use_device_name(self): + """Return whether to use the device name for the entity name""" + own_name = self._config.name or self._attr_translation_key + return not own_name @property def unique_id(self):