Added timer class

This commit is contained in:
2020-11-08 01:16:47 +01:00
parent 24d0b05cef
commit 0d8359e9f8

26
functions/timer.py Normal file
View File

@@ -0,0 +1,26 @@
import asyncio
class Timer():
def __init__(self, minutes, seconds):
self.minutes = minutes
self.seconds = seconds
self.ended = True
def start(self):
self.ended = False
self.timer_task = asyncio.ensure_future(self.update())
def stop(self):
self.timer_task.cancel()
self.endend = True
async def update(self):
while self.ended == False:
await asyncio.sleep(1)
if (self.minutes > 0 and self.seconds == 0):
self.minutes -= 1
self.seconds = 59
elif (self.seconds > 0):
self.seconds -= 1
if (self.minutes == 0 and self.seconds == 0):
self.ended = True