diff --git a/ocp_pipeline/legacy.py b/ocp_pipeline/legacy.py index 6fb0709..f17cb12 100644 --- a/ocp_pipeline/legacy.py +++ b/ocp_pipeline/legacy.py @@ -1,7 +1,7 @@ import time from typing import Tuple, Optional -from ovos_bus_client.message import Message +from ovos_bus_client.message import Message, dig_for_message from ovos_bus_client.util import wait_for_reply from ovos_utils.ocp import MediaType, PlaybackType, MediaEntry @@ -67,19 +67,19 @@ def handle_cps_response(self, message): # Collect all replies until the timeout self.query_replies[message.data["phrase"]].append(message.data) - def send_query(self, phrase): + def send_query(self, phrase, message: Optional[Message] = None): self.query_replies[phrase] = [] self.query_extensions[phrase] = [] - self.bus.emit(Message('play:query', - {"phrase": phrase})) + message = message or dig_for_message() or Message("") + self.bus.emit(message.forward('play:query',{"phrase": phrase})) def get_results(self, phrase): if self.query_replies.get(phrase): return [self.cps2media(r) for r in self.query_replies[phrase]] return [] - def search(self, phrase, timeout=5): - self.send_query(phrase) + def search(self, phrase, timeout=5, message: Optional[Message] = None): + self.send_query(phrase, message) self.waiting = True start_ts = time.time() while self.waiting and time.time() - start_ts <= timeout: diff --git a/ocp_pipeline/opm.py b/ocp_pipeline/opm.py index 42ad536..4dbdb63 100644 --- a/ocp_pipeline/opm.py +++ b/ocp_pipeline/opm.py @@ -14,8 +14,7 @@ from ovos_bus_client.session import SessionManager from ovos_config import Configuration from ovos_plugin_manager.ocp import available_extractors -from ovos_plugin_manager.templates.pipeline import IntentHandlerMatch, ConfidenceMatcherPipeline, PipelineStageMatcher, \ - PipelineMatch +from ovos_plugin_manager.templates.pipeline import IntentHandlerMatch, ConfidenceMatcherPipeline from ovos_utils.lang import standardize_lang_tag, get_language_dir from ovos_utils.log import LOG, deprecated, log_deprecation from ovos_utils.messagebus import FakeBus @@ -1062,7 +1061,7 @@ def match_fallback(self, utterances: List[str], lang: str, message: Message = No return self.match_low(utterances, lang, message) @deprecated("match_legacy is deprecated! use MycroftCPSLegacyPipeline class directly instead", "2.0.0") - def match_legacy(self, utterances: List[str], lang: str, message: Message = None) -> Optional[PipelineMatch]: + def match_legacy(self, utterances: List[str], lang: str, message: Message = None) -> Optional[IntentHandlerMatch]: """ match legacy mycroft common play skills (must import from deprecated mycroft module) not recommended, legacy support only @@ -1071,17 +1070,19 @@ def match_legacy(self, utterances: List[str], lang: str, message: Message = None return MycroftCPSLegacyPipeline(self.bus, self.config).match(utterances, lang, message) -class MycroftCPSLegacyPipeline(PipelineStageMatcher): +class MycroftCPSLegacyPipeline(ConfidenceMatcherPipeline, OVOSAbstractApplication): def __init__(self, bus: Optional[Union[MessageBusClient, FakeBus]] = None, config: Optional[Dict] = None): - super().__init__(bus, config) + OVOSAbstractApplication.__init__(self, bus=bus or FakeBus(), + skill_id=OCP_ID, resources_dir=f"{dirname(__file__)}") + ConfidenceMatcherPipeline.__init__(self, bus, config) self.mycroft_cps = LegacyCommonPlay(self.bus) OCPPipelineMatcher.load_intent_files() - self.bus.on("ocp:legacy_cps", self.handle_legacy_cps) + self.add_event("ocp:legacy_cps", self.handle_legacy_cps, is_intent=True) ############ # Legacy Mycroft CommonPlay skills - def match(self, utterances: List[str], lang: str, message: Message = None) -> Optional[PipelineMatch]: + def match(self, utterances: List[str], lang: str, message: Message = None) -> Optional[IntentHandlerMatch]: """ match legacy mycroft common play skills (must import from deprecated mycroft module) not recommended, legacy support only @@ -1104,13 +1105,11 @@ def match(self, utterances: List[str], lang: str, message: Message = None) -> Op if match["name"] == "play": LOG.info(f"Legacy Mycroft CommonPlay match: {match}") utterance = match["entities"].pop("query") - self.bus.emit(Message("ocp:legacy_cps", - {"query": utterance, "conf": 0.7})) - return PipelineMatch(handled=True, - match_data={"query": utterance, - "conf": 0.7}, - skill_id=OCP_ID, - utterance=utterance) + return IntentHandlerMatch(match_type="ocp:legacy_cps", + match_data={"query": utterance, + "conf": 0.7}, + skill_id=OCP_ID, + utterance=utterance) def match_medium(self, utterances: List[str], lang: str, message: Message = None) -> Optional[IntentHandlerMatch]: return None @@ -1121,7 +1120,7 @@ def match_low(self, utterances: List[str], lang: str, message: Message = None) - def handle_legacy_cps(self, message: Message): """intent handler for legacy CPS matches""" utt = message.data["query"] - res = self.mycroft_cps.search(utt) + res = self.mycroft_cps.search(utt, message=message) if res: best = OCPPipelineMatcher.select_best([r[0] for r in res], message) if best: