Add warning to custom integrations without version (#45919)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
@@ -130,13 +130,69 @@ async def test_custom_component_name(hass):
|
||||
|
||||
async def test_log_warning_custom_component(hass, caplog):
|
||||
"""Test that we log a warning when loading a custom component."""
|
||||
hass.components.test_standalone
|
||||
await loader.async_get_integration(hass, "test_standalone")
|
||||
assert "You are using a custom integration test_standalone" in caplog.text
|
||||
|
||||
await loader.async_get_integration(hass, "test")
|
||||
assert "You are using a custom integration test " in caplog.text
|
||||
|
||||
|
||||
async def test_custom_integration_missing_version(hass, caplog):
|
||||
"""Test that we log a warning when custom integrations are missing a version."""
|
||||
test_integration_1 = loader.Integration(
|
||||
hass, "custom_components.test1", None, {"domain": "test1"}
|
||||
)
|
||||
test_integration_2 = loader.Integration(
|
||||
hass,
|
||||
"custom_components.test2",
|
||||
None,
|
||||
loader.manifest_from_legacy_module("test2", "custom_components.test2"),
|
||||
)
|
||||
|
||||
with patch("homeassistant.loader.async_get_custom_components") as mock_get:
|
||||
mock_get.return_value = {
|
||||
"test1": test_integration_1,
|
||||
"test2": test_integration_2,
|
||||
}
|
||||
|
||||
await loader.async_get_integration(hass, "test1")
|
||||
assert (
|
||||
"No 'version' key in the manifest file for custom integration 'test1'."
|
||||
in caplog.text
|
||||
)
|
||||
|
||||
await loader.async_get_integration(hass, "test2")
|
||||
assert (
|
||||
"No 'version' key in the manifest file for custom integration 'test2'."
|
||||
in caplog.text
|
||||
)
|
||||
|
||||
|
||||
async def test_no_version_warning_for_none_custom_integrations(hass, caplog):
|
||||
"""Test that we do not log a warning when core integrations are missing a version."""
|
||||
await loader.async_get_integration(hass, "hue")
|
||||
assert (
|
||||
"No 'version' key in the manifest file for custom integration 'hue'."
|
||||
not in caplog.text
|
||||
)
|
||||
|
||||
|
||||
async def test_custom_integration_version_not_valid(hass, caplog):
|
||||
"""Test that we log a warning when custom integrations have a invalid version."""
|
||||
test_integration = loader.Integration(
|
||||
hass, "custom_components.test", None, {"domain": "test", "version": "test"}
|
||||
)
|
||||
|
||||
with patch("homeassistant.loader.async_get_custom_components") as mock_get:
|
||||
mock_get.return_value = {"test": test_integration}
|
||||
|
||||
await loader.async_get_integration(hass, "test")
|
||||
assert (
|
||||
"'test' is not a valid version for custom integration 'test'."
|
||||
in caplog.text
|
||||
)
|
||||
|
||||
|
||||
async def test_get_integration(hass):
|
||||
"""Test resolving integration."""
|
||||
integration = await loader.async_get_integration(hass, "hue")
|
||||
@@ -154,7 +210,6 @@ async def test_get_integration_legacy(hass):
|
||||
async def test_get_integration_custom_component(hass, enable_custom_integrations):
|
||||
"""Test resolving integration."""
|
||||
integration = await loader.async_get_integration(hass, "test_package")
|
||||
print(integration)
|
||||
assert integration.get_component().DOMAIN == "test_package"
|
||||
assert integration.name == "Test Package"
|
||||
|
||||
@@ -189,6 +244,7 @@ def test_integration_properties(hass):
|
||||
{"manufacturer": "Signify", "modelName": "Philips hue bridge 2015"},
|
||||
],
|
||||
"mqtt": ["hue/discovery"],
|
||||
"version": "1.0.0",
|
||||
},
|
||||
)
|
||||
assert integration.name == "Philips Hue"
|
||||
@@ -215,6 +271,7 @@ def test_integration_properties(hass):
|
||||
assert integration.dependencies == ["test-dep"]
|
||||
assert integration.requirements == ["test-req==1.0.0"]
|
||||
assert integration.is_built_in is True
|
||||
assert integration.version == "1.0.0"
|
||||
|
||||
integration = loader.Integration(
|
||||
hass,
|
||||
@@ -233,6 +290,7 @@ def test_integration_properties(hass):
|
||||
assert integration.dhcp is None
|
||||
assert integration.ssdp is None
|
||||
assert integration.mqtt is None
|
||||
assert integration.version is None
|
||||
|
||||
integration = loader.Integration(
|
||||
hass,
|
||||
|
||||
Reference in New Issue
Block a user