Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the Pre-Attribute checking for laundry washer controls cluster (#…
Browse files Browse the repository at this point in the history
…28618)

* Add the PreAttribute checking for laundry washer controls cluster

Signed-off-by: Chin-Ran Lo <[email protected]>

* Restyled by clang-format

* Fix the warning in Darwin platform

Signed-off-by: Chin-Ran Lo <[email protected]>

* Move the Pre-Attribute checking from the delegate to cluster handler

Signed-off-by: Chin-Ran Lo <[email protected]>

* Restyled by clang-format

* * Remove the redundant checking for read-only attributes
* Not adding the API to get the size of the spin-speed list
* Add the nullable attribute checking

Signed-off-by: Chin-Ran Lo <[email protected]>

* Fix by follow review's comment
    - Replace a infinit for loop with a  while true loop
    - Use the meaning variables to access

Signed-off-by: Chin-Ran Lo <[email protected]>

* Restyled by clang-format

* Fix the tidy warning for "Build on Linux"

Signed-off-by: Chin-Ran Lo <[email protected]>

* Abort the program if delegate does not exist while writing the attribute

Signed-off-by: Chin-Ran Lo <[email protected]>

---------

Signed-off-by: Chin-Ran Lo <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
2 people authored and pull[bot] committed Oct 27, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
lilnasy Arsh
1 parent 83d7982 commit 1373636
Showing 3 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/all-clusters-app/linux/main-common.cpp
Original file line number Diff line number Diff line change
@@ -210,7 +210,7 @@ void ApplicationShutdown()
using namespace chip::app::Clusters::LaundryWasherControls;
void emberAfLaundryWasherControlsClusterInitCallback(EndpointId endpoint)
{
LaundryWasherControlsServer::SetDefaultDelegate(1, &LaundryWasherControlDelegate::getLaundryWasherControlDelegate());
LaundryWasherControlsServer::SetDefaultDelegate(endpoint, &LaundryWasherControlDelegate::getLaundryWasherControlDelegate());
}

void emberAfLowPowerClusterInitCallback(EndpointId endpoint)
Original file line number Diff line number Diff line change
@@ -192,3 +192,50 @@ void MatterLaundryWasherControlsPluginServerInitCallback()
LaundryWasherControlsServer & laundryWasherControlsServer = LaundryWasherControlsServer::Instance();
registerAttributeAccessOverride(&laundryWasherControlsServer);
}

Status MatterLaundryWasherControlsClusterServerPreAttributeChangedCallback(const chip::app::ConcreteAttributePath & attributePath,
EmberAfAttributeType attributeType, uint16_t size,
uint8_t * value)
{
Delegate * delegate = GetDelegate(attributePath.mEndpointId);
VerifyOrDie((delegate != nullptr) && "Washer Controls implementation requires a registered delegate for validation.");
switch (attributePath.mAttributeId)
{
case Attributes::SpinSpeedCurrent::Id: {
if (NumericAttributeTraits<uint8_t>::IsNullValue(*value))
{
return Status::Success;
}
char buffer[LaundryWasherControlsServer::kMaxSpinSpeedLength];
MutableCharSpan spinSpeed(buffer);
uint8_t spinSpeedIndex = *value;
auto err = delegate->GetSpinSpeedAtIndex(spinSpeedIndex, spinSpeed);
if (err == CHIP_NO_ERROR)
{
return Status::Success;
}
return Status::ConstraintError;
}
case Attributes::NumberOfRinses::Id: {
uint8_t supportedRinseIdx = 0;
while (true)
{
NumberOfRinsesEnum supportedRinse;
auto err = delegate->GetSupportedRinseAtIndex(supportedRinseIdx, supportedRinse);
if (err != CHIP_NO_ERROR)
{
// Can't find the attribute to be written in the supported list (CHIP_ERROR_PROVIDER_LIST_EXHAUSTED)
// Or can't get the correct supported list
return Status::InvalidInState;
}
if (supportedRinse == static_cast<NumberOfRinsesEnum>(*value))
{
// The written attribute is one of the supported item
return Status::Success;
}
supportedRinseIdx++;
}
}
}
return Status::Success;
}
1 change: 1 addition & 0 deletions src/app/common/templates/config-data.yaml
Original file line number Diff line number Diff line change
@@ -73,3 +73,4 @@ ClustersWithPreAttributeChangeFunctions:
- Mode Select
- Fan Control
- Thermostat
- Laundry Washer Controls

0 comments on commit 1373636

Please sign in to comment.