Lock app minor fixes (#21764)
* Update comment in lock app
* remove unused mEndpointId
* add RequirePinForRemoteOperation logic to door lock linux example
* Restyled by clang-format
Co-authored-by: Restyled.io <commits@restyled.io>
diff --git a/examples/lock-app/efr32/include/LockManager.h b/examples/lock-app/efr32/include/LockManager.h
index 01332f9..0e6a3d5 100644
--- a/examples/lock-app/efr32/include/LockManager.h
+++ b/examples/lock-app/efr32/include/LockManager.h
@@ -171,7 +171,6 @@
private:
friend LockManager & LockMgr();
- chip::EndpointId mEndpointId;
State_t mState;
Callback_fn_initiated mActionInitiated_CB;
diff --git a/examples/lock-app/efr32/src/LockManager.cpp b/examples/lock-app/efr32/src/LockManager.cpp
index 7e52e95..63ce72e 100644
--- a/examples/lock-app/efr32/src/LockManager.cpp
+++ b/examples/lock-app/efr32/src/LockManager.cpp
@@ -643,7 +643,7 @@
// If a pin code is not given
if (!pin.HasValue())
{
- ChipLogDetail(Zcl, "Door Lock App: PIN code is not specified, but it is required [endpointId=%d]", mEndpointId);
+ ChipLogDetail(Zcl, "Door Lock App: PIN code is not specified [endpointId=%d]", endpointId);
// If a pin code is not required
if (!requirePin)
@@ -656,6 +656,8 @@
return true;
}
+ ChipLogError(Zcl, "Door Lock App: PIN code is not specified, but it is required [endpointId=%d]", endpointId);
+
return false;
}
@@ -672,7 +674,7 @@
{
ChipLogDetail(Zcl,
"Lock App: specified PIN code was found in the database, setting lock state to \"%s\" [endpointId=%d]",
- lockStateToString(lockState), mEndpointId);
+ lockStateToString(lockState), endpointId);
DoorLockServer::Instance().SetLockState(endpointId, lockState);
@@ -683,7 +685,7 @@
ChipLogDetail(Zcl,
"Door Lock App: specified PIN code was not found in the database, ignoring command to set lock state to \"%s\" "
"[endpointId=%d]",
- lockStateToString(lockState), mEndpointId);
+ lockStateToString(lockState), endpointId);
err = DlOperationError::kInvalidCredential;
return false;
diff --git a/examples/lock-app/linux/src/LockEndpoint.cpp b/examples/lock-app/linux/src/LockEndpoint.cpp
index 7c8518c..c3d52c6 100644
--- a/examples/lock-app/linux/src/LockEndpoint.cpp
+++ b/examples/lock-app/linux/src/LockEndpoint.cpp
@@ -16,6 +16,7 @@
* limitations under the License.
*/
#include "LockEndpoint.h"
+#include <app-common/zap-generated/attributes/Accessors.h>
#include <cstring>
using chip::to_underlying;
@@ -362,15 +363,29 @@
bool LockEndpoint::setLockState(DlLockState lockState, const Optional<chip::ByteSpan> & pin, DlOperationError & err)
{
+ // Assume pin is required until told otherwise
+ bool requirePin = true;
+ chip::app::Clusters::DoorLock::Attributes::RequirePINforRemoteOperation::Get(mEndpointId, &requirePin);
+
+ // If a pin code is not given
if (!pin.HasValue())
{
- ChipLogDetail(Zcl, "Lock App: PIN code is not specified, setting door lock state to \"%s\" [endpointId=%d]",
- lockStateToString(lockState), mEndpointId);
+ ChipLogDetail(Zcl, "Door Lock App: PIN code is not specified [endpointId=%d]", mEndpointId);
- mLockState = lockState;
- DoorLockServer::Instance().SetLockState(mEndpointId, mLockState);
+ // If a pin code is not required
+ if (!requirePin)
+ {
+ ChipLogDetail(Zcl, "Door Lock App: setting door lock state to \"%s\" [endpointId=%d]", lockStateToString(lockState),
+ mEndpointId);
- return true;
+ DoorLockServer::Instance().SetLockState(mEndpointId, lockState);
+
+ return true;
+ }
+
+ ChipLogError(Zcl, "Door Lock App: PIN code is not specified, but it is required [endpointId=%d]", mEndpointId);
+
+ return false;
}
// Find the credential so we can make sure it is not absent right away