ESPHome
2024.11.0
|
Base class for all locks. More...
#include <lock.h>
Public Member Functions | |
Lock () | |
LockCall | make_call () |
Make a lock device control call, this is used to control the lock device, see the LockCall description for more info. More... | |
void | publish_state (LockState state) |
Publish a state to the front-end from the back-end. More... | |
void | lock () |
Turn this lock on. More... | |
void | unlock () |
Turn this lock off. More... | |
void | open () |
Open (unlatch) this lock. More... | |
void | add_on_state_callback (std::function< void()> &&callback) |
Set callback for state changes. More... | |
Public Member Functions inherited from esphome::EntityBase | |
const StringRef & | get_name () const |
void | set_name (const char *name) |
bool | has_own_name () const |
std::string | get_object_id () const |
void | set_object_id (const char *object_id) |
uint32_t | get_object_id_hash () |
bool | is_internal () const |
void | set_internal (bool internal) |
bool | is_disabled_by_default () const |
void | set_disabled_by_default (bool disabled_by_default) |
EntityCategory | get_entity_category () const |
void | set_entity_category (EntityCategory entity_category) |
std::string | get_icon () const |
void | set_icon (const char *icon) |
Data Fields | |
LockState | state {LOCK_STATE_NONE} |
The current reported state of the lock. More... | |
LockTraits | traits |
Protected Member Functions | |
virtual void | open_latch () |
Perform the open latch action with hardware. More... | |
virtual void | control (const LockCall &call)=0 |
Control the lock device, this is a virtual method that each lock integration must implement. More... | |
Protected Member Functions inherited from esphome::EntityBase | |
virtual uint32_t | hash_base () |
The hash_base() function has been deprecated. More... | |
void | calc_object_id_ () |
Protected Attributes | |
friend | LockCall |
CallbackManager< void()> | state_callback_ {} |
Deduplicator< LockState > | publish_dedup_ |
ESPPreferenceObject | rtc_ |
Protected Attributes inherited from esphome::EntityBase | |
StringRef | name_ |
const char * | object_id_c_str_ {nullptr} |
const char * | icon_c_str_ {nullptr} |
uint32_t | object_id_hash_ |
bool | has_own_name_ {false} |
bool | internal_ {false} |
bool | disabled_by_default_ {false} |
EntityCategory | entity_category_ {ENTITY_CATEGORY_NONE} |
Base class for all locks.
A lock is basically a switch with a combination of a binary sensor (for reporting lock values) and a write_state method that writes a state to the hardware. Locks can also have an "open" method to unlatch.
For integrations: Integrations must implement the method control(). Control will be called with the arguments supplied by the user and should be used to control all values of the lock.
void esphome::lock::Lock::add_on_state_callback | ( | std::function< void()> && | callback | ) |
|
protectedpure virtual |
Control the lock device, this is a virtual method that each lock integration must implement.
See more info in LockCall. The integration should check all of its values in this method and set them accordingly. At the end of the call, the integration must call publish_state()
to notify the frontend of a changed state.
call | The LockCall instance encoding all attribute changes. |
Implemented in esphome::template_::TemplateLock, esphome::output::OutputLock, and esphome::copy::CopyLock.
void esphome::lock::Lock::lock | ( | ) |
LockCall esphome::lock::Lock::make_call | ( | ) |
void esphome::lock::Lock::open | ( | ) |
|
inlineprotectedvirtual |
Perform the open latch action with hardware.
This method is optional to implement when creating a new lock.
In the implementation of this method, it is recommended you also call publish_state with "unlock" to acknowledge that the state was written to the hardware.
Reimplemented in esphome::template_::TemplateLock.
void esphome::lock::Lock::publish_state | ( | LockState | state | ) |
void esphome::lock::Lock::unlock | ( | ) |
|
protected |
|
protected |
LockState esphome::lock::Lock::state {LOCK_STATE_NONE} |
|
protected |
LockTraits esphome::lock::Lock::traits |