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

Use single rather than double underscores for members.

An example I followed was using double underscores, but they are better
reserved for system library use.  Single underscore is enough to avoid
name clash with properties.
Jason Rumney 4 лет назад
Родитель
Сommit
b0a6b426ca
1 измененных файлов с 26 добавлено и 26 удалено
  1. 26 26
      custom_components/tuya_local/helpers/device_config.py

+ 26 - 26
custom_components/tuya_local/helpers/device_config.py

@@ -40,35 +40,35 @@ class TuyaDeviceConfig:
         Args:
         Args:
             fname (string): The filename of the yaml config to load."""
             fname (string): The filename of the yaml config to load."""
         _CONFIG_DIR = dirname(config_dir.__file__)
         _CONFIG_DIR = dirname(config_dir.__file__)
-        self.__fname = fname
+        self._fname = fname
         filename = join(_CONFIG_DIR, fname)
         filename = join(_CONFIG_DIR, fname)
-        self.__config = load_yaml(filename)
+        self._config = load_yaml(filename)
         _LOGGER.debug("Loaded device config %s", fname)
         _LOGGER.debug("Loaded device config %s", fname)
 
 
     @property
     @property
     def name(self):
     def name(self):
         """Return the friendly name for this device."""
         """Return the friendly name for this device."""
-        return self.__config["name"]
+        return self._config["name"]
 
 
     @property
     @property
     def config(self):
     def config(self):
         """Return the config file associated with this device."""
         """Return the config file associated with this device."""
-        return self.__fname
+        return self._fname
 
 
     @property
     @property
     def legacy_type(self):
     def legacy_type(self):
         """Return the legacy conf_type associated with this device."""
         """Return the legacy conf_type associated with this device."""
-        return self.__config.get("legacy_type", None)
+        return self._config.get("legacy_type", None)
 
 
     @property
     @property
     def primary_entity(self):
     def primary_entity(self):
         """Return the primary type of entity for this device."""
         """Return the primary type of entity for this device."""
-        return TuyaEntityConfig(self, self.__config["primary_entity"])
+        return TuyaEntityConfig(self, self._config["primary_entity"])
 
 
     def secondary_entities(self):
     def secondary_entities(self):
         """Iterate through entites for any secondary entites supported."""
         """Iterate through entites for any secondary entites supported."""
-        if "secondary_entities" in self.__config.keys():
-            for conf in self.__config["secondary_entities"]:
+        if "secondary_entities" in self._config.keys():
+            for conf in self._config["secondary_entities"]:
                 yield TuyaEntityConfig(self, conf)
                 yield TuyaEntityConfig(self, conf)
 
 
     def matches(self, dps):
     def matches(self, dps):
@@ -105,18 +105,18 @@ class TuyaEntityConfig:
     """Representation of an entity config for a supported entity."""
     """Representation of an entity config for a supported entity."""
 
 
     def __init__(self, device, config):
     def __init__(self, device, config):
-        self.__device = device
-        self.__config = config
+        self._device = device
+        self._config = config
 
 
     @property
     @property
     def name(self):
     def name(self):
         """The friendly name for this entity."""
         """The friendly name for this entity."""
-        return self.__config.get("name", self.__device.name)
+        return self._config.get("name", self._device.name)
 
 
     @property
     @property
     def legacy_class(self):
     def legacy_class(self):
         """Return the legacy device corresponding to this config."""
         """Return the legacy device corresponding to this config."""
-        name = self.__config.get("legacy_class", None)
+        name = self._config.get("legacy_class", None)
         if name is None:
         if name is None:
             return None
             return None
         return locate("custom_components.tuya_local" + name)
         return locate("custom_components.tuya_local" + name)
@@ -124,11 +124,11 @@ class TuyaEntityConfig:
     @property
     @property
     def entity(self):
     def entity(self):
         """The entity type of this entity."""
         """The entity type of this entity."""
-        return self.__config["entity"]
+        return self._config["entity"]
 
 
     def dps(self):
     def dps(self):
         """Iterate through the list of dps for this entity."""
         """Iterate through the list of dps for this entity."""
-        for d in self.__config["dps"]:
+        for d in self._config["dps"]:
             yield TuyaDpsConfig(self, d)
             yield TuyaDpsConfig(self, d)
 
 
 
 
@@ -136,16 +136,16 @@ class TuyaDpsConfig:
     """Representation of a dps config."""
     """Representation of a dps config."""
 
 
     def __init__(self, entity, config):
     def __init__(self, entity, config):
-        self.__entity = entity
-        self.__config = config
+        self._entity = entity
+        self._config = config
 
 
     @property
     @property
     def id(self):
     def id(self):
-        return str(self.__config["id"])
+        return str(self._config["id"])
 
 
     @property
     @property
     def type(self):
     def type(self):
-        t = self.__config["type"]
+        t = self._config["type"]
         types = {
         types = {
             "boolean": bool,
             "boolean": bool,
             "integer": int,
             "integer": int,
@@ -157,21 +157,21 @@ class TuyaDpsConfig:
 
 
     @property
     @property
     def name(self):
     def name(self):
-        return self.__config["name"]
+        return self._config["name"]
 
 
     @property
     @property
     def isreadonly(self):
     def isreadonly(self):
-        return "readonly" in self.__config.keys() and self.__config["readonly"] is True
+        return "readonly" in self._config.keys() and self._config["readonly"] is True
 
 
     def map_from_dps(self, value):
     def map_from_dps(self, value):
         result = value
         result = value
-        if "mapping" in self.__config.keys():
-            for map in self.__config["mapping"]:
+        if "mapping" in self._config.keys():
+            for map in self._config["mapping"]:
                 if map["dps_val"] == value and "value" in map:
                 if map["dps_val"] == value and "value" in map:
                     result = map["value"]
                     result = map["value"]
                     _LOGGER.debug(
                     _LOGGER.debug(
                         "%s: Mapped dps %d value from %s to %s",
                         "%s: Mapped dps %d value from %s to %s",
-                        self.__entity.__device.name,
+                        self._entity._device.name,
                         self.id,
                         self.id,
                         value,
                         value,
                         result,
                         result,
@@ -180,13 +180,13 @@ class TuyaDpsConfig:
 
 
     def map_to_dps(self, value):
     def map_to_dps(self, value):
         result = value
         result = value
-        if "mapping" in self.__config.keys():
-            for map in self.__config["mapping"]:
+        if "mapping" in self._config.keys():
+            for map in self._config["mapping"]:
                 if "value" in map and map["value"] == value:
                 if "value" in map and map["value"] == value:
                     result = map["dps_val"]
                     result = map["dps_val"]
                     _LOGGER.debug(
                     _LOGGER.debug(
                         "%s: Mapped dps %d to %s from %s",
                         "%s: Mapped dps %d to %s from %s",
-                        self.__entity.__device.name,
+                        self._entity._device.name,
                         self.id,
                         self.id,
                         result,
                         result,
                         value,
                         value,