Skip to content

Commit

Permalink
send LockOperationEvent Unlatch immediately within HandleRemoteLockOp…
Browse files Browse the repository at this point in the history
…eration
  • Loading branch information
mmarc committed May 26, 2023
1 parent 0aa35a9 commit 2b6befc
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 8 deletions.
37 changes: 34 additions & 3 deletions src/app/clusters/door-lock-server/door-lock-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3307,7 +3307,7 @@ bool DoorLockServer::HandleRemoteLockOperation(chip::app::CommandHandler * comma
const chip::app::ConcreteCommandPath & commandPath, LockOperationTypeEnum opType,
RemoteLockOpHandler opHandler, const Optional<ByteSpan> & pinCode)
{
VerifyOrDie(LockOperationTypeEnum::kLock == opType || LockOperationTypeEnum::kUnlock == opType);
VerifyOrDie(LockOperationTypeEnum::kLock == opType || LockOperationTypeEnum::kUnlock == opType || LockOperationTypeEnum::kUnlatch == opType);
VerifyOrDie(nullptr != opHandler);

EndpointId endpoint = commandPath.mEndpointId;
Expand Down Expand Up @@ -3432,9 +3432,26 @@ bool DoorLockServer::HandleRemoteLockOperation(chip::app::CommandHandler * comma
credentials.SetNonNull(foundCred);
}

// Failed Unlatch requests SHALL generate only a LockOperationError event with LockOperationType set to Unlock
if (LockOperationTypeEnum::kUnlatch == opType && !success)
{
opType = LockOperationTypeEnum::kUnlock;
}

SendLockOperationEvent(endpoint, opType, OperationSourceEnum::kRemote, reason, pinUserIdx,
Nullable<chip::FabricIndex>(getFabricIndex(commandObj)), Nullable<chip::NodeId>(getNodeId(commandObj)),
credentials, success);

// SHALL generate a LockOperation event with LockOperationType set to Unlatch when the unlatched state is reached and a LockOperation
// event with LockOperationType set to Unlock when the lock successfully completes the unlock.
// But as the current implementation here is sending LockOperation events immediately we're sending both events immediately.
if (LockOperationTypeEnum::kUnlatch == opType && success)
{
SendLockOperationEvent(endpoint, LockOperationTypeEnum::kUnlock, OperationSourceEnum::kRemote, reason, pinUserIdx,
Nullable<chip::FabricIndex>(getFabricIndex(commandObj)), Nullable<chip::NodeId>(getNodeId(commandObj)),
credentials, success);
}

return success;
}

Expand Down Expand Up @@ -3536,7 +3553,14 @@ bool emberAfDoorLockClusterUnlockDoorCallback(
{
emberAfDoorLockClusterPrintln("Received command: UnlockDoor");

if (DoorLockServer::Instance().HandleRemoteLockOperation(commandObj, commandPath, LockOperationTypeEnum::kUnlock,
LockOperationTypeEnum lockOp = LockOperationTypeEnum::kUnlock;

if (DoorLockServer::Instance().SupportsUnbolt(commandPath.mEndpointId))
{
lockOp = LockOperationTypeEnum::kUnlatch;
}

if (DoorLockServer::Instance().HandleRemoteLockOperation(commandObj, commandPath, lockOp,
emberAfPluginDoorLockOnDoorUnlockCommand, commandData.PINCode))
{
// appclusters.pdf 5.3.3.25:
Expand All @@ -3558,7 +3582,14 @@ bool emberAfDoorLockClusterUnlockWithTimeoutCallback(
{
emberAfDoorLockClusterPrintln("Received command: UnlockWithTimeout");

if (DoorLockServer::Instance().HandleRemoteLockOperation(commandObj, commandPath, LockOperationTypeEnum::kUnlock,
LockOperationTypeEnum lockOp = LockOperationTypeEnum::kUnlock;

if (DoorLockServer::Instance().SupportsUnbolt(commandPath.mEndpointId))
{
lockOp = LockOperationTypeEnum::kUnlatch;
}

if (DoorLockServer::Instance().HandleRemoteLockOperation(commandObj, commandPath, lockOp,
emberAfPluginDoorLockOnDoorUnlockCommand, commandData.PINCode))
{
// appclusters.pdf 5.3.4.3:
Expand Down
17 changes: 17 additions & 0 deletions src/app/tests/suites/DL_LockUnlock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ tests:
command: "readEvent"
event: "LockOperation"
response:
- values:
- value:
{
"LockOperationType": 4,
"OperationSource": 7,
"UserIndex": null,
"Credentials": null,
}
- values:
- value:
{
Expand Down Expand Up @@ -197,6 +205,15 @@ tests:
"UserIndex": null,
"Credentials": null,
}
- values:
- value:
{
"LockOperationType": 4,
"OperationSource": 7,
"UserIndex": 1,
"Credentials":
[{ "CredentialType": 1, "CredentialIndex": 2 }],
}
- values:
- value:
{
Expand Down
48 changes: 43 additions & 5 deletions zzz_generated/chip-tool/zap-generated/test/Commands.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2b6befc

Please sign in to comment.