mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Fix zeroconf starting later than expected (#81023)
This commit is contained in:
parent
0e2bea038d
commit
abb3ce6d69
@ -22,11 +22,7 @@ from homeassistant import config_entries
|
||||
from homeassistant.components import network
|
||||
from homeassistant.components.network import MDNS_TARGET_IP, async_get_source_ip
|
||||
from homeassistant.components.network.models import Adapter
|
||||
from homeassistant.const import (
|
||||
EVENT_HOMEASSISTANT_START,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
__version__,
|
||||
)
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, __version__
|
||||
from homeassistant.core import Event, HomeAssistant, callback
|
||||
from homeassistant.data_entry_flow import BaseServiceInfo
|
||||
from homeassistant.helpers import discovery_flow, instance_id
|
||||
@ -40,6 +36,7 @@ from homeassistant.loader import (
|
||||
async_get_zeroconf,
|
||||
bind_hass,
|
||||
)
|
||||
from homeassistant.setup import async_when_setup_or_start
|
||||
|
||||
from .models import HaAsyncServiceBrowser, HaAsyncZeroconf, HaZeroconf
|
||||
from .usage import install_multiple_zeroconf_catcher
|
||||
@ -194,7 +191,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
discovery = ZeroconfDiscovery(hass, zeroconf, zeroconf_types, homekit_models, ipv6)
|
||||
await discovery.async_setup()
|
||||
|
||||
async def _async_zeroconf_hass_start(_event: Event) -> None:
|
||||
async def _async_zeroconf_hass_start(hass: HomeAssistant, comp: str) -> None:
|
||||
"""Expose Home Assistant on zeroconf when it starts.
|
||||
|
||||
Wait till started or otherwise HTTP is not up and running.
|
||||
@ -206,7 +203,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
await discovery.async_stop()
|
||||
|
||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _async_zeroconf_hass_stop)
|
||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, _async_zeroconf_hass_start)
|
||||
async_when_setup_or_start(hass, "frontend", _async_zeroconf_hass_start)
|
||||
|
||||
return True
|
||||
|
||||
|
@ -13,12 +13,13 @@ from homeassistant.components.zeroconf import (
|
||||
_get_announced_addresses,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
EVENT_COMPONENT_LOADED,
|
||||
EVENT_HOMEASSISTANT_START,
|
||||
EVENT_HOMEASSISTANT_STARTED,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
)
|
||||
from homeassistant.generated import zeroconf as zc_gen
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.setup import ATTR_COMPONENT, async_setup_component
|
||||
|
||||
NON_UTF8_VALUE = b"ABCDEF\x8a"
|
||||
NON_ASCII_KEY = b"non-ascii-key\x8a"
|
||||
@ -1159,3 +1160,13 @@ async def test_no_name(hass, mock_async_zeroconf):
|
||||
register_call = mock_async_zeroconf.async_register_service.mock_calls[-1]
|
||||
info = register_call.args[0]
|
||||
assert info.name == "Home._home-assistant._tcp.local."
|
||||
|
||||
|
||||
async def test_start_with_frontend(hass, mock_async_zeroconf):
|
||||
"""Test we start with the frontend."""
|
||||
with patch("homeassistant.components.zeroconf.HaZeroconf"):
|
||||
assert await async_setup_component(hass, zeroconf.DOMAIN, {zeroconf.DOMAIN: {}})
|
||||
hass.bus.async_fire(EVENT_COMPONENT_LOADED, {ATTR_COMPONENT: "frontend"})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
mock_async_zeroconf.async_register_service.assert_called_once()
|
||||
|
Loading…
x
Reference in New Issue
Block a user