Skip to content

Commit

Permalink
fix/session manager update
Browse files Browse the repository at this point in the history
when a session changes it needs to update the reference in SessionManager
  • Loading branch information
JarbasAl committed Sep 30, 2023
1 parent 6bf4c7d commit 400ca9a
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions ovos_bus_client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand All @@ -347,13 +348,15 @@ 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):
"""
Mark a skill as not expecting a response (handling intents normally)
@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):
"""
Expand All @@ -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):
"""
Expand All @@ -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:
"""
Expand Down Expand Up @@ -403,6 +408,7 @@ def clear(self):
"""
self.active_skills = []
self.history = []
SessionManager.update(self)

def serialize(self) -> dict:
"""
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()

0 comments on commit 400ca9a

Please sign in to comment.