diff --git a/esphome/core/__init__.py b/esphome/core/__init__.py index bb7c16c5ed..368e2affe9 100644 --- a/esphome/core/__init__.py +++ b/esphome/core/__init__.py @@ -523,7 +523,7 @@ 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, object_id) tuples + # Set of (device_id, platform, sanitized_name) tuples self.unique_ids: set[tuple[str, str, str]] = set() # Whether ESPHome was started in verbose mode self.verbose = False diff --git a/tests/integration/test_duplicate_entities.py b/tests/integration/test_duplicate_entities.py index 2fdfad979a..99968204d4 100644 --- a/tests/integration/test_duplicate_entities.py +++ b/tests/integration/test_duplicate_entities.py @@ -64,8 +64,7 @@ async def test_duplicate_entities_on_different_devices( temp_object_ids = set() for sensor in temp_sensors: - device_id = getattr(sensor, "device_id", None) - temp_device_ids.add(device_id) + temp_device_ids.add(sensor.device_id) temp_object_ids.add(sensor.object_id) # All should have object_id "temperature" (no suffix) @@ -128,19 +127,11 @@ async def test_duplicate_entities_on_different_devices( ) # Group by device - c1_buttons = [ - b - for b in empty_buttons - if getattr(b, "device_id", 0) == controller_1.device_id - ] - c2_buttons = [ - b - for b in empty_buttons - if getattr(b, "device_id", 0) == controller_2.device_id - ] + c1_buttons = [b for b in empty_buttons if b.device_id == controller_1.device_id] + c2_buttons = [b for b in empty_buttons if b.device_id == controller_2.device_id] # For main device, device_id is 0 - main_buttons = [b for b in empty_buttons if getattr(b, "device_id", 0) == 0] + main_buttons = [b for b in empty_buttons if b.device_id == 0] # Check object IDs for empty name entities assert len(c1_buttons) == 1 and c1_buttons[0].object_id == "controller_1"