@@ -40,12 +40,14 @@ class TestDelegate : public Delegate
40
40
{
41
41
public:
42
42
TestDelegate () {}
43
- DataModel::Nullable<chip:: Percent> HandleOpenValve (DataModel::Nullable<chip:: Percent> level) override
43
+ DataModel::Nullable<Percent> HandleOpenValve (DataModel::Nullable<Percent> level) override
44
44
{
45
+ lastRequestedLevel = level;
45
46
return DataModel::NullNullable;
46
47
}
47
48
CHIP_ERROR HandleCloseValve () override { return CHIP_NO_ERROR; }
48
49
void HandleRemainingDurationTick (uint32_t duration) override {}
50
+ DataModel::Nullable<Percent> lastRequestedLevel;
49
51
};
50
52
51
53
TEST_F (TestValveConfigurationAndControlClusterLogic, TestConformanceValid)
@@ -504,6 +506,76 @@ TEST_F(TestValveConfigurationAndControlClusterLogic, TestSetDefaultOpenLevel)
504
506
EXPECT_EQ (logic_no_level.SetDefaultOpenLevel (testVal), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
505
507
}
506
508
509
+ TEST_F (TestValveConfigurationAndControlClusterLogic, TestHandleOpenDuration)
510
+ {
511
+ TestDelegate delegate;
512
+ TestPersistentStorageDelegate storageDelegate;
513
+ EndpointId endpoint = 0 ;
514
+ MatterContext context = MatterContext (endpoint, storageDelegate);
515
+ ClusterLogic logic = ClusterLogic (delegate, context);
516
+
517
+ ClusterConformance conformance = { .featureMap = to_underlying (Feature::kLevel ) | to_underlying (Feature::kTimeSync ),
518
+ .supportsDefaultOpenLevel = true ,
519
+ .supportsValveFault = true ,
520
+ .supportsLevelStep = true };
521
+ EXPECT_EQ (logic.Init (conformance), CHIP_NO_ERROR);
522
+
523
+ DataModel::Nullable<ElapsedS> valElapsedSNullable;
524
+
525
+ EXPECT_EQ (logic.GetOpenDuration (valElapsedSNullable), CHIP_NO_ERROR);
526
+ EXPECT_EQ (valElapsedSNullable, DataModel::NullNullable);
527
+
528
+ EXPECT_EQ (logic.GetDefaultOpenDuration (valElapsedSNullable), CHIP_NO_ERROR);
529
+ EXPECT_EQ (valElapsedSNullable, DataModel::NullNullable);
530
+
531
+ // Fall back to default
532
+ EXPECT_EQ (logic.HandleOpenCommand (std::nullopt, std::nullopt), CHIP_NO_ERROR);
533
+ EXPECT_EQ (logic.GetOpenDuration (valElapsedSNullable), CHIP_NO_ERROR);
534
+ EXPECT_EQ (valElapsedSNullable, DataModel::NullNullable);
535
+
536
+ DataModel::Nullable<ElapsedS> defaultOpenDuration;
537
+ defaultOpenDuration.SetNonNull (12u );
538
+ EXPECT_EQ (logic.SetDefaultOpenDuration (defaultOpenDuration), CHIP_NO_ERROR);
539
+ EXPECT_EQ (logic.HandleOpenCommand (std::nullopt, std::nullopt), CHIP_NO_ERROR);
540
+ EXPECT_EQ (logic.GetOpenDuration (valElapsedSNullable), CHIP_NO_ERROR);
541
+ EXPECT_EQ (valElapsedSNullable, defaultOpenDuration);
542
+
543
+ // Set from command parameters
544
+ DataModel::Nullable<ElapsedS> openDuration;
545
+ openDuration.SetNull ();
546
+ EXPECT_EQ (logic.HandleOpenCommand (std::make_optional (openDuration), std::nullopt), CHIP_NO_ERROR);
547
+ EXPECT_EQ (logic.GetOpenDuration (valElapsedSNullable), CHIP_NO_ERROR);
548
+ EXPECT_EQ (valElapsedSNullable, DataModel::NullNullable);
549
+
550
+ openDuration.SetNonNull (12u );
551
+ EXPECT_EQ (logic.HandleOpenCommand (std::make_optional (openDuration), std::nullopt), CHIP_NO_ERROR);
552
+ EXPECT_EQ (logic.GetOpenDuration (valElapsedSNullable), CHIP_NO_ERROR);
553
+ EXPECT_EQ (valElapsedSNullable.ValueOr (0 ), 12u );
554
+ }
555
+
556
+ TEST_F (TestValveConfigurationAndControlClusterLogic, TestHandleOpenTargetLevelFeatureUnsupported)
557
+ {
558
+ TestDelegate delegate;
559
+ TestPersistentStorageDelegate storageDelegate;
560
+ EndpointId endpoint = 0 ;
561
+ MatterContext context = MatterContext (endpoint, storageDelegate);
562
+ ClusterLogic logic = ClusterLogic (delegate, context);
563
+
564
+ ClusterConformance conformance = {
565
+ .featureMap = 0 , .supportsDefaultOpenLevel = false , .supportsValveFault = false , .supportsLevelStep = false
566
+ };
567
+ EXPECT_EQ (logic.Init (conformance), CHIP_NO_ERROR);
568
+
569
+ // Set the last value to something non-null first so we can ensure the delegate was called correctly.
570
+ delegate.lastRequestedLevel .SetNonNull (0 );
571
+ EXPECT_EQ (logic.HandleOpenCommand (std::nullopt, std::nullopt), CHIP_NO_ERROR);
572
+ // This configuration doesn't support level, so the delegate should be called with a NullNullable
573
+ EXPECT_EQ (delegate.lastRequestedLevel , DataModel::NullNullable);
574
+
575
+ // Should get an error when this is called with target level set since the feature is unsupported.
576
+ EXPECT_EQ (logic.HandleOpenCommand (std::nullopt, std::make_optional (50u )), CHIP_ERROR_INVALID_ARGUMENT);
577
+ }
578
+
507
579
} // namespace ValveConfigurationAndControl
508
580
} // namespace Clusters
509
581
} // namespace app
0 commit comments