Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the Pre-Attribute checking for laundry washer controls cluster #28618

Merged
merged 10 commits into from
Aug 25, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,17 @@ class LaundryWasherControlDelegate : public Delegate
static const NumberOfRinsesEnum supportRinsesOptions[];
static LaundryWasherControlDelegate instance;

static constexpr uint8_t kDefaultRinseIndex = 0;
static constexpr uint8_t kDefaultSpinSpeedIndex = 0;
crlonxp marked this conversation as resolved.
Show resolved Hide resolved

public:
CHIP_ERROR GetSpinSpeedAtIndex(size_t index, MutableCharSpan & spinSpeed);
CHIP_ERROR GetSupportedRinseAtIndex(size_t index, NumberOfRinsesEnum & supportedRinse);
size_t GetGetSpinSpeedSize();

LaundryWasherControlDelegate() = default;
~LaundryWasherControlDelegate() = default;
void Init(EndpointId endpointId);

static inline LaundryWasherControlDelegate & getLaundryWasherControlDelegate() { return instance; }
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

using namespace chip;
using namespace chip::app::Clusters::LaundryWasherControls;
using namespace chip::Protocols::InteractionModel;

const CharSpan LaundryWasherControlDelegate::spinSpeedsNameOptions[] = {
CharSpan::fromCharString("Off"),
Expand Down Expand Up @@ -54,3 +55,19 @@ CHIP_ERROR LaundryWasherControlDelegate::GetSupportedRinseAtIndex(size_t index,
supportedRinse = LaundryWasherControlDelegate::supportRinsesOptions[index];
return CHIP_NO_ERROR;
}

size_t LaundryWasherControlDelegate::GetGetSpinSpeedSize()
{
return ArraySize(spinSpeedsNameOptions);
}

void LaundryWasherControlDelegate::Init(EndpointId endpointId)
{
LaundryWasherControlsServer laundryWasherControlsServer = LaundryWasherControlsServer::Instance();
NumberOfRinsesEnum supportedRinse;

GetSupportedRinseAtIndex(kDefaultRinseIndex, supportedRinse);
laundryWasherControlsServer.SetNumberOfRinses(endpointId, supportedRinse);
laundryWasherControlsServer.SetSpinSpeedCurrent(endpointId, DataModel::Nullable<uint8_t>(kDefaultSpinSpeedIndex));
LaundryWasherControlsServer::SetDefaultDelegate(endpointId, this);
}
3 changes: 1 addition & 2 deletions examples/all-clusters-app/linux/main-common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,9 @@ void ApplicationShutdown()
}
}

using namespace chip::app::Clusters::LaundryWasherControls;
void emberAfLaundryWasherControlsClusterInitCallback(EndpointId endpoint)
{
LaundryWasherControlsServer::SetDefaultDelegate(1, &LaundryWasherControlDelegate::getLaundryWasherControlDelegate());
Clusters::LaundryWasherControls::LaundryWasherControlDelegate::getLaundryWasherControlDelegate().Init(endpoint);
}

void emberAfLowPowerClusterInitCallback(EndpointId endpoint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class Delegate
* @return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED if the index is out of range for the list of supported rinses.
*/
virtual CHIP_ERROR GetSupportedRinseAtIndex(size_t index, NumberOfRinsesEnum & supportedRinse) = 0;

virtual size_t GetGetSpinSpeedSize() = 0;
crlonxp marked this conversation as resolved.
Show resolved Hide resolved
};

} // namespace LaundryWasherControls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,49 @@ void MatterLaundryWasherControlsPluginServerInitCallback()
LaundryWasherControlsServer & laundryWasherControlsServer = LaundryWasherControlsServer::Instance();
registerAttributeAccessOverride(&laundryWasherControlsServer);
}

Status MatterLaundryWasherControlsClusterServerPreAttributeChangedCallback(const chip::app::ConcreteAttributePath & attributePath,
crlonxp marked this conversation as resolved.
Show resolved Hide resolved
EmberAfAttributeType attributeType, uint16_t size,
uint8_t * value)
{
switch (attributePath.mAttributeId)
{
case Attributes::SpinSpeeds::Id:
case Attributes::SupportedRinses::Id:
return Status::UnsupportedWrite;
crlonxp marked this conversation as resolved.
Show resolved Hide resolved
}
Delegate * delegate = GetDelegate(attributePath.mEndpointId);
if (delegate == nullptr)
{
return Status::Success;
crlonxp marked this conversation as resolved.
Show resolved Hide resolved
}
switch (attributePath.mAttributeId)
{
case Attributes::SpinSpeedCurrent::Id: {
if (*value >= (uint8_t) delegate->GetGetSpinSpeedSize())
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
{
return Status::ConstraintError;
crlonxp marked this conversation as resolved.
Show resolved Hide resolved
}
return Status::Success;
}
case Attributes::NumberOfRinses::Id: {
for (uint8_t i = 0; true; i++)
crlonxp marked this conversation as resolved.
Show resolved Hide resolved
{
NumberOfRinsesEnum supportedRinse;
auto err = delegate->GetSupportedRinseAtIndex(i, 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;
}
}
}
}
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