From 9de48b789c0f1d4ae7c1de3066402260e08d31c5 Mon Sep 17 00:00:00 2001
From: Chris Pastl <christoph.pastl@fro.at>
Date: Wed, 19 Jun 2024 17:37:22 +0200
Subject: [PATCH] chore: remove fallback config

---
 config/engine-tests.yaml         |  4 ----
 config/sample.engine.docker.yaml |  4 ----
 config/sample.engine.yaml        |  4 ----
 sample.docker.env                |  4 ----
 src/aura_engine/base/config.py   |  2 --
 src/aura_engine/engine.py        | 26 ++++---------------------
 src/aura_engine/plugins/clock.py | 33 ++------------------------------
 tests/test_engine_config.py      |  2 --
 8 files changed, 6 insertions(+), 73 deletions(-)

diff --git a/config/engine-tests.yaml b/config/engine-tests.yaml
index c3574d63..d8226cbb 100644
--- a/config/engine-tests.yaml
+++ b/config/engine-tests.yaml
@@ -8,10 +8,6 @@ general:
   # Directory to store temporary data
   cache_dir: ./.cache
 
-  # Details for the Station Fallback
-  fallback_show_name: Random Music
-  fallback_show_id: -1
-
 log:
   # Directory where the log file resides
   directory: logs
diff --git a/config/sample.engine.docker.yaml b/config/sample.engine.docker.yaml
index 7b6fe3bb..706ca88a 100644
--- a/config/sample.engine.docker.yaml
+++ b/config/sample.engine.docker.yaml
@@ -8,10 +8,6 @@ general:
   # Directory to store temporary data
   cache_dir: /tmp
 
-  # Details for the Station Fallback
-  fallback_show_name: ${AURA_ENGINE_FALLBACK_SHOW_NAME}
-  fallback_show_id: ${AURA_ENGINE_FALLBACK_SHOW_ID}
-
 log:
   # Directory where the log file resides
   directory: logs
diff --git a/config/sample.engine.yaml b/config/sample.engine.yaml
index a6438ed0..1cc67b23 100644
--- a/config/sample.engine.yaml
+++ b/config/sample.engine.yaml
@@ -8,10 +8,6 @@ general:
   # Directory to store temporary data
   cache_dir: ./.cache
 
-  # Details for the Station Fallback
-  fallback_show_name: Random Music
-  fallback_show_id: -1
-
 log:
   # Directory where the log file resides
   directory: logs
diff --git a/sample.docker.env b/sample.docker.env
index acb95b70..5bfa426b 100644
--- a/sample.docker.env
+++ b/sample.docker.env
@@ -10,10 +10,6 @@ AURA_TANK_BASE_URL=http://127.0.0.1:8040/
 AURA_TANK_ENGINE_USER=engine
 AURA_TANK_ENGINE_PASSWORD=rather-secret
 
-# Details for the Station Fallback i.e. the default show when nothing is scheduled
-AURA_ENGINE_FALLBACK_SHOW_NAME=Random Music
-AURA_ENGINE_FALLBACK_SHOW_ID=-1
-
 # Offset in seconds how long it takes for Liquidsoap to actually execute a scheduler command; Crucial to keep things in sync
 AURA_ENGINE_LATENCY_OFFSET=0.5
 
