Skip to content

Commit

Permalink
Add forwards-compat with ovos-core 0.0.8 CommonQuery
Browse files Browse the repository at this point in the history
Mark CommonQuerySkill as deprecated
  • Loading branch information
NeonDaniel committed Apr 4, 2024
1 parent 4003b27 commit 41d963e
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion neon_utils/skills/common_query_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from ovos_workshop.decorators.layers import IntentLayers
from ovos_workshop.skills.common_query_skill import CQSMatchLevel, CQSVisualMatchLevel
from ovos_workshop.skills.common_query_skill import CommonQuerySkill as _CQS
from ovos_workshop.decorators.compat import backwards_compat
from ovos_utils.file_utils import resolve_resource_file
from ovos_utils.log import log_deprecation
from neon_utils.skills.neon_skill import NeonSkill
Expand Down Expand Up @@ -76,6 +77,9 @@ class CommonQuerySkill(NeonSkill, _CQS):
answers from several skills presenting the best one available.
"""
def __init__(self, *args, **kwargs):
log_deprecation("This base class is deprecated. Implement "
"`ovos_workshop.skills.common_query_skill."
"CommonQuerySkill`", "2.0.0")
# these should probably be configurable
self.level_confidence = {
CQSMatchLevel.EXACT: 0.9,
Expand Down Expand Up @@ -130,7 +134,7 @@ def __calc_confidence(self, match, phrase, level):
else:
return 0.0 # should never happen

def __handle_query_action(self, message):
def __handle_query_classic(self, message):
"""Message handler for question:action.
Extracts phrase and data from message forward this to the skills
Expand All @@ -146,6 +150,27 @@ def __handle_query_action(self, message):
self.bus.emit(message.forward("mycroft.skill.handler.complete",
{"handler": "common_query"}))

@backwards_compat(classic_core=__handle_query_classic,
pre_008=__handle_query_classic)
def __handle_query_action(self, message):
"""
If this skill's response was spoken to the user, this method is called.
Phrase and callback data from `CQS_match_query_phrase` will be passed
to the `CQS_action` method.
@param message: `question:action` message
"""
if message.data["skill_id"] != self.skill_id:
# Not for this skill!
return
phrase = message.data["phrase"]
data = message.data.get("callback_data") or {}
if data.get("answer"):
self.speak(data["answer"])
# Invoke derived class to provide playback data
self.CQS_action(phrase, data)
self.bus.emit(message.forward("mycroft.skill.handler.complete",
{"handler": "common_query"}))

def __handle_question_query(self, message):
# Override ovos-workshop implementation that doesn't pass `message`
search_phrase = message.data["phrase"]
Expand Down

0 comments on commit 41d963e

Please sign in to comment.