sleep.py 934 B

123456789101112131415161718192021222324252627282930
  1. import time
  2. import six
  3. from kalliope.core.NeuronModule import NeuronModule, MissingParameterException
  4. class Sleep(NeuronModule):
  5. def __init__(self, **kwargs):
  6. super(Sleep, self).__init__(**kwargs)
  7. self.seconds = kwargs.get('seconds', None)
  8. # check parameters
  9. if self._is_parameters_ok():
  10. if isinstance(self.seconds, str) or \
  11. isinstance(self.seconds, six.text_type):
  12. self.seconds = float(self.seconds)
  13. time.sleep(self.seconds)
  14. def _is_parameters_ok(self):
  15. """
  16. Check if received parameters are ok to perform operations in the neuron
  17. :return: true if parameters are ok, raise an exception otherwise
  18. .. raises:: MissingParameterException
  19. """
  20. if self.seconds is None:
  21. raise MissingParameterException("You must set a number of seconds as parameter")
  22. return True