Don't block startup more than 60 seconds while waiting for components. (#7739)
This commit is contained in:
parent
fce09f624b
commit
7055fddfb4
3 changed files with 40 additions and 6 deletions
|
@ -19,6 +19,7 @@ from homeassistant.util.async import (
|
|||
|
||||
DEFAULT_SCAN_INTERVAL = timedelta(seconds=15)
|
||||
SLOW_SETUP_WARNING = 10
|
||||
SLOW_SETUP_MAX_WAIT = 60
|
||||
|
||||
|
||||
class EntityComponent(object):
|
||||
|
@ -145,20 +146,26 @@ class EntityComponent(object):
|
|||
|
||||
try:
|
||||
if getattr(platform, 'async_setup_platform', None):
|
||||
yield from platform.async_setup_platform(
|
||||
task = platform.async_setup_platform(
|
||||
self.hass, platform_config,
|
||||
entity_platform.async_schedule_add_entities, discovery_info
|
||||
)
|
||||
else:
|
||||
yield from self.hass.loop.run_in_executor(
|
||||
task = self.hass.loop.run_in_executor(
|
||||
None, platform.setup_platform, self.hass, platform_config,
|
||||
entity_platform.schedule_add_entities, discovery_info
|
||||
)
|
||||
|
||||
yield from asyncio.wait_for(
|
||||
asyncio.shield(task, loop=self.hass.loop),
|
||||
SLOW_SETUP_MAX_WAIT, loop=self.hass.loop)
|
||||
yield from entity_platform.async_block_entities_done()
|
||||
|
||||
self.hass.config.components.add(
|
||||
'{}.{}'.format(self.domain, platform_type))
|
||||
except asyncio.TimeoutError:
|
||||
self.logger.error(
|
||||
"Setup of platform %s is taking longer than %s seconds."
|
||||
" Startup will proceed without waiting any longer.",
|
||||
platform_type, SLOW_SETUP_MAX_WAIT)
|
||||
except Exception: # pylint: disable=broad-except
|
||||
self.logger.exception(
|
||||
"Error while setting up platform %s", platform_type)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue