add boot delay component
This commit is contained in:
12
components/boot_delay/README.md
Normal file
12
components/boot_delay/README.md
Normal 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
|
||||
```
|
||||
|
||||
18
components/boot_delay/__init__.py
Normal file
18
components/boot_delay/__init__.py
Normal 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]))
|
||||
13
components/boot_delay/boot_delay.cpp
Normal file
13
components/boot_delay/boot_delay.cpp
Normal 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
|
||||
|
||||
19
components/boot_delay/boot_delay.h
Normal file
19
components/boot_delay/boot_delay.h
Normal 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
|
||||
|
||||
Reference in New Issue
Block a user