mirror of
https://github.com/esphome/esphome.git
synced 2026-10-03 09:46:03 +00:00
[time] Skip automation.cpp when no on_time or on_time_sync automation is configured (#18750)
This commit is contained in:
@@ -426,7 +426,12 @@ async def setup_time_core_(time_var, config):
|
||||
raise EsphomeError(f"Invalid timezone: {timezone}") from e
|
||||
_emit_parsed_timezone_fields(parsed)
|
||||
|
||||
for conf in config.get(CONF_ON_TIME, []):
|
||||
on_time = config.get(CONF_ON_TIME, [])
|
||||
on_time_sync = config.get(CONF_ON_TIME_SYNC, [])
|
||||
if on_time or on_time_sync:
|
||||
cg.add_define("USE_TIME_TRIGGERS")
|
||||
|
||||
for conf in on_time:
|
||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], time_var)
|
||||
|
||||
seconds = conf.get(CONF_SECONDS, list(range(61)))
|
||||
@@ -445,7 +450,7 @@ async def setup_time_core_(time_var, config):
|
||||
await cg.register_component(trigger, conf)
|
||||
await automation.build_automation(trigger, [], conf)
|
||||
|
||||
for conf in config.get(CONF_ON_TIME_SYNC, []):
|
||||
for conf in on_time_sync:
|
||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], time_var)
|
||||
|
||||
await cg.register_component(trigger, conf)
|
||||
@@ -479,7 +484,11 @@ async def time_has_time_to_code(config, condition_id, template_arg, args):
|
||||
|
||||
|
||||
# posix_tz.cpp is fully #ifdef'd on USE_TIME_TIMEZONE, set only when a
|
||||
# timezone is configured or detected.
|
||||
# timezone is configured or detected; automation.cpp holds the on_time and
|
||||
# on_time_sync triggers and is #ifdef'd on USE_TIME_TRIGGERS.
|
||||
FILTER_SOURCE_FILES = filter_source_files_from_defines(
|
||||
{"posix_tz.cpp": "USE_TIME_TIMEZONE"}
|
||||
{
|
||||
"posix_tz.cpp": "USE_TIME_TIMEZONE",
|
||||
"automation.cpp": "USE_TIME_TRIGGERS",
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "automation.h"
|
||||
#ifdef USE_TIME_TRIGGERS
|
||||
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
@@ -98,3 +99,5 @@ SyncTrigger::SyncTrigger(RealTimeClock *rtc) : rtc_(rtc) {
|
||||
}
|
||||
|
||||
} // namespace esphome::time
|
||||
|
||||
#endif // USE_TIME_TRIGGERS
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/defines.h"
|
||||
#ifdef USE_TIME_TRIGGERS
|
||||
|
||||
#include "esphome/core/automation.h"
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/time.h"
|
||||
@@ -49,3 +52,5 @@ class SyncTrigger final : public Trigger<>, public Component {
|
||||
RealTimeClock *rtc_;
|
||||
};
|
||||
} // namespace esphome::time
|
||||
|
||||
#endif // USE_TIME_TRIGGERS
|
||||
|
||||
Reference in New Issue
Block a user