Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/session manager update #51

Merged
merged 1 commit into from
Sep 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Loading