Parcourir la source

Config parser: Check for strings using instanceof rather than type

In HA 2023.12 beta, the yaml parser has been modified to return objects that
are a subclass of str, rather than str objects themselves.  This breaks the
check for multiple conditions, which needs to differentiate strings from
other sequences.
- second location that needed changing to fix cases where multiple dps
  are expected to be set together.

- renamed argument from type to vtype to avoid shadowing builtins.
Jason Rumney il y a 2 ans
Parent
commit
ca046eb2ec
1 fichiers modifiés avec 7 ajouts et 7 suppressions
  1. 7 7
      custom_components/tuya_local/helpers/device_config.py

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

@@ -18,22 +18,22 @@ import custom_components.tuya_local.devices as config_dir
 _LOGGER = logging.getLogger(__name__)
 
 
-def _typematch(type, value):
+def _typematch(vtype, value):
     # Workaround annoying legacy of bool being a subclass of int in Python
-    if type is int and isinstance(value, bool):
+    if vtype is int and isinstance(value, bool):
         return False
 
     # Allow integers to pass as floats.
-    if type is float and isinstance(value, Number):
+    if vtype is float and isinstance(value, Number):
         return True
 
-    if isinstance(value, type):
+    if isinstance(value, vtype):
         return True
     # Allow values embedded in strings if they can be converted
     # But not for bool, as everything can be converted to bool
-    elif isinstance(value, str) and type is not bool:
+    elif isinstance(value, str) and vtype is not bool:
         try:
-            type(value)
+            vtype(value)
             return True
         except ValueError:
             return False
@@ -844,7 +844,7 @@ class TuyaDpsConfig:
                 if cval == value:
                     c_dps = self._entity.find_dps(mapping.get("constraint", self.name))
                     cond_dpsval = cond.get("dps_val")
-                    single_match = type(cond_dpsval) == str or (
+                    single_match = isinstance(cond_dpsval, str) or (
                         not isinstance(cond_dpsval, Sequence)
                     )
                     if c_dps.id != self.id and single_match: