예제 #1
0
 def schedule_event(self, handler, when, data=None, name=None, context=None):
     # TODO: should 'when' already be a datetime? DM
     if isinstance(when, int) or isinstance(when, float):
         from datetime import datetime as dt, timedelta
         when = to_system_time(dt.now(self.sys_tz)) + timedelta(seconds=when)
         LOG.info(f"Made a datetime: {when}")
     super().schedule_event(handler, when, data, name, context)
예제 #2
0
    def await_confirmation(self, user, actions, timeout=None):
        """
        Used to add an action for which to await a response (note: this will disable skill reload when called and enable
        on timeout)
        :param user: username ("local" for non-server)
        :param actions: string action name (or list of action names) we are confirming,
                       handled in skill's converse method
        :param timeout: duration to wait in seconds before removing the action from the list
        """
        from datetime import datetime as dt, timedelta
        self.reload_skill = False
        if isinstance(actions, str):
            actions = [actions]
        self.actions_to_confirm[user] = actions
        if not timeout:
            timeout = self.default_intent_timeout
        expiration = dt.now(self.sys_tz) + timedelta(seconds=timeout)

        self.cancel_scheduled_event(user)
        time.sleep(1)
        self.schedule_event(self._confirmation_timeout,
                            to_system_time(expiration),
                            data={
                                "user": user,
                                "action": actions
                            },
                            name=user)
        LOG.debug(f"Scheduled {user}")
예제 #3
0
 def clear_gui_timeout(self, timeout_seconds=60):
     """
     Called by a skill to clear its gui display after the specified timeout
     :param timeout_seconds: seconds to wait before clearing gui display
     """
     from datetime import datetime as dt, timedelta
     expiration = dt.now(self.sys_tz) + timedelta(seconds=timeout_seconds)
     self.schedule_event(self._clear_gui_timeout, to_system_time(expiration))
예제 #4
0
 def to_system_time(dt):
     LOG.warning("This method is depreciated, use location_utils.to_system_time() directly")
     return to_system_time(dt)