Ensure MockEntityPlatform shuts down after tests (#89849)

This commit is contained in:
epenet 2023-03-17 10:22:43 +01:00 committed by GitHub
parent aa72b48725
commit abd91dd934
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -37,6 +37,7 @@ from homeassistant.config import async_process_component_config
from homeassistant.const import (
DEVICE_DEFAULT_NAME,
EVENT_HOMEASSISTANT_CLOSE,
EVENT_HOMEASSISTANT_STOP,
EVENT_STATE_CHANGED,
STATE_OFF,
STATE_ON,
@ -757,7 +758,7 @@ class MockEntityPlatform(entity_platform.EntityPlatform):
def __init__(
self,
hass,
hass: HomeAssistant,
logger=None,
domain="test_domain",
platform_name="test_platform",
@ -783,6 +784,11 @@ class MockEntityPlatform(entity_platform.EntityPlatform):
entity_namespace=entity_namespace,
)
async def _async_on_stop(_: Event) -> None:
await self.async_shutdown()
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _async_on_stop)
class MockToggleEntity(entity.ToggleEntity):
"""Provide a mock toggle device."""