Ensure device_automation can handle RequirementsNotFound (#92037)
This commit is contained in:
parent
330a7afdfc
commit
ead761dfa2
2 changed files with 32 additions and 1 deletions
|
@ -29,7 +29,10 @@ from homeassistant.helpers import (
|
||||||
)
|
)
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.loader import IntegrationNotFound
|
from homeassistant.loader import IntegrationNotFound
|
||||||
from homeassistant.requirements import async_get_integration_with_requirements
|
from homeassistant.requirements import (
|
||||||
|
RequirementsNotFound,
|
||||||
|
async_get_integration_with_requirements,
|
||||||
|
)
|
||||||
|
|
||||||
from .const import ( # noqa: F401
|
from .const import ( # noqa: F401
|
||||||
CONF_IS_OFF,
|
CONF_IS_OFF,
|
||||||
|
@ -171,6 +174,10 @@ async def async_get_device_automation_platform(
|
||||||
raise InvalidDeviceAutomationConfig(
|
raise InvalidDeviceAutomationConfig(
|
||||||
f"Integration '{domain}' not found"
|
f"Integration '{domain}' not found"
|
||||||
) from err
|
) from err
|
||||||
|
except RequirementsNotFound as err:
|
||||||
|
raise InvalidDeviceAutomationConfig(
|
||||||
|
f"Integration '{domain}' could not be loaded"
|
||||||
|
) from err
|
||||||
except ImportError as err:
|
except ImportError as err:
|
||||||
raise InvalidDeviceAutomationConfig(
|
raise InvalidDeviceAutomationConfig(
|
||||||
f"Integration '{domain}' does not support device automation "
|
f"Integration '{domain}' does not support device automation "
|
||||||
|
|
|
@ -17,6 +17,8 @@ from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
from homeassistant.loader import IntegrationNotFound
|
||||||
|
from homeassistant.requirements import RequirementsNotFound
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import (
|
from tests.common import (
|
||||||
|
@ -1554,3 +1556,25 @@ async def test_automation_with_device_component_not_loaded(
|
||||||
)
|
)
|
||||||
|
|
||||||
module.async_validate_trigger_config.assert_not_awaited()
|
module.async_validate_trigger_config.assert_not_awaited()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"exc",
|
||||||
|
[
|
||||||
|
IntegrationNotFound("test"),
|
||||||
|
RequirementsNotFound("test", []),
|
||||||
|
ImportError("test"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
async def test_async_get_device_automations_platform_reraises_exceptions(
|
||||||
|
hass: HomeAssistant, exc: Exception
|
||||||
|
) -> None:
|
||||||
|
"""Test InvalidDeviceAutomationConfig is raised when async_get_integration_with_requirements fails."""
|
||||||
|
await async_setup_component(hass, "device_automation", {})
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.device_automation.async_get_integration_with_requirements",
|
||||||
|
side_effect=exc,
|
||||||
|
), pytest.raises(InvalidDeviceAutomationConfig):
|
||||||
|
await device_automation.async_get_device_automation_platform(
|
||||||
|
hass, "test", device_automation.DeviceAutomationType.TRIGGER
|
||||||
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue