diff --git a/tests/components/snooz/__init__.py b/tests/components/snooz/__init__.py index 1e38978f447..1e414fb337c 100644 --- a/tests/components/snooz/__init__.py +++ b/tests/components/snooz/__init__.py @@ -5,7 +5,8 @@ from dataclasses import dataclass from unittest.mock import patch from pysnooz.commands import SnoozCommandData -from pysnooz.testing import MockSnoozDevice +from pysnooz.device import DisconnectionReason +from pysnooz.testing import MockSnoozDevice as ParentMockSnoozDevice from homeassistant.components.snooz.const import DOMAIN from homeassistant.const import CONF_ADDRESS, CONF_TOKEN @@ -65,6 +66,18 @@ class SnoozFixture: device: MockSnoozDevice +class MockSnoozDevice(ParentMockSnoozDevice): + """Used for testing integration with Bleak. + + Adjusted for https://github.com/AustinBrunkhorst/pysnooz/issues/6 + """ + + def _on_device_disconnected(self, e) -> None: + if self._is_manually_disconnecting: + e.kwargs.set("reason", DisconnectionReason.USER) + return super()._on_device_disconnected(e) + + async def create_mock_snooz( connected: bool = True, initial_state: SnoozCommandData = SnoozCommandData(on=False, volume=0), diff --git a/tests/conftest.py b/tests/conftest.py index b076a394a22..7184fac8189 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -538,6 +538,15 @@ async def _hass( yield hass + # Config entries are not normally unloaded on HA shutdown. They are unloaded here + # to ensure that they could, and to help track lingering tasks and timers. + await asyncio.gather( + *( + config_entry.async_unload(hass) + for config_entry in hass.config_entries.async_entries() + ) + ) + await hass.async_stop(force=True) # Restore timezone, it is set when creating the hass object