SignalModule.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import logging
  2. from kalliope.core import Utils
  3. from kalliope.core.ConfigurationManager import BrainLoader
  4. logging.basicConfig()
  5. logger = logging.getLogger("kalliope")
  6. class MissingParameter(Exception):
  7. """
  8. An exception when parameters are missing from signals.
  9. """
  10. pass
  11. class SignalModule(object):
  12. def __init__(self, **kwargs):
  13. super(SignalModule, self).__init__(**kwargs)
  14. # get the child who called the class
  15. self.signal_name = self.__class__.__name__
  16. Utils.print_info('Init Signal :' + self.signal_name)
  17. self.brain = BrainLoader().brain
  18. def get_list_synapse(self):
  19. for synapse in self.brain.synapses:
  20. for signal in synapse.signals:
  21. # if the signal is a child we add it to the synapses list
  22. if signal.name == self.signal_name.lower(): # Lowercase !
  23. if not self.check_parameters(parameters=signal.parameters):
  24. logger.debug(
  25. "[SignalModule] The signal " + self.signal_name + " is missing mandatory parameters, check documentation")
  26. raise MissingParameter()
  27. else:
  28. yield synapse
  29. break # if there is multiple signals in the synapse, we only add it once !
  30. @staticmethod
  31. def check_parameters(parameters):
  32. raise NotImplementedError("[SignalModule] Must override check_parameters method !")