From f99151b2f43ddec2a11dcdafc1990efc6feb8a2d Mon Sep 17 00:00:00 2001 From: Benjamin Braatz Date: Sun, 7 Mar 2021 03:20:55 +0100 Subject: [PATCH] Accept int where float specified JSON does not distinguish int and float. --- controlpi/messagebus.py | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/controlpi/messagebus.py b/controlpi/messagebus.py index ee5a242..f87b38f 100644 --- a/controlpi/messagebus.py +++ b/controlpi/messagebus.py @@ -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) -- 2.34.1