Add timeout to platform/component
parent
b4159c7dc9
commit
280a311e48
|
@ -9,6 +9,7 @@ from collections import defaultdict
|
|||
from types import ModuleType
|
||||
from typing import Any, Optional, Dict
|
||||
|
||||
import async_timeout
|
||||
import voluptuous as vol
|
||||
from voluptuous.humanize import humanize_error
|
||||
|
||||
|
@ -142,11 +143,12 @@ def _async_setup_component(hass: core.HomeAssistant,
|
|||
async_comp = hasattr(component, 'async_setup')
|
||||
|
||||
try:
|
||||
if async_comp:
|
||||
result = yield from component.async_setup(hass, config)
|
||||
else:
|
||||
result = yield from hass.loop.run_in_executor(
|
||||
None, component.setup, hass, config)
|
||||
with async_timeout.timeout(30, loop=hass.loop):
|
||||
if async_comp:
|
||||
result = yield from component.async_setup(hass, config)
|
||||
else:
|
||||
result = yield from hass.loop.run_in_executor(
|
||||
None, component.setup, hass, config)
|
||||
except Exception: # pylint: disable=broad-except
|
||||
_LOGGER.exception('Error during setup of component %s', domain)
|
||||
_async_persistent_notification(hass, domain, True)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
"""Helpers for components that manage entities."""
|
||||
import asyncio
|
||||
|
||||
import async_timeout
|
||||
|
||||
from homeassistant import config as conf_util
|
||||
from homeassistant.bootstrap import (
|
||||
async_prepare_setup_platform, async_prepare_setup_component)
|
||||
|
@ -138,16 +140,18 @@ class EntityComponent(object):
|
|||
entity_platform = self._platforms[key]
|
||||
|
||||
try:
|
||||
if getattr(platform, 'async_setup_platform', None):
|
||||
yield from platform.async_setup_platform(
|
||||
self.hass, platform_config,
|
||||
entity_platform.async_add_entities, discovery_info
|
||||
)
|
||||
else:
|
||||
yield from self.hass.loop.run_in_executor(
|
||||
None, platform.setup_platform, self.hass, platform_config,
|
||||
entity_platform.add_entities, discovery_info
|
||||
)
|
||||
with async_timeout.timeout(30, loop=self.hass.loop):
|
||||
if getattr(platform, 'async_setup_platform', None):
|
||||
yield from platform.async_setup_platform(
|
||||
self.hass, platform_config,
|
||||
entity_platform.async_add_entities, discovery_info
|
||||
)
|
||||
else:
|
||||
yield from self.hass.loop.run_in_executor(
|
||||
None, platform.setup_platform, self.hass,
|
||||
platform_config, entity_platform.add_entities,
|
||||
discovery_info
|
||||
)
|
||||
|
||||
self.hass.config.components.append(
|
||||
'{}.{}'.format(self.domain, platform_type))
|
||||
|
|
Loading…
Reference in New Issue