Skip to content

Commit

Permalink
Fixes #31925 - QA team expect HarmonicCurrents and HarmonicPhases to …
Browse files Browse the repository at this point in the history
…have 1 entry in the list for testing
  • Loading branch information
jamesharrow committed Feb 13, 2024
1 parent ec69c76 commit c2cdde3
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ void emberAfElectricalPowerMeasurementClusterInitCallback(chip::EndpointId endpo
OptionalAttributes::kOptionalAttributeNeutralCurrent));

gEPMInstance->Init();

gEPMDelegate->SetPowerMode(PowerModeEnum::kAc);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,17 @@ CHIP_ERROR ElectricalPowerMeasurementDelegate::EndRangesRead()
return CHIP_NO_ERROR;
}

static const Structs::HarmonicMeasurementStruct::Type kHarmonicCurrentMeasurements[] = {
{ .order = 1, .measurement = MakeNullable(static_cast<int64_t>(100000)) }
};

/* @brief This function is called by the cluster server at the start of read cycle
* This could take a semaphore to stop a background update of the data
*/
CHIP_ERROR ElectricalPowerMeasurementDelegate::StartHarmonicCurrentsRead()
CHIP_ERROR
ElectricalPowerMeasurementDelegate::StartHarmonicCurrentsRead()
{
/* Since we don't an implementation here we don't need to do anything here */
/* Since we have a static array we don't need to do anything here */
return CHIP_NO_ERROR;
}
CHIP_ERROR
Expand All @@ -269,34 +274,34 @@ ElectricalPowerMeasurementDelegate::GetHarmonicCurrentsByIndex(uint8_t harmonicC
* MatterReportingAttributeChangeCallback(mEndpointId, ElectricalPowerMeasurement::Id, HarmonicCurrents::Id);
*/

/* if (rangeIndex >= ArraySize(mHarmonicCurrentMeasurements))
* {
* return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
* }
*
* range = mHarmonicCurrentMeasurements[rangeIndex];
*
* return CHIP_NO_ERROR;
*/
/* Added to support testing using a static array for now */
if (harmonicCurrentsIndex >= ArraySize(kHarmonicCurrentMeasurements))
{
return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
}

/* Return an empty list for now */
return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
harmonicCurrent = kHarmonicCurrentMeasurements[harmonicCurrentsIndex];
return CHIP_NO_ERROR;
}
/* @brief This function is called by the cluster server at the end of read cycle
* This could release a semaphore to allow a background update of the data
*/
CHIP_ERROR ElectricalPowerMeasurementDelegate::EndHarmonicCurrentsRead()
{
/* Since we don't an implementation here we don't need to do anything here */
/* Since we have a static array we don't need to do anything here */
return CHIP_NO_ERROR;
}

static const Structs::HarmonicMeasurementStruct::Type kHarmonicPhaseMeasurements[] = {
{ .order = 1, .measurement = MakeNullable(static_cast<int64_t>(100000)) }
};

/* @brief This function is called by the cluster server at the start of read cycle
* This could take a semaphore to stop a background update of the data
*/
CHIP_ERROR ElectricalPowerMeasurementDelegate::StartHarmonicPhasesRead()
{
/* Since we don't an implementation here we don't need to do anything here */
/* Since we have a static array we don't need to do anything here */
return CHIP_NO_ERROR;
}

Expand All @@ -314,25 +319,21 @@ CHIP_ERROR ElectricalPowerMeasurementDelegate::GetHarmonicPhasesByIndex(uint8_t
* MatterReportingAttributeChangeCallback(mEndpointId, ElectricalPowerMeasurement::Id, HarmonicPhases::Id);
*/

/* if (rangeIndex >= ArraySize(mHarmonicPhaseMeasurements))
* {
* return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
* }
*
* range = mHarmonicPhaseMeasurements[rangeIndex];
*
* return CHIP_NO_ERROR;
*/
/* Added to support testing using a static array for now */
if (harmonicPhaseIndex >= ArraySize(kHarmonicPhaseMeasurements))
{
return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
}

/* Return an empty list for now */
return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
harmonicPhase = kHarmonicPhaseMeasurements[harmonicPhaseIndex];
return CHIP_NO_ERROR;
}
/* @brief This function is called by the cluster server at the end of read cycle
* This could release a semaphore to allow a background update of the data
*/
CHIP_ERROR ElectricalPowerMeasurementDelegate::EndHarmonicPhasesRead()
{
/* Since we don't an implementation here we don't need to do anything here */
/* Since we have a static array we don't need to do anything here */
return CHIP_NO_ERROR;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,27 @@ CHIP_ERROR EnergyMeterInit()
}

/* Manufacturer may optionally not support all features, commands & attributes */
/* Turning on all optional features and attributes for test certification purposes */
gEPMInstance = std::make_unique<ElectricalPowerMeasurementInstance>(
EndpointId(ENERGY_EVSE_ENDPOINT), *gEPMDelegate,
BitMask<ElectricalPowerMeasurement::Feature, uint32_t>(ElectricalPowerMeasurement::Feature::kAlternatingCurrent),
BitMask<ElectricalPowerMeasurement::Feature, uint32_t>(
ElectricalPowerMeasurement::Feature::kDirectCurrent, ElectricalPowerMeasurement::Feature::kAlternatingCurrent,
ElectricalPowerMeasurement::Feature::kPolyphasePower, ElectricalPowerMeasurement::Feature::kHarmonics,
ElectricalPowerMeasurement::Feature::kPowerQuality),
BitMask<ElectricalPowerMeasurement::OptionalAttributes, uint32_t>(
ElectricalPowerMeasurement::OptionalAttributes::kOptionalAttributeRanges,
ElectricalPowerMeasurement::OptionalAttributes::kOptionalAttributeVoltage,
ElectricalPowerMeasurement::OptionalAttributes::kOptionalAttributeActiveCurrent));
ElectricalPowerMeasurement::OptionalAttributes::kOptionalAttributeActiveCurrent,
ElectricalPowerMeasurement::OptionalAttributes::kOptionalAttributeReactiveCurrent,
ElectricalPowerMeasurement::OptionalAttributes::kOptionalAttributeApparentCurrent,
ElectricalPowerMeasurement::OptionalAttributes::kOptionalAttributeReactivePower,
ElectricalPowerMeasurement::OptionalAttributes::kOptionalAttributeApparentPower,
ElectricalPowerMeasurement::OptionalAttributes::kOptionalAttributeRMSVoltage,
ElectricalPowerMeasurement::OptionalAttributes::kOptionalAttributeRMSCurrent,
ElectricalPowerMeasurement::OptionalAttributes::kOptionalAttributeRMSPower,
ElectricalPowerMeasurement::OptionalAttributes::kOptionalAttributeFrequency,
ElectricalPowerMeasurement::OptionalAttributes::kOptionalAttributePowerFactor,
ElectricalPowerMeasurement::OptionalAttributes::kOptionalAttributeNeutralCurrent));

if (!gEPMInstance)
{
Expand Down
39 changes: 26 additions & 13 deletions src/python_testing/TC_EPM_2_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

logger = logging.getLogger(__name__)

MIN_INT64_ALLOWED = -pow(2, 62) # -(2^62)
MAX_INT64_ALLOWED = pow(2, 62) # (2^62)


class TC_EPM_2_1(MatterBaseTest, EnergyReportingBaseTestHelper):

Expand Down Expand Up @@ -133,52 +136,52 @@ async def test_TC_EPM_2_1(self):

self.step("6")
if self.pics_guard(Clusters.ElectricalPowerMeasurement.Attributes.Voltage.attribute_id in supported_attributes):
voltage = await self.check_epm_attribute_in_range("Voltage", -2 ^ 62, 2 ^ 62, allow_null=True)
voltage = await self.check_epm_attribute_in_range("Voltage", MIN_INT64_ALLOWED, MAX_INT64_ALLOWED, allow_null=True)
logger.info(f"Rx'd Voltage: {voltage}")

self.step("7")
if self.pics_guard(Clusters.ElectricalPowerMeasurement.Attributes.ActiveCurrent.attribute_id in supported_attributes):
active_current = await self.check_epm_attribute_in_range("ActiveCurrent", -2 ^ 62, 2 ^ 62, allow_null=True)
active_current = await self.check_epm_attribute_in_range("ActiveCurrent", MIN_INT64_ALLOWED, MAX_INT64_ALLOWED, allow_null=True)
logger.info(f"Rx'd ActiveCurrent: {active_current}")

self.step("8")
if self.pics_guard(Clusters.ElectricalPowerMeasurement.Attributes.ReactiveCurrent.attribute_id in supported_attributes):
reactive_current = await self.check_epm_attribute_in_range("ReactiveCurrent", -2 ^ 62, 2 ^ 62, allow_null=True)
reactive_current = await self.check_epm_attribute_in_range("ReactiveCurrent", MIN_INT64_ALLOWED, MAX_INT64_ALLOWED, allow_null=True)
logger.info(f"Rx'd ReactiveCurrent: {reactive_current}")

self.step("9")
if self.pics_guard(Clusters.ElectricalPowerMeasurement.Attributes.ApparentCurrent.attribute_id in supported_attributes):
apparent_current = await self.check_epm_attribute_in_range("ApparentCurrent", 0, 2 ^ 62, allow_null=True)
apparent_current = await self.check_epm_attribute_in_range("ApparentCurrent", 0, MAX_INT64_ALLOWED, allow_null=True)
logger.info(f"Rx'd ApparentCurrent: {apparent_current}")

self.step("10")
if self.pics_guard(Clusters.ElectricalPowerMeasurement.Attributes.ActivePower.attribute_id in supported_attributes):
active_power = await self.check_epm_attribute_in_range("ActivePower", -2 ^ 62, 2 ^ 62, allow_null=True)
active_power = await self.check_epm_attribute_in_range("ActivePower", MIN_INT64_ALLOWED, MAX_INT64_ALLOWED, allow_null=True)
logger.info(f"Rx'd ActivePower: {active_power}")

self.step("11")
if self.pics_guard(Clusters.ElectricalPowerMeasurement.Attributes.ReactivePower.attribute_id in supported_attributes):
reactive_power = await self.check_epm_attribute_in_range("ReactivePower", -2 ^ 62, 2 ^ 62, allow_null=True)
reactive_power = await self.check_epm_attribute_in_range("ReactivePower", MIN_INT64_ALLOWED, MAX_INT64_ALLOWED, allow_null=True)
logger.info(f"Rx'd ReactivePower: {reactive_power}")

self.step("12")
if self.pics_guard(Clusters.ElectricalPowerMeasurement.Attributes.ApparentPower.attribute_id in supported_attributes):
apparent_power = await self.check_epm_attribute_in_range("ApparentPower", -2 ^ 62, 2 ^ 62, allow_null=True)
apparent_power = await self.check_epm_attribute_in_range("ApparentPower", MIN_INT64_ALLOWED, MAX_INT64_ALLOWED, allow_null=True)
logger.info(f"Rx'd ApparentPower: {apparent_power}")

self.step("13")
if self.pics_guard(Clusters.ElectricalPowerMeasurement.Attributes.RMSVoltage.attribute_id in supported_attributes):
rms_voltage = await self.check_epm_attribute_in_range("RMSVoltage", -2 ^ 62, 2 ^ 62, allow_null=True)
rms_voltage = await self.check_epm_attribute_in_range("RMSVoltage", MIN_INT64_ALLOWED, MAX_INT64_ALLOWED, allow_null=True)
logger.info(f"Rx'd RMSVoltage: {rms_voltage}")

self.step("14")
if self.pics_guard(Clusters.ElectricalPowerMeasurement.Attributes.RMSCurrent.attribute_id in supported_attributes):
rms_current = await self.check_epm_attribute_in_range("RMSCurrent", -2 ^ 62, 2 ^ 62, allow_null=True)
rms_current = await self.check_epm_attribute_in_range("RMSCurrent", MIN_INT64_ALLOWED, MAX_INT64_ALLOWED, allow_null=True)
logger.info(f"Rx'd RMSCurrent: {rms_current}")

self.step("15")
if self.pics_guard(Clusters.ElectricalPowerMeasurement.Attributes.RMSPower.attribute_id in supported_attributes):
rms_power = await self.check_epm_attribute_in_range("RMSPower", -2 ^ 62, 2 ^ 62, allow_null=True)
rms_power = await self.check_epm_attribute_in_range("RMSPower", MIN_INT64_ALLOWED, MAX_INT64_ALLOWED, allow_null=True)
logger.info(f"Rx'd RMSPower: {rms_power}")

self.step("16")
Expand All @@ -188,13 +191,23 @@ async def test_TC_EPM_2_1(self):

self.step("17")
if self.pics_guard(Clusters.ElectricalPowerMeasurement.Attributes.HarmonicCurrents.attribute_id in supported_attributes):
harmonic_currents = await self.read_epm_attribute_expect_success("HarmonicCurrents", allow_null=True)
harmonic_currents = await self.read_epm_attribute_expect_success("HarmonicCurrents")
logger.info(f"Rx'd HarmonicCurrents: {harmonic_currents}")
asserts.assert_is(type(harmonic_currents), list)
for index, entry in enumerate(harmonic_currents):
logging.info(f" [{index}] order:{entry.order} measurement:{entry.measurement}")
asserts.assert_greater_equal(entry.order, 1)
self.check_value_in_range("Measurement", entry.measurement, MIN_INT64_ALLOWED, MAX_INT64_ALLOWED)

self.step("18")
if self.pics_guard(Clusters.ElectricalPowerMeasurement.Attributes.HarmonicPhases.attribute_id in supported_attributes):
harmonic_phases = await self.read_epm_attribute_expect_success("HarmonicPhases", allow_null=True)
harmonic_phases = await self.read_epm_attribute_expect_success("HarmonicPhases")
logger.info(f"Rx'd HarmonicPhases: {harmonic_phases}")
asserts.assert_is(type(harmonic_phases), list)
for index, entry in enumerate(harmonic_phases):
logging.info(f" [{index}] order:{entry.order} measurement:{entry.measurement}")
asserts.assert_greater_equal(entry.order, 1)
self.check_value_in_range("Measurement", entry.measurement, MIN_INT64_ALLOWED, MAX_INT64_ALLOWED)

self.step("19")
if self.pics_guard(Clusters.ElectricalPowerMeasurement.Attributes.PowerFactor.attribute_id in supported_attributes):
Expand All @@ -203,7 +216,7 @@ async def test_TC_EPM_2_1(self):

self.step("20")
if self.pics_guard(Clusters.ElectricalPowerMeasurement.Attributes.NeutralCurrent.attribute_id in supported_attributes):
neutral_current = await self.check_epm_attribute_in_range("NeutralCurrent", -2 ^ 62, 2 ^ 62, allow_null=True)
neutral_current = await self.check_epm_attribute_in_range("NeutralCurrent", MIN_INT64_ALLOWED, MAX_INT64_ALLOWED, allow_null=True)
logger.info(f"Rx'd NeutralCurrent: {neutral_current}")


Expand Down

0 comments on commit c2cdde3

Please sign in to comment.