Skip to content

Commit

Permalink
fix: update store_state to return tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
dreulavelle committed Nov 14, 2024
1 parent d140838 commit 716801c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/program/media/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,13 @@ def __generate_composite_key(item: dict) -> str | None:
item_type = item.get("type", "unknown")
return f"{item_type}_{trakt_id}"

def store_state(self, given_state=None) -> None:
def store_state(self, given_state=None) -> tuple[States, States]:
"""Store the state of the item."""
new_state = given_state if given_state else self._determine_state()
if self.last_state and self.last_state != new_state:
sse_manager.publish_event("item_update", {"last_state": self.last_state, "new_state": new_state, "item_id": self.id})
self.last_state = new_state
return (self.last_state, new_state)

def is_stream_blacklisted(self, stream: Stream):
"""Check if a stream is blacklisted for this item."""
Expand Down
7 changes: 3 additions & 4 deletions src/program/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,10 @@ def _update_ongoing(self) -> None:
try:
item = session.execute(select(MediaItem).filter_by(id=item_id)).unique().scalar_one_or_none()
if item:
previous_state = item.last_state
item.store_state()
if previous_state != item.last_state:
previous_state, new_state = item.store_state()
if previous_state != new_state:
self.em.add_event(Event(emitted_by="UpdateOngoing", item_id=item_id))
logger.debug(f"Updated state for {item.log_string} ({item.id}) from {previous_state} to {item.last_state}")
logger.debug(f"Updated state for {item.log_string} ({item.id}) from {previous_state.name} to {new_state.name}")
counter += 1
session.merge(item)
session.commit()
Expand Down

0 comments on commit 716801c

Please sign in to comment.