feat(microphone): PollMonitor meldet fehlendes Gerät sofort beim Start
This commit is contained in:
@@ -65,3 +65,33 @@ async def test_on_device_removed_fires_when_device_disappears():
|
|||||||
monitor.stop()
|
monitor.stop()
|
||||||
|
|
||||||
assert removed == ["Mic B"]
|
assert removed == ["Mic B"]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_on_configured_missing_fires_immediately_at_start():
|
||||||
|
monitor = PollMonitor(configured_device="Headset USB", interval=99.0)
|
||||||
|
missing_called = asyncio.Event()
|
||||||
|
|
||||||
|
async def on_missing() -> None:
|
||||||
|
missing_called.set()
|
||||||
|
|
||||||
|
monitor.on_configured_missing = on_missing
|
||||||
|
|
||||||
|
with patch("sounddevice.query_devices", return_value=_fake_devices(["Mic A"])):
|
||||||
|
await monitor.start()
|
||||||
|
|
||||||
|
assert missing_called.is_set()
|
||||||
|
monitor.stop()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_on_configured_missing_does_not_fire_when_device_present():
|
||||||
|
monitor = PollMonitor(configured_device="Headset USB", interval=99.0)
|
||||||
|
missing_mock = AsyncMock()
|
||||||
|
monitor.on_configured_missing = missing_mock
|
||||||
|
|
||||||
|
with patch("sounddevice.query_devices", return_value=_fake_devices(["Headset USB", "Mic A"])):
|
||||||
|
await monitor.start()
|
||||||
|
|
||||||
|
missing_mock.assert_not_called()
|
||||||
|
monitor.stop()
|
||||||
|
|||||||
@@ -32,6 +32,12 @@ class PollMonitor:
|
|||||||
|
|
||||||
async def start(self) -> None:
|
async def start(self) -> None:
|
||||||
self._known_devices = self._current_devices()
|
self._known_devices = self._current_devices()
|
||||||
|
if (
|
||||||
|
self.configured_device
|
||||||
|
and self.configured_device not in self._known_devices
|
||||||
|
and self.on_configured_missing
|
||||||
|
):
|
||||||
|
await self.on_configured_missing()
|
||||||
self._task = asyncio.create_task(self._loop())
|
self._task = asyncio.create_task(self._loop())
|
||||||
|
|
||||||
def stop(self) -> None:
|
def stop(self) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user