+def pause(action, **kwargs):
+ if action.sleep_event_paused:
+ return
+
+ action.sleep_event_paused = True
+
+ if not action.sleep_event_timer.is_alive():
+ return
+
+ action.sleep_event_timer.cancel()
+
+ action.sleep_event_left_time = action.sleep_event_left_time\
+ - (time.time() - action.sleep_event_started_time)
+ if action.sleep_event_left_time < 0:
+ action.sleep_event.set()
+
+def unpause(action, **kwargs):
+ if not action.sleep_event_paused:
+ return
+
+ action.sleep_event_paused = False
+
+ action.sleep_event_timer = threading.Timer(
+ action.sleep_event_left_time,
+ action.sleep_event.set)
+
+ action.sleep_event_timer.start()
+ action.sleep_event_started_time = time.time()
+
+def reset(action, **kwargs):
+ action.sleep_event_timer.cancel()
+
+ action.sleep_event_left_time = action.sleep_event_initial_duration
+
+ if action.sleep_event_paused:
+ return
+
+ action.sleep_event_timer = threading.Timer(
+ action.sleep_event_left_time,
+ action.sleep_event.set)
+
+ action.sleep_event_timer.start()
+ action.sleep_event_started_time = time.time()
+