mirror of
https://github.com/esphome/esphome.git
synced 2024-11-21 22:48:10 +01:00
Add duration option to action start deep sleep (#1526)
This commit is contained in:
parent
f95be6a0df
commit
dce20680d7
3 changed files with 29 additions and 5 deletions
|
@ -84,18 +84,28 @@ def to_code(config):
|
|||
cg.add_define('USE_DEEP_SLEEP')
|
||||
|
||||
|
||||
DEEP_SLEEP_ACTION_SCHEMA = automation.maybe_simple_id({
|
||||
DEEP_SLEEP_ENTER_SCHEMA = automation.maybe_simple_id({
|
||||
cv.GenerateID(): cv.use_id(DeepSleepComponent),
|
||||
cv.Optional(CONF_SLEEP_DURATION): cv.positive_time_period_milliseconds,
|
||||
})
|
||||
|
||||
|
||||
DEEP_SLEEP_PREVENT_SCHEMA = automation.maybe_simple_id({
|
||||
cv.GenerateID(): cv.use_id(DeepSleepComponent),
|
||||
})
|
||||
|
||||
|
||||
@automation.register_action('deep_sleep.enter', EnterDeepSleepAction, DEEP_SLEEP_ACTION_SCHEMA)
|
||||
@automation.register_action('deep_sleep.enter', EnterDeepSleepAction, DEEP_SLEEP_ENTER_SCHEMA)
|
||||
def deep_sleep_enter_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
yield cg.new_Pvariable(action_id, template_arg, paren)
|
||||
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||
if CONF_SLEEP_DURATION in config:
|
||||
template_ = yield cg.templatable(config[CONF_SLEEP_DURATION], args, cg.int32)
|
||||
cg.add(var.set_sleep_duration(template_))
|
||||
yield var
|
||||
|
||||
|
||||
@automation.register_action('deep_sleep.prevent', PreventDeepSleepAction, DEEP_SLEEP_ACTION_SCHEMA)
|
||||
@automation.register_action('deep_sleep.prevent', PreventDeepSleepAction, DEEP_SLEEP_PREVENT_SCHEMA)
|
||||
def deep_sleep_prevent_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
yield cg.new_Pvariable(action_id, template_arg, paren)
|
||||
|
|
|
@ -84,8 +84,14 @@ extern bool global_has_deep_sleep;
|
|||
template<typename... Ts> class EnterDeepSleepAction : public Action<Ts...> {
|
||||
public:
|
||||
EnterDeepSleepAction(DeepSleepComponent *deep_sleep) : deep_sleep_(deep_sleep) {}
|
||||
TEMPLATABLE_VALUE(uint32_t, sleep_duration);
|
||||
|
||||
void play(Ts... x) override { this->deep_sleep_->begin_sleep(true); }
|
||||
void play(Ts... x) override {
|
||||
if (this->sleep_duration_.has_value()) {
|
||||
this->deep_sleep_->set_sleep_duration(this->sleep_duration_.value(x...));
|
||||
}
|
||||
this->deep_sleep_->begin_sleep(true);
|
||||
}
|
||||
|
||||
protected:
|
||||
DeepSleepComponent *deep_sleep_;
|
||||
|
|
|
@ -45,6 +45,12 @@ ota:
|
|||
logger:
|
||||
level: DEBUG
|
||||
|
||||
deep_sleep:
|
||||
run_duration: 20s
|
||||
sleep_duration: 50s
|
||||
wakeup_pin: GPIO39
|
||||
wakeup_pin_mode: INVERT_WAKEUP
|
||||
|
||||
as3935_i2c:
|
||||
irq_pin: GPIO12
|
||||
|
||||
|
@ -302,6 +308,8 @@ text_sensor:
|
|||
- homeassistant.tag_scanned:
|
||||
tag: 1234-abcd
|
||||
- homeassistant.tag_scanned: 1234-abcd
|
||||
- deep_sleep.enter:
|
||||
sleep_duration: 30min
|
||||
- platform: template
|
||||
name: 'Template Text Sensor'
|
||||
lambda: |-
|
||||
|
|
Loading…
Reference in a new issue