mirror of
https://github.com/esphome/esphome.git
synced 2025-10-15 00:03:51 +01:00
[core] Improve entity duplicate validation error messages (#10184)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from collections import defaultdict
|
||||
from contextlib import contextmanager
|
||||
import logging
|
||||
import math
|
||||
import os
|
||||
@@ -38,7 +39,7 @@ from esphome.util import OrderedDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..cpp_generator import MockObj, MockObjClass, Statement
|
||||
from ..types import ConfigType
|
||||
from ..types import ConfigType, EntityMetadata
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -571,14 +572,16 @@ class EsphomeCore:
|
||||
# Key: platform name (e.g. "sensor", "binary_sensor"), Value: count
|
||||
self.platform_counts: defaultdict[str, int] = defaultdict(int)
|
||||
# Track entity unique IDs to handle duplicates
|
||||
# Set of (device_id, platform, sanitized_name) tuples
|
||||
self.unique_ids: set[tuple[str, str, str]] = set()
|
||||
# Dict mapping (device_id, platform, sanitized_name) -> entity metadata
|
||||
self.unique_ids: dict[tuple[str, str, str], EntityMetadata] = {}
|
||||
# Whether ESPHome was started in verbose mode
|
||||
self.verbose = False
|
||||
# Whether ESPHome was started in quiet mode
|
||||
self.quiet = False
|
||||
# A list of all known ID classes
|
||||
self.id_classes = {}
|
||||
# The current component being processed during validation
|
||||
self.current_component: str | None = None
|
||||
|
||||
def reset(self):
|
||||
from esphome.pins import PIN_SCHEMA_REGISTRY
|
||||
@@ -604,9 +607,20 @@ class EsphomeCore:
|
||||
self.loaded_integrations = set()
|
||||
self.component_ids = set()
|
||||
self.platform_counts = defaultdict(int)
|
||||
self.unique_ids = set()
|
||||
self.unique_ids = {}
|
||||
self.current_component = None
|
||||
PIN_SCHEMA_REGISTRY.reset()
|
||||
|
||||
@contextmanager
|
||||
def component_context(self, component: str):
|
||||
"""Context manager to set the current component being processed."""
|
||||
old_component = self.current_component
|
||||
self.current_component = component
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
self.current_component = old_component
|
||||
|
||||
@property
|
||||
def address(self) -> str | None:
|
||||
if self.config is None:
|
||||
|
Reference in New Issue
Block a user