hassfest detect built-in domain override for custom integrations (#49845)

pull/49855/head
Franck Nijhof 2021-04-29 11:43:23 +02:00 committed by GitHub
parent b7184b669f
commit 52f3a7249f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 5 deletions

View File

@ -1,6 +1,7 @@
"""Manifest validation."""
from __future__ import annotations
from pathlib import Path
from urllib.parse import urlparse
import voluptuous as vol
@ -8,7 +9,7 @@ from voluptuous.humanize import humanize_error
from homeassistant.loader import validate_custom_integration_version
from .model import Integration
from .model import Config, Integration
DOCUMENTATION_URL_SCHEMA = "https"
DOCUMENTATION_URL_HOST = "www.home-assistant.io"
@ -227,7 +228,7 @@ def validate_version(integration: Integration):
return
def validate_manifest(integration: Integration):
def validate_manifest(integration: Integration, core_components_dir: Path) -> None:
"""Validate manifest."""
if not integration.manifest:
return
@ -245,6 +246,14 @@ def validate_manifest(integration: Integration):
if integration.manifest["domain"] != integration.path.name:
integration.add_error("manifest", "Domain does not match dir name")
if (
not integration.core
and (core_components_dir / integration.manifest["domain"]).exists()
):
integration.add_warning(
"manifest", "Domain collides with built-in core integration"
)
if (
integration.manifest["domain"] in NO_IOT_CLASS
and "iot_class" in integration.manifest
@ -261,7 +270,8 @@ def validate_manifest(integration: Integration):
validate_version(integration)
def validate(integrations: dict[str, Integration], config):
def validate(integrations: dict[str, Integration], config: Config) -> None:
"""Handle all integrations manifests."""
core_components_dir = config.root / "homeassistant/components"
for integration in integrations.values():
validate_manifest(integration)
validate_manifest(integration, core_components_dir)

View File

@ -100,7 +100,7 @@ class Integration:
"""Add an error."""
self.errors.append(Error(*args, **kwargs))
def add_warning(self, *args, **kwargs):
def add_warning(self, *args: Any, **kwargs: Any) -> None:
"""Add an warning."""
self.warnings.append(Error(*args, **kwargs))