|
| 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 | +# See https://github.com/project-chip/connectedhomeip/blob/master/docs/testing/python.md#defining-the-ci-test-arguments |
| 19 | +# for details about the block below. |
| 20 | +# |
| 21 | +# === BEGIN CI TEST ARGUMENTS === |
| 22 | +# test-runner-runs: |
| 23 | +# run1: |
| 24 | +# app: ${ALL_CLUSTERS_APP} |
| 25 | +# app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json |
| 26 | +# script-args: > |
| 27 | +# --storage-path admin_storage.json |
| 28 | +# --commissioning-method on-network |
| 29 | +# --discriminator 1234 |
| 30 | +# --passcode 20202021 |
| 31 | +# --endpoint 1 |
| 32 | +# --PICS src/app/tests/suites/certification/ci-pics-values |
| 33 | +# --trace-to json:${TRACE_TEST_JSON}.json |
| 34 | +# --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto |
| 35 | +# factory-reset: true |
| 36 | +# quiet: true |
| 37 | +# === END CI TEST ARGUMENTS === |
| 38 | + |
| 39 | +import logging |
| 40 | + |
| 41 | +import chip.clusters as Clusters |
| 42 | +from chip.interaction_model import Status |
| 43 | +from chip.testing.matter_testing import MatterBaseTest, TestStep, default_matter_test_main, has_feature, run_if_endpoint_matches |
| 44 | +from mobly import asserts |
| 45 | + |
| 46 | +logger = logging.getLogger(__name__) |
| 47 | + |
| 48 | + |
| 49 | +MAX_SPIN_SPEEDS = 16 |
| 50 | + |
| 51 | + |
| 52 | +class TC_WASHERCTRL_2_1(MatterBaseTest): |
| 53 | + |
| 54 | + def desc_TC_WASHERCTRL_2_1(self) -> str: |
| 55 | + """Returns a description of this test""" |
| 56 | + return "[TC-WASHERCTRL-2.1] Optional Spin attributes with DUT as Server" |
| 57 | + |
| 58 | + def pics_TC_WASHERCTRL_2_1(self) -> list[str]: |
| 59 | + pics = [ |
| 60 | + "WASHERCTRL.S.F00", |
| 61 | + "WASHERCTRL.S.A0000", |
| 62 | + "WASHERCTRL.S.A0001" |
| 63 | + ] |
| 64 | + return pics |
| 65 | + |
| 66 | + def steps_TC_WASHERCTRL_2_1(self) -> list[TestStep]: |
| 67 | + steps = [ |
| 68 | + TestStep(1, "Commissioning, already done", |
| 69 | + is_commissioning=True), |
| 70 | + TestStep(2, description="TH reads from the DUT the SpinSpeeds attribute", |
| 71 | + expectation="Verify that the DUT response contains a list of strings. The maximum size of the list is 16."), |
| 72 | + TestStep(3, description="TH reads from the DUT the SpinSpeedCurrent attribute", |
| 73 | + expectation="Verify that the DUT response contains a uint8 with value between 0 and numSpinSpeeds-1 inclusive."), |
| 74 | + TestStep(4, description="TH writes a supported SpinSpeedCurrent attribute that is a valid index into the list" |
| 75 | + + "of spin speeds (0 to numSpinSpeeds - 1) and then read the SpinSpeedCurrent value", |
| 76 | + expectation="Verify DUT responds w/ status SUCCESS(0x00) and the SpinSpeedCurrent value was set accordingly"), |
| 77 | + TestStep(5, description="TH writes an unsupported SpinSpeedCurrent attribute that is other than 0 to DUT", |
| 78 | + expectation="Verify that the DUT response contains Status CONSTRAINT_ERROR response") |
| 79 | + ] |
| 80 | + |
| 81 | + return steps |
| 82 | + |
| 83 | + @run_if_endpoint_matches(has_feature(Clusters.LaundryWasherControls, |
| 84 | + Clusters.LaundryWasherControls.Bitmaps.Feature.kSpin)) |
| 85 | + async def test_TC_WASHERCTRL_2_1(self): |
| 86 | + |
| 87 | + endpoint = self.get_endpoint(default=1) |
| 88 | + |
| 89 | + self.step(1) |
| 90 | + |
| 91 | + # Read the SpinSpeeds attributes |
| 92 | + self.step(2) |
| 93 | + list_speed_speeds = await self.read_single_attribute_check_success(endpoint=endpoint, |
| 94 | + cluster=Clusters.Objects.LaundryWasherControls, |
| 95 | + attribute=Clusters.LaundryWasherControls.Attributes.SpinSpeeds) |
| 96 | + |
| 97 | + asserts.assert_true(isinstance(list_speed_speeds, list), "Returned value was not a list") |
| 98 | + numSpinSpeeds = len(list_speed_speeds) |
| 99 | + asserts.assert_less_equal(numSpinSpeeds, MAX_SPIN_SPEEDS, "List of SpinSpeeds larger than maximum allowed") |
| 100 | + |
| 101 | + # Read the SpinSpeedCurrent attribute |
| 102 | + self.step(3) |
| 103 | + spin_speed_current = await self.read_single_attribute_check_success(endpoint=endpoint, |
| 104 | + cluster=Clusters.Objects.LaundryWasherControls, |
| 105 | + attribute=Clusters.LaundryWasherControls.Attributes.SpinSpeedCurrent) |
| 106 | + asserts.assert_true(isinstance(spin_speed_current, int), "SpinSpeedCurrent has an invalid value") |
| 107 | + asserts.assert_true(0 <= spin_speed_current <= (numSpinSpeeds - 1), "SpinSpeedCurrent outside valid range") |
| 108 | + |
| 109 | + self.step(4) |
| 110 | + for requested_speed in range(0, numSpinSpeeds): |
| 111 | + # Write a valid SpinSpeedCurrent value |
| 112 | + result = await self.write_single_attribute(attribute_value=Clusters.LaundryWasherControls.Attributes.SpinSpeedCurrent(requested_speed), |
| 113 | + endpoint_id=endpoint) |
| 114 | + asserts.assert_equal(result, Status.Success, "Error when trying to write a valid SpinSpeed value") |
| 115 | + |
| 116 | + # Read SpinSpeedCurrent value and verify that was changed. |
| 117 | + current_value = await self.read_single_attribute_check_success(endpoint=endpoint, |
| 118 | + cluster=Clusters.Objects.LaundryWasherControls, |
| 119 | + attribute=Clusters.LaundryWasherControls.Attributes.SpinSpeedCurrent) |
| 120 | + asserts.assert_equal(current_value, requested_speed, "Value obtained different than the previously written one") |
| 121 | + |
| 122 | + # Try to write an invalid value (outside supported range) |
| 123 | + self.step(5) |
| 124 | + result = await self.write_single_attribute(attribute_value=Clusters.LaundryWasherControls.Attributes.SpinSpeedCurrent(numSpinSpeeds), |
| 125 | + endpoint_id=endpoint, expect_success=False) |
| 126 | + asserts.assert_equal(result, Status.ConstraintError, "Trying to write an invalid value should return ConstraintError") |
| 127 | + |
| 128 | + |
| 129 | +if __name__ == "__main__": |
| 130 | + default_matter_test_main() |
0 commit comments