Ensure config entries are unloaded in tests (#90850)
This commit is contained in:
parent
4ed23b18e3
commit
98b1005b63
2 changed files with 23 additions and 1 deletions
|
@ -5,7 +5,8 @@ from dataclasses import dataclass
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from pysnooz.commands import SnoozCommandData
|
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.components.snooz.const import DOMAIN
|
||||||
from homeassistant.const import CONF_ADDRESS, CONF_TOKEN
|
from homeassistant.const import CONF_ADDRESS, CONF_TOKEN
|
||||||
|
@ -65,6 +66,18 @@ class SnoozFixture:
|
||||||
device: MockSnoozDevice
|
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(
|
async def create_mock_snooz(
|
||||||
connected: bool = True,
|
connected: bool = True,
|
||||||
initial_state: SnoozCommandData = SnoozCommandData(on=False, volume=0),
|
initial_state: SnoozCommandData = SnoozCommandData(on=False, volume=0),
|
||||||
|
|
|
@ -538,6 +538,15 @@ async def _hass(
|
||||||
|
|
||||||
yield 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)
|
await hass.async_stop(force=True)
|
||||||
|
|
||||||
# Restore timezone, it is set when creating the hass object
|
# Restore timezone, it is set when creating the hass object
|
||||||
|
|
Loading…
Add table
Reference in a new issue