Просмотр исходного кода

Entity name: Use device name explicitly, not implicitly.

New guidelines are to return None from name when you explicitly want to use the
device name.  super().name returns a constant UNDEFINED rather than None, so we
need to catch that and ensure we return None.

Issue #992
Jason Rumney 2 лет назад
Родитель
Сommit
5ab27da749
1 измененных файлов с 6 добавлено и 0 удалено
  1. 6 0
      custom_components/tuya_local/helpers/mixin.py

+ 6 - 0
custom_components/tuya_local/helpers/mixin.py

@@ -9,6 +9,7 @@ from homeassistant.const import (
     UnitOfTemperature,
 )
 from homeassistant.helpers.entity import EntityCategory
+from homeassistant.helpers.typing import UNDEFINED
 
 _LOGGER = logging.getLogger(__name__)
 
@@ -44,7 +45,12 @@ class TuyaLocalEntity:
     @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
 
     @property