|
| 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 | +import chip.clusters as Clusters |
| 18 | +from chip.clusters.Types import NullValue |
| 19 | +from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main |
| 20 | +from mobly import asserts |
| 21 | + |
| 22 | + |
| 23 | +class TC_TMP_2_1(MatterBaseTest): |
| 24 | + def desc_TC_TMP_2_1(self) -> str: |
| 25 | + return "[TC-TMP-2.1] Attributes with Server as DUT" |
| 26 | + |
| 27 | + def pics_TC_TMP_2_1(self): |
| 28 | + return ["TMP.S"] |
| 29 | + |
| 30 | + def steps_TC_TMP_2_1(self) -> list[TestStep]: |
| 31 | + return [ |
| 32 | + TestStep(1, "Commissioning, already done", is_commissioning=True), |
| 33 | + TestStep( |
| 34 | + 2, "Set default bounds `min_bound` = -27315, `max_bound` = 32767"), |
| 35 | + TestStep(3, "TH reads the MinMeasuredValue attribute from the DUT and saves as `min_measured_value`. If `min_measured_value` is not null, set `min_bound` to `min_measured_value`"), |
| 36 | + TestStep(4, "TH reads the MaxMeasuredValue attribute from the DUT and saves as `max_measured_value`. If `max_measured_value` is not null, set `max_bound` to `max_measured_value", |
| 37 | + "Verify that `max_measured_value` is either null or an int16 where min_bound < `max_measured_value` ≤ 32767."), |
| 38 | + TestStep(5, "If `min_measured_value` is not null, verify min measured value range", |
| 39 | + "Verify that -27315 ≤ `min_measured_value` < `max_bound`"), |
| 40 | + TestStep(6, "TH reads the MeasuredValue attribute from the DUT", |
| 41 | + "Verify that the DUT response contains either null or a int16 where `min_bound` ≤ MeasuredValue ≤ `max_bound`."), |
| 42 | + TestStep(7, "TH reads the Tolerance attribute from the DUT", |
| 43 | + "Verify that Tolerance is in the range of 0 to 2048"), |
| 44 | + ] |
| 45 | + |
| 46 | + @async_test_body |
| 47 | + async def test_TC_TMP_2_1(self): |
| 48 | + cluster = Clusters.TemperatureMeasurement |
| 49 | + attr = Clusters.TemperatureMeasurement.Attributes |
| 50 | + |
| 51 | + # Commission DUT - already done |
| 52 | + self.step(1) |
| 53 | + |
| 54 | + self.step(2) |
| 55 | + min_bound = -27315 |
| 56 | + max_bound = 32767 |
| 57 | + |
| 58 | + self.step(3) |
| 59 | + min_measured_value = await self.read_single_attribute_check_success(cluster=cluster, attribute=attr.MinMeasuredValue) |
| 60 | + if min_measured_value != NullValue: |
| 61 | + min_bound = min_measured_value |
| 62 | + |
| 63 | + self.step(4) |
| 64 | + max_measured_value = await self.read_single_attribute_check_success(cluster=cluster, attribute=attr.MaxMeasuredValue) |
| 65 | + if max_measured_value != NullValue: |
| 66 | + max_bound = max_measured_value |
| 67 | + asserts.assert_greater(max_measured_value, min_bound, |
| 68 | + "MaxMeasuredValue is not greater than the minimum bound") |
| 69 | + asserts.assert_less_equal( |
| 70 | + max_measured_value, 32767, "MaxMeasuredValue is not less than or equal to than 32767") |
| 71 | + |
| 72 | + self.step(5) |
| 73 | + if min_measured_value != NullValue: |
| 74 | + asserts.assert_greater_equal(min_measured_value, -27315, "MinMeasuredValue is out of range") |
| 75 | + asserts.assert_less(min_measured_value, max_bound, "MinMeasuredValue is out of range") |
| 76 | + else: |
| 77 | + self.mark_current_step_skipped() |
| 78 | + |
| 79 | + self.step(6) |
| 80 | + measured_value = await self.read_single_attribute_check_success(cluster=cluster, attribute=attr.MeasuredValue) |
| 81 | + if measured_value != NullValue: |
| 82 | + print(measured_value) |
| 83 | + print(min_bound) |
| 84 | + asserts.assert_greater_equal( |
| 85 | + measured_value, min_bound, "Measured value is less than min bound") |
| 86 | + asserts.assert_less_equal( |
| 87 | + measured_value, max_bound, "Measured value is greater than max bound") |
| 88 | + |
| 89 | + self.step(7) |
| 90 | + tolerance = await self.read_single_attribute_check_success(cluster=cluster, attribute=attr.Tolerance) |
| 91 | + asserts.assert_greater_equal(tolerance, 0, "Tolerance is less than 0") |
| 92 | + asserts.assert_less_equal( |
| 93 | + tolerance, 2048, "Tolerance is greater than 2048") |
| 94 | + |
| 95 | + |
| 96 | +if __name__ == "__main__": |
| 97 | + default_matter_test_main() |
0 commit comments