mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Integrate add worker to bootstrap.setup_component
This commit is contained in:
parent
3e4c0261b1
commit
8c62ae4ce5
@ -17,7 +17,7 @@ from collections import defaultdict
|
||||
import homeassistant
|
||||
import homeassistant.loader as loader
|
||||
import homeassistant.components as core_components
|
||||
|
||||
import homeassistant.components.group as group
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -35,6 +35,11 @@ def setup_component(hass, domain, config=None):
|
||||
|
||||
_LOGGER.info("component %s initialized", domain)
|
||||
|
||||
# Assumption: if a component does not depend on groups
|
||||
# it communicates with devices
|
||||
if group.DOMAIN not in component.DEPENDENCIES:
|
||||
hass.pool.add_worker()
|
||||
|
||||
return True
|
||||
|
||||
else:
|
||||
@ -75,18 +80,8 @@ def from_config_dict(config, hass=None):
|
||||
_LOGGER.info("Home Assistant core initialized")
|
||||
|
||||
# Setup the components
|
||||
|
||||
# We assume that all components that load before the group component loads
|
||||
# are components that poll devices. As their tasks are IO based, we will
|
||||
# add an extra worker for each of them.
|
||||
add_worker = True
|
||||
|
||||
for domain in loader.load_order_components(components):
|
||||
if setup_component(hass, domain, config):
|
||||
add_worker = add_worker and domain != "group"
|
||||
|
||||
if add_worker:
|
||||
hass.pool.add_worker()
|
||||
setup_component(hass, domain, config)
|
||||
|
||||
return hass
|
||||
|
||||
|
@ -68,8 +68,7 @@ def setup(hass, config):
|
||||
logger.info("Found new service: %s %s", service, info)
|
||||
|
||||
if component and component not in hass.components:
|
||||
if bootstrap.setup_component(hass, component, config):
|
||||
hass.pool.add_worker()
|
||||
bootstrap.setup_component(hass, component, config)
|
||||
|
||||
hass.bus.fire(EVENT_PLATFORM_DISCOVERED, {
|
||||
ATTR_SERVICE: service,
|
||||
|
@ -39,9 +39,7 @@ def setup(hass, config):
|
||||
|
||||
# Ensure component is loaded
|
||||
if component.DOMAIN not in hass.components:
|
||||
# Add a worker on succesfull setup
|
||||
if bootstrap.setup_component(hass, component.DOMAIN, config):
|
||||
hass.pool.add_worker()
|
||||
bootstrap.setup_component(hass, component.DOMAIN, config)
|
||||
|
||||
# Fire discovery event
|
||||
hass.bus.fire(EVENT_PLATFORM_DISCOVERED, {
|
||||
|
Loading…
x
Reference in New Issue
Block a user