add boot delay component

This commit is contained in:
Samuel Sieb
2024-01-07 22:23:12 -08:00
parent 0f4795817d
commit 5abeac2a65
4 changed files with 62 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
# delay boot for a period of time
A component to make the boot wait at a certain priority.
Can be used multiple times.
Example:
```yaml
boot_delay:
delay: 5s # the amount of time since the boot started
setup_priority: 600
```

View File

@@ -0,0 +1,18 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.const import CONF_ID, CONF_DELAY
MULTI_CONF = True
set_ns = cg.esphome_ns.namespace('boot_delay')
BootDelay = set_ns.class_('BootDelay', cg.Component)
CONFIG_SCHEMA = cv.COMPONENT_SCHEMA.extend({
cv.GenerateID(): cv.declare_id(BootDelay),
cv.Required(CONF_DELAY): cv.positive_time_period_milliseconds,
})
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
cg.add(var.set_delay(config[CONF_DELAY]))

View File

@@ -0,0 +1,13 @@
#include "boot_delay.h"
#include "esphome/core/hal.h"
namespace esphome {
namespace boot_delay {
bool BootDelay::can_proceed() {
return millis() >= this->delay_;
}
} // namespace boot_delay
} // namespace esphome

View File

@@ -0,0 +1,19 @@
#pragma once
#include "esphome/core/component.h"
namespace esphome {
namespace boot_delay {
class BootDelay : public Component {
public:
bool can_proceed() override;
void set_delay(uint32_t delay) { this->delay_ = delay; }
protected:
uint32_t delay_;
};
} // namespace boot_delay
} // namespace esphome