[uptime] Skip the timestamp sensor source unless a timestamp sensor is configured (#18746)

This commit is contained in:
J. Nick Koston
2026-08-25 17:24:20 +12:00
committed by GitHub
parent 036e5cda7e
commit 791590c8a3
8 changed files with 74 additions and 5 deletions
+2 -1
View File
@@ -61,8 +61,9 @@ async def to_code(config: ConfigType) -> None:
if time_id_config := config.get(CONF_TIME_ID):
time_id = await cg.get_variable(time_id_config)
cg.add(var.set_time(time_id))
cg.add_define("USE_UPTIME_TIMESTAMP")
FILTER_SOURCE_FILES = filter_source_files_from_defines(
{"uptime_timestamp_sensor.cpp": "USE_TIME"}
{"uptime_timestamp_sensor.cpp": "USE_UPTIME_TIMESTAMP"}
)
@@ -1,6 +1,6 @@
#include "uptime_timestamp_sensor.h"
#ifdef USE_TIME
#ifdef USE_UPTIME_TIMESTAMP
#include "esphome/core/hal.h"
#include "esphome/core/helpers.h"
@@ -34,4 +34,4 @@ void UptimeTimestampSensor::dump_config() {
} // namespace esphome::uptime
#endif // USE_TIME
#endif // USE_UPTIME_TIMESTAMP
@@ -2,7 +2,7 @@
#include "esphome/core/defines.h"
#ifdef USE_TIME
#ifdef USE_UPTIME_TIMESTAMP
#include "esphome/components/sensor/sensor.h"
#include "esphome/components/time/real_time_clock.h"
@@ -25,4 +25,4 @@ class UptimeTimestampSensor final : public sensor::Sensor, public Component {
} // namespace esphome::uptime
#endif // USE_TIME
#endif // USE_UPTIME_TIMESTAMP