mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
Detect attempt to setup config entry integration via YAML (#93589)
This commit is contained in:
parent
ef68f2c3ff
commit
8b662dc94f
@ -866,7 +866,7 @@ def _deprecated_or_removed(
|
|||||||
|
|
||||||
logger_func(warning, *arguments)
|
logger_func(warning, *arguments)
|
||||||
value = config[key]
|
value = config[key]
|
||||||
if replacement_key:
|
if replacement_key or option_removed:
|
||||||
config.pop(key)
|
config.pop(key)
|
||||||
else:
|
else:
|
||||||
value = default
|
value = default
|
||||||
|
@ -222,6 +222,20 @@ async def _async_setup_component(
|
|||||||
log_error("Invalid config.")
|
log_error("Invalid config.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
# Detect attempt to setup integration which can be setup only from config entry
|
||||||
|
if (
|
||||||
|
domain in processed_config
|
||||||
|
and not hasattr(component, "async_setup")
|
||||||
|
and not hasattr(component, "setup")
|
||||||
|
):
|
||||||
|
_LOGGER.error(
|
||||||
|
(
|
||||||
|
"The %s integration does not support YAML setup, please remove it from "
|
||||||
|
"your configuration"
|
||||||
|
),
|
||||||
|
domain,
|
||||||
|
)
|
||||||
|
|
||||||
start = timer()
|
start = timer()
|
||||||
_LOGGER.info("Setting up %s", domain)
|
_LOGGER.info("Setting up %s", domain)
|
||||||
with async_start_setup(hass, [domain]):
|
with async_start_setup(hass, [domain]):
|
||||||
|
@ -1048,7 +1048,10 @@ def test_deprecated_or_removed_logger_with_config_attributes(
|
|||||||
setattr(config, "__config_file__", file)
|
setattr(config, "__config_file__", file)
|
||||||
setattr(config, "__line__", line)
|
setattr(config, "__line__", line)
|
||||||
|
|
||||||
cv.deprecated("mars", replacement_key=replacement_key, default=False)(config)
|
validated = cv.deprecated("mars", replacement_key=replacement_key, default=False)(
|
||||||
|
config
|
||||||
|
)
|
||||||
|
assert "mars" not in validated # Removed because a replacement_key is defined
|
||||||
|
|
||||||
assert len(caplog.records) == 1
|
assert len(caplog.records) == 1
|
||||||
assert replacement in caplog.text
|
assert replacement in caplog.text
|
||||||
@ -1063,7 +1066,8 @@ def test_deprecated_or_removed_logger_with_config_attributes(
|
|||||||
setattr(config, "__config_file__", file)
|
setattr(config, "__config_file__", file)
|
||||||
setattr(config, "__line__", line)
|
setattr(config, "__line__", line)
|
||||||
|
|
||||||
cv.removed("mars", default=False, raise_if_present=False)(config)
|
validated = cv.removed("mars", default=False, raise_if_present=False)(config)
|
||||||
|
assert "mars" not in validated # Removed because by cv.removed
|
||||||
|
|
||||||
assert len(caplog.records) == 1
|
assert len(caplog.records) == 1
|
||||||
assert replacement in caplog.text
|
assert replacement in caplog.text
|
||||||
|
@ -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 "august" not in hass.data[setup.DATA_SETUP_STARTED]
|
||||||
assert isinstance(hass.data[setup.DATA_SETUP_TIME]["august"], datetime.timedelta)
|
assert isinstance(hass.data[setup.DATA_SETUP_TIME]["august"], datetime.timedelta)
|
||||||
assert "sensor" not in hass.data[setup.DATA_SETUP_TIME]
|
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")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user