Răsfoiți Sursa

Allow for stringify property on dps.

This property will signify that they are to be set as strings, even though
they are required to act as another type internally (eg int that must be scaled
and range checked).
Jason Rumney 4 ani în urmă
părinte
comite
59ddc5f957
1 a modificat fișierele cu 10 adăugiri și 2 ștergeri
  1. 10 2
      custom_components/tuya_local/helpers/device_config.py

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

@@ -287,7 +287,11 @@ class TuyaDpsConfig:
 
     @property
     def readonly(self):
-        return "readonly" in self._config.keys() and self._config["readonly"] is True
+        return self._config.get("readonly", False)
+
+    @property
+    def stringify(self):
+        return self._config.get("stringify", False)
 
     def invalid_for(self, value, device):
         mapping = self._find_map_for_value(value)
@@ -299,7 +303,7 @@ class TuyaDpsConfig:
 
     @property
     def hidden(self):
-        return "hidden" in self._config.keys() and self._config["hidden"] is True
+        return self._config.get("hidden", False)
 
     def _find_map_for_dps(self, value):
         if "mapping" not in self._config.keys():
@@ -453,6 +457,10 @@ class TuyaDpsConfig:
             result = float(result)
         elif self.type is str:
             result = str(result)
+
+        if self.stringify:
+            result = str(result)
+
         dps_map[self.id] = result
         return dps_map