@@ -1947,9 +1947,168 @@ TEST_F(TestValveConfigurationAndControlClusterLogic, TestCloseCalledAtOpenDurati
1947
1947
// =========================================================================================
1948
1948
// Tests for handling close commands
1949
1949
// =========================================================================================
1950
- // while remaining duration is null and valve is open
1951
1950
// while remaining duration is not null and valve is open
1951
+
1952
+ TEST_F (TestValveConfigurationAndControlClusterLogic, TestCloseCommandOpenValveDurationLevel)
1953
+ {
1954
+ TestDelegateLevel delegate;
1955
+ TestPersistentStorageDelegate storageDelegate;
1956
+ EndpointId endpoint = 0 ;
1957
+ MockedMatterContext context (endpoint, storageDelegate);
1958
+ ClusterLogic logic (delegate, context);
1959
+
1960
+ ClusterConformance conformance = { .featureMap = to_underlying (Feature::kLevel ) | to_underlying (Feature::kTimeSync ),
1961
+ .supportsDefaultOpenLevel = true ,
1962
+ .supportsValveFault = true ,
1963
+ .supportsLevelStep = true };
1964
+ EXPECT_EQ (logic.Init (conformance), CHIP_NO_ERROR);
1965
+
1966
+ gSystemLayerAndClock .SetMonotonic (0_ms64);
1967
+ gSystemLayerAndClock .Clear ();
1968
+ DataModel::Nullable<ElapsedS> openDuration;
1969
+ openDuration.SetNonNull (2u );
1970
+ EXPECT_EQ (logic.HandleOpenCommand (std::make_optional (openDuration), std::nullopt), CHIP_NO_ERROR);
1971
+ EXPECT_TRUE (HasAttributeChanges (context.GetDirtyList (), Attributes::OpenDuration::Id));
1972
+ EXPECT_EQ (delegate.numHandleCloseValveCalls , 0 );
1973
+
1974
+ gSystemLayerAndClock .AdvanceMonotonic (1000_ms64);
1975
+ EXPECT_EQ (logic.HandleCloseCommand (), CHIP_NO_ERROR);
1976
+ EXPECT_EQ (delegate.numHandleCloseValveCalls , 1 );
1977
+
1978
+ // Ensure the timer was cancelled
1979
+ gSystemLayerAndClock .AdvanceMonotonic (1000_ms64);
1980
+ EXPECT_EQ (delegate.numHandleCloseValveCalls , 1 );
1981
+ }
1982
+
1983
+ TEST_F (TestValveConfigurationAndControlClusterLogic, TestCloseCommandOpenValveDurationNoLevel)
1984
+ {
1985
+ TestDelegateNoLevel delegate;
1986
+ TestPersistentStorageDelegate storageDelegate;
1987
+ EndpointId endpoint = 0 ;
1988
+ MockedMatterContext context (endpoint, storageDelegate);
1989
+ ClusterLogic logic (delegate, context);
1990
+
1991
+ ClusterConformance conformance = {
1992
+ .featureMap = 0 , .supportsDefaultOpenLevel = false , .supportsValveFault = true , .supportsLevelStep = false
1993
+ };
1994
+ EXPECT_EQ (logic.Init (conformance), CHIP_NO_ERROR);
1995
+
1996
+ gSystemLayerAndClock .SetMonotonic (0_ms64);
1997
+ gSystemLayerAndClock .Clear ();
1998
+ DataModel::Nullable<ElapsedS> openDuration;
1999
+ openDuration.SetNonNull (2u );
2000
+ EXPECT_EQ (logic.HandleOpenCommand (std::make_optional (openDuration), std::nullopt), CHIP_NO_ERROR);
2001
+ EXPECT_TRUE (HasAttributeChanges (context.GetDirtyList (), Attributes::OpenDuration::Id));
2002
+ EXPECT_EQ (delegate.numHandleCloseValveCalls , 0 );
2003
+
2004
+ gSystemLayerAndClock .AdvanceMonotonic (2000_ms64);
2005
+ EXPECT_EQ (delegate.numHandleCloseValveCalls , 1 );
2006
+
2007
+ gSystemLayerAndClock .AdvanceMonotonic (1000_ms64);
2008
+ EXPECT_EQ (logic.HandleCloseCommand (), CHIP_NO_ERROR);
2009
+ EXPECT_EQ (delegate.numHandleCloseValveCalls , 1 );
2010
+
2011
+ // Ensure the timer was cancelled
2012
+ gSystemLayerAndClock .AdvanceMonotonic (1000_ms64);
2013
+ EXPECT_EQ (delegate.numHandleCloseValveCalls , 1 );
2014
+ }
2015
+
2016
+ // while remaining duration is null and valve is open
2017
+ TEST_F (TestValveConfigurationAndControlClusterLogic, TestCloseCommandOpenValveNoDurationLevel)
2018
+ {
2019
+ TestDelegateLevel delegate;
2020
+ TestPersistentStorageDelegate storageDelegate;
2021
+ EndpointId endpoint = 0 ;
2022
+ MockedMatterContext context (endpoint, storageDelegate);
2023
+ ClusterLogic logic (delegate, context);
2024
+
2025
+ ClusterConformance conformance = { .featureMap = to_underlying (Feature::kLevel ) | to_underlying (Feature::kTimeSync ),
2026
+ .supportsDefaultOpenLevel = true ,
2027
+ .supportsValveFault = true ,
2028
+ .supportsLevelStep = true };
2029
+ EXPECT_EQ (logic.Init (conformance), CHIP_NO_ERROR);
2030
+
2031
+ gSystemLayerAndClock .SetMonotonic (0_ms64);
2032
+ gSystemLayerAndClock .Clear ();
2033
+ EXPECT_EQ (logic.HandleOpenCommand (std::nullopt, std::nullopt), CHIP_NO_ERROR);
2034
+ EXPECT_TRUE (HasAttributeChanges (context.GetDirtyList (), Attributes::OpenDuration::Id));
2035
+ EXPECT_EQ (delegate.numHandleCloseValveCalls , 0 );
2036
+
2037
+ gSystemLayerAndClock .AdvanceMonotonic (1000_ms64);
2038
+ EXPECT_EQ (logic.HandleCloseCommand (), CHIP_NO_ERROR);
2039
+ EXPECT_EQ (delegate.numHandleCloseValveCalls , 1 );
2040
+ }
2041
+
2042
+ TEST_F (TestValveConfigurationAndControlClusterLogic, TestCloseCommandOpenValveNoDurationNoLevel)
2043
+ {
2044
+ TestDelegateNoLevel delegate;
2045
+ TestPersistentStorageDelegate storageDelegate;
2046
+ EndpointId endpoint = 0 ;
2047
+ MockedMatterContext context (endpoint, storageDelegate);
2048
+ ClusterLogic logic (delegate, context);
2049
+
2050
+ ClusterConformance conformance = {
2051
+ .featureMap = 0 , .supportsDefaultOpenLevel = false , .supportsValveFault = true , .supportsLevelStep = false
2052
+ };
2053
+ EXPECT_EQ (logic.Init (conformance), CHIP_NO_ERROR);
2054
+
2055
+ gSystemLayerAndClock .SetMonotonic (0_ms64);
2056
+ gSystemLayerAndClock .Clear ();
2057
+ EXPECT_EQ (logic.HandleOpenCommand (std::nullopt, std::nullopt), CHIP_NO_ERROR);
2058
+ EXPECT_TRUE (HasAttributeChanges (context.GetDirtyList (), Attributes::OpenDuration::Id));
2059
+ EXPECT_EQ (delegate.numHandleCloseValveCalls , 0 );
2060
+
2061
+ gSystemLayerAndClock .AdvanceMonotonic (2000_ms64);
2062
+ EXPECT_EQ (delegate.numHandleCloseValveCalls , 1 );
2063
+
2064
+ gSystemLayerAndClock .AdvanceMonotonic (1000_ms64);
2065
+ EXPECT_EQ (logic.HandleCloseCommand (), CHIP_NO_ERROR);
2066
+ EXPECT_EQ (delegate.numHandleCloseValveCalls , 1 );
2067
+ }
2068
+
1952
2069
// while valve is closed
2070
+ TEST_F (TestValveConfigurationAndControlClusterLogic, TestCloseCommandClosedLevel)
2071
+ {
2072
+ TestDelegateLevel delegate;
2073
+ TestPersistentStorageDelegate storageDelegate;
2074
+ EndpointId endpoint = 0 ;
2075
+ MockedMatterContext context (endpoint, storageDelegate);
2076
+ ClusterLogic logic (delegate, context);
2077
+
2078
+ ClusterConformance conformance = { .featureMap = to_underlying (Feature::kLevel ) | to_underlying (Feature::kTimeSync ),
2079
+ .supportsDefaultOpenLevel = true ,
2080
+ .supportsValveFault = true ,
2081
+ .supportsLevelStep = true };
2082
+ EXPECT_EQ (logic.Init (conformance), CHIP_NO_ERROR);
2083
+
2084
+ gSystemLayerAndClock .SetMonotonic (0_ms64);
2085
+ gSystemLayerAndClock .Clear ();
2086
+
2087
+ EXPECT_EQ (logic.HandleCloseCommand (), CHIP_NO_ERROR);
2088
+ EXPECT_EQ (delegate.numHandleCloseValveCalls , 1 );
2089
+ }
2090
+
2091
+ TEST_F (TestValveConfigurationAndControlClusterLogic, TestCloseCommandClosedNoLevel)
2092
+ {
2093
+ TestDelegateNoLevel delegate;
2094
+ TestPersistentStorageDelegate storageDelegate;
2095
+ EndpointId endpoint = 0 ;
2096
+ MockedMatterContext context (endpoint, storageDelegate);
2097
+ ClusterLogic logic (delegate, context);
2098
+
2099
+ ClusterConformance conformance = {
2100
+ .featureMap = 0 , .supportsDefaultOpenLevel = false , .supportsValveFault = true , .supportsLevelStep = false
2101
+ };
2102
+ EXPECT_EQ (logic.Init (conformance), CHIP_NO_ERROR);
2103
+
2104
+ gSystemLayerAndClock .SetMonotonic (0_ms64);
2105
+ gSystemLayerAndClock .Clear ();
2106
+
2107
+ EXPECT_EQ (logic.HandleCloseCommand (), CHIP_NO_ERROR);
2108
+ EXPECT_EQ (delegate.numHandleCloseValveCalls , 1 );
2109
+ }
2110
+ // Before init
2111
+ // simulated failures return error
1953
2112
1954
2113
// =========================================================================================
1955
2114
// Tests for timing for async read updates to current / target level and state
@@ -1972,10 +2131,9 @@ TEST_F(TestValveConfigurationAndControlClusterLogic, TestCloseCalledAtOpenDurati
1972
2131
// =========================================================================================
1973
2132
// Tests for attribute callbacks from delegates
1974
2133
// =========================================================================================
1975
- // TODO: Should the delegate call the cluster logic class direclty, or should this be piped through the delegate class so the app
1976
- // layer ONLY has to interact with the delegate?
1977
- // Test setter for valve fault Test attribute change notifications are sent out and not
1978
- // sent out when the attribute is change do the same value - add in prior
2134
+ // TODO: Should the delegate call the cluster logic class direclty, or should this be piped through the delegate class so the
2135
+ // app layer ONLY has to interact with the delegate? Test setter for valve fault Test attribute change notifications are sent
2136
+ // out and not sent out when the attribute is change do the same value - add in prior
1979
2137
1980
2138
// =========================================================================================
1981
2139
// Tests for attribute callbacks from delegates
0 commit comments