From 52f3a7249f604b0130047a336083e880d47eb0ab Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Thu, 29 Apr 2021 11:43:23 +0200 Subject: [PATCH] hassfest detect built-in domain override for custom integrations (#49845) --- script/hassfest/manifest.py | 18 ++++++++++++++---- script/hassfest/model.py | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/script/hassfest/manifest.py b/script/hassfest/manifest.py index 8b3489facf6..016e3a0a322 100644 --- a/script/hassfest/manifest.py +++ b/script/hassfest/manifest.py @@ -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) diff --git a/script/hassfest/model.py b/script/hassfest/model.py index eee25df079d..10bc10626a2 100644 --- a/script/hassfest/model.py +++ b/script/hassfest/model.py @@ -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))