Browse Source

Add new hook on_processed_synapses for post-synapse tasks

Joshua Boniface 7 years ago
parent
commit
5108f7a954

+ 1 - 0
Docs/settings.md

@@ -245,6 +245,7 @@ List of available hook
 | on_stop_listening      | When the Speech to Text engine stop listening for an order      |
 | on_order_found         | When the pronounced order has been found in the brain           |
 | on_order_not_found     | When the pronounced order has not been found in the brain       |
+| on_processed_synapses  | When all neurons in synapses have been processed                |
 | on_mute                | When Kalliope switches from non muted to muted                  |
 | on_unmute              | When Kalliope switches from muted to non muted                  |
 | on_start_speaking      | When Kalliope starts speaking via the text to speech engine     |

+ 1 - 0
Tests/settings/settings_test.yml

@@ -91,6 +91,7 @@ hooks:
   on_order_found:
   on_order_not_found:
     - "order-not-found-synapse"
+  on_processed_synapses:
   on_mute: []
   on_unmute: []
   on_start_speaking:

+ 3 - 0
Tests/test_hook_manager.py

@@ -74,6 +74,9 @@ class TestInit(unittest.TestCase):
             mock_synapse_launcher.assert_called_with(["order-not-found-synapse"], new_lifo=True)
             mock_synapse_launcher.reset_mock()
 
+    def test_on_processed_synapses(self):
+        self.assertIsNone(HookManager.on_processed_synapses())
+
     def test_on_mute(self):
         """
         test that empty list of synapse return none

+ 2 - 0
Tests/test_settings_loader.py

@@ -62,6 +62,7 @@ class TestSettingLoader(unittest.TestCase):
                       'on_mute': [],
                       'on_order_not_found': [
                           'order-not-found-synapse'],
+                      'on_processed_synapses': None,
                       'on_start_speaking': None,
                       'on_stop_speaking': None
                       }
@@ -137,6 +138,7 @@ class TestSettingLoader(unittest.TestCase):
                                  'on_mute': [],
                                  'on_order_not_found': [
                                      'order-not-found-synapse'],
+                                 'on_processed_synapses': None,
                                  'on_start_speaking': None,
                                  'on_stop_speaking': None,
                                  }

+ 4 - 0
kalliope/core/HookManager.py

@@ -35,6 +35,10 @@ class HookManager(object):
     def on_order_not_found(cls):
         return cls.execute_synapses_in_hook_name("on_order_not_found")
 
+    @classmethod
+    def on_processed_synapses(cls):
+        return cls.execute_synapses_in_hook_name("on_processed_synapses")
+
     @classmethod
     def on_mute(cls):
         return cls.execute_synapses_in_hook_name("on_mute")

+ 3 - 1
kalliope/core/SynapseLauncher.py

@@ -126,4 +126,6 @@ class SynapseLauncher(object):
             lifo_buffer.add_synapse_list_to_lifo(list_synapse_to_process)
             lifo_buffer.api_response.user_order = order_to_process
 
-            return lifo_buffer.execute(is_api_call=is_api_call, no_voice=no_voice)
+            execdata = lifo_buffer.execute(is_api_call=is_api_call, no_voice=no_voice)
+            HookManager.on_processed_synapses()
+            return execdata

+ 1 - 0
kalliope/settings.yml

@@ -118,6 +118,7 @@ hooks:
   on_stop_listening:
   on_order_found:
   on_order_not_found: "order-not-found-synapse"
+  on_processed_synapses:
   on_mute:
   on_unmute:
   on_start_speaking: