Skip to content

Commit

Permalink
[#18677] Set the initial lock state to null (#18914)
Browse files Browse the repository at this point in the history
- Set the actual lock state from the app without event generation
  • Loading branch information
Morozov-5F authored and pull[bot] committed Jul 2, 2022
1 parent 246f252 commit 859ba12
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
2 changes: 2 additions & 0 deletions examples/lock-app/linux/include/LockEndpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class LockEndpoint
{
lockUser.credentials.reserve(numberOfCredentialsPerUser);
}

DoorLockServer::Instance().SetLockState(endpointId, mLockState);
}

inline chip::EndpointId GetEndpointId() const { return mEndpointId; }
Expand Down
13 changes: 11 additions & 2 deletions src/app/clusters/door-lock-server/door-lock-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,22 @@ void DoorLockServer::InitServer(chip::EndpointId endpointId)
{
emberAfDoorLockClusterPrintln("Door Lock cluster initialized at endpoint #%u", endpointId);

SetLockState(endpointId, DlLockState::kLocked, DlOperationSource::kUnspecified);
auto status = Attributes::LockState::SetNull(endpointId);
if (EMBER_ZCL_STATUS_SUCCESS != status)
{
ChipLogError(Zcl, "[InitDoorLockServer] Unable to set the Lock State attribute to null [status=%d]", status);
}
SetActuatorEnabled(endpointId, true);
}

bool DoorLockServer::SetLockState(chip::EndpointId endpointId, DlLockState newLockState)
{
return SetAttribute(endpointId, Attributes::LockState::Id, Attributes::LockState::Set, newLockState);
}

bool DoorLockServer::SetLockState(chip::EndpointId endpointId, DlLockState newLockState, DlOperationSource opSource)
{
bool success = SetAttribute(endpointId, Attributes::LockState::Id, Attributes::LockState::Set, newLockState);
bool success = SetLockState(endpointId, newLockState);

// Remote operations are handled separately as they use more data unavailable here
VerifyOrReturnError(DlOperationSource::kRemote != opSource, success);
Expand Down
26 changes: 23 additions & 3 deletions src/app/clusters/door-lock-server/door-lock-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,30 @@ class DoorLockServer

void InitServer(chip::EndpointId endpointId);

/**
* Updates the LockState attribute with new value and sends LockOperation event.
*
* @note Does not send an event of opSource is kRemote.
*
* @param endpointId ID of the endpoint to the lock state
* @param newLockState new lock state
* @param opSource source of the operation (will be used in the event).
*
* @return true on success, false on failure.
*/
bool SetLockState(chip::EndpointId endpointId, DlLockState newLockState, DlOperationSource opSource);

/**
* Updates the LockState attribute with new value.
*
* @note Does not generate Lock Operation event
*
* @param endpointId ID of the endpoint to the lock state
* @param newLockState new lock state
*
* @return true on success, false on failure.
*/
bool SetLockState(chip::EndpointId endpointId, DlLockState newLockState);
bool SetActuatorEnabled(chip::EndpointId endpointId, bool newActuatorState);
bool SetDoorState(chip::EndpointId endpointId, DlDoorState newDoorState);

Expand Down Expand Up @@ -113,9 +136,6 @@ class DoorLockServer
void ClearCredentialCommandHandler(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath,
const chip::app::Clusters::DoorLock::Commands::ClearCredential::DecodableType & commandData);

void LockUnlockDoorCommandHandler(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath,
DlLockOperationType operationType, const chip::Optional<chip::ByteSpan> & pinCode);

void SetWeekDayScheduleCommandHandler(
chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath,
const chip::app::Clusters::DoorLock::Commands::SetWeekDaySchedule::DecodableType & commandData);
Expand Down

0 comments on commit 859ba12

Please sign in to comment.