Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.0.1 #72

Merged
merged 12 commits into from
Apr 2, 2024
35 changes: 25 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,44 @@
# Changelog

## [0.3.2a4](https://github.com/NeonGeckoCom/skill-caffeinewiz/tree/0.3.2a4) (2023-06-28)
## [1.0.1a5](https://github.com/NeonGeckoCom/skill-caffeinewiz/tree/1.0.1a5) (2024-03-01)

[Full Changelog](https://github.com/NeonGeckoCom/skill-caffeinewiz/compare/0.3.2a3...0.3.2a4)
[Full Changelog](https://github.com/NeonGeckoCom/skill-caffeinewiz/compare/1.0.1a4...1.0.1a5)

**Merged pull requests:**

- Troubleshoot missing caffeine data [\#65](https://github.com/NeonGeckoCom/skill-caffeinewiz/pull/65) ([NeonDaniel](https://github.com/NeonDaniel))
- Update neon-minerva test dependency to stable spec [\#71](https://github.com/NeonGeckoCom/skill-caffeinewiz/pull/71) ([NeonDaniel](https://github.com/NeonDaniel))

## [0.3.2a3](https://github.com/NeonGeckoCom/skill-caffeinewiz/tree/0.3.2a3) (2023-06-15)
## [1.0.1a4](https://github.com/NeonGeckoCom/skill-caffeinewiz/tree/1.0.1a4) (2024-02-05)

[Full Changelog](https://github.com/NeonGeckoCom/skill-caffeinewiz/compare/0.3.2a2...0.3.2a3)
[Full Changelog](https://github.com/NeonGeckoCom/skill-caffeinewiz/compare/1.0.1a3...1.0.1a4)

**Merged pull requests:**

- Deprecate `create_skill` method and update `__init__` for best practices [\#64](https://github.com/NeonGeckoCom/skill-caffeinewiz/pull/64) ([NeonDaniel](https://github.com/NeonDaniel))
- Support ovos-utils 0.1 [\#70](https://github.com/NeonGeckoCom/skill-caffeinewiz/pull/70) ([NeonDaniel](https://github.com/NeonDaniel))

## [0.3.2a2](https://github.com/NeonGeckoCom/skill-caffeinewiz/tree/0.3.2a2) (2023-06-14)
## [1.0.1a3](https://github.com/NeonGeckoCom/skill-caffeinewiz/tree/1.0.1a3) (2024-01-15)

[Full Changelog](https://github.com/NeonGeckoCom/skill-caffeinewiz/compare/0.3.1...0.3.2a2)
[Full Changelog](https://github.com/NeonGeckoCom/skill-caffeinewiz/compare/1.0.1a2...1.0.1a3)

**Merged pull requests:**

- Update GH automation to best practices [\#63](https://github.com/NeonGeckoCom/skill-caffeinewiz/pull/63) ([NeonDaniel](https://github.com/NeonDaniel))
- Refactor mycroft-messagebus-client to ovos-bus-client [\#61](https://github.com/NeonGeckoCom/skill-caffeinewiz/pull/61) ([NeonDaniel](https://github.com/NeonDaniel))
- Update to use shared CommonQuery test class [\#69](https://github.com/NeonGeckoCom/skill-caffeinewiz/pull/69) ([NeonDaniel](https://github.com/NeonDaniel))

## [1.0.1a2](https://github.com/NeonGeckoCom/skill-caffeinewiz/tree/1.0.1a2) (2024-01-09)

[Full Changelog](https://github.com/NeonGeckoCom/skill-caffeinewiz/compare/1.0.1a1...1.0.1a2)

**Merged pull requests:**

- Update to better handle CQS exceptions [\#67](https://github.com/NeonGeckoCom/skill-caffeinewiz/pull/67) ([NeonDaniel](https://github.com/NeonDaniel))

## [1.0.1a1](https://github.com/NeonGeckoCom/skill-caffeinewiz/tree/1.0.1a1) (2024-01-09)

[Full Changelog](https://github.com/NeonGeckoCom/skill-caffeinewiz/compare/1.0.0...1.0.1a1)

**Merged pull requests:**

- Update Unit Tests [\#68](https://github.com/NeonGeckoCom/skill-caffeinewiz/pull/68) ([NeonDaniel](https://github.com/NeonDaniel))



Expand Down
111 changes: 59 additions & 52 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from bs4 import BeautifulSoup
from time import sleep

from lingua_franca import load_language
from ovos_bus_client import Message
from ovos_utils import classproperty
from ovos_utils.log import LOG
Expand All @@ -47,9 +48,8 @@
from neon_utils.skills.common_query_skill import \
CQSMatchLevel, CommonQuerySkill
from neon_utils import web_utils

from mycroft.util.parse import normalize
from mycroft.skills import intent_handler
from ovos_workshop.decorators import intent_handler
from lingua_franca.parse import normalize


TIME_TO_CHECK = 3600
Expand Down Expand Up @@ -83,6 +83,8 @@ def __init__(self, **kwargs):
self.from_caffeine_informer = list()
self._update_event = Event()
CommonQuerySkill.__init__(self, **kwargs)
from neon_utils.signal_utils import init_signal_bus
init_signal_bus(self.bus)

@classproperty
def runtime_requirements(self):
Expand Down Expand Up @@ -200,62 +202,66 @@ def handle_caffeine_intent(self, message):
self.speak_dialog("not_found", {'drink': drink})

def CQS_match_query_phrase(self, utt, message: Message = None):
# TODO: Language agnostic parsing here
if " of " in utt:
drink = utt.split(" of ", 1)[1]
elif " in " in utt:
drink = utt.split(" in ", 1)[1]
else:
drink = utt
drink = self._clean_drink_name(drink)
if not drink:
LOG.debug("No drink matched")
return None
try:
# TODO: Language agnostic parsing here
if " of " in utt:
drink = utt.split(" of ", 1)[1]
elif " in " in utt:
drink = utt.split(" in ", 1)[1]
else:
drink = utt
drink = self._clean_drink_name(drink)
if not drink:
LOG.debug("No drink matched")
return None

# If we wait very long, CommonQuery will time out
if not self._update_event.wait(5):
LOG.warning("CaffeineWiz is updating")
# If we wait very long, CommonQuery will time out
if not self._update_event.wait(5):
LOG.warning("CaffeineWiz is updating")

if self._drink_in_database(drink):
try:
to_speak, results = self._generate_drink_dialog(drink, message)
matched_drink = results[0][0]
LOG.debug(matched_drink)
if not to_speak:
# No dialog generated
if self._drink_in_database(drink):
try:
to_speak, results = self._generate_drink_dialog(drink, message)
matched_drink = results[0][0]
LOG.debug(matched_drink)
if not to_speak:
# No dialog generated
return None
if self.voc_match(utt, "caffeine"):
conf = CQSMatchLevel.EXACT
elif matched_drink.lower() in utt.lower():
# If the exact drink name was matched
# but caffeine not requested, consider this a general match
conf = CQSMatchLevel.GENERAL
else:
# We didn't match "caffeine" or an exact drink name
# this request isn't for this skill
return None
except Exception as e:
LOG.error(e)
LOG.error(drink)
return None
elif drink == utt:
LOG.debug("No drink extracted from utterance")
return None
else:
LOG.debug(f"No match for: {drink}")
if self.voc_match(utt, "caffeine"):
conf = CQSMatchLevel.EXACT
elif matched_drink.lower() in utt.lower():
# If the exact drink name was matched
# but caffeine not requested, consider this a general match
conf = CQSMatchLevel.GENERAL
conf = CQSMatchLevel.CATEGORY
results = None
to_speak = self.dialog_renderer.render("not_found",
{"drink": drink})
else:
# We didn't match "caffeine" or an exact drink name
# this request isn't for this skill
return None
except Exception as e:
LOG.error(e)
LOG.error(drink)
return None
elif drink == utt:
LOG.debug("No drink extracted from utterance")
LOG.info(f"results={results}, to_speak={to_speak}")
user = get_message_user(message) if message else 'local'
return utt, conf, to_speak, {"user": user,
"message": message.serialize() if message
else None,
"results": results}
except FileNotFoundError as e:
LOG.warning(f"Missing resource for lang: {self.lang} - {e}")
return None
else:
LOG.debug(f"No match for: {drink}")
to_speak = self.dialog_renderer.render("not_found",
{"drink": drink})
results = None
if self.voc_match(utt, "caffeine"):
conf = CQSMatchLevel.CATEGORY
else:
return None
LOG.info(f"results={results}, to_speak={to_speak}")
user = get_message_user(message) if message else 'local'
return utt, conf, to_speak, {"user": user,
"message": message.serialize() if message
else None,
"results": results}

def CQS_action(self, phrase, data):
results = data.get("results")
Expand Down Expand Up @@ -425,6 +431,7 @@ def _get_new_info(self, reply=False):

# Add Normalized drink names
def _normalize_drink_list(drink_list):
load_language(self.lang) # Necessary for intent tests
for drink in drink_list:
try:
parsed_name = normalize(drink[0].replace('-', ' '), 'en')
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
neon-utils~=1.0
neon-utils~=1.0,!=1.9.0
beautifulsoup4~=4.0
ovos-utils~=0.0.28
ovos-utils~=0.0, >=0.0.28
ovos-bus-client~=0.0.3
1 change: 1 addition & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
neon-minerva[padatious]~=0.2
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def find_resource_files():
url=f'https://github.com/NeonGeckoCom/{SKILL_NAME}',
license='BSD-3-Clause',
install_requires=get_requirements("requirements.txt"),
extras_require={"test": get_requirements("requirements/test.txt")},
author='Neongecko',
author_email='[email protected]',
long_description=long_description,
Expand Down
4 changes: 2 additions & 2 deletions skill.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"requirements": {
"python": [
"beautifulsoup4~=4.0",
"neon-utils~=1.0",
"neon-utils~=1.0,!=1.9.0",
"ovos-bus-client~=0.0.3",
"ovos-utils~=0.0.28"
"ovos-utils~=0.0, >=0.0.28"
],
"system": {},
"skill": []
Expand Down
33 changes: 3 additions & 30 deletions test/test_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,16 @@
# Specialized conversational reconveyance options from Conversation Processing Intelligence Corp.
# US Patents 2008-2021: US7424516, US20140161250, US20140177813, US8638908, US8068604, US8553852, US10530923, US10530924
# China Patent: CN102017585 - Europe Patent: EU2156652 - Patents Pending
import json
import os

import unittest

from copy import deepcopy
from os import mkdir
from os.path import dirname, join, exists
from mock import Mock
from ovos_utils.messagebus import FakeBus
from ovos_bus_client import Message
from mycroft.skills.skill_loader import SkillLoader


class TestSkill(unittest.TestCase):
@classmethod
def setUpClass(cls) -> None:
bus = FakeBus()
bus.run_in_thread()
skill_loader = SkillLoader(bus, dirname(dirname(__file__)))
skill_loader.load()
cls.skill = skill_loader.instance

# Define a directory to use for testing
cls.test_fs = join(dirname(__file__), "skill_fs")
if not exists(cls.test_fs):
mkdir(cls.test_fs)

# Override fs paths to use the test directory
cls.skill.settings_write_path = cls.test_fs
cls.skill.file_system.path = cls.test_fs
cls.skill._init_settings()
cls.skill.initialize()
from neon_minerva.tests.skill_unit_test_base import SkillTestCase

# Override speak and speak_dialog to test passed arguments
cls.skill.speak = Mock()
cls.skill.speak_dialog = Mock()

class TestSkillMethods(SkillTestCase):
def test_00_skill_init(self):
# Test any parameters expected to be set in init or initialize methods
from neon_utils.skills.common_query_skill import CommonQuerySkill
Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

__version__ = "1.0.0"
__version__ = "1.0.1"
Loading