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

Add a method to get the legacy_class.

This will be used in initial stages to replace the huge if/elif... statement
that determines device type from dps state.
Jason Rumney 4 лет назад
Родитель
Сommit
a442a60ff0
1 измененных файлов с 12 добавлено и 8 удалено
  1. 12 8
      custom_components/tuya_local/helpers/device_config.py

+ 12 - 8
custom_components/tuya_local/helpers/device_config.py

@@ -45,6 +45,16 @@ class TuyaDeviceConfig:
         """Return the friendly name for this device."""
         return self.__config["name"]
 
+    @property
+    def config(self):
+        """Return the config file associated with this device."""
+        return self.__fname
+
+    @property
+    def legacy_type(self):
+        """Return the legacy conf_type associated with this device."""
+        return self.__config.get("legacy_type", None)
+
     @property
     def primary_entity(self):
         """Return the primary type of entity for this device."""
@@ -80,18 +90,12 @@ class TuyaEntityConfig:
     @property
     def name(self):
         """The friendly name for this entity."""
-        if "name" in self.__config:
-            return self.__config["name"]
-        else:
-            return self.__device.name
+        return self.__config.get("name", self.__device_name)
 
     @property
     def legacy_device(self):
         """Return the legacy device corresponding to this config."""
-        if "legacy_class" in self.__config:
-            return self.__config["legacy_class"]
-        else:
-            return None
+        return self.__config.get("legacy_class", None)
 
     @property
     def entity(self):