From 44860ff5125af133276f8a66ded1790c9fd23637 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" <3060199+jesserockz@users.noreply.github.com> Date: Tue, 25 Aug 2026 00:22:41 -0500 Subject: [PATCH] [time] Skip posix_tz.cpp when no timezone is configured (#18680) --- esphome/components/time/__init__.py | 8 ++++++++ tests/benchmarks/components/time/__init__.py | 2 +- tests/components/time/__init__.py | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/esphome/components/time/__init__.py b/esphome/components/time/__init__.py index 94ff6ab051..7ad084493c 100644 --- a/esphome/components/time/__init__.py +++ b/esphome/components/time/__init__.py @@ -9,6 +9,7 @@ from esphome import automation from esphome.automation import Condition import esphome.codegen as cg from esphome.components.zephyr import zephyr_add_prj_conf +from esphome.config_helpers import filter_source_files_from_defines import esphome.config_validation as cv from esphome.const import ( CONF_AT, @@ -475,3 +476,10 @@ async def to_code(config): async def time_has_time_to_code(config, condition_id, template_arg, args): paren = await cg.get_variable(config[CONF_ID]) return cg.new_Pvariable(condition_id, template_arg, paren) + + +# posix_tz.cpp is fully #ifdef'd on USE_TIME_TIMEZONE, set only when a +# timezone is configured or detected. +FILTER_SOURCE_FILES = filter_source_files_from_defines( + {"posix_tz.cpp": "USE_TIME_TIMEZONE"} +) diff --git a/tests/benchmarks/components/time/__init__.py b/tests/benchmarks/components/time/__init__.py index 7f68003e29..8b4fd955f2 100644 --- a/tests/benchmarks/components/time/__init__.py +++ b/tests/benchmarks/components/time/__init__.py @@ -4,6 +4,6 @@ from tests.testing_helpers import ComponentManifestOverride def override_manifest(manifest: ComponentManifestOverride) -> None: async def to_code(config): - cg.add_build_flag("-DUSE_TIME_TIMEZONE") + cg.add_define("USE_TIME_TIMEZONE") manifest.to_code = to_code diff --git a/tests/components/time/__init__.py b/tests/components/time/__init__.py index 7f68003e29..8b4fd955f2 100644 --- a/tests/components/time/__init__.py +++ b/tests/components/time/__init__.py @@ -4,6 +4,6 @@ from tests.testing_helpers import ComponentManifestOverride def override_manifest(manifest: ComponentManifestOverride) -> None: async def to_code(config): - cg.add_build_flag("-DUSE_TIME_TIMEZONE") + cg.add_define("USE_TIME_TIMEZONE") manifest.to_code = to_code