diff --git a/src/python_testing/TC_RVCCLEANM_3_2.py b/src/python_testing/TC_RVCCLEANM_3_2.py index 1d5d24beea5ac1..7f29c8807262b9 100644 --- a/src/python_testing/TC_RVCCLEANM_3_2.py +++ b/src/python_testing/TC_RVCCLEANM_3_2.py @@ -16,8 +16,11 @@ # import logging +import random import chip.clusters as Clusters +from chip.clusters.Types import NullValue +from chip.interaction_model import Status from matter_testing_support import MatterBaseTest, async_test_body, default_matter_test_main, type_matches from mobly import asserts @@ -38,6 +41,10 @@ async def send_change_to_mode_cmd(self, newMode) -> Clusters.Objects.RvcCleanMod "Unexpected return type for ChangeToMode") return ret + async def write_start_up_mode(self, newMode): + ret = await self.default_controller.WriteAttribute(self.dut_node_id, [(self.endpoint, Clusters.RvcCleanMode.Attributes.StartUpMode(newMode))]) + asserts.assert_equal(ret[0].Status, Status.Success, "Writing to StartUpMode failed") + @async_test_body async def test_TC_RVCCLEANM_3_2(self): @@ -69,16 +76,32 @@ class CommonCodes(Enum): startup_mode = await self.read_mod_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.StartUpMode) logging.info("StartUpMode: %s" % (startup_mode)) + if startup_mode == NullValue: + self.print_step(3, "Read SupportedModes attribute") + supported_modes = await self.read_mod_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.SupportedModes) + + logging.info("SupportedModes: %s" % (supported_modes)) + + asserts.assert_greater_equal(len(supported_modes), 2, "SupportedModes must have at least two entries!") + + modes = [m.mode for m in supported_modes] + new_startup_mode = random.choice(modes) - self.print_step(3, "Read CurrentMode attribute") + self.print_step(4, "Write the value %s to StartUpMode" % (new_startup_mode)) + + await self.write_start_up_mode(newMode=new_startup_mode) + else: + new_startup_mode = startup_mode + + self.print_step(5, "Read CurrentMode attribute") old_current_mode = await self.read_mod_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.CurrentMode) logging.info("CurrentMode: %s" % (old_current_mode)) - if old_current_mode == startup_mode: + if old_current_mode == new_startup_mode: - self.print_step(4, "Read SupportedModes attribute") + self.print_step(6, "Read SupportedModes attribute") supported_modes = await self.read_mod_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.SupportedModes) logging.info("SupportedModes: %s" % (supported_modes)) @@ -88,21 +111,28 @@ class CommonCodes(Enum): new_mode = None for m in supported_modes: - if m.mode != startup_mode: + if m.mode != new_startup_mode: new_mode = m.mode break - self.print_step(5, "Send ChangeToMode command with NewMode set to %d" % (new_mode)) + self.print_step(7, "Send ChangeToMode command with NewMode set to %d" % (new_mode)) ret = await self.send_change_to_mode_cmd(newMode=new_mode) asserts.assert_true(ret.status == CommonCodes.SUCCESS.value, "Changing the mode should succeed") self.default_controller.ExpireSessions(self.dut_node_id) - self.print_step(6, "Physically power cycle the device") + self.print_step(8, "Physically power cycle the device") input("Press Enter when done.\n") - self.print_step(7, "Read CurrentMode attribute") + self.print_step(9, "Read StartUpMode attribute") + + startup_mode = await self.read_mod_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.StartUpMode) + + logging.info("StartUpMode: %s" % (startup_mode)) + asserts.assert_equal(startup_mode, new_startup_mode, "StartUpMode must match the value it was before a power cycle") + + self.print_step(10, "Read CurrentMode attribute") current_mode = await self.read_mod_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.CurrentMode) diff --git a/src/python_testing/TC_RVCRUNM_3_2.py b/src/python_testing/TC_RVCRUNM_3_2.py index 09cfebec90d6eb..683395ef1db72a 100644 --- a/src/python_testing/TC_RVCRUNM_3_2.py +++ b/src/python_testing/TC_RVCRUNM_3_2.py @@ -16,8 +16,11 @@ # import logging +import random import chip.clusters as Clusters +from chip.clusters.Types import NullValue +from chip.interaction_model import Status from matter_testing_support import MatterBaseTest, async_test_body, default_matter_test_main, type_matches from mobly import asserts @@ -38,6 +41,10 @@ async def send_change_to_mode_cmd(self, newMode) -> Clusters.Objects.RvcRunMode. "Unexpected return type for ChangeToMode") return ret + async def write_start_up_mode(self, newMode): + ret = await self.default_controller.WriteAttribute(self.dut_node_id, [(self.endpoint, Clusters.RvcRunMode.Attributes.StartUpMode(newMode))]) + asserts.assert_equal(ret[0].Status, Status.Success, "Writing to StartUpMode failed") + @async_test_body async def test_TC_RVCRUNM_3_2(self): @@ -69,16 +76,32 @@ class CommonCodes(Enum): startup_mode = await self.read_mod_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.StartUpMode) logging.info("StartUpMode: %s" % (startup_mode)) + if startup_mode == NullValue: + self.print_step(3, "Read SupportedModes attribute") + supported_modes = await self.read_mod_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.SupportedModes) + + logging.info("SupportedModes: %s" % (supported_modes)) + + asserts.assert_greater_equal(len(supported_modes), 2, "SupportedModes must have at least two entries!") + + modes = [m.mode for m in supported_modes] + new_startup_mode = random.choice(modes) - self.print_step(3, "Read CurrentMode attribute") + self.print_step(4, "Write the value %s to StartUpMode" % (new_startup_mode)) + + await self.write_start_up_mode(newMode=new_startup_mode) + else: + new_startup_mode = startup_mode + + self.print_step(5, "Read CurrentMode attribute") old_current_mode = await self.read_mod_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.CurrentMode) logging.info("CurrentMode: %s" % (old_current_mode)) - if old_current_mode == startup_mode: + if old_current_mode == new_startup_mode: - self.print_step(4, "Read SupportedModes attribute") + self.print_step(6, "Read SupportedModes attribute") supported_modes = await self.read_mod_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.SupportedModes) logging.info("SupportedModes: %s" % (supported_modes)) @@ -88,21 +111,28 @@ class CommonCodes(Enum): new_mode = None for m in supported_modes: - if m.mode != startup_mode: + if m.mode != new_startup_mode: new_mode = m.mode break - self.print_step(5, "Send ChangeToMode command with NewMode set to %d" % (new_mode)) + self.print_step(7, "Send ChangeToMode command with NewMode set to %d" % (new_mode)) ret = await self.send_change_to_mode_cmd(newMode=new_mode) asserts.assert_true(ret.status == CommonCodes.SUCCESS.value, "Changing the mode should succeed") self.default_controller.ExpireSessions(self.dut_node_id) - self.print_step(6, "Physically power cycle the device") + self.print_step(8, "Physically power cycle the device") input("Press Enter when done.\n") - self.print_step(7, "Read CurrentMode attribute") + self.print_step(9, "Read StartUpMode attribute") + + startup_mode = await self.read_mod_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.StartUpMode) + + logging.info("StartUpMode: %s" % (startup_mode)) + asserts.assert_equal(startup_mode, new_startup_mode, "StartUpMode must match the value it was before a power cycle") + + self.print_step(10, "Read CurrentMode attribute") current_mode = await self.read_mod_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.CurrentMode)