diff --git a/src/aura_engine/base/config.py b/src/aura_engine/base/config.py
index 7f910e08..3e7ee6e3 100644
--- a/src/aura_engine/base/config.py
+++ b/src/aura_engine/base/config.py
@@ -35,8 +35,6 @@ template = {
     "general": {
         "socket_dir": str,
         "cache_dir": str,
-        "fallback_show_name": str,
-        "fallback_show_id": int,
     },
     "log": {
         "directory": str,
diff --git a/src/aura_engine/engine.py b/src/aura_engine/engine.py
index 94906cc6..4aae2501 100644
--- a/src/aura_engine/engine.py
+++ b/src/aura_engine/engine.py
@@ -55,14 +55,13 @@ class Engine:
     The Engine.
     """
 
-    instance = None
+    instance: Engine = None
     logger: logging.Logger
     config: confuse.Configuration
     engine_time_offset = 0.0
     scheduler: scheduler.AuraScheduler = None  # noqa: F811
-    event_dispatcher = None
-    client = None
-    playout = None
+    event_dispatcher: events.EngineEventDispatcher = None
+    playout: PlayoutClient = None
     playout_state = None
 
     def __init__(self):
@@ -104,13 +103,8 @@ class Engine:
         while not self.is_connected():
             self.logger.info(SU.yellow("Waiting for Liquidsoap to be running ..."))
             time.sleep(2)
-        self.logger.info(SU.green("Engine Core ------[ connected ]-------- Liquidsoap"))
-        result = self.engine_update_config()
-        if result == "OK":
-            self.logger.info(SU.green("Playout config successfully updated"))
-        else:
-            self.logger.info(SU.red("Error while updating playout config"))
 
+        self.logger.info(SU.green("Engine Core ------[ connected ]-------- Liquidsoap"))
         self.event_dispatcher.on_boot()
 
         self.logger.info(EngineSplash.splash_screen())
@@ -173,18 +167,6 @@ class Engine:
         """
         return self.playout_state
 
-    def engine_update_config(self):
-        """
-        Update the config of playout with the current values.
-        """
-        playout_config = {
-            "fallback_show_id": self.config.general.fallback_show_id,
-            "fallback_show_name": self.config.general.fallback_show_name,
-        }
-        json_config = json.dumps(playout_config, ensure_ascii=False)
-        response = self.playout.set_config(json_config)
-        return response
-
     def init_version(self) -> dict:
         """
         Get the versions of Engine components and store in configuration.
diff --git a/src/aura_engine/plugins/clock.py b/src/aura_engine/plugins/clock.py
index eb6e31a5..6495ea6d 100644
--- a/src/aura_engine/plugins/clock.py
+++ b/src/aura_engine/plugins/clock.py
@@ -31,7 +31,6 @@ TODO Refactor: It should be reviewed if it's worth storing all the current, addi
 from __future__ import annotations
 
 import logging
-from datetime import datetime, timedelta
 
 import confuse
 
@@ -75,41 +74,13 @@ class ClockInfoHandler:
         """
         Call when a fallback is activated.
 
-        Fallback means the station fallback audio source is played when:
-            1. no timeslot is available.
-            2. the current timefrome of the active timeslot provides no audio source/playlists.
-
-        TODO In the future case (1) should technically not happen, as "Virtual Timeslots" ensure
-        there is always some timeslot available, even without any playlists/media sources assigned.
-
         Args:
-            timeslot (Timeslot): The active timeslot, if available. Can be `None`.
+            timeslot (Timeslot): The active timeslot.
         """
         scheduler = self.engine.scheduler
         upcoming_timeslots: list[domain.Timeslot] = scheduler.timetable.get_next_timeslots()
 
-        # Check if we are within a valid timeslot
-        if timeslot:
-            self.logger.info(f"Fallback activated within timeslot '{timeslot}'")
-        else:
-            self.logger.info("Fallback activated outsite of timeslot")
-
-            # Interpolate timeslot-less slot (in the future provided by Virtual Timeslots)
-            virtual_start_time = datetime.now()
-            virtual_end_time = virtual_start_time + timedelta(hours=1)
-            if len(upcoming_timeslots) > 0:
-                virtual_end_time = upcoming_timeslots[0].get_start()
-
-            # 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.logger.info(f"Fallback activated within timeslot '{timeslot}'")
         self.post_clock_info(timeslot, None, upcoming_timeslots)
 
     def on_play(self, item: domain.PlaylistItem):
diff --git a/tests/test_engine_config.py b/tests/test_engine_config.py
index 52931975..8ecb35c6 100644
--- a/tests/test_engine_config.py
+++ b/tests/test_engine_config.py
@@ -53,8 +53,6 @@ class TestConfig(unittest.TestCase):
         # general
         self.assertRegex(cfg.general.socket_dir, directory_regex)
         self.assertRegex(cfg.general.cache_dir, directory_regex)
-        self.assertIsInstance(cfg.general.fallback_show_name, str)
-        self.assertIsInstance(cfg.general.fallback_show_id, int)
 
         # log
         self.assertTrue(os.path.isdir(cfg.log.directory))
-- 
GitLab