Skip to content

Commit

Permalink
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]>
  • Loading branch information
2 people authored and pull[bot] committed Sep 22, 2023
1 parent 542f647 commit 4883521
Show file tree
Hide file tree
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
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -73,3 +73,4 @@ ClustersWithPreAttributeChangeFunctions:
- Mode Select
- Fan Control
- Thermostat
- Laundry Washer Controls

0 comments on commit 4883521

Please sign in to comment.