mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Fix zeroconf shutting down too early (#113638)
This commit is contained in:
parent
513da0f71e
commit
fa68c5633c
@ -24,7 +24,11 @@ from zeroconf.asyncio import AsyncServiceBrowser, AsyncServiceInfo
|
|||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components import network
|
from homeassistant.components import network
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, __version__
|
from homeassistant.const import (
|
||||||
|
EVENT_HOMEASSISTANT_CLOSE,
|
||||||
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
|
__version__,
|
||||||
|
)
|
||||||
from homeassistant.core import Event, HomeAssistant, callback
|
from homeassistant.core import Event, HomeAssistant, callback
|
||||||
from homeassistant.data_entry_flow import BaseServiceInfo
|
from homeassistant.data_entry_flow import BaseServiceInfo
|
||||||
from homeassistant.helpers import discovery_flow, instance_id
|
from homeassistant.helpers import discovery_flow, instance_id
|
||||||
@ -163,7 +167,11 @@ async def _async_get_instance(hass: HomeAssistant, **zcargs: Any) -> HaAsyncZero
|
|||||||
"""Stop Zeroconf."""
|
"""Stop Zeroconf."""
|
||||||
await aio_zc.ha_async_close()
|
await aio_zc.ha_async_close()
|
||||||
|
|
||||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _async_stop_zeroconf)
|
# Wait to the close event to shutdown zeroconf to give
|
||||||
|
# integrations time to send a good bye message
|
||||||
|
hass.bus.async_listen_once(
|
||||||
|
EVENT_HOMEASSISTANT_CLOSE, _async_stop_zeroconf, run_immediately=True
|
||||||
|
)
|
||||||
hass.data[DOMAIN] = aio_zc
|
hass.data[DOMAIN] = aio_zc
|
||||||
|
|
||||||
return aio_zc
|
return aio_zc
|
||||||
@ -240,7 +248,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
async def _async_zeroconf_hass_stop(_event: Event) -> None:
|
async def _async_zeroconf_hass_stop(_event: Event) -> None:
|
||||||
await discovery.async_stop()
|
await discovery.async_stop()
|
||||||
|
|
||||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _async_zeroconf_hass_stop)
|
hass.bus.async_listen_once(
|
||||||
|
EVENT_HOMEASSISTANT_STOP, _async_zeroconf_hass_stop, run_immediately=True
|
||||||
|
)
|
||||||
async_when_setup_or_start(hass, "frontend", _async_zeroconf_hass_start)
|
async_when_setup_or_start(hass, "frontend", _async_zeroconf_hass_start)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -15,6 +15,7 @@ from zeroconf.asyncio import AsyncServiceInfo
|
|||||||
from homeassistant.components import zeroconf
|
from homeassistant.components import zeroconf
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
EVENT_COMPONENT_LOADED,
|
EVENT_COMPONENT_LOADED,
|
||||||
|
EVENT_HOMEASSISTANT_CLOSE,
|
||||||
EVENT_HOMEASSISTANT_START,
|
EVENT_HOMEASSISTANT_START,
|
||||||
EVENT_HOMEASSISTANT_STARTED,
|
EVENT_HOMEASSISTANT_STARTED,
|
||||||
EVENT_HOMEASSISTANT_STOP,
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
@ -935,6 +936,11 @@ async def test_get_instance(hass: HomeAssistant, mock_async_zeroconf: None) -> N
|
|||||||
)
|
)
|
||||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
assert len(mock_async_zeroconf.ha_async_close.mock_calls) == 0
|
||||||
|
# Only shutdown at the close event so integrations have time
|
||||||
|
# to send out their goodbyes
|
||||||
|
hass.bus.async_fire(EVENT_HOMEASSISTANT_CLOSE)
|
||||||
|
await hass.async_block_till_done()
|
||||||
assert len(mock_async_zeroconf.ha_async_close.mock_calls) == 1
|
assert len(mock_async_zeroconf.ha_async_close.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user