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

update imports #160

Merged
merged 2 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions ovos_workshop/intents.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# adapt is optional

class Intent:
def __init__(self, name, requires, at_least_one, optional):
def __init__(self, name, requires=None, at_least_one=None, optional=None):
"""Create Intent object
Args:
name(str): Name for Intent
Expand All @@ -21,9 +21,9 @@ def __init__(self, name, requires, at_least_one, optional):
optional(list): Optional Entities used by the intent
"""
self.name = name
self.requires = requires
self.at_least_one = at_least_one
self.optional = optional
self.requires = requires or []
self.at_least_one = at_least_one or []
self.optional = optional or []

def validate(self, tags, confidence):
"""Using this method removes tags from the result of validate_with_tags
Expand Down Expand Up @@ -488,9 +488,6 @@ def open_intent_envelope(message):
"""
Convert dictionary received over messagebus to Intent.
"""
# TODO can this method be fully removed from ovos_utils ?
from adapt.intent import Intent

intent_dict = message.data
return Intent(intent_dict.get('name'),
intent_dict.get('requires'),
Expand Down
28 changes: 14 additions & 14 deletions ovos_workshop/skills/ovos.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@
from ovos_bus_client.apis.ocp import OCPInterface
from ovos_bus_client.message import Message, dig_for_message
from ovos_bus_client.session import SessionManager, Session
from ovos_bus_client.util import get_message_lang
from ovos_plugin_manager.language import OVOSLangTranslationFactory, OVOSLangDetectionFactory
from ovos_utils import camel_case_split, classproperty
from ovos_utils.dialog import get_dialog, MustacheDialogRenderer
from ovos_utils.events import EventContainer, EventSchedulerInterface
from ovos_utils.file_utils import FileWatcher
from ovos_utils.events import get_handler_name, create_wrapper
from ovos_utils.file_utils import FileWatcher, resolve_resource_file
from ovos_utils.gui import get_ui_directories
from ovos_utils.json_helper import merge_dict
from ovos_utils.log import LOG, log_deprecation, deprecated
from ovos_utils.events import get_handler_name, create_wrapper
from ovos_bus_client.util import get_message_lang
from ovos_utils.parse import match_one
from ovos_utils.process_utils import RuntimeRequirements
from ovos_utils.skills import get_non_properties
Expand Down Expand Up @@ -1224,14 +1224,9 @@ def register_intent(self, intent_parser: Union[IntentBuilder, Intent, str],
file to parse utterance for the handler.
handler (func): function to register with intent
"""
if isinstance(intent_parser, IntentBuilder):
intent_parser = intent_parser.build()
if (isinstance(intent_parser, str) and
intent_parser.endswith('.intent')):
return self.register_intent_file(intent_parser, handler)
elif not isinstance(intent_parser, Intent):
raise ValueError('"' + str(intent_parser) + '" is not an Intent')

return self._register_adapt_intent(intent_parser, handler)

def register_intent_file(self, intent_file: str, handler: callable):
Expand Down Expand Up @@ -1418,6 +1413,11 @@ def _register_adapt_intent(self,
intent_parser: Intent object to parse utterance for the handler.
handler (func): function to register with intent
"""
if isinstance(intent_parser, IntentBuilder):
intent_parser = intent_parser.build()
elif not isinstance(intent_parser, Intent):
raise ValueError('"' + str(intent_parser) + '" is not an Intent')

# Default to the handler's function name if none given
is_anonymous = not intent_parser.name
name = intent_parser.name or handler.__name__
Expand Down Expand Up @@ -1882,19 +1882,19 @@ def _real_wait_response(self, is_cancel, validator, on_fail, num_retries,
else:
self.bus.emit(message.reply('mycroft.mic.listen'))

@staticmethod
def __acknowledge_classic():
def __acknowledge_classic(self):
"""
Acknowledge a successful request.

This method plays a sound to acknowledge a request that does not
require a verbal response. This is intended to provide simple feedback
to the user that their request was handled successfully.
"""
# DEPRECATED - note that this is a staticmethod and uses the old endpoint
# the OVOSSkill class does things properly
from ovos_utils.sound import play_acknowledge_sound
return play_acknowledge_sound()
audio_file = self.config_core.get('sounds', {}).get('acknowledge',
'snd/acknowledge.mp3')
audio_file = resolve_resource_file(audio_file)
if audio_file:
return play_audio(audio_file)

@backwards_compat(classic_core=__acknowledge_classic)
def acknowledge(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ def wait_for_new_converse():
return wait_for_new_converse


@mock.patch('mycroft.configuration.Configuration')
@mock.patch('ovos_workshop.skills.ovos.Configuration')
def create_skill(mock_conf, lang='en-us'):
cfg = base_config()
cfg["lang"] = lang
mock_conf.get.return_value = cfg
mock_conf.return_value = cfg
bus = mock.Mock()
skill = MycroftSkill(name='test_skill')
skill.root_dir = join(dirname(__file__), 'test_skill')
Expand Down Expand Up @@ -233,7 +234,6 @@ def test_ask_yesno_other(self):
response = skill.ask_yesno('Do you like breakfast')
self.assertEqual(response, 'I am a fish')

@skip("TODO - fix me")
@mock.patch('ovos_bus_client.message.dig_for_message')
def test_ask_yesno_german(self, dig_mock):
"""Check that when the skill is set to german it responds to "ja"."""
Expand Down
Loading