From ac69618d29ba288fee832bc3f3e1f1d3f1069744 Mon Sep 17 00:00:00 2001 From: Omar Amin <65174210+omaramin-2000@users.noreply.github.com> Date: Sat, 21 Feb 2026 16:25:16 +0200 Subject: [PATCH] Add volume handling to Preferences and persistence method Added volume attribute to Preferences and implemented persist_volume method to save normalized media volume. --- linux_voice_assistant/models.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/linux_voice_assistant/models.py b/linux_voice_assistant/models.py index dc433a6..e72f1a8 100644 --- a/linux_voice_assistant/models.py +++ b/linux_voice_assistant/models.py @@ -57,6 +57,7 @@ class AvailableWakeWord: @dataclass class Preferences: active_wake_words: List[str] = field(default_factory=list) + volume: Optional[float] = None thinking_sound: int = 0 # 0 = disabled, 1 = enabled @@ -92,6 +93,7 @@ class ServerState: thinking_sound_enabled: bool = False muted: bool = False connected: bool = False + volume: float = 1.0 def save_preferences(self) -> None: """Save preferences as JSON.""" @@ -101,3 +103,18 @@ class ServerState: json.dump( asdict(self.preferences), preferences_file, ensure_ascii=False, indent=4 ) + + def persist_volume(self, volume: float) -> None: + """Persist the normalized media volume (0.0 - 1.0).""" + clamped_volume = max(0.0, min(1.0, volume)) + + if ( + abs(self.volume - clamped_volume) < 0.0001 + and self.preferences.volume is not None + and abs(self.preferences.volume - clamped_volume) < 0.0001 + ): + return + + self.volume = clamped_volume + self.preferences.volume = clamped_volume + self.save_preferences()