소스 검색

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 년 전
부모
커밋
59ddc5f957
1개의 변경된 파일10개의 추가작업 그리고 2개의 파일을 삭제
  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
     @property
     def readonly(self):
     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):
     def invalid_for(self, value, device):
         mapping = self._find_map_for_value(value)
         mapping = self._find_map_for_value(value)
@@ -299,7 +303,7 @@ class TuyaDpsConfig:
 
 
     @property
     @property
     def hidden(self):
     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):
     def _find_map_for_dps(self, value):
         if "mapping" not in self._config.keys():
         if "mapping" not in self._config.keys():
@@ -453,6 +457,10 @@ class TuyaDpsConfig:
             result = float(result)
             result = float(result)
         elif self.type is str:
         elif self.type is str:
             result = str(result)
             result = str(result)
+
+        if self.stringify:
+            result = str(result)
+
         dps_map[self.id] = result
         dps_map[self.id] = result
         return dps_map
         return dps_map