From 43241600149bef67032373b0c93efa2a6829e58c Mon Sep 17 00:00:00 2001 From: Aaro Varis Date: Wed, 18 Feb 2026 16:35:01 +0200 Subject: [PATCH] Refactor AudioPlayer initialization and update audio file path handling in main --- src/__init__.py | 1 - src/audio.py | 9 +++++++-- src/main.py | 5 ++++- 3 files changed, 11 insertions(+), 4 deletions(-) delete mode 100644 src/__init__.py diff --git a/src/__init__.py b/src/__init__.py deleted file mode 100644 index 4d49332..0000000 --- a/src/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# Alarm Clock IoT Application diff --git a/src/audio.py b/src/audio.py index a3e284f..b27e795 100644 --- a/src/audio.py +++ b/src/audio.py @@ -2,12 +2,17 @@ import subprocess from typing import Callable class AudioPlayer: + file_path: str + loop: bool + current_stop_function: Callable[[], None] | None = None def __init__(self, file_path: str, loop: bool = False): + self.file_path = file_path + self.loop = loop self.current_stop_function: Callable[[], None] | None = None - def play(self, file_path: str, loop: bool = False): + def play(self): """Play the specified audio file, stopping any currently playing audio.""" self.stop() # Stop any currently playing audio - self.current_stop_function = play_audio(file_path, loop) + self.current_stop_function = play_audio(self.file_path, self.loop) def stop(self): """Stop any currently playing audio.""" if self.current_stop_function: diff --git a/src/main.py b/src/main.py index 33109b6..f7387ad 100644 --- a/src/main.py +++ b/src/main.py @@ -2,9 +2,12 @@ from .config import SHELLY_DEVICE_ID from .shelly import ShellyDevice from .audio import AudioPlayer from .alarm_clock import AlarmClock +from os import path shellyDevice = ShellyDevice(SHELLY_DEVICE_ID) -audio_player = AudioPlayer('./boxing_bell_multiple.wav', loop=True) + +audioFileAbsolutePath = path.abspath('./boxing_bell_multiple.wav') +audio_player = AudioPlayer(audioFileAbsolutePath, loop=True) def main():