Bladeren bron

Make entity config name a property.

In the log in #309, the message is obsured because config.name is a
function not a property, so it outputs as some obsure internal details
instead of the name we wanted.
Since the function only takes a self argument, it can easily be a property.
Jason Rumney 3 jaren geleden
bovenliggende
commit
45821f5063

+ 3 - 2
custom_components/tuya_local/helpers/device_config.py

@@ -178,13 +178,14 @@ class TuyaEntityConfig:
         self._config = config
         self._is_primary = primary
 
+    @property
     def name(self):
         """The friendly name for this entity."""
         return self._config.get("name")
 
     def unique_id(self, device_uid):
         """Return a suitable unique_id for this entity."""
-        own_name = self.name()
+        own_name = self.name
         if own_name:
             return f"{device_uid}-{slugify(own_name)}"
         else:
@@ -218,7 +219,7 @@ class TuyaEntityConfig:
     @property
     def config_id(self):
         """The identifier for this entity in the config."""
-        own_name = self.name()
+        own_name = self.name
         if own_name:
             return f"{self.entity}_{slugify(own_name)}"
 

+ 1 - 1
custom_components/tuya_local/helpers/mixin.py

@@ -37,7 +37,7 @@ class TuyaLocalEntity:
     @property
     def name(self):
         """Return the name for the UI."""
-        return self._config.name()
+        return self._config.name
 
     @property
     def has_entity_name(self):

+ 2 - 2
tests/devices/base_device_tests.py

@@ -66,10 +66,10 @@ class TuyaDeviceTestCase(IsolatedAsyncioTestCase):
         self.entities[self.primary_entity] = self.create_entity(cfg.primary_entity)
 
         self.names = {}
-        self.names[cfg.primary_entity.config_id] = cfg.primary_entity.name()
+        self.names[cfg.primary_entity.config_id] = cfg.primary_entity.name
         for e in cfg.secondary_entities():
             self.entities[e.config_id] = self.create_entity(e)
-            self.names[e.config_id] = e.name()
+            self.names[e.config_id] = e.name
 
     def create_entity(self, config):
         """Create an entity to match the config"""