|
| 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 | + |
| 23 | +# This test requires several additional command line arguments |
| 24 | +# run with |
| 25 | +# --endpoint endpoint |
| 26 | + |
| 27 | + |
| 28 | +class TC_MWOCTRL_2_1(MatterBaseTest): |
| 29 | + |
| 30 | + async def read_mwoctrl_attribute_expect_success(self, endpoint, attribute): |
| 31 | + cluster = Clusters.Objects.MicrowaveOvenControl |
| 32 | + return await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attribute) |
| 33 | + |
| 34 | + async def set_cook_time_expect_success(self, endpoint, value): |
| 35 | + commands = Clusters.Objects.MicrowaveOvenControl.Commands |
| 36 | + try: |
| 37 | + await self.send_single_cmd(cmd=commands.SetCookingParameters(cookTime=value), endpoint=endpoint) |
| 38 | + except InteractionModelError as e: |
| 39 | + asserts.assert_equal(e.status, Status.Success, "Unexpected error returned") |
| 40 | + |
| 41 | + async def set_bad_cook_time_value_expect_failure(self, endpoint, value): |
| 42 | + commands = Clusters.Objects.MicrowaveOvenControl.Commands |
| 43 | + try: |
| 44 | + await self.send_single_cmd(cmd=commands.SetCookingParameters(cookTime=value), endpoint=endpoint) |
| 45 | + asserts.assert_fail("Expected an exception but received none.") |
| 46 | + except InteractionModelError as e: |
| 47 | + asserts.assert_equal(e.status, Status.ConstraintError, "Expected a CONSTRAINT_ERROR but got a different response.") |
| 48 | + |
| 49 | + async def read_and_check_cook_time_value(self, endpoint, value): |
| 50 | + attributes = Clusters.MicrowaveOvenControl.Attributes |
| 51 | + cooktime = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.CookTime) |
| 52 | + asserts.assert_equal(cooktime, value, "Cooktime value not as expected") |
| 53 | + |
| 54 | + def desc_TC_MWOCTRL_2_1(self) -> str: |
| 55 | + return "[TC-MWOCTRL-2.1] Primary functionality with DUT as Server" |
| 56 | + |
| 57 | + def steps_TC_MWOCTRL_2_1(self) -> list[TestStep]: |
| 58 | + steps = [ |
| 59 | + TestStep(1, "Commissioning, already done", is_commissioning=True), |
| 60 | + TestStep(2, "Read the MaxCookTime attribute and check limits", |
| 61 | + "Verify that the DUT response contains an elapsed-s value between 1 and 86400 inclusive. Save value as MaxCookTime." |
| 62 | + ), |
| 63 | + TestStep(3, "Read the CookTime attribute and check limits", |
| 64 | + "Verify that the DUT response contains an elapsed-s value between 1 and MaxCookTime inclusive." |
| 65 | + ), |
| 66 | + TestStep(4, "Set the CookTime attribute to 60", "Verify DUT responds w/ status SUCCESS(0x00)."), |
| 67 | + TestStep(5, "Read the CookTime attribute and check for 60", |
| 68 | + "Verify that the DUT response contains the CookTime value 60."), |
| 69 | + TestStep(6, "Set the CookTime attribute to 1", "Verify DUT responds w/ status SUCCESS(0x00)"), |
| 70 | + TestStep(7, "Read the CookTime attribute and check for 1", |
| 71 | + "Verify that the DUT response contains the CookTime value 1."), |
| 72 | + TestStep(8, "Set the CookTime attribute to MaxCookTime", "Verify DUT responds w/ status SUCCESS(0x00)"), |
| 73 | + TestStep(9, "Read the CookTime attribute and check for MaxCookTime", |
| 74 | + "Verify that the DUT response contains the CookTime value MaxCookTime."), |
| 75 | + TestStep(10, "Read the WattRating attribute, if supported", "Verify that the DUT response contains a uint16 value."), |
| 76 | + TestStep(11, "Set the CookTime attribute to 0", "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), |
| 77 | + TestStep(12, "Set the CookTime attribute to MaxCookTime+1", "Verify DUT responds w/ status CONSTRAINT_ERROR(0x87)"), |
| 78 | + ] |
| 79 | + return steps |
| 80 | + |
| 81 | + def pics_TC_MWOCTRL_2_1(self) -> list[str]: |
| 82 | + pics = [ |
| 83 | + "MWOCTRL.S", |
| 84 | + ] |
| 85 | + return pics |
| 86 | + |
| 87 | + @async_test_body |
| 88 | + async def test_TC_MWOCTRL_2_1(self): |
| 89 | + |
| 90 | + endpoint = self.user_params.get("endpoint", 1) |
| 91 | + |
| 92 | + self.step(1) |
| 93 | + attributes = Clusters.MicrowaveOvenControl.Attributes |
| 94 | + |
| 95 | + self.step(2) |
| 96 | + maxCookTime = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.MaxCookTime) |
| 97 | + asserts.assert_greater_equal(maxCookTime, 1, "maxCookTime is less than 1") |
| 98 | + asserts.assert_less_equal(maxCookTime, 86400, "maxCookTime is greater than 86400") |
| 99 | + |
| 100 | + self.step(3) |
| 101 | + cookTime = await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.CookTime) |
| 102 | + asserts.assert_greater_equal(cookTime, 1, "cookTime is less than 1") |
| 103 | + asserts.assert_less_equal(cookTime, maxCookTime, "cookTime is greater than maxCookTime") |
| 104 | + |
| 105 | + self.step(4) |
| 106 | + newCookTime = 60 |
| 107 | + await self.set_cook_time_expect_success(endpoint, newCookTime) |
| 108 | + |
| 109 | + self.step(5) |
| 110 | + await self.read_and_check_cook_time_value(endpoint, newCookTime) |
| 111 | + |
| 112 | + self.step(6) |
| 113 | + await self.set_cook_time_expect_success(endpoint, 1) |
| 114 | + |
| 115 | + self.step(7) |
| 116 | + await self.read_and_check_cook_time_value(endpoint, 1) |
| 117 | + |
| 118 | + self.step(8) |
| 119 | + await self.set_cook_time_expect_success(endpoint, maxCookTime) |
| 120 | + |
| 121 | + self.step(9) |
| 122 | + await self.read_and_check_cook_time_value(endpoint, maxCookTime) |
| 123 | + |
| 124 | + self.step(10) |
| 125 | + if self.pics_guard(self.check_pics("MWOCTRL.S.F01")): |
| 126 | + await self.read_mwoctrl_attribute_expect_success(endpoint=endpoint, attribute=attributes.WattRating) |
| 127 | + |
| 128 | + self.step(11) |
| 129 | + await self.set_bad_cook_time_value_expect_failure(endpoint, 0) |
| 130 | + |
| 131 | + self.step(12) |
| 132 | + await self.set_bad_cook_time_value_expect_failure(endpoint, maxCookTime+1) |
| 133 | + |
| 134 | + |
| 135 | +if __name__ == "__main__": |
| 136 | + default_matter_test_main() |
0 commit comments