Accept int where float specified
authorBenjamin Braatz <bb@bbraatz.eu>
Sun, 7 Mar 2021 02:20:55 +0000 (03:20 +0100)
committerBenjamin Braatz <bb@bbraatz.eu>
Sun, 7 Mar 2021 02:20:55 +0000 (03:20 +0100)
JSON does not distinguish int and float.

controlpi/messagebus.py

index ee5a2420a6992280c99fcd355c629d8d324003a1..f87b38f917f4f0f5e4538eef2fe39b5ba82517e9 100644 (file)
@@ -339,14 +339,9 @@ class MessageTemplateRegistry:
             if k in message:
                 v = message[k]
                 for t in self._children[k]:
-                    match = False
-                    if isinstance(t, type):
-                        if isinstance(v, t):
-                            match = True
-                    else:
-                        if v == t:
-                            match = True
-                    if match:
+                    if (v == t or (isinstance(t, type) and
+                                   (isinstance(v, t) or
+                                    (t == float and isinstance(v, int))))):
                         if self._children[k][t].check(client, message):
                             return True
         return False
@@ -373,14 +368,9 @@ class MessageTemplateRegistry:
             if k in message:
                 v = message[k]
                 for t in self._children[k]:
-                    match = False
-                    if isinstance(t, type):
-                        if isinstance(v, t):
-                            match = True
-                    else:
-                        if v == t:
-                            match = True
-                    if match:
+                    if (v == t or (isinstance(t, type) and
+                                   (isinstance(v, t) or
+                                    (t == float and isinstance(v, int))))):
                         for c in self._children[k][t].get(message):
                             if c not in result:
                                 result.append(c)