From 8e71cca295b4f0dcad8c73816f83bd9680352df0 Mon Sep 17 00:00:00 2001 From: JarbasAI <33701864+JarbasAl@users.noreply.github.com> Date: Thu, 20 Jun 2024 19:37:15 +0100 Subject: [PATCH] fix/activation+session (#212) do not activate/deactivate the skill if there was no change to Session (avoid bus spam) update session data so the skill already sees the skill as active, otherwise since it was async the Session was outdated in the intent handler --- ovos_workshop/skills/ovos.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/ovos_workshop/skills/ovos.py b/ovos_workshop/skills/ovos.py index 966fac32..8a0c96ae 100644 --- a/ovos_workshop/skills/ovos.py +++ b/ovos_workshop/skills/ovos.py @@ -1548,17 +1548,29 @@ def _on_event_start(self, message: Message, handler_info: str, """ Indicate that the skill handler is starting. - activation (bool, optional): activate skill if True, deactivate if False, do nothing if None + activation (bool, optional): activate skill if True, + deactivate if False, + do nothing if None """ if handler_info: # Indicate that the skill handler is starting if requested msg_type = handler_info + '.start' message.context["skill_id"] = self.skill_id self.bus.emit(message.forward(msg_type, skill_data)) - if activation is True: + + # in latest versions of ovos-core the skill is + # activated by the intent service and this step is no longer needed + sess = SessionManager.get(message) + is_active = any([s[0] == self.skill_id + for s in sess.active_skills]) + if not is_active and activation is True: self.activate() - elif activation is False: + sess.activate_skill(self.skill_id) + message.context["session"] = sess.serialize() + elif is_active and activation is False: self.deactivate() + sess.deactivate_skill(self.skill_id) + message.context["session"] = sess.serialize() def _on_event_end(self, message: Message, handler_info: str, skill_data: dict, is_intent: bool = False):