Skip to content
Snippets Groups Projects
Commit c8b213a0 authored by David Trattnig's avatar David Trattnig
Browse files

refactor: adapt according to new domain model

parent 4a0d869c
No related branches found
No related tags found
1 merge request!35ORM-less scheduling
Pipeline #7708 failed
...@@ -36,8 +36,8 @@ import confuse ...@@ -36,8 +36,8 @@ import confuse
import aura_engine.scheduling.domain as domain import aura_engine.scheduling.domain as domain
from aura_engine.base.api import SimpleRestApi from aura_engine.base.api import SimpleRestApi
from aura_engine.base.config import AuraConfig from aura_engine.base.config import AuraConfig
from aura_engine.base.lang import DotDict
from aura_engine.resources import ResourceUtil from aura_engine.resources import ResourceUtil
from aura_engine.scheduling.scheduler import AuraScheduler
class ClockInfoHandler: class ClockInfoHandler:
...@@ -69,40 +69,46 @@ class ClockInfoHandler: ...@@ -69,40 +69,46 @@ class ClockInfoHandler:
# This will be part of the coming "default station playlist" logic # This will be part of the coming "default station playlist" logic
pass pass
def on_fallback_active(self, timeslot, fallback_name): def on_fallback_active(self, timeslot: domain.Timeslot):
""" """
Call when a fallback is activated. Call when a fallback is activated.
"""
if timeslot:
# Only update the current show to the fallback show,
# in case no timeslot is scheduled
return
self.logger.info(f"Fallback '{fallback_name}' activated, clock update required") Fallback means the station fallback audio source is played when:
fallback_show_id = self.config.general.fallback_show_id 1. no timeslot is available.
fallback_show_name = self.config.general.fallback_show_name 2. the current timefrome of the active timeslot provides no audio source/playlists.
# Interpolate timeslot-less slot TODO In the future case (1) should technically not happen, as "Virtual Timeslots" ensure
# TODO start time to be calculated based on previous timeslot (future station logic) there is always some timeslot available, even without any playlists/media sources assigned.
scheduler = self.engine.scheduler
upcoming_timeslots: [domain.Timeslot] = scheduler.timetable.get_next_timeslots() Args:
virtual_start_time = datetime.now() timeslot (Timeslot): The active timeslot, if available. Can be `None`.
virtual_end_time = virtual_start_time + timedelta(hours=1) """
if len(upcoming_timeslots) > 0:
virtual_end_time = upcoming_timeslots[0].get_start() # Check if we are within a valid timeslot
if timeslot:
fallback_timeslot = DotDict( self.logger.info(f"Fallback activated within timeslot '{timeslot}'")
{ else:
"timeslotId": -1, self.logger.info("Fallback activated outsite of timeslot")
"timeslotStart": virtual_start_time,
"timeslotEnd": virtual_end_time, # Interpolate timeslot-less slot (in the future provided by Virtual Timeslots)
"showId": fallback_show_id, scheduler: AuraScheduler = self.engine.scheduler
"showName": fallback_show_name, upcoming_timeslots: list[domain.Timeslot] = scheduler.timetable.get_next_timeslots()
"playlistId": -1, virtual_start_time = datetime.now()
"playlistType": -1, virtual_end_time = virtual_start_time + timedelta(hours=1)
} if len(upcoming_timeslots) > 0:
) virtual_end_time = upcoming_timeslots[0].get_start()
self.post_clock_info(-1, None, fallback_timeslot, upcoming_timeslots)
# Create fallback timeslot if event was triggered outsite of a valid timeslot
fallback_show_id = self.config.general.fallback_show_id
fallback_show_name = self.config.general.fallback_show_name
fallback_show = domain.Show(
fallback_show_id, fallback_show_name, None, None, None, None
)
timeslot = domain.Timeslot(
-1, None, virtual_start_time, virtual_end_time, fallback_show, None
)
self.post_clock_info(timeslot, None, upcoming_timeslots)
def on_play(self, _): def on_play(self, _):
""" """
...@@ -122,13 +128,13 @@ class ClockInfoHandler: ...@@ -122,13 +128,13 @@ class ClockInfoHandler:
active_playlist: domain.Playlist = active_timeslot.get_current_playlist() active_playlist: domain.Playlist = active_timeslot.get_current_playlist()
upcoming_timeslots = scheduler.timetable.get_next_timeslots() upcoming_timeslots = scheduler.timetable.get_next_timeslots()
self.post_clock_info(active_playlist, active_timeslot, upcoming_timeslots) self.post_clock_info(active_timeslot, active_playlist, upcoming_timeslots)
def post_clock_info( def post_clock_info(
self, self,
active_playlist: domain.Playlist,
active_timeslot: domain.Timeslot, active_timeslot: domain.Timeslot,
upcoming_timeslots: [domain.Timeslot], active_playlist: domain.Playlist,
upcoming_timeslots: list[domain.Timeslot],
): ):
""" """
Post current information on timeslots and playlist to the Engine API clock endpoint. Post current information on timeslots and playlist to the Engine API clock endpoint.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment