|
| 1 | +# |
| 2 | +# Copyright (c) 2024 Project CHIP Authors |
| 3 | +# All rights reserved. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | + |
| 18 | +import chip.clusters as Clusters |
| 19 | +from chip.interaction_model import InteractionModelError, Status |
| 20 | +from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main |
| 21 | +from mobly import asserts |
| 22 | +import logging |
| 23 | + |
| 24 | +# This test requires several additional command line arguments |
| 25 | +# run with |
| 26 | +# --endpoint endpoint |
| 27 | + |
| 28 | + |
| 29 | +class TC_MWOCTRL_2_5(MatterBaseTest): |
| 30 | + |
| 31 | + async def read_mwoctrl_attribute_expect_success(self, endpoint, attribute): |
| 32 | + cluster = Clusters.Objects.MicrowaveOvenControl |
| 33 | + return await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attribute) |
| 34 | + |
| 35 | + async def set_cook_time_expect_success(self, endpoint, value): |
| 36 | + commands = Clusters.Objects.MicrowaveOvenControl.Commands |
| 37 | + try: |
| 38 | + await self.send_single_cmd(cmd=commands.SetCookingParameters(cookTime=value), endpoint=endpoint) |
| 39 | + except InteractionModelError as e: |
| 40 | + asserts.assert_equal(e.status, Status.Success, "Unexpected error returned") |
| 41 | + |
| 42 | + async def send_add_more_time_command_expect_response(self, endpoint, value, expectedError = Status.Success): |
| 43 | + commands = Clusters.Objects.MicrowaveOvenControl.Commands |
| 44 | + try: |
| 45 | + await self.send_single_cmd(cmd=commands.AddMoreTime(timeToAdd=value), endpoint=endpoint) |
| 46 | + asserts.assert_equal(Status.Success, expectedError, "No error occured but unexpected response received.") |
| 47 | + except InteractionModelError as e: |
| 48 | + asserts.assert_equal(e.status, expectedError, "Unexpected error response received.") |
| 49 | + |
| 50 | + async def read_and_check_cook_time_value(self, endpoint, value): |
| 51 | + attributes = Clusters.MicrowaveOvenControl.Attributes |
| 52 | + cooktime = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.CookTime) |
| 53 | + asserts.assert_equal(cooktime, value, "Cooktime value not as expected") |
| 54 | + |
| 55 | + def desc_TC_MWOCTRL_2_5(self) -> str: |
| 56 | + return "[TC-MWOCTRL-2.1] Primary functionality with DUT as Server" |
| 57 | + |
| 58 | + def steps_TC_MWOCTRL_2_5(self) -> list[TestStep]: |
| 59 | + steps = [ |
| 60 | + TestStep(1, "Commissioning, already done", is_commissioning=True), |
| 61 | + TestStep(2, "Set the CookTime attribute to 60", |
| 62 | + "Verify DUT responds w/ status SUCCESS(0x00)." |
| 63 | + ), |
| 64 | + TestStep(3, "Send the AddMoreTime command with a value of 30.", |
| 65 | + "Verify DUT responds w/ status SUCCESS(0x00)." |
| 66 | + ), |
| 67 | + TestStep(4, "Read the CookTime attribute and verify it is 90", |
| 68 | + "Verify DUT responds w/ a value of 90."), |
| 69 | + TestStep(5, "Read the MaxCookTime attribute", |
| 70 | + "Save the response as MaxCookTime"), |
| 71 | + TestStep(6, "Send the AddMoreTime command with a value of MaxCookTime+1.", |
| 72 | + "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)." |
| 73 | + ), |
| 74 | + TestStep(7, "Manually set the device into a state where it will respond with INVALID_IN_STATE for the AddMoreTime command."), |
| 75 | + TestStep(8, "Send the AddMoreTime command with a value of 30.", |
| 76 | + "Verify DUT responds w/ status INVALID_IN_STATE(0xCB)." |
| 77 | + ), |
| 78 | + ] |
| 79 | + return steps |
| 80 | + |
| 81 | + def pics_TC_MWOCTRL_2_5(self) -> list[str]: |
| 82 | + pics = [ |
| 83 | + "MWOCTRL.S", |
| 84 | + "MWOCTRL.SC.ADD_MORE_TIME" |
| 85 | + ] |
| 86 | + return pics |
| 87 | + |
| 88 | + @async_test_body |
| 89 | + async def test_TC_MWOCTRL_2_5(self): |
| 90 | + |
| 91 | + endpoint = self.user_params.get("endpoint", 1) |
| 92 | + |
| 93 | + self.step(1) |
| 94 | + attributes = Clusters.MicrowaveOvenControl.Attributes |
| 95 | + |
| 96 | + self.step(2) |
| 97 | + await self.set_cook_time_expect_success(endpoint, 60) |
| 98 | + |
| 99 | + self.step(3) |
| 100 | + await self.send_add_more_time_command_expect_response(endpoint, 30) |
| 101 | + |
| 102 | + self.step(4) |
| 103 | + await self.read_and_check_cook_time_value(endpoint, 90) |
| 104 | + |
| 105 | + self.step(5) |
| 106 | + maxCookTime = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.MaxCookTime) |
| 107 | + |
| 108 | + self.step(6) |
| 109 | + await self.send_add_more_time_command_expect_response(endpoint, maxCookTime+1, Status.ConstraintError) |
| 110 | + |
| 111 | + if self.check_pics("MWOCTRL.S.M.ManualInvalidAddTime"): |
| 112 | + self.step(7) |
| 113 | + input("Press Enter when done.\n") |
| 114 | + |
| 115 | + self.step(8) |
| 116 | + await self.send_add_more_time_command_expect_response(endpoint, 30, Status.InvalidInState) |
| 117 | + else: |
| 118 | + self.skip_step(7) |
| 119 | + self.skip_step(8) |
| 120 | + |
| 121 | + |
| 122 | +if __name__ == "__main__": |
| 123 | + default_matter_test_main() |
0 commit comments