ESPHome 2025.12.3
Loading...
Searching...
No Matches
template_lock.cpp
Go to the documentation of this file.
1#include "template_lock.h"
2#include "esphome/core/log.h"
3
4namespace esphome::template_ {
5
6using namespace esphome::lock;
7
8static const char *const TAG = "template.lock";
9
11 : lock_trigger_(new Trigger<>()), unlock_trigger_(new Trigger<>()), open_trigger_(new Trigger<>()) {}
12
14 if (!this->f_.has_value())
15 this->disable_loop();
16}
17
19 auto val = this->f_();
20 if (val.has_value()) {
21 this->publish_state(*val);
22 }
23}
25 if (this->prev_trigger_ != nullptr) {
27 }
28
29 auto state = *call.get_state();
30 if (state == LOCK_STATE_LOCKED) {
31 this->prev_trigger_ = this->lock_trigger_;
32 this->lock_trigger_->trigger();
33 } else if (state == LOCK_STATE_UNLOCKED) {
34 this->prev_trigger_ = this->unlock_trigger_;
35 this->unlock_trigger_->trigger();
36 }
37
38 if (this->optimistic_)
39 this->publish_state(state);
40}
42 if (this->prev_trigger_ != nullptr) {
44 }
45 this->prev_trigger_ = this->open_trigger_;
46 this->open_trigger_->trigger();
47}
48void TemplateLock::set_optimistic(bool optimistic) { this->optimistic_ = optimistic; }
54 LOG_LOCK("", "Template Lock", this);
55 ESP_LOGCONFIG(TAG, " Optimistic: %s", YESNO(this->optimistic_));
56}
57
58} // namespace esphome::template_
void disable_loop()
Disable this component's loop.
bool has_value() const
Check if a lambda is set.
void trigger(const Ts &...x)
Inform the parent automation that the event has triggered.
Definition automation.h:204
void stop_action()
Stop any action connected to this trigger.
Definition automation.h:212
This class is used to encode all control actions on a lock device.
Definition lock.h:79
const optional< LockState > & get_state() const
Definition lock.cpp:107
void publish_state(LockState state)
Publish a state to the front-end from the back-end.
Definition lock.cpp:49
LockState state
The current reported state of the lock.
Definition lock.h:130
float get_setup_priority() const override
void set_optimistic(bool optimistic)
void control(const lock::LockCall &call) override
TemplateLambda< lock::LockState > f_
mopeka_std_values val[4]
@ LOCK_STATE_UNLOCKED
Definition lock.h:28
@ LOCK_STATE_LOCKED
Definition lock.h:27
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition component.cpp:80
const char *const TAG
Definition spi.cpp:8