2022-02-25 20:03:36 +00:00
|
|
|
"""Module providing a timer class"""
|
2024-03-22 07:19:13 +00:00
|
|
|
|
2022-02-25 20:03:36 +00:00
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
|
|
class Timer:
|
|
|
|
"""Class implementing a timer class. Takes an activation delay and
|
|
|
|
sets a flag if the activation delay exprires."""
|
2022-11-30 05:19:17 +00:00
|
|
|
|
2022-02-25 20:03:36 +00:00
|
|
|
def __init__(self, activation_delay):
|
|
|
|
self.start_timestamp = int(time.time())
|
|
|
|
self.activation_delay = activation_delay
|
|
|
|
self.enabled = False
|
|
|
|
|
|
|
|
def check_timer(self):
|
|
|
|
"""Checks the timer whether it has reached the activation delay."""
|
|
|
|
current_timestamp = int(time.time())
|
|
|
|
timestamp_diff = current_timestamp - self.start_timestamp
|
|
|
|
|
|
|
|
if timestamp_diff >= self.activation_delay:
|
|
|
|
self.enabled = True
|
|
|
|
|
|
|
|
def reset_timer(self):
|
|
|
|
"""Resets the timer and starts from the beginning."""
|
|
|
|
self.start_timestamp = int(time.time())
|
|
|
|
self.enabled = False
|