Fix tplink blocking startup by waiting for discovery (#111788)

* Fix tplink blocking statup by waiting for discovery

* remove started
pull/111791/head
J. Nick Koston 2024-02-28 16:34:08 -10:00 committed by GitHub
parent b11e97e132
commit 59b7f8d103
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 12 deletions

View File

@ -28,7 +28,6 @@ from homeassistant.const import (
CONF_MODEL,
CONF_PASSWORD,
CONF_USERNAME,
EVENT_HOMEASSISTANT_STARTED,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
@ -112,14 +111,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the TP-Link component."""
hass.data.setdefault(DOMAIN, {})
if discovered_devices := await async_discover_devices(hass):
async_trigger_discovery(hass, discovered_devices)
async def _async_discovery(*_: Any) -> None:
if discovered := await async_discover_devices(hass):
async_trigger_discovery(hass, discovered)
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STARTED, _async_discovery)
hass.async_create_background_task(
_async_discovery(), "tplink first discovery", eager_start=True
)
async_track_time_interval(
hass, _async_discovery, DISCOVERY_INTERVAL, cancel_on_shutdown=True
)

View File

@ -17,7 +17,6 @@ from homeassistant.const import (
CONF_HOST,
CONF_PASSWORD,
CONF_USERNAME,
EVENT_HOMEASSISTANT_STARTED,
STATE_ON,
STATE_UNAVAILABLE,
)
@ -52,17 +51,13 @@ async def test_configuring_tplink_causes_discovery(hass: HomeAssistant) -> None:
call_count = len(discover.mock_calls)
assert discover.mock_calls
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(minutes=15))
await hass.async_block_till_done()
assert len(discover.mock_calls) == call_count * 2
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(minutes=15))
await hass.async_block_till_done()
assert len(discover.mock_calls) == call_count * 3
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(minutes=30))
await hass.async_block_till_done()
assert len(discover.mock_calls) == call_count * 4
assert len(discover.mock_calls) == call_count * 3
async def test_config_entry_reload(hass: HomeAssistant) -> None: