From 91b49ece562f42c58e0210bf988f2ea9c2a2584c Mon Sep 17 00:00:00 2001 From: Mike Date: Mon, 28 Oct 2024 22:29:50 -0500 Subject: [PATCH] feat: intent for "wake me" closes #119 --- .gitignore | 163 +++++++++++++++++++++++++++++ __init__.py | 3 +- locale/en-us/intent/wake_me.intent | 1 + requirements.txt | 4 +- requirements/test.txt | 2 + test/test_intents.yaml | 5 + test/test_resources.yaml | 1 + test/test_skill.py | 20 +++- util/parse_utils.py | 2 +- 9 files changed, 196 insertions(+), 5 deletions(-) create mode 100644 locale/en-us/intent/wake_me.intent diff --git a/.gitignore b/.gitignore index 719302ce..cd490bec 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,166 @@ *.pyc __pycache__/ !.github/* + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/latest/usage/project/#working-with-version-control +.pdm.toml +.pdm-python +.pdm-build/ + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ diff --git a/__init__.py b/__init__.py index 1c426c76..40f2f246 100644 --- a/__init__.py +++ b/__init__.py @@ -1,6 +1,6 @@ # NEON AI (TM) SOFTWARE, Software Development Kit & Application Framework # All trademark and other rights reserved by their respective owners -# Copyright 2008-2022 Neongecko.com Inc. +# Copyright 2008-2024 Neongecko.com Inc. # Contributors: Daniel McKnight, Guy Daniels, Elon Gasper, Richard Leeds, # Regina Bloomstine, Casimiro Ferreira, Andrii Pernatii, Kirill Hrymailo # BSD-3 License @@ -218,6 +218,7 @@ def on_ready(self, _: Message): self._update_homescreen(True, True) # Intent Handlers + @intent_handler("wake_me.intent") @intent_handler(IntentBuilder("CreateAlarm").require("set") .require("alarm").optionally("playable") .optionally("weekdays").optionally("weekends") diff --git a/locale/en-us/intent/wake_me.intent b/locale/en-us/intent/wake_me.intent new file mode 100644 index 00000000..f39d6a8c --- /dev/null +++ b/locale/en-us/intent/wake_me.intent @@ -0,0 +1 @@ +wake me (|up )(at|in) {time} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 4d270472..7cc670c7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,6 @@ neon-utils[network]~=1.2,>=1.11.1a3 combo_lock~=0.2 ovos-utils~=0.0, >=0.0.32 ovos-bus-client~=0.0,>=0.0.3 -ovos-workshop~=0.0,>=0.0.12 \ No newline at end of file +ovos-workshop~=0.0,>=0.0.12 +ovos-plugin-manager<1.0.0 +ovos-core<1.0.0 diff --git a/requirements/test.txt b/requirements/test.txt index 19363c17..b21a4319 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -1 +1,3 @@ neon-minerva[padatious]~=0.2 +mock +pytest diff --git a/test/test_intents.yaml b/test/test_intents.yaml index 0abfad0b..c5d3b529 100644 --- a/test/test_intents.yaml +++ b/test/test_intents.yaml @@ -119,6 +119,11 @@ en-us: - do i have any upcoming events - list my alarms - what are the reminders + wake_me.intent: + - wake me up at {time} + - wake me up in {time} + - wake me at {time} + - wake me in {time} TimerStatus: - how much time is left - how long on that timer diff --git a/test/test_resources.yaml b/test/test_resources.yaml index dcc6da3b..01db313b 100644 --- a/test/test_resources.yaml +++ b/test/test_resources.yaml @@ -85,6 +85,7 @@ intents: - list_alerts.intent - quiet_hours_start.intent - quiet_hours_end.intent + - wake_me.intent adapt: - 'CreateAlarm' diff --git a/test/test_skill.py b/test/test_skill.py index df430568..563f8051 100644 --- a/test/test_skill.py +++ b/test/test_skill.py @@ -24,7 +24,6 @@ import lingua_franca import pytest import random -import sys import shutil import unittest import datetime as dt @@ -2297,6 +2296,24 @@ def _validate_alert_default_params(reminder: Alert): self.assertEqual(rotate_logs_reminder.repeat_frequency, dt.timedelta(hours=8)) + def test_wake_me_intent(self): + from skill_alerts.util.parse_utils import build_alert_from_intent + sea_tz = gettz("America/Los_Angeles") + wake_me_up = _get_message_from_file("wake_me_up_at_time_alarm.json") + wake_me_in = _get_message_from_file("wake_me_up_in_time_alarm.json") + + wake_me_up_alert = build_alert_from_intent(wake_me_up, AlertType.ALARM, + sea_tz) + wake_me_in_alert = build_alert_from_intent(wake_me_in, AlertType.ALARM, + sea_tz) + + self.assertEqual(wake_me_up_alert.alert_name, "7:00 AM alarm") + self.assertEqual(wake_me_in_alert.alert_name, "in 8 hours alarm") + self.assertEqual(wake_me_up_alert.next_expiration.time(), + dt.time(hour=7)) + self.assertAlmostEqual(wake_me_in_alert.next_expiration.timestamp(), + (dt.datetime.now(sea_tz) + + dt.timedelta(hours=8)).timestamp(), delta=2) class TestUIModels(unittest.TestCase): lingua_franca.load_language('en') @@ -2386,6 +2403,5 @@ def test_build_alarm_data(self): self.assertEqual(metric_display['alarmIndex'], get_alert_id(metric_alarm)) - if __name__ == '__main__': pytest.main() diff --git a/util/parse_utils.py b/util/parse_utils.py index 7b2f91a0..0dc824b5 100644 --- a/util/parse_utils.py +++ b/util/parse_utils.py @@ -1,6 +1,6 @@ # NEON AI (TM) SOFTWARE, Software Development Kit & Application Framework # All trademark and other rights reserved by their respective owners -# Copyright 2008-2022 Neongecko.com Inc. +# Copyright 2008-2024 Neongecko.com Inc. # Contributors: Daniel McKnight, Guy Daniels, Elon Gasper, Richard Leeds, # Regina Bloomstine, Casimiro Ferreira, Andrii Pernatii, Kirill Hrymailo # BSD-3 License