Raise and suppress stack trace when reloading yaml fails (#102410)

* Allow async_integration_yaml_config to raise

* Docstr - split check

* Implement as wrapper, return dataclass

* Fix setup error handling

* Fix reload test mock

* Move log_messages to error handler

* Remove unreachable code

* Remove config test helper

* Refactor and ensure notifications during setup

* Remove redundat error, adjust tests notifications

* Fix patch

* Apply suggestions from code review

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Follow up comments

* Add call_back decorator

* Split long lines

* Update exception abbreviations

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
Jan Bouwhuis 2023-11-24 17:34:45 +01:00 committed by GitHub
parent 852fb58ca8
commit af71c2bb45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 954 additions and 195 deletions

View file

@ -4,7 +4,7 @@ from __future__ import annotations
import asyncio
from collections.abc import Iterable
import logging
from typing import Any
from typing import Any, Literal, overload
from homeassistant import config as conf_util
from homeassistant.const import SERVICE_RELOAD
@ -60,7 +60,7 @@ async def _resetup_platform(
"""Resetup a platform."""
integration = await async_get_integration(hass, platform_domain)
conf = await conf_util.async_process_component_config(
conf = await conf_util.async_process_component_and_handle_errors(
hass, unprocessed_config, integration
)
@ -136,14 +136,41 @@ async def _async_reconfig_platform(
await asyncio.gather(*tasks)
@overload
async def async_integration_yaml_config(
hass: HomeAssistant, integration_name: str
) -> ConfigType | None:
...
@overload
async def async_integration_yaml_config(
hass: HomeAssistant,
integration_name: str,
*,
raise_on_failure: Literal[True],
) -> ConfigType:
...
@overload
async def async_integration_yaml_config(
hass: HomeAssistant,
integration_name: str,
*,
raise_on_failure: Literal[False] | bool,
) -> ConfigType | None:
...
async def async_integration_yaml_config(
hass: HomeAssistant, integration_name: str, *, raise_on_failure: bool = False
) -> ConfigType | None:
"""Fetch the latest yaml configuration for an integration."""
integration = await async_get_integration(hass, integration_name)
return await conf_util.async_process_component_config(
hass, await conf_util.async_hass_config_yaml(hass), integration
config = await conf_util.async_hass_config_yaml(hass)
return await conf_util.async_process_component_and_handle_errors(
hass, config, integration, raise_on_failure=raise_on_failure
)