ESPHome 2025.5.0
Loading...
Searching...
No Matches
automation.h
Go to the documentation of this file.
1#pragma once
2
6
7namespace esphome {
8namespace lock {
9
10template<typename... Ts> class LockAction : public Action<Ts...> {
11 public:
12 explicit LockAction(Lock *a_lock) : lock_(a_lock) {}
13
14 void play(Ts... x) override { this->lock_->lock(); }
15
16 protected:
18};
19
20template<typename... Ts> class UnlockAction : public Action<Ts...> {
21 public:
22 explicit UnlockAction(Lock *a_lock) : lock_(a_lock) {}
23
24 void play(Ts... x) override { this->lock_->unlock(); }
25
26 protected:
28};
29
30template<typename... Ts> class OpenAction : public Action<Ts...> {
31 public:
32 explicit OpenAction(Lock *a_lock) : lock_(a_lock) {}
33
34 void play(Ts... x) override { this->lock_->open(); }
35
36 protected:
38};
39
40template<typename... Ts> class LockCondition : public Condition<Ts...> {
41 public:
42 LockCondition(Lock *parent, bool state) : parent_(parent), state_(state) {}
43 bool check(Ts... x) override {
45 return this->parent_->state == check_state;
46 }
47
48 protected:
50 bool state_;
51};
52
53class LockLockTrigger : public Trigger<> {
54 public:
56 a_lock->add_on_state_callback([this, a_lock]() {
57 if (a_lock->state == LockState::LOCK_STATE_LOCKED) {
58 this->trigger();
59 }
60 });
61 }
62};
63
64class LockUnlockTrigger : public Trigger<> {
65 public:
67 a_lock->add_on_state_callback([this, a_lock]() {
69 this->trigger();
70 }
71 });
72 }
73};
74
75} // namespace lock
76} // namespace esphome
Base class for all automation conditions.
Definition automation.h:75
void trigger(Ts... x)
Definition automation.h:96
void play(Ts... x) override
Definition automation.h:14
LockAction(Lock *a_lock)
Definition automation.h:12
LockCondition(Lock *parent, bool state)
Definition automation.h:42
bool check(Ts... x) override
Definition automation.h:43
Base class for all locks.
Definition lock.h:103
void lock()
Turn this lock on.
Definition lock.cpp:30
void add_on_state_callback(std::function< void()> &&callback)
Set callback for state changes.
Definition lock.cpp:58
LockState state
The current reported state of the lock.
Definition lock.h:122
void unlock()
Turn this lock off.
Definition lock.cpp:35
void open()
Open (unlatch) this lock.
Definition lock.cpp:40
void play(Ts... x) override
Definition automation.h:34
OpenAction(Lock *a_lock)
Definition automation.h:32
void play(Ts... x) override
Definition automation.h:24
bool state
Definition fan.h:0
@ LOCK_STATE_UNLOCKED
Definition lock.h:29
@ LOCK_STATE_LOCKED
Definition lock.h:28
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint16_t x
Definition tt21100.cpp:5