Skip to content

Commit

Permalink
Review changes:Use NumericAttributeTraits in Write callback.Fix nits.
Browse files Browse the repository at this point in the history
  • Loading branch information
sxb427 committed Jan 22, 2025
1 parent d2d2619 commit 9ecd1ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ CHIP_ERROR DelegateImpl::HandleCloseValve()
return CHIP_NO_ERROR;
}

void DelegateImpl::HandleRemainingDurationTick(uint32_t duration)
void DelegateImpl::HandleRemainingDurationTick(uint32_t duration_sec)
{
ChipLogProgress(DeviceLayer, "HandleRemainingDurationTick with duration = %d", duration);
ChipLogProgress(DeviceLayer, "HandleRemainingDurationTick with duration_sec = %d", duration_sec);
}

void ValveConfigurationAndControl::Shutdown()
Expand All @@ -76,27 +76,25 @@ chefValveConfigurationAndControlWriteCallback(chip::EndpointId endpointId, chip:

switch (attributeId)
{
case chip::app::Clusters::ValveConfigurationAndControl::Attributes::RemainingDuration::Id: {
uint32_t newVal = 0;
std::memcpy(&newVal, buffer, sizeof(uint32_t));
ChipLogProgress(DeviceLayer, "Setting RemainingDuration to %d", newVal);
case Attributes::RemainingDuration::Id: {
CHIP_ERROR err;
if (newVal == static_cast<uint32_t>(std::numeric_limits<uint32_t>::max())) // Max value is interpreted as NULL
if (NumericAttributeTraits<uint32_t>::IsNullValue(*buffer)) // Max value is interpreted as NULL
{
ChipLogProgress(DeviceLayer, "Setting RemainingDuration to NULL.");
err = SetRemainingDurationNull(endpointId);
}
else
{
DataModel::Nullable<uint32_t> aRemainingDuration(newVal);
DataModel::Nullable<uint32_t> aRemainingDuration(NumericAttributeTraits<uint32_t>::StorageToWorking(*buffer));
ChipLogProgress(DeviceLayer, "Setting RemainingDuration to %d.", aRemainingDuration.Value());
err = SetRemainingDuration(endpointId, aRemainingDuration);
}
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "Unable to write RemainingDuration: %" CHIP_ERROR_FORMAT, err.Format());
return chip::Protocols::InteractionModel::Status::Failure;
}
MatterReportingAttributeChangeCallback(endpointId, ValveConfigurationAndControl::Id,
ValveConfigurationAndControl::Attributes::RemainingDuration::Id);
MatterReportingAttributeChangeCallback(endpointId, ValveConfigurationAndControl::Id, Attributes::RemainingDuration::Id);
break;
}
default:
Expand All @@ -122,7 +120,7 @@ chefValveConfigurationAndControlReadCallback(chip::EndpointId endpointId, chip::

switch (attributeId)
{
case chip::app::Clusters::ValveConfigurationAndControl::Attributes::RemainingDuration::Id: {
case Attributes::RemainingDuration::Id: {

DataModel::Nullable<uint32_t> duration;
CHIP_ERROR err = GetRemainingDuration(endpointId, duration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ CHIP_ERROR GetRemainingDuration(EndpointId endpoint, DataModel::Nullable<uint32_
{
uint16_t epIdx = emberAfGetClusterServerEndpointIndex(endpoint, ValveConfigurationAndControl::Id,
MATTER_DM_VALVE_CONFIGURATION_AND_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT);
VerifyOrReturnValue(epIdx < kValveConfigurationAndControlDelegateTableSize, CHIP_ERROR_READ_FAILED);
VerifyOrReturnValue(epIdx < kValveConfigurationAndControlDelegateTableSize, CHIP_ERROR_NOT_FOUND);
duration = gRemainingDuration[epIdx].remainingDuration;
return CHIP_NO_ERROR;
}
Expand Down

0 comments on commit 9ecd1ca

Please sign in to comment.