From 61d1285ea4e5308c02e067ddad4840a54c9e9b5b Mon Sep 17 00:00:00 2001 From: miro Date: Thu, 9 Jan 2025 21:46:36 +0000 Subject: [PATCH] fix: stop DRY no need for 2 handlers, decrease complexity the only difference is an emitted event that is not listened too anywhere --- ovos_workshop/skills/ovos.py | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/ovos_workshop/skills/ovos.py b/ovos_workshop/skills/ovos.py index 4423d67..9c420c1 100644 --- a/ovos_workshop/skills/ovos.py +++ b/ovos_workshop/skills/ovos.py @@ -1166,7 +1166,7 @@ def _register_system_event_handlers(self): """ Register default messagebus event handlers """ - self.add_event('mycroft.stop', self._handle_stop, speak_errors=False) + self.add_event('mycroft.stop', self._handle_session_stop, speak_errors=False) self.add_event(f"{self.skill_id}.stop", self._handle_session_stop, speak_errors=False) self.add_event(f"{self.skill_id}.stop.ping", self._handle_stop_ack, speak_errors=False) @@ -1356,22 +1356,6 @@ def _handle_session_stop(self, message: Message): self.__responses[sess.session_id] = None # abort any ongoing get_response self.bus.emit(message.reply(f"{self.skill_id}.stop.response", data)) - def _handle_stop(self, message): - """Handler for the "mycroft.stop" signal. Runs the user defined - `stop()` method. - """ - message.context['skill_id'] = self.skill_id - self.bus.emit(message.forward(self.skill_id + ".stop")) - sess = SessionManager.get(message) - try: - stopped = self.stop_session(sess) or self.stop() or False - LOG.debug(f"{self.skill_id} stopped: {stopped}") - if stopped: - self.bus.emit(message.reply("mycroft.stop.handled", - {"by": "skill:" + self.skill_id})) - except Exception as e: - self.log.exception(f'Failed to stop skill: {self.skill_id}: {e}') - def default_shutdown(self): """ Parent function called internally to shut down everything.