Skip to content

Refactoring and Migrating Concentration Measurement Cluster #71608

Draft
marybadalyan wants to merge 13 commits intoproject-chip:masterfrom
marybadalyan:ConcentMeasureCluster
Draft

Refactoring and Migrating Concentration Measurement Cluster #71608
marybadalyan wants to merge 13 commits intoproject-chip:masterfrom
marybadalyan:ConcentMeasureCluster

Conversation

@marybadalyan
Copy link
Copy Markdown
Contributor

Summary

This PR Migrates ConcnetrationMeasurementCluster and migrates it.

Related issues

#71607

Testing

@marybadalyan marybadalyan marked this pull request as draft April 16, 2026 11:51
@github-actions github-actions bot added examples app examples chef Changes in examples/chef labels Apr 16, 2026
@pullapprove pullapprove bot added review - pending and removed examples app examples chef Changes in examples/chef labels Apr 16, 2026
@github-actions github-actions bot added examples app examples chef Changes in examples/chef labels Apr 16, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the Concentration Measurement cluster to a code-driven implementation, replacing the previous template-based approach with a delegate-based architecture. It introduces a new ConcentrationMeasurementCluster class and a Delegate interface to handle attribute reads across all 10 aliased concentration clusters. However, the current implementation contains critical bugs: the Delegate base class is missing the SetCluster method required by the cluster's lifecycle, and the DefaultDelegate fails to notify the cluster when attributes change, which will break attribute reporting. Additionally, several unused helper methods and constants were left in the header files and should be removed.

I am having trouble creating individual review comments. Click here to see my feedback.

src/app/clusters/concentration-measurement-server/ConcentrationMeasurementDelegate.h (30-39)

critical

The Delegate class is missing the SetCluster method, which is called by ConcentrationMeasurementCluster in its destructor and Startup method. This will result in a compilation error. A forward declaration of ConcentrationMeasurementCluster is also required to avoid circular dependencies. This addition is consistent with the existing API design for cluster delegates.

class ConcentrationMeasurementCluster;

// Delegate — abstract interface your application implements to supply attribute values.
class Delegate
{
public:
    Delegate()          = default;
    virtual ~Delegate() = default;

    virtual void SetCluster(ConcentrationMeasurementCluster * cluster) {}

    // Called once by ConcentrationMeasurementCluster::Startup().
    // Override to initialise your hardware or sensor driver. Default is a no-op.
    virtual CHIP_ERROR Init() { return CHIP_NO_ERROR; }
References
  1. When adding new methods to a class, ensure they are consistent with the existing API design, for example by using class members instead of passing redundant parameters.

src/app/clusters/concentration-measurement-server/ConcentrationMeasurementDelegate.h (143-189)

high

The DefaultDelegate implementation is missing the logic to notify the cluster of attribute changes. To maintain consistency with existing patterns, DefaultDelegate should store a pointer to the cluster and call NotifyAttributeChanged in its setters. This implementation should use defensive null checks for the cluster pointer and ensure that invalid enum values are not silently ignored.

    // ── Handle*()
    // Each method stores the value and notifies the cluster of the change to trigger reporting.

    void SetCluster(ConcentrationMeasurementCluster * cluster) override { mCluster = cluster; }

    void HandleNewMeasuredValue(DataModel::Nullable<float> v)
    {
        if (mMeasuredValue != v)
        {
            mMeasuredValue = v;
            if (mCluster) mCluster->NotifyAttributeChanged(Attributes::MeasuredValue::Id);
        }
    }

    void HandleNewMinMeasuredValue(DataModel::Nullable<float> v)
    {
        if (mMinMeasuredValue != v)
        {
            mMinMeasuredValue = v;
            if (mCluster) mCluster->NotifyAttributeChanged(Attributes::MinMeasuredValue::Id);
        }
    }

    void HandleNewMaxMeasuredValue(DataModel::Nullable<float> v)
    {
        if (mMaxMeasuredValue != v)
        {
            mMaxMeasuredValue = v;
            if (mCluster) mCluster->NotifyAttributeChanged(Attributes::MaxMeasuredValue::Id);
        }
    }

    void HandleNewUncertainty(float v)
    {
        if (mUncertainty != v)
        {
            mUncertainty = v;
            if (mCluster) mCluster->NotifyAttributeChanged(Attributes::Uncertainty::Id);
        }
    }

    void HandleNewPeakMeasuredValue(DataModel::Nullable<float> v)
    {
        if (mPeakMeasuredValue != v)
        {
            mPeakMeasuredValue = v;
            if (mCluster) mCluster->NotifyAttributeChanged(Attributes::PeakMeasuredValue::Id);
        }
    }

    void HandleNewPeakMeasuredValueWindow(uint32_t v)
    {
        if (mPeakMeasuredValueWindow != v)
        {
            mPeakMeasuredValueWindow = v;
            if (mCluster) mCluster->NotifyAttributeChanged(Attributes::PeakMeasuredValueWindow::Id);
        }
    }

    void HandleNewAverageMeasuredValue(DataModel::Nullable<float> v)
    {
        if (mAverageMeasuredValue != v)
        {
            mAverageMeasuredValue = v;
            if (mCluster) mCluster->NotifyAttributeChanged(Attributes::AverageMeasuredValue::Id);
        }
    }

    void HandleNewAverageMeasuredValueWindow(uint32_t v)
    {
        if (mAverageMeasuredValueWindow != v)
        {
            mAverageMeasuredValueWindow = v;
            if (mCluster) mCluster->NotifyAttributeChanged(Attributes::AverageMeasuredValueWindow::Id);
        }
    }

    void HandleNewLevelValue(LevelValueEnum v)
    {
        if (mLevelValue != v)
        {
            mLevelValue = v;
            if (mCluster) mCluster->NotifyAttributeChanged(Attributes::LevelValue::Id);
        }
    }

private:
    // All fields start null/zero/unknown — safe defaults before first reading.
    DataModel::Nullable<float> mMeasuredValue;
    DataModel::Nullable<float> mMinMeasuredValue;
    DataModel::Nullable<float> mMaxMeasuredValue;
    DataModel::Nullable<float> mPeakMeasuredValue;
    uint32_t                   mPeakMeasuredValueWindow  = 0;
    DataModel::Nullable<float> mAverageMeasuredValue;
    uint32_t                   mAverageMeasuredValueWindow = 0;
    float                      mUncertainty               = 0.0f;
    MeasurementMediumEnum      mMedium;
    MeasurementUnitEnum        mUnit;
    LevelValueEnum             mLevelValue = LevelValueEnum::kUnknown;
    ConcentrationMeasurementCluster * mCluster = nullptr;
};
References
  1. Prefer defensive null checks (e.g., if (mCluster)) over using VerifyOrDie for delegate or cluster pointers to ensure consistency across the repository.
  2. Use NotifyAttributeChanged for attribute change notifications to align with modern cluster implementation patterns.
  3. Silently ignoring writes of invalid enum values is considered an unexpected pattern and should be reviewed.

src/app/clusters/concentration-measurement-server/ConcentrationMeasurementCluster.h (135-155)

medium

These static helper methods (CheckConstraintMinMax, CheckConstraintsLessThanOrEqualTo, CheckConstraintsGreaterThanOrEqualTo) are defined but not used anywhere in the new implementation. Since the cluster now only handles attribute reads and delegates value management to the application, these constraints should be enforced by the application/delegate before updating the values. These should be removed to clean up the code.

src/app/clusters/concentration-measurement-server/ConcentrationMeasurementCluster.h (126)

medium

The constant kWindowMaxSeconds is defined but not used within the class. It should be removed if it is no longer needed.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 16, 2026

PR #71608: Size comparison from a6e7ae0 to e39b415

Full report (23 builds for bl602, bl616, bl702, bl702l, cc13x4_26x4, nxp, qpg, realtek, stm32, telink)
platform target config section a6e7ae0 e39b415 change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1090616 1090616 0 0.0
RAM 144858 144858 0 0.0
bl616 lighting-app bl616+thread FLASH 1102108 1102108 0 0.0
RAM 104280 104280 0 0.0
bl616+wifi+shell FLASH 1588996 1588996 0 0.0
RAM 98176 98176 0 0.0
bl702 lighting-app bl702+eth FLASH 1053786 1053786 0 0.0
RAM 108469 108469 0 0.0
bl702l contact-sensor-app bl702l+mfd+littlefs FLASH 892484 892484 0 0.0
RAM 105860 105860 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 775960 775960 0 0.0
RAM 103420 103420 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 788204 788204 0 0.0
RAM 108604 108604 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 735596 735596 0 0.0
RAM 97444 97444 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 717980 717980 0 0.0
RAM 97572 97572 0 0.0
nxp contact mcxw71+release FLASH 740408 740408 0 0.0
RAM 67040 67040 0 0.0
qpg lighting-app qpg6200+debug FLASH 842772 842772 0 0.0
RAM 127884 127884 0 0.0
lock-app qpg6200+debug FLASH 781372 781372 0 0.0
RAM 118832 118832 0 0.0
realtek light-switch-app rtl8777g FLASH 681104 681104 0 0.0
RAM 101632 101632 0 0.0
lighting-app rtl8777g FLASH 724904 724904 0 0.0
RAM 101964 101964 0 0.0
stm32 light STM32WB5MM-DK FLASH 475548 475548 0 0.0
RAM 141412 141412 0 0.0
telink bridge-app tl7218x FLASH 730740 730740 0 0.0
RAM 95932 95932 0 0.0
light-app-ota-compress-lzma-shell-factory-data tl3218x FLASH 850324 850324 0 0.0
RAM 44348 44348 0 0.0
tl7218x FLASH 841730 841730 0 0.0
RAM 99736 99736 0 0.0
light-switch-app-ota-compress-lzma-factory-data tl7218x_retention FLASH 730322 730322 0 0.0
RAM 56012 56012 0 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 793548 793548 0 0.0
RAM 75188 75188 0 0.0
light-switch-app-ota-factory-data tl3218x_retention FLASH 730244 730244 0 0.0
RAM 33492 33492 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 613124 613124 0 0.0
RAM 118404 118404 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 839864 839868 4 0.0
RAM 97444 97444 0 0.0

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 16, 2026

PR #71608: Size comparison from a6e7ae0 to 214c3c3

Full report (9 builds for cc13x4_26x4, cc32xx, realtek, stm32)
platform target config section a6e7ae0 214c3c3 change % change
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 775960 775960 0 0.0
RAM 103420 103420 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 788204 788204 0 0.0
RAM 108604 108604 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 735596 735596 0 0.0
RAM 97444 97444 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 717980 717980 0 0.0
RAM 97572 97572 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 560954 560658 -296 -0.1
RAM 204616 204616 0 0.0
lock CC3235SF_LAUNCHXL FLASH 592858 592858 0 0.0
RAM 204824 204824 0 0.0
realtek light-switch-app rtl8777g FLASH 681104 681104 0 0.0
RAM 101632 101632 0 0.0
lighting-app rtl8777g FLASH 724904 724904 0 0.0
RAM 101964 101964 0 0.0
stm32 light STM32WB5MM-DK FLASH 475548 475548 0 0.0
RAM 141412 141412 0 0.0

@marybadalyan marybadalyan force-pushed the ConcentMeasureCluster branch from 214c3c3 to 4a61ea6 Compare April 16, 2026 18:02
@github-actions
Copy link
Copy Markdown

PR #71608: Size comparison from 3a0c11a to 172eb74

Full report (1 build for stm32)
platform target config section 3a0c11a 172eb74 change % change
stm32 light STM32WB5MM-DK FLASH 475476 475476 0 0.0
RAM 141412 141412 0 0.0

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 16, 2026

PR #71608: Size comparison from 3a0c11a to 678ab13

Full report (29 builds for bl602, bl616, bl702, bl702l, cc13x4_26x4, cc32xx, nxp, psoc6, qpg, realtek, stm32, telink)
platform target config section 3a0c11a 678ab13 change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1090528 1090528 0 0.0
RAM 144850 144850 0 0.0
bl616 lighting-app bl616+thread FLASH 1102012 1102012 0 0.0
RAM 104280 104280 0 0.0
bl616+wifi+shell FLASH 1588900 1588900 0 0.0
RAM 98176 98176 0 0.0
bl702 lighting-app bl702+eth FLASH 1053702 1053702 0 0.0
RAM 108461 108461 0 0.0
bl702l contact-sensor-app bl702l+mfd+littlefs FLASH 892400 892400 0 0.0
RAM 105852 105852 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 775896 775896 0 0.0
RAM 103420 103420 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 788132 788132 0 0.0
RAM 108604 108604 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 735532 735532 0 0.0
RAM 97444 97444 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 717916 717916 0 0.0
RAM 97572 97572 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 560890 560586 -304 -0.1
RAM 204616 204616 0 0.0
lock CC3235SF_LAUNCHXL FLASH 592794 592794 0 0.0
RAM 204824 204824 0 0.0
nxp contact mcxw71+release FLASH 740336 740336 0 0.0
RAM 67040 67040 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1714948 1715892 944 0.1
RAM 214180 214260 80 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1612364 1612364 0 0.0
RAM 211052 211052 0 0.0
light cy8ckit_062s2_43012 FLASH 1466940 1466940 0 0.0
RAM 197092 197092 0 0.0
lock cy8ckit_062s2_43012 FLASH 1499668 1499668 0 0.0
RAM 224828 224828 0 0.0
qpg lighting-app qpg6200+debug FLASH 842700 842700 0 0.0
RAM 127884 127884 0 0.0
lock-app qpg6200+debug FLASH 781300 781300 0 0.0
RAM 118832 118832 0 0.0
realtek light-switch-app rtl8777g FLASH 681032 681032 0 0.0
RAM 101632 101632 0 0.0
lighting-app rtl8777g FLASH 724832 724832 0 0.0
RAM 101964 101964 0 0.0
stm32 light STM32WB5MM-DK FLASH 475476 475476 0 0.0
RAM 141412 141412 0 0.0
telink bridge-app tl7218x FLASH 730658 730658 0 0.0
RAM 95932 95932 0 0.0
light-app-ota-compress-lzma-shell-factory-data tl3218x FLASH 850242 850242 0 0.0
RAM 44348 44348 0 0.0
tl7218x FLASH 841648 841648 0 0.0
RAM 99736 99736 0 0.0
light-switch-app-ota-compress-lzma-factory-data tl7218x_retention FLASH 730240 730240 0 0.0
RAM 56012 56012 0 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 793466 793466 0 0.0
RAM 75188 75188 0 0.0
light-switch-app-ota-factory-data tl3218x_retention FLASH 730162 730162 0 0.0
RAM 33492 33492 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 613042 613042 0 0.0
RAM 118404 118404 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 839782 839786 4 0.0
RAM 97444 97444 0 0.0

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 16, 2026

Codecov Report

❌ Patch coverage is 59.33014% with 85 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.36%. Comparing base (5f28762) to head (5b9fba3).

Files with missing lines Patch % Lines
...urement-server/ConcentrationMeasurementCluster.cpp 7.35% 63 Missing ⚠️
...surement-server/ConcentrationMeasurementDelegate.h 35.29% 22 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #71608      +/-   ##
==========================================
- Coverage   54.40%   54.36%   -0.05%     
==========================================
  Files        1582     1584       +2     
  Lines      108395   108364      -31     
  Branches    13384    13399      +15     
==========================================
- Hits        58976    58912      -64     
- Misses      49419    49452      +33     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 17, 2026

PR #71608: Size comparison from 3a0c11a to 4ee42b0

Full report (29 builds for bl602, bl616, bl702, bl702l, cc13x4_26x4, cc32xx, nxp, psoc6, qpg, realtek, stm32, telink)
platform target config section 3a0c11a 4ee42b0 change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1090528 1090528 0 0.0
RAM 144850 144850 0 0.0
bl616 lighting-app bl616+thread FLASH 1102012 1102012 0 0.0
RAM 104280 104280 0 0.0
bl616+wifi+shell FLASH 1588900 1588900 0 0.0
RAM 98176 98176 0 0.0
bl702 lighting-app bl702+eth FLASH 1053702 1053702 0 0.0
RAM 108461 108461 0 0.0
bl702l contact-sensor-app bl702l+mfd+littlefs FLASH 892400 892400 0 0.0
RAM 105852 105852 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 775896 775896 0 0.0
RAM 103420 103420 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 788132 788132 0 0.0
RAM 108604 108604 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 735532 735532 0 0.0
RAM 97444 97444 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 717916 717916 0 0.0
RAM 97572 97572 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 560890 560586 -304 -0.1
RAM 204616 204616 0 0.0
lock CC3235SF_LAUNCHXL FLASH 592794 592794 0 0.0
RAM 204824 204824 0 0.0
nxp contact mcxw71+release FLASH 740336 740336 0 0.0
RAM 67040 67040 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1714948 1715892 944 0.1
RAM 214180 214260 80 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1612364 1612364 0 0.0
RAM 211052 211052 0 0.0
light cy8ckit_062s2_43012 FLASH 1466940 1466940 0 0.0
RAM 197092 197092 0 0.0
lock cy8ckit_062s2_43012 FLASH 1499668 1499668 0 0.0
RAM 224828 224828 0 0.0
qpg lighting-app qpg6200+debug FLASH 842700 842700 0 0.0
RAM 127884 127884 0 0.0
lock-app qpg6200+debug FLASH 781300 781300 0 0.0
RAM 118832 118832 0 0.0
realtek light-switch-app rtl8777g FLASH 681032 681032 0 0.0
RAM 101632 101632 0 0.0
lighting-app rtl8777g FLASH 724832 724832 0 0.0
RAM 101964 101964 0 0.0
stm32 light STM32WB5MM-DK FLASH 475476 475476 0 0.0
RAM 141412 141412 0 0.0
telink bridge-app tl7218x FLASH 730658 730658 0 0.0
RAM 95932 95932 0 0.0
light-app-ota-compress-lzma-shell-factory-data tl3218x FLASH 850242 850242 0 0.0
RAM 44348 44348 0 0.0
tl7218x FLASH 841648 841648 0 0.0
RAM 99736 99736 0 0.0
light-switch-app-ota-compress-lzma-factory-data tl7218x_retention FLASH 730240 730240 0 0.0
RAM 56012 56012 0 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 793466 793466 0 0.0
RAM 75188 75188 0 0.0
light-switch-app-ota-factory-data tl3218x_retention FLASH 730162 730162 0 0.0
RAM 33492 33492 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 613042 613042 0 0.0
RAM 118404 118404 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 839782 839786 4 0.0
RAM 97444 97444 0 0.0

@marybadalyan marybadalyan force-pushed the ConcentMeasureCluster branch from 295f0c4 to e258ff2 Compare April 17, 2026 16:04
@marybadalyan marybadalyan force-pushed the ConcentMeasureCluster branch from e258ff2 to 5b9fba3 Compare April 17, 2026 16:11
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 17, 2026

PR #71608: Size comparison from 5f28762 to 5b9fba3

Full report (29 builds for bl602, bl616, bl702, bl702l, cc13x4_26x4, cc32xx, nxp, psoc6, qpg, realtek, stm32, telink)
platform target config section 5f28762 5b9fba3 change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1090528 1090528 0 0.0
RAM 144850 144850 0 0.0
bl616 lighting-app bl616+thread FLASH 1102012 1102012 0 0.0
RAM 104280 104280 0 0.0
bl616+wifi+shell FLASH 1588900 1588900 0 0.0
RAM 98176 98176 0 0.0
bl702 lighting-app bl702+eth FLASH 1053702 1053702 0 0.0
RAM 108461 108461 0 0.0
bl702l contact-sensor-app bl702l+mfd+littlefs FLASH 892400 892400 0 0.0
RAM 105852 105852 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 775896 775896 0 0.0
RAM 103420 103420 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 788132 788132 0 0.0
RAM 108604 108604 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 735532 735532 0 0.0
RAM 97444 97444 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 717916 717916 0 0.0
RAM 97572 97572 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 560890 560586 -304 -0.1
RAM 204616 204616 0 0.0
lock CC3235SF_LAUNCHXL FLASH 592794 592794 0 0.0
RAM 204824 204824 0 0.0
nxp contact mcxw71+release FLASH 740336 740336 0 0.0
RAM 67040 67040 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1714948 1715892 944 0.1
RAM 214180 214260 80 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1612364 1612364 0 0.0
RAM 211052 211052 0 0.0
light cy8ckit_062s2_43012 FLASH 1466940 1466940 0 0.0
RAM 197092 197092 0 0.0
lock cy8ckit_062s2_43012 FLASH 1499668 1499668 0 0.0
RAM 224828 224828 0 0.0
qpg lighting-app qpg6200+debug FLASH 842700 842700 0 0.0
RAM 127884 127884 0 0.0
lock-app qpg6200+debug FLASH 781300 781300 0 0.0
RAM 118832 118832 0 0.0
realtek light-switch-app rtl8777g FLASH 681032 681032 0 0.0
RAM 101632 101632 0 0.0
lighting-app rtl8777g FLASH 724832 724832 0 0.0
RAM 101964 101964 0 0.0
stm32 light STM32WB5MM-DK FLASH 475476 475476 0 0.0
RAM 141412 141412 0 0.0
telink bridge-app tl7218x FLASH 730658 730658 0 0.0
RAM 95932 95932 0 0.0
light-app-ota-compress-lzma-shell-factory-data tl3218x FLASH 850462 850462 0 0.0
RAM 44348 44348 0 0.0
tl7218x FLASH 841868 841868 0 0.0
RAM 99736 99736 0 0.0
light-switch-app-ota-compress-lzma-factory-data tl7218x_retention FLASH 730460 730460 0 0.0
RAM 56012 56012 0 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 793686 793686 0 0.0
RAM 75188 75188 0 0.0
light-switch-app-ota-factory-data tl3218x_retention FLASH 730382 730382 0 0.0
RAM 33492 33492 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 613268 613268 0 0.0
RAM 118404 118404 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 840002 840006 4 0.0
RAM 97444 97444 0 0.0

@marybadalyan
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the Concentration Measurement cluster implementation to a delegate-based architecture, replacing the previous template-based approach. It introduces new cluster and delegate classes and updates multiple example applications to align with this new structure. Feedback includes a critical issue where ReadAttribute fails to delegate to the base class for global attributes, and a requirement to use NotifyAttributeChanged for attribute reporting in the delegate. Additionally, several instances of dead code (unused helper methods and constants) and a logging format typo were identified.

