Detect attempt to setup config entry integration via YAML (#93589)

This commit is contained in:
Erik Montnemery
2023-05-29 21:01:47 +02:00
committed by GitHub
parent ef68f2c3ff
commit 8b662dc94f
4 changed files with 75 additions and 3 deletions

View File

@@ -728,3 +728,57 @@ async def test_async_start_setup_platforms(hass: HomeAssistant) -> None:
assert "august" not in hass.data[setup.DATA_SETUP_STARTED]
assert isinstance(hass.data[setup.DATA_SETUP_TIME]["august"], datetime.timedelta)
assert "sensor" not in hass.data[setup.DATA_SETUP_TIME]
async def test_setup_config_entry_from_yaml(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test attempting to setup an integration which only supports config_entries."""
expected_warning = (
"The test_integration_only_entry integration does not support YAML setup, "
"please remove it from your configuration"
)
mock_integration(
hass,
MockModule(
"test_integration_only_entry",
setup=False,
async_setup_entry=AsyncMock(return_value=True),
),
)
assert await setup.async_setup_component(hass, "test_integration_only_entry", {})
assert expected_warning not in caplog.text
caplog.clear()
hass.data.pop(setup.DATA_SETUP)
hass.config.components.remove("test_integration_only_entry")
# There should be a warning, but setup should not fail
assert await setup.async_setup_component(
hass, "test_integration_only_entry", {"test_integration_only_entry": None}
)
assert expected_warning in caplog.text
caplog.clear()
hass.data.pop(setup.DATA_SETUP)
hass.config.components.remove("test_integration_only_entry")
# There should be a warning, but setup should not fail
assert await setup.async_setup_component(
hass, "test_integration_only_entry", {"test_integration_only_entry": {}}
)
assert expected_warning in caplog.text
caplog.clear()
hass.data.pop(setup.DATA_SETUP)
hass.config.components.remove("test_integration_only_entry")
# There should be a warning, but setup should not fail
assert await setup.async_setup_component(
hass,
"test_integration_only_entry",
{"test_integration_only_entry": {"hello": "world"}},
)
assert expected_warning in caplog.text
caplog.clear()
hass.data.pop(setup.DATA_SETUP)
hass.config.components.remove("test_integration_only_entry")