2023-06-14 15:57:12 +00:00
|
|
|
from skills.config import ntfy_url
|
2023-06-14 15:10:18 +00:00
|
|
|
import requests
|
2023-06-14 14:38:04 +00:00
|
|
|
|
|
|
|
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:
|
2023-06-14 15:10:18 +00:00
|
|
|
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)
|
2023-06-14 14:38:04 +00:00
|
|
|
#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
|
|
|
|
|
|
|
|
|
2023-06-14 15:10:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
time = Timers()
|
|
|
|
time._add_timer(123, "123")
|
|
|
|
time._trigger_timer("123")
|