ESPHome 2026.3.0
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 opt_state = call.get_state();
29 if (!opt_state.has_value())
30 return;
31 auto state = *opt_state;
32 if (state == LOCK_STATE_LOCKED) {
33 this->prev_trigger_ = &this->lock_trigger_;
34 this->lock_trigger_.trigger();
35 } else if (state == LOCK_STATE_UNLOCKED) {
36 this->prev_trigger_ = &this->unlock_trigger_;
38 }
39
40 if (this->optimistic_)
41 this->publish_state(state);
42}
44 if (this->prev_trigger_ != nullptr) {
46 }
47 this->prev_trigger_ = &this->open_trigger_;
48 this->open_trigger_.trigger();
49}
50void TemplateLock::set_optimistic(bool optimistic) { this->optimistic_ = optimistic; }
53 LOG_LOCK("", "Template Lock", this);
54 ESP_LOGCONFIG(TAG, " Optimistic: %s", YESNO(this->optimistic_));
55}
56
57} // 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:325
void stop_action()
Stop any action connected to this trigger.
Definition automation.h:333
This class is used to encode all control actions on a lock device.
Definition lock.h:77
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[3]
@ LOCK_STATE_UNLOCKED
Definition lock.h:26
@ LOCK_STATE_LOCKED
Definition lock.h:25
constexpr float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition component.h:29
const char *const TAG
Definition spi.cpp:7