From b06472ad19af3312ca08d3a088fd19efa0e73640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Thu, 12 Jul 2018 15:20:35 +0200 Subject: [PATCH] Reintroduce FSM update messages with minor changes --- .../components/fsm_managing_event_handler.py | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/tfw/components/fsm_managing_event_handler.py b/lib/tfw/components/fsm_managing_event_handler.py index 78efa66..f84186f 100644 --- a/lib/tfw/components/fsm_managing_event_handler.py +++ b/lib/tfw/components/fsm_managing_event_handler.py @@ -1,13 +1,13 @@ # Copyright (C) 2018 Avatao.com Innovative Learning Kft. # All Rights Reserved. See LICENSE file for details. -from tfw import BroadcastingEventHandler +from tfw import EventHandlerBase from tfw.config.logs import logging LOG = logging.getLogger(__name__) -class FSMManagingEventHandler(BroadcastingEventHandler): +class FSMManagingEventHandler(EventHandlerBase): def __init__(self, key, fsm_type): super().__init__(key) self.fsm = fsm_type() @@ -22,28 +22,29 @@ class FSMManagingEventHandler(BroadcastingEventHandler): try: data = message['data'] message['data'] = self.command_handlers[data['command']](data) + self.server_connector.broadcast(self._fsm_updater.generate_fsm_update()) return message except KeyError: LOG.error('IGNORING MESSAGE: Invalid message received: %s', message) def handle_trigger(self, data): self.fsm.step(data['value']) - return self.with_fsm_update(data) - - def with_fsm_update(self, data): - return { - **data, - **self._fsm_updater.get_fsm_state_and_transitions() - } + return data def handle_update(self, data): - return self.with_fsm_update(data) + return data class FSMUpdater: def __init__(self, fsm): self.fsm = fsm + def generate_fsm_update(self): + return { + 'key': 'fsm_update', + 'data': self.get_fsm_state_and_transitions() + } + def get_fsm_state_and_transitions(self): state = self.fsm.state valid_transitions = [