Restore stop word sensitivity from preferences on startup (#394)
* Restore stop word sensitivity from preferences on startup The Home Assistant number entity persists preferences.stop_word_sensitivity whenever it changes, but nothing ever read it back. main() did not pass stop_word_threshold when constructing ServerState, so it always took the dataclass default of 0.5, and lowering the sensitivity in Home Assistant silently reverted at the next restart. volume and mic_volume are restored at startup, and the two wake word sensitivities are restored when wake models load. Only the stop word was missed, so the block that syncs all three sensitivity entities back to Home Assistant was pushing a default it had never loaded. Restored alongside volume and clamped the same way. The resolution lives in a small helper so it can be covered by tests. * Move the threshold helper to models.py so tests do not import __main__ CI has no PulseAudio daemon. Importing linux_voice_assistant.__main__ pulls in `import soundcard as sc`, and soundcard/pulseaudio.py instantiates _PulseAudio() at module scope, which asserts on a live connection. So the four new tests failed on the runner while passing locally, where a daemon happens to be running. That is also why no other test in the suite imports __main__, and why the existing tests in test_main.py re-implement the logic they check rather than calling it. initial_stop_word_threshold() now lives in models.py, which owns both fields it resolves between: Preferences.stop_word_sensitivity and ServerState.stop_word_threshold. It imports cleanly, test_models.py already imports it, and the reference to the ServerState default becomes local. Behaviour is unchanged. Verified by reproducing the CI environment locally with PULSE_SERVER pointed at a nonexistent socket: 4 failed before, 298 pass after. --------- Co-authored-by: ryan felder <7475484+ryanfelder@users.noreply.github.com> Co-authored-by: Omar Amin <65174210+omaramin-2000@users.noreply.github.com>
This commit is contained in:
3 files changed
+44
-1
No files matched your search
@@ -282,3 +282,30 @@ class TestPersistMicNoise:
|
||||
with patch.object(state, "save_preferences") as mock_save:
|
||||
state.persist_mic_noise(4.0)
|
||||
mock_save.assert_called_once()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# initial_stop_word_threshold()
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class TestInitialStopWordThreshold:
|
||||
def test_saved_sensitivity_is_restored(self):
|
||||
from linux_voice_assistant.models import initial_stop_word_threshold
|
||||
|
||||
assert initial_stop_word_threshold(0.9) == pytest.approx(0.9)
|
||||
|
||||
def test_falls_back_to_server_state_default_when_never_set(self):
|
||||
from linux_voice_assistant.models import ServerState, initial_stop_word_threshold
|
||||
|
||||
assert initial_stop_word_threshold(None) == pytest.approx(ServerState.stop_word_threshold)
|
||||
|
||||
def test_clamped_to_one_when_above(self):
|
||||
from linux_voice_assistant.models import initial_stop_word_threshold
|
||||
|
||||
assert initial_stop_word_threshold(1.5) == pytest.approx(1.0)
|
||||
|
||||
def test_clamped_to_zero_when_below(self):
|
||||
from linux_voice_assistant.models import initial_stop_word_threshold
|
||||
|
||||
assert initial_stop_word_threshold(-0.5) == pytest.approx(0.0)
|
||||
Reference in new issue
Block a user