ESPHome  2024.9.2
Public Member Functions | Protected Member Functions | Protected Attributes
esphome::lock::LockCall Class Reference

This class is used to encode all control actions on a lock device. More...

#include <lock.h>

Public Member Functions

 LockCall (Lock *parent)
 
LockCallset_state (LockState state)
 Set the state of the lock device. More...
 
LockCallset_state (optional< LockState > state)
 Set the state of the lock device. More...
 
LockCallset_state (const std::string &state)
 Set the state of the lock device based on a string. More...
 
void perform ()
 
const optional< LockState > & get_state () const
 

Protected Member Functions

void validate_ ()
 

Protected Attributes

Lock *const parent_
 
optional< LockStatestate_
 

Detailed Description

This class is used to encode all control actions on a lock device.

It is supposed to be used by all code that wishes to control a lock device (mqtt, api, lambda etc). Create an instance of this class by calling id(lock_device).make_call();. Then set all attributes with the set_x methods. Finally, to apply the changes call .perform();.

The integration that implements the lock device receives this instance with the control method. It should check all the properties it implements and apply them as needed. It should do so by getting all properties it controls with the getter methods in this class. If the optional value is set (check with .has_value()) that means the user wants to control this property. Get the value of the optional with the star operator (*call.get_state()) and apply it.

Definition at line 71 of file lock.h.

Constructor & Destructor Documentation

◆ LockCall()

esphome::lock::LockCall::LockCall ( Lock parent)
inline

Definition at line 73 of file lock.h.

Member Function Documentation

◆ get_state()

const optional< LockState > & esphome::lock::LockCall::get_state ( ) const

Definition at line 104 of file lock.cpp.

◆ perform()

void esphome::lock::LockCall::perform ( )

Definition at line 60 of file lock.cpp.

◆ set_state() [1/3]

LockCall & esphome::lock::LockCall::set_state ( LockState  state)

Set the state of the lock device.

Definition at line 78 of file lock.cpp.

◆ set_state() [2/3]

LockCall & esphome::lock::LockCall::set_state ( optional< LockState state)

Set the state of the lock device.

Definition at line 82 of file lock.cpp.

◆ set_state() [3/3]

LockCall & esphome::lock::LockCall::set_state ( const std::string &  state)

Set the state of the lock device based on a string.

Definition at line 86 of file lock.cpp.

◆ validate_()

void esphome::lock::LockCall::validate_ ( )
protected

Definition at line 69 of file lock.cpp.

Field Documentation

◆ parent_

Lock* const esphome::lock::LockCall::parent_
protected

Definition at line 89 of file lock.h.

◆ state_

optional<LockState> esphome::lock::LockCall::state_
protected

Definition at line 90 of file lock.h.


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