ESPHome 2025.12.0-dev
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 {
5namespace template_ {
6
7using namespace esphome::lock;
8
9static const char *const TAG = "template.lock";
10
12 : lock_trigger_(new Trigger<>()), unlock_trigger_(new Trigger<>()), open_trigger_(new Trigger<>()) {}
13
15 if (!this->f_.has_value())
16 this->disable_loop();
17}
18
20 auto val = this->f_();
21 if (val.has_value()) {
22 this->publish_state(*val);
23 }
24}
26 if (this->prev_trigger_ != nullptr) {
28 }
29
30 auto state = *call.get_state();
31 if (state == LOCK_STATE_LOCKED) {
32 this->prev_trigger_ = this->lock_trigger_;
33 this->lock_trigger_->trigger();
34 } else if (state == LOCK_STATE_UNLOCKED) {
35 this->prev_trigger_ = this->unlock_trigger_;
36 this->unlock_trigger_->trigger();
37 }
38
39 if (this->optimistic_)
40 this->publish_state(state);
41}
43 if (this->prev_trigger_ != nullptr) {
45 }
46 this->prev_trigger_ = this->open_trigger_;
47 this->open_trigger_->trigger();
48}
49void TemplateLock::set_optimistic(bool optimistic) { this->optimistic_ = optimistic; }
55 LOG_LOCK("", "Template Lock", this);
56 ESP_LOGCONFIG(TAG, " Optimistic: %s", YESNO(this->optimistic_));
57}
58
59} // namespace template_
60} // namespace esphome
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:169
void stop_action()
Stop any action connected to this trigger.
Definition automation.h:177
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:109
void publish_state(LockState state)
Publish a state to the front-end from the back-end.
Definition lock.cpp:50
LockState state
The current reported state of the lock.
Definition lock.h:128
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:29
@ LOCK_STATE_LOCKED
Definition lock.h:28
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition component.cpp:58
const char *const TAG
Definition spi.cpp:8
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7