From 836f403d5323276e61c6870dd28508af12d9b193 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 1 Mar 2026 12:11:44 -1000 Subject: [PATCH] reduce generated code --- esphome/core/config.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/esphome/core/config.py b/esphome/core/config.py index 475c441793..002ea65cee 100644 --- a/esphome/core/config.py +++ b/esphome/core/config.py @@ -1,5 +1,6 @@ from __future__ import annotations +from collections import Counter import logging import os from pathlib import Path @@ -515,10 +516,11 @@ async def _add_looping_components() -> None: if not entries: return - # Build constexpr sum for the exact count + # Build constexpr sum for the exact count, deduplicating by type + type_counts = Counter(entries) terms = [ - f"(!std::is_same_v)" - for cpp_type in entries + f"({count} * !std::is_same_v)" + for cpp_type, count in type_counts.items() ] constexpr_expr = " + \\\n ".join(terms) cg.add_global(