From 400ca9a51714d031386bdc859469b2d659b74275 Mon Sep 17 00:00:00 2001 From: JarbasAi Date: Sat, 30 Sep 2023 04:22:05 +0100 Subject: [PATCH] fix/session manager update when a session changes it needs to update the reference in SessionManager --- ovos_bus_client/session.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ovos_bus_client/session.py b/ovos_bus_client/session.py index ae97858..8ae41d3 100644 --- a/ovos_bus_client/session.py +++ b/ovos_bus_client/session.py @@ -329,6 +329,7 @@ def touch(self): update the touch_time on the session """ self.touch_time = int(time.time()) + SessionManager.update(self) def expired(self) -> bool: """ @@ -347,6 +348,7 @@ def enable_response_mode(self, skill_id: str): @param skill_id: ID of skill expecting a response """ self.utterance_states[skill_id] = UtteranceState.RESPONSE.value + SessionManager.update(self) def disable_response_mode(self, skill_id: str): """ @@ -354,6 +356,7 @@ def disable_response_mode(self, skill_id: str): @param skill_id: ID of skill expecting a response """ self.utterance_states[skill_id] = UtteranceState.INTENT.value + SessionManager.update(self) def activate_skill(self, skill_id: str): """ @@ -364,6 +367,7 @@ def activate_skill(self, skill_id: str): self.deactivate_skill(skill_id) # add skill with timestamp to start of active list self.active_skills.insert(0, [skill_id, time.time()]) + SessionManager.update(self) def deactivate_skill(self, skill_id: str): """ @@ -374,6 +378,7 @@ def deactivate_skill(self, skill_id: str): if skill_id in active_ids: idx = active_ids.index(skill_id) self.active_skills.pop(idx) + SessionManager.update(self) def is_active(self, skill_id: str) -> bool: """ @@ -403,6 +408,7 @@ def clear(self): """ self.active_skills = [] self.history = [] + SessionManager.update(self) def serialize(self) -> dict: """ @@ -442,6 +448,7 @@ def update_history(self, message: Message = None): m["context"] = {} # clear personal data self.history.append((m, time.time())) self._prune_history() + SessionManager.update(self) @staticmethod def deserialize(data: dict): @@ -558,13 +565,15 @@ def update(sess: Session, make_default: bool = False): """ if not sess: raise ValueError(f"Expected Session and got None") - sess.touch() + if make_default: sess.session_id = "default" LOG.debug(f"replacing default session with: {sess.serialize()}") - SessionManager.default_session = sess else: LOG.debug(f"session updated: {sess.session_id}") + + if sess.session_id == "default": + SessionManager.default_session = sess SessionManager.sessions[sess.session_id] = sess @staticmethod @@ -598,4 +607,5 @@ def touch(message: Message = None): @param message: Message to get Session for to update """ - SessionManager.get(message).touch() + sess = SessionManager.get(message) + sess.touch()