ESPHome  2022.6.2
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
esphome::lock::Lock Class Referenceabstract

Base class for all locks. More...

#include <lock.h>

Inheritance diagram for esphome::lock::Lock:
esphome::EntityBase esphome::copy::CopyLock esphome::output::OutputLock esphome::template_::TemplateLock

Public Member Functions

 Lock ()
 
 Lock (const std::string &name)
 
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
 EntityBase ()
 
 EntityBase (std::string name)
 
const std::string & get_name () const
 
void set_name (const std::string &name)
 
const std::string & get_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)
 
const std::string & get_icon () const
 
void set_icon (const std::string &name)
 

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< LockStatepublish_dedup_
 
ESPPreferenceObject rtc_
 
- Protected Attributes inherited from esphome::EntityBase
std::string name_
 
std::string object_id_
 
std::string icon_
 
uint32_t object_id_hash_
 
bool internal_ {false}
 
bool disabled_by_default_ {false}
 
EntityCategory entity_category_ {ENTITY_CATEGORY_NONE}
 

Detailed Description

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.

Definition at line 103 of file lock.h.

Constructor & Destructor Documentation

◆ Lock() [1/2]

esphome::lock::Lock::Lock ( )
explicit

Definition at line 28 of file lock.cpp.

◆ Lock() [2/2]

esphome::lock::Lock::Lock ( const std::string &  name)
explicit

Definition at line 27 of file lock.cpp.

Member Function Documentation

◆ add_on_state_callback()

void esphome::lock::Lock::add_on_state_callback ( std::function< void()> &&  callback)

Set callback for state changes.

Parameters
callbackThe void(bool) callback.

Definition at line 59 of file lock.cpp.

◆ control()

virtual void esphome::lock::Lock::control ( const LockCall call)
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.

Parameters
callThe LockCall instance encoding all attribute changes.

Implemented in esphome::template_::TemplateLock, esphome::output::OutputLock, and esphome::copy::CopyLock.

◆ lock()

void esphome::lock::Lock::lock ( )

Turn this lock on.

This is called by the front-end.

For implementing locks, please override control.

Definition at line 31 of file lock.cpp.

◆ make_call()

LockCall esphome::lock::Lock::make_call ( )

Make a lock device control call, this is used to control the lock device, see the LockCall description for more info.

Returns
A new LockCall instance targeting this lock device.

Definition at line 29 of file lock.cpp.

◆ open()

void esphome::lock::Lock::open ( )

Open (unlatch) this lock.

This is called by the front-end.

For implementing locks, please override control.

Definition at line 41 of file lock.cpp.

◆ open_latch()

virtual void esphome::lock::Lock::open_latch ( )
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.

Definition at line 158 of file lock.h.

◆ publish_state()

void esphome::lock::Lock::publish_state ( LockState  state)

Publish a state to the front-end from the back-end.

Then the internal value member is set and finally the callbacks are called.

Parameters
stateThe new state.

Definition at line 49 of file lock.cpp.

◆ unlock()

void esphome::lock::Lock::unlock ( )

Turn this lock off.

This is called by the front-end.

For implementing locks, please override control.

Definition at line 36 of file lock.cpp.

Field Documentation

◆ LockCall

friend esphome::lock::Lock::LockCall
protected

Definition at line 150 of file lock.h.

◆ publish_dedup_

Deduplicator<LockState> esphome::lock::Lock::publish_dedup_
protected

Definition at line 171 of file lock.h.

◆ rtc_

ESPPreferenceObject esphome::lock::Lock::rtc_
protected

Definition at line 172 of file lock.h.

◆ state

LockState esphome::lock::Lock::state {LOCK_STATE_NONE}

The current reported state of the lock.

Definition at line 123 of file lock.h.

◆ state_callback_

CallbackManager<void()> esphome::lock::Lock::state_callback_ {}
protected

Definition at line 170 of file lock.h.

◆ traits

LockTraits esphome::lock::Lock::traits

Definition at line 125 of file lock.h.


The documentation for this class was generated from the following files: