Skip to content

Commit

Permalink
Add missing features to EPM stub
Browse files Browse the repository at this point in the history
  • Loading branch information
hasty committed Jan 27, 2024
1 parent 8f1edea commit 3b4ad35
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ bool StubAccuracyIterator::Next(MeasurementAccuracyStruct::Type & output)

void StubAccuracyIterator::Release()
{
mIndex = 0;
return;
}

Expand Down Expand Up @@ -254,7 +255,9 @@ void emberAfElectricalPowerMeasurementClusterInitCallback(chip::EndpointId endpo
if (gDelegate)
{
gInstance = std::make_unique<Instance>(
endpointId, *gDelegate, BitMask<Feature, uint32_t>(Feature::kAlternatingCurrent),
endpointId, *gDelegate,
BitMask<Feature, uint32_t>(Feature::kDirectCurrent, Feature::kAlternatingCurrent, Feature::kPolyphasePower,
Feature::kHarmonics, Feature::kPowerQuality),
BitMask<OptionalAttributes, uint32_t>(
OptionalAttributes::kOptionalAttributeRanges, OptionalAttributes::kOptionalAttributeVoltage,
OptionalAttributes::kOptionalAttributeActiveCurrent, OptionalAttributes::kOptionalAttributeReactiveCurrent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,22 @@ CHIP_ERROR Instance::ReadAccuracy(AttributeValueEncoder & aEncoder)
CHIP_ERROR err = CHIP_NO_ERROR;
auto accuracies = mDelegate.IterateAccuracy();
VerifyOrReturnError(accuracies != nullptr, CHIP_IM_GLOBAL_STATUS(ResourceExhausted));
err = aEncoder.EncodeList([&accuracies](const auto & encoder) -> CHIP_ERROR {
Structs::MeasurementAccuracyStruct::Type accuracy;
while (accuracies->Next(accuracy))
{
encoder.Encode(accuracy);
}
if (accuracies->Count() == 0)
{
err = aEncoder.EncodeEmptyList();
}
else
{
err = aEncoder.EncodeList([&accuracies](const auto & encoder) -> CHIP_ERROR {
Structs::MeasurementAccuracyStruct::Type accuracy;
while (accuracies->Next(accuracy))
{
encoder.Encode(accuracy);
}

return CHIP_NO_ERROR;
});
return CHIP_NO_ERROR;
});
}
accuracies->Release();
return err;
}
Expand All @@ -230,15 +237,22 @@ CHIP_ERROR Instance::ReadRanges(AttributeValueEncoder & aEncoder)
CHIP_ERROR err = CHIP_NO_ERROR;
auto ranges = mDelegate.IterateRanges();
VerifyOrReturnError(ranges != nullptr, CHIP_IM_GLOBAL_STATUS(ResourceExhausted));
err = aEncoder.EncodeList([&ranges](const auto & encoder) -> CHIP_ERROR {
Structs::MeasurementRangeStruct::Type range;
while (ranges->Next(range))
{
encoder.Encode(range);
}
if (ranges->Count() == 0)
{
err = aEncoder.EncodeEmptyList();
}
else
{
err = aEncoder.EncodeList([&ranges](const auto & encoder) -> CHIP_ERROR {
Structs::MeasurementRangeStruct::Type range;
while (ranges->Next(range))
{
encoder.Encode(range);
}

return CHIP_NO_ERROR;
});
return CHIP_NO_ERROR;
});
}
ranges->Release();
return err;
}
Expand All @@ -251,15 +265,22 @@ CHIP_ERROR Instance::ReadHarmonicCurrents(AttributeValueEncoder & aEncoder)
CHIP_ERROR err = CHIP_NO_ERROR;
auto currents = mDelegate.IterateHarmonicCurrents();
VerifyOrReturnError(currents != nullptr, CHIP_IM_GLOBAL_STATUS(ResourceExhausted));
err = aEncoder.EncodeList([&currents](const auto & encoder) -> CHIP_ERROR {
Structs::HarmonicMeasurementStruct::Type current;
while (currents->Next(current))
{
encoder.Encode(current);
}
if (currents->Count() == 0)
{
err = aEncoder.EncodeEmptyList();
}
else
{
err = aEncoder.EncodeList([&currents](const auto & encoder) -> CHIP_ERROR {
Structs::HarmonicMeasurementStruct::Type current;
while (currents->Next(current))
{
encoder.Encode(current);
}

return CHIP_NO_ERROR;
});
return CHIP_NO_ERROR;
});
}
currents->Release();
return err;
}
Expand All @@ -271,15 +292,22 @@ CHIP_ERROR Instance::ReadHarmonicPhases(AttributeValueEncoder & aEncoder)
CHIP_ERROR err = CHIP_NO_ERROR;
auto phases = mDelegate.IterateHarmonicPhases();
VerifyOrReturnError(phases != nullptr, CHIP_IM_GLOBAL_STATUS(ResourceExhausted));
err = aEncoder.EncodeList([&phases](const auto & encoder) -> CHIP_ERROR {
Structs::HarmonicMeasurementStruct::Type phase;
while (phases->Next(phase))
{
encoder.Encode(phase);
}
if (phases->Count() == 0)
{
err = aEncoder.EncodeEmptyList();
}
else
{
err = aEncoder.EncodeList([&phases](const auto & encoder) -> CHIP_ERROR {
Structs::HarmonicMeasurementStruct::Type phase;
while (phases->Next(phase))
{
encoder.Encode(phase);
}

return CHIP_NO_ERROR;
});
return CHIP_NO_ERROR;
});
}
phases->Release();
return err;
}
Expand Down

0 comments on commit 3b4ad35

Please sign in to comment.