From db1b008fc93a88bda080327cbff08922eab3aebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 18 Apr 2018 20:16:56 +0200 Subject: [PATCH] Fix EventHandlerBase.event_handler_callback broken logic --- lib/tfw/event_handler_base.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/tfw/event_handler_base.py b/lib/tfw/event_handler_base.py index bc5d948..cca44b1 100644 --- a/lib/tfw/event_handler_base.py +++ b/lib/tfw/event_handler_base.py @@ -23,17 +23,20 @@ class EventHandlerBase(ABC): def event_handler_callback(self, msg_parts): """ Callback that is invoked when receiving a message. + Dispatches messages to handler methods and sends + a response back in case the handler returned something. This is subscribed in __init__(). """ - # TODO: fix faulty logic below message = deserialize_tfw_msg(*msg_parts) response = self.dispatch_handling(message) - response['key'] = message['key'] - if response is None: - return - self.server_connector.send(response) + if response: + response['key'] = message['key'] + self.server_connector.send(response) def dispatch_handling(self, message): + """ + Used to dispatch messages to their specific handlers. + """ if message['key'] != 'reset': return self.handle_event(message) return self.handle_reset(message) @@ -50,7 +53,7 @@ class EventHandlerBase(ABC): def handle_reset(self, message): # pylint: disable=unused-argument,no-self-use """ - 'reset' events usually receive some sort of special treatment. + Usually 'reset' events receive some sort of special treatment. :param message: the message received """