mirror of
https://github.com/esphome/esphome.git
synced 2025-01-31 02:00:55 +00:00
Add startup_delay to interval. (#5327)
This commit is contained in:
parent
8738cef5a3
commit
3ac59180ab
@ -1,7 +1,7 @@
|
|||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome import automation
|
from esphome import automation
|
||||||
from esphome.const import CONF_ID, CONF_INTERVAL
|
from esphome.const import CONF_ID, CONF_INTERVAL, CONF_STARTUP_DELAY
|
||||||
|
|
||||||
CODEOWNERS = ["@esphome/core"]
|
CODEOWNERS = ["@esphome/core"]
|
||||||
interval_ns = cg.esphome_ns.namespace("interval")
|
interval_ns = cg.esphome_ns.namespace("interval")
|
||||||
@ -13,6 +13,9 @@ CONFIG_SCHEMA = automation.validate_automation(
|
|||||||
cv.Schema(
|
cv.Schema(
|
||||||
{
|
{
|
||||||
cv.GenerateID(): cv.declare_id(IntervalTrigger),
|
cv.GenerateID(): cv.declare_id(IntervalTrigger),
|
||||||
|
cv.Optional(
|
||||||
|
CONF_STARTUP_DELAY, default="0s"
|
||||||
|
): cv.positive_time_period_milliseconds,
|
||||||
cv.Required(CONF_INTERVAL): cv.positive_time_period_milliseconds,
|
cv.Required(CONF_INTERVAL): cv.positive_time_period_milliseconds,
|
||||||
}
|
}
|
||||||
).extend(cv.COMPONENT_SCHEMA)
|
).extend(cv.COMPONENT_SCHEMA)
|
||||||
@ -26,3 +29,4 @@ async def to_code(config):
|
|||||||
await automation.build_automation(var, [], conf)
|
await automation.build_automation(var, [], conf)
|
||||||
|
|
||||||
cg.add(var.set_update_interval(conf[CONF_INTERVAL]))
|
cg.add(var.set_update_interval(conf[CONF_INTERVAL]))
|
||||||
|
cg.add(var.set_startup_delay(conf[CONF_STARTUP_DELAY]))
|
||||||
|
@ -8,8 +8,26 @@ namespace interval {
|
|||||||
|
|
||||||
class IntervalTrigger : public Trigger<>, public PollingComponent {
|
class IntervalTrigger : public Trigger<>, public PollingComponent {
|
||||||
public:
|
public:
|
||||||
void update() override { this->trigger(); }
|
void update() override {
|
||||||
|
if (this->started_)
|
||||||
|
this->trigger();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup() override {
|
||||||
|
if (this->startup_delay_ == 0) {
|
||||||
|
this->started_ = true;
|
||||||
|
} else {
|
||||||
|
this->set_timeout(this->startup_delay_, [this] { this->started_ = true; });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_startup_delay(const uint32_t startup_delay) { this->startup_delay_ = startup_delay; }
|
||||||
|
|
||||||
float get_setup_priority() const override { return setup_priority::DATA; }
|
float get_setup_priority() const override { return setup_priority::DATA; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
uint32_t startup_delay_{0};
|
||||||
|
bool started_{false};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace interval
|
} // namespace interval
|
||||||
|
@ -718,6 +718,7 @@ stepper:
|
|||||||
|
|
||||||
interval:
|
interval:
|
||||||
interval: 5s
|
interval: 5s
|
||||||
|
startup_delay: 10s
|
||||||
then:
|
then:
|
||||||
- logger.log: Interval Run
|
- logger.log: Interval Run
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user