ESPHome 2026.2.1
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
13 if (!this->f_.has_value())
14 this->disable_loop();
15}
16
18 auto val = this->f_();
19 if (val.has_value()) {
20 this->publish_state(*val);
21 }
22}
24 if (this->prev_trigger_ != nullptr) {
26 }
27
28 auto state = *call.get_state();
29 if (state == LOCK_STATE_LOCKED) {
30 this->prev_trigger_ = &this->lock_trigger_;
31 this->lock_trigger_.trigger();
32 } else if (state == LOCK_STATE_UNLOCKED) {
33 this->prev_trigger_ = &this->unlock_trigger_;
35 }
36
37 if (this->optimistic_)
38 this->publish_state(state);
39}
41 if (this->prev_trigger_ != nullptr) {
43 }
44 this->prev_trigger_ = &this->open_trigger_;
45 this->open_trigger_.trigger();
46}
47void TemplateLock::set_optimistic(bool optimistic) { this->optimistic_ = optimistic; }
50 LOG_LOCK("", "Template Lock", this);
51 ESP_LOGCONFIG(TAG, " Optimistic: %s", YESNO(this->optimistic_));
52}
53
54} // 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:279
void stop_action()
Stop any action connected to this trigger.
Definition automation.h:287
This class is used to encode all control actions on a lock device.
Definition lock.h:77
const optional< LockState > & get_state() const
Definition lock.cpp:96
void publish_state(LockState state)
Publish a state to the front-end from the back-end.
Definition lock.cpp:38
LockState state
The current reported state of the lock.
Definition lock.h:129
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:26
@ LOCK_STATE_LOCKED
Definition lock.h:25
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition component.cpp:83
const char *const TAG
Definition spi.cpp:7