mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Integration requirement check refactor (#25626)
* Factor out code getting requirements for integration * Have process requirements raise an exception * One more lint fix * Blackify * Catch new exception * Let RequirementsNotFound be a HomeAssistantError * Correct another test * Split catching of exceptions and avoid complete log
This commit is contained in:
committed by
Paulus Schoutsen
parent
c3455efc11
commit
d1b9ebc7b2
@@ -5,7 +5,7 @@ from typing import List
|
||||
import attr
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import loader, requirements
|
||||
from homeassistant import loader
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.config import (
|
||||
CONF_CORE,
|
||||
@@ -18,6 +18,10 @@ from homeassistant.config import (
|
||||
extract_domain_configs,
|
||||
config_per_platform,
|
||||
)
|
||||
from homeassistant.requirements import (
|
||||
async_get_integration_with_requirements,
|
||||
RequirementsNotFound,
|
||||
)
|
||||
|
||||
import homeassistant.util.yaml.loader as yaml_loader
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
@@ -101,29 +105,15 @@ async def async_check_ha_config_file(hass: HomeAssistant) -> HomeAssistantConfig
|
||||
# Process and validate config
|
||||
for domain in components:
|
||||
try:
|
||||
integration = await loader.async_get_integration(hass, domain)
|
||||
except loader.IntegrationNotFound:
|
||||
result.add_error("Integration not found: {}".format(domain))
|
||||
continue
|
||||
|
||||
if (
|
||||
not hass.config.skip_pip
|
||||
and integration.requirements
|
||||
and not await requirements.async_process_requirements(
|
||||
hass, integration.domain, integration.requirements
|
||||
)
|
||||
):
|
||||
result.add_error(
|
||||
"Unable to install all requirements: {}".format(
|
||||
", ".join(integration.requirements)
|
||||
)
|
||||
)
|
||||
integration = await async_get_integration_with_requirements(hass, domain)
|
||||
except (RequirementsNotFound, loader.IntegrationNotFound) as ex:
|
||||
result.add_error("Component error: {} - {}".format(domain, ex))
|
||||
continue
|
||||
|
||||
try:
|
||||
component = integration.get_component()
|
||||
except ImportError:
|
||||
result.add_error("Component not found: {}".format(domain))
|
||||
except ImportError as ex:
|
||||
result.add_error("Component error: {} - {}".format(domain, ex))
|
||||
continue
|
||||
|
||||
config_schema = getattr(component, "CONFIG_SCHEMA", None)
|
||||
@@ -161,32 +151,16 @@ async def async_check_ha_config_file(hass: HomeAssistant) -> HomeAssistantConfig
|
||||
continue
|
||||
|
||||
try:
|
||||
p_integration = await loader.async_get_integration(hass, p_name)
|
||||
except loader.IntegrationNotFound:
|
||||
result.add_error(
|
||||
"Integration {} not found when trying to verify its {} "
|
||||
"platform.".format(p_name, domain)
|
||||
p_integration = await async_get_integration_with_requirements(
|
||||
hass, p_name
|
||||
)
|
||||
continue
|
||||
|
||||
if (
|
||||
not hass.config.skip_pip
|
||||
and p_integration.requirements
|
||||
and not await requirements.async_process_requirements(
|
||||
hass, p_integration.domain, p_integration.requirements
|
||||
)
|
||||
):
|
||||
result.add_error(
|
||||
"Unable to install all requirements: {}".format(
|
||||
", ".join(integration.requirements)
|
||||
)
|
||||
)
|
||||
continue
|
||||
|
||||
try:
|
||||
platform = p_integration.get_platform(domain)
|
||||
except ImportError:
|
||||
result.add_error("Platform not found: {}.{}".format(domain, p_name))
|
||||
except (
|
||||
loader.IntegrationNotFound,
|
||||
RequirementsNotFound,
|
||||
ImportError,
|
||||
) as ex:
|
||||
result.add_error("Platform error {}.{} - {}".format(domain, p_name, ex))
|
||||
continue
|
||||
|
||||
# Validate platform specific schema
|
||||
|
||||
Reference in New Issue
Block a user