mirror of
				https://github.com/esphome/esphome.git
				synced 2025-11-04 09:01:49 +00:00 
			
		
		
		
	migrate
This commit is contained in:
		@@ -524,7 +524,7 @@ class EsphomeCore:
 | 
				
			|||||||
        self.platform_counts: defaultdict[str, int] = defaultdict(int)
 | 
					        self.platform_counts: defaultdict[str, int] = defaultdict(int)
 | 
				
			||||||
        # Track entity unique IDs to handle duplicates
 | 
					        # Track entity unique IDs to handle duplicates
 | 
				
			||||||
        # Set of (device_id, platform, object_id) tuples
 | 
					        # Set of (device_id, platform, object_id) tuples
 | 
				
			||||||
        self.unique_ids: set[tuple[int, str, str]] = set()
 | 
					        self.unique_ids: set[tuple[str, str, str]] = set()
 | 
				
			||||||
        # Whether ESPHome was started in verbose mode
 | 
					        # Whether ESPHome was started in verbose mode
 | 
				
			||||||
        self.verbose = False
 | 
					        self.verbose = False
 | 
				
			||||||
        # Whether ESPHome was started in quiet mode
 | 
					        # Whether ESPHome was started in quiet mode
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -186,31 +186,22 @@ def entity_duplicate_validator(platform: str) -> Callable[[ConfigType], ConfigTy
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        # Get the entity name and device info
 | 
					        # Get the entity name and device info
 | 
				
			||||||
        entity_name = config[CONF_NAME]
 | 
					        entity_name = config[CONF_NAME]
 | 
				
			||||||
        device_id = 0  # Main device by default
 | 
					        device_id = ""  # Empty string for main device
 | 
				
			||||||
        device_name = None
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if CONF_DEVICE_ID in config:
 | 
					        if CONF_DEVICE_ID in config:
 | 
				
			||||||
            device_config = config[CONF_DEVICE_ID]
 | 
					            device_id_obj = config[CONF_DEVICE_ID]
 | 
				
			||||||
            if hasattr(device_config, "id"):
 | 
					            # Use the device ID string directly for uniqueness
 | 
				
			||||||
                device_id = hash(device_config.id)
 | 
					            device_id = device_id_obj.id
 | 
				
			||||||
                # Try to get device name from CORE if available
 | 
					 | 
				
			||||||
                for dev in getattr(CORE, "devices", []):
 | 
					 | 
				
			||||||
                    if hasattr(dev, "id") and dev.id == device_config.id:
 | 
					 | 
				
			||||||
                        device_name = getattr(dev, "name", None)
 | 
					 | 
				
			||||||
                        break
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Calculate the base object ID
 | 
					        # For duplicate detection, just use the sanitized name
 | 
				
			||||||
        base_object_id = get_base_entity_object_id(
 | 
					        name_key = sanitize(snake_case(entity_name))
 | 
				
			||||||
            entity_name, CORE.friendly_name, device_name
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Check for duplicates
 | 
					        # Check for duplicates
 | 
				
			||||||
        unique_key = (device_id, platform, base_object_id)
 | 
					        unique_key = (device_id, platform, name_key)
 | 
				
			||||||
        if unique_key in CORE.unique_ids:
 | 
					        if unique_key in CORE.unique_ids:
 | 
				
			||||||
            entity_name_display = entity_name or base_object_id
 | 
					            device_prefix = f" on device '{device_id}'" if device_id else ""
 | 
				
			||||||
            device_prefix = f" on device '{device_name}'" if device_name else ""
 | 
					 | 
				
			||||||
            raise cv.Invalid(
 | 
					            raise cv.Invalid(
 | 
				
			||||||
                f"Duplicate {platform} entity with name '{entity_name_display}' found{device_prefix}. "
 | 
					                f"Duplicate {platform} entity with name '{entity_name}' found{device_prefix}. "
 | 
				
			||||||
                f"Each entity on a device must have a unique name within its platform."
 | 
					                f"Each entity on a device must have a unique name within its platform."
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user