Comment on lines +112 to +114
default:
return Status::UnsupportedAttribute;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The ReadAttribute implementation does not delegate to the base class DefaultServerCluster::ReadAttribute for attributes it doesn't handle (the default case). This will prevent mandatory global attributes like AttributeList, AcceptedCommandList, GeneratedCommandList, and EventList from being readable, even though they are correctly advertised in the Attributes() method.

    default:
        return DefaultServerCluster::ReadAttribute(request, encoder);
    }

Comment on lines +148 to +164
void HandleNewMeasuredValue(DataModel::Nullable<float> v) { mMeasuredValue = v; }

void HandleNewMinMeasuredValue(DataModel::Nullable<float> v) { mMinMeasuredValue = v; }

void HandleNewMaxMeasuredValue(DataModel::Nullable<float> v) { mMaxMeasuredValue = v; }

void HandleNewUncertainty(float v) { mUncertainty = v; }

void HandleNewPeakMeasuredValue(DataModel::Nullable<float> v) { mPeakMeasuredValue = v; }

void HandleNewPeakMeasuredValueWindow(uint32_t v) { mPeakMeasuredValueWindow = v; }

void HandleNewAverageMeasuredValue(DataModel::Nullable<float> v) { mAverageMeasuredValue = v; }

void HandleNewAverageMeasuredValueWindow(uint32_t v) { mAverageMeasuredValueWindow = v; }

void HandleNewLevelValue(LevelValueEnum v) { mLevelValue = v; }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The HandleNew* methods in DefaultDelegate update the internal state but do not trigger attribute reports. In accordance with repository standards, NotifyAttributeChanged should be used for notifications rather than MatterReportingAttributeChangeCallback. The delegate needs a mechanism to notify the cluster of changes so that NotifyAttributeChanged() can be called.

References
  1. In the Groupcast cluster, use NotifyAttributeChanged for attribute change notifications, not MatterReportingAttributeChangeCallback.

Comment on lines +136 to +153
static bool CheckConstraintMinMax(DataModel::Nullable<float> value, DataModel::Nullable<float> minValue,
DataModel::Nullable<float> maxValue)
{
return (minValue.IsNull() || value.IsNull() || (value.Value() >= minValue.Value())) &&
(maxValue.IsNull() || value.IsNull() || (value.Value() <= maxValue.Value()));
}

static bool CheckConstraintsLessThanOrEqualTo(DataModel::Nullable<float> value,
DataModel::Nullable<float> valueToBeLessThanOrEqualTo)
{
return valueToBeLessThanOrEqualTo.IsNull() || value.IsNull() || (value.Value() <= valueToBeLessThanOrEqualTo.Value());
}

static bool CheckConstraintsGreaterThanOrEqualTo(DataModel::Nullable<float> value,
DataModel::Nullable<float> valueToBeGreaterThanOrEqualTo)
{
return valueToBeGreaterThanOrEqualTo.IsNull() || value.IsNull() || (value.Value() >= valueToBeGreaterThanOrEqualTo.Value());
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

These private static helper methods (CheckConstraintMinMax, CheckConstraintsLessThanOrEqualTo, and CheckConstraintsGreaterThanOrEqualTo) are defined but not used anywhere in the cluster implementation. Since this cluster is read-only and delegates data retrieval to the Delegate, these validation helpers are dead code and should be removed.

{
mAirQualityInstance.UpdateAirQuality(newValue);
airQualityInstance.UpdateAirQuality(newValue);
ChipLogDetail(NotSpecified, "Updated AirQuality value: %huu", chip::to_underlying(newValue));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Typo in the log format string: %huu is invalid and should be corrected to %u or %d.

    ChipLogDetail(NotSpecified, "Updated AirQuality value: %u", chip::to_underlying(newValue));


private:
// Per-spec maximum window for PeakMeasuredValueWindow / AverageMeasuredValueWindow: 7 days
static constexpr uint32_t kWindowMaxSeconds = 604800;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The constant kWindowMaxSeconds is defined but not used in the current implementation. It should be removed to avoid dead code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants