[core] Fix compilation errors when platform sections have no entities (#10023)

This commit is contained in:
J. Nick Koston 2025-08-02 13:59:20 -10:00 committed by GitHub
parent fd442cc485
commit 296442d8f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 18 additions and 22 deletions

View File

@ -348,4 +348,3 @@ async def alarm_control_panel_is_armed_to_code(
@coroutine_with_priority(100.0)
async def to_code(config):
cg.add_global(alarm_control_panel_ns.using)
cg.add_define("USE_ALARM_CONTROL_PANEL")

View File

@ -654,7 +654,6 @@ async def binary_sensor_is_off_to_code(config, condition_id, template_arg, args)
@coroutine_with_priority(100.0)
async def to_code(config):
cg.add_define("USE_BINARY_SENSOR")
cg.add_global(binary_sensor_ns.using)

View File

@ -137,4 +137,3 @@ async def button_press_to_code(config, action_id, template_arg, args):
@coroutine_with_priority(100.0)
async def to_code(config):
cg.add_global(button_ns.using)
cg.add_define("USE_BUTTON")

View File

@ -519,5 +519,4 @@ async def climate_control_to_code(config, action_id, template_arg, args):
@coroutine_with_priority(100.0)
async def to_code(config):
cg.add_define("USE_CLIMATE")
cg.add_global(climate_ns.using)

View File

@ -265,5 +265,4 @@ async def cover_control_to_code(config, action_id, template_arg, args):
@coroutine_with_priority(100.0)
async def to_code(config):
cg.add_define("USE_COVER")
cg.add_global(cover_ns.using)

View File

@ -164,7 +164,6 @@ async def register_datetime(var, config):
cg.add(getattr(cg.App, f"register_{entity_type}")(var))
CORE.register_platform_component(entity_type, var)
await setup_datetime_core_(var, config)
cg.add_define(f"USE_DATETIME_{config[CONF_TYPE]}")
async def new_datetime(config, *args):
@ -175,7 +174,6 @@ async def new_datetime(config, *args):
@coroutine_with_priority(100.0)
async def to_code(config):
cg.add_define("USE_DATETIME")
cg.add_global(datetime_ns.using)

View File

@ -145,5 +145,4 @@ async def event_fire_to_code(config, action_id, template_arg, args):
@coroutine_with_priority(100.0)
async def to_code(config):
cg.add_define("USE_EVENT")
cg.add_global(event_ns.using)

View File

@ -400,5 +400,4 @@ async def fan_is_on_off_to_code(config, condition_id, template_arg, args):
@coroutine_with_priority(100.0)
async def to_code(config):
cg.add_define("USE_FAN")
cg.add_global(fan_ns.using)

View File

@ -285,5 +285,4 @@ async def new_light(config, *args):
@coroutine_with_priority(100.0)
async def to_code(config):
cg.add_define("USE_LIGHT")
cg.add_global(light_ns.using)

View File

@ -158,4 +158,3 @@ async def lock_is_off_to_code(config, condition_id, template_arg, args):
@coroutine_with_priority(100.0)
async def to_code(config):
cg.add_global(lock_ns.using)
cg.add_define("USE_LOCK")

View File

@ -323,7 +323,6 @@ async def number_in_range_to_code(config, condition_id, template_arg, args):
@coroutine_with_priority(100.0)
async def to_code(config):
cg.add_define("USE_NUMBER")
cg.add_global(number_ns.using)

View File

@ -126,7 +126,6 @@ async def new_select(config, *, options: list[str]):
@coroutine_with_priority(100.0)
async def to_code(config):
cg.add_define("USE_SELECT")
cg.add_global(select_ns.using)

View File

@ -1139,5 +1139,4 @@ def _lstsq(a, b):
@coroutine_with_priority(100.0)
async def to_code(config):
cg.add_define("USE_SENSOR")
cg.add_global(sensor_ns.using)

View File

@ -202,4 +202,3 @@ async def switch_is_off_to_code(config, condition_id, template_arg, args):
@coroutine_with_priority(100.0)
async def to_code(config):
cg.add_global(switch_ns.using)
cg.add_define("USE_SWITCH")

View File

@ -151,7 +151,6 @@ async def new_text(
@coroutine_with_priority(100.0)
async def to_code(config):
cg.add_define("USE_TEXT")
cg.add_global(text_ns.using)

View File

@ -232,7 +232,6 @@ async def new_text_sensor(config, *args):
@coroutine_with_priority(100.0)
async def to_code(config):
cg.add_define("USE_TEXT_SENSOR")
cg.add_global(text_sensor_ns.using)

View File

@ -126,7 +126,6 @@ async def new_update(config):
@coroutine_with_priority(100.0)
async def to_code(config):
cg.add_define("USE_UPDATE")
cg.add_global(update_ns.using)

View File

@ -235,5 +235,4 @@ async def valve_control_to_code(config, action_id, template_arg, args):
@coroutine_with_priority(100.0)
async def to_code(config):
cg.add_define("USE_VALVE")
cg.add_global(valve_ns.using)

View File

@ -419,13 +419,28 @@ async def _add_automations(config):
await automation.build_automation(trigger, [], conf)
# Datetime component has special subtypes that need additional defines
DATETIME_SUBTYPES = {"date", "time", "datetime"}
@coroutine_with_priority(-100.0)
async def _add_platform_reserves() -> None:
# Generate compile-time entity count defines for static_entity_vector
async def _add_platform_defines() -> None:
# Generate compile-time defines for platforms that have actual entities
# Only add USE_* and count defines when there are entities
for platform_name, count in sorted(CORE.platform_counts.items()):
if count <= 0:
continue
define_name = f"ESPHOME_ENTITY_{platform_name.upper()}_COUNT"
cg.add_define(define_name, count)
# Datetime subtypes only use USE_DATETIME_* defines
if platform_name in DATETIME_SUBTYPES:
cg.add_define(f"USE_DATETIME_{platform_name.upper()}")
else:
# Regular platforms use USE_* defines
cg.add_define(f"USE_{platform_name.upper()}")
@coroutine_with_priority(100.0)
async def to_code(config: ConfigType) -> None:
@ -449,7 +464,7 @@ async def to_code(config: ConfigType) -> None:
cg.RawStatement(f"App.reserve_components({len(CORE.component_ids)});"),
)
CORE.add_job(_add_platform_reserves)
CORE.add_job(_add_platform_defines)
CORE.add_job(_add_automations, config)