jarvis/backend/skills/timers.py

47 lines
1.1 KiB
Python
Raw Normal View History

from skills.config import ntfy_url
import requests
class Timers:
def __init__(self):
self.trigger_phrase = "timer"
self.timers = {}
def _add_timer(self, time, name):
self.timers[name] = time
# use https://schedule.readthedocs.io/en/stable/examples.html#run-a-job-once to trigger self._trigger_timer()
def _remove_timer(self, name):
del self.timers[name]
def _trigger_timer(self, name):
if name in self.timers:
r = requests.post(f"https://ntfy.sh/{ntfy_url}",
data=f"{name}",
headers={
"Title": "Your timer is going off!",
"Priority": "default",
"Tags": "bell"
})
print(r.text)
#TODO: send ntfy.sh to device
#TODO: play timer done sound
def run(self, query):
if "add" in query:
time = 0 #TODO: Natural Language parse time out of phrase
self._add_timer(time)
return True # Return true to indicate success
if "remove" in query:
time = 0 #TODO: Natural Language parse time out of phrase
self._remove_timer(time)
return True
return False # Return false to indicate failure
if __name__ == "__main__":
time = Timers()
time._add_timer(123, "123")
time._trigger_timer("123")