mirror of
https://github.com/esphome/esphome.git
synced 2025-08-03 00:47:47 +00:00
[core] Fix compilation errors when platform sections have no entities (#10023)
This commit is contained in:
parent
fd442cc485
commit
296442d8f1
@ -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")
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
@ -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")
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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")
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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")
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user