|
| 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 logging |
| 19 | +import time |
| 20 | + |
| 21 | +import chip.clusters as Clusters |
| 22 | +from chip.interaction_model import Status |
| 23 | +from matter_testing_support import MatterBaseTest, async_test_body, default_matter_test_main |
| 24 | +from mobly import asserts |
| 25 | + |
| 26 | +logger = logging.getLogger(__name__) |
| 27 | + |
| 28 | + |
| 29 | +class TC_FAN_3_1(MatterBaseTest): |
| 30 | + |
| 31 | + async def read_fc_attribute_expect_success(self, endpoint, attribute): |
| 32 | + cluster = Clusters.Objects.FanControl |
| 33 | + return await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attribute) |
| 34 | + |
| 35 | + async def read_fan_mode(self, endpoint): |
| 36 | + return await self.read_fc_attribute_expect_success(endpoint, Clusters.FanControl.Attributes.FanMode) |
| 37 | + |
| 38 | + async def read_percent_setting(self, endpoint): |
| 39 | + return await self.read_fc_attribute_expect_success(endpoint, Clusters.FanControl.Attributes.PercentSetting) |
| 40 | + |
| 41 | + async def read_percent_current(self, endpoint): |
| 42 | + return await self.read_fc_attribute_expect_success(endpoint, Clusters.FanControl.Attributes.PercentCurrent) |
| 43 | + |
| 44 | + async def write_fan_mode(self, endpoint, fan_mode) -> Status: |
| 45 | + result = await self.default_controller.WriteAttribute(self.dut_node_id, [(endpoint, Clusters.FanControl.Attributes.FanMode(fan_mode))]) |
| 46 | + return result[0].Status |
| 47 | + |
| 48 | + async def write_percent_setting(self, endpoint, percent_setting) -> Status: |
| 49 | + result = await self.default_controller.WriteAttribute(self.dut_node_id, [(endpoint, Clusters.FanControl.Attributes.PercentSetting(percent_setting))]) |
| 50 | + return result[0].Status |
| 51 | + |
| 52 | + def pics_TC_FAN_3_1(self) -> list[str]: |
| 53 | + return ["FAN.S"] |
| 54 | + |
| 55 | + @async_test_body |
| 56 | + async def test_TC_FAN_3_1(self): |
| 57 | + endpoint = self.user_params.get("endpoint", 1) |
| 58 | + |
| 59 | + self.print_step(1, "Commissioning, already done") |
| 60 | + |
| 61 | + self.print_step("2a", "Read from the DUT the FanMode attribute and store") |
| 62 | + existing_fan_mode = await self.read_fan_mode(endpoint=endpoint) |
| 63 | + |
| 64 | + self.print_step("2b", "Write High to FanMode") |
| 65 | + status = await self.write_fan_mode(endpoint=endpoint, fan_mode=Clusters.FanControl.Enums.FanModeEnum.kHigh) |
| 66 | + status_ok = (status == Status.Success) or (status == Status.InvalidInState) |
| 67 | + asserts.assert_true(status_ok, "FanMode write did not return a value of Success or InvalidInState") |
| 68 | + |
| 69 | + self.print_step("2c", "After a few seconds, read from the DUT the FanMode attribute") |
| 70 | + time.sleep(3) |
| 71 | + |
| 72 | + new_fan_mode = await self.read_fan_mode(endpoint=endpoint) |
| 73 | + |
| 74 | + if status == Status.Success: |
| 75 | + asserts.assert_equal(new_fan_mode, Clusters.FanControl.Enums.FanModeEnum.kHigh, "FanMode is not High") |
| 76 | + else: |
| 77 | + asserts.assert_equal(new_fan_mode, existing_fan_mode, "FanMode is not unchanged") |
| 78 | + |
| 79 | + self.print_step("3a", "Read from the DUT the PercentSetting attribute and store") |
| 80 | + existing_percent_setting = await self.read_percent_setting(endpoint=endpoint) |
| 81 | + |
| 82 | + self.print_step("3b", "Write Off to Fan Mode") |
| 83 | + status = await self.write_fan_mode(endpoint=endpoint, fan_mode=Clusters.FanControl.Enums.FanModeEnum.kOff) |
| 84 | + status_ok = (status == Status.Success) or (status == Status.InvalidInState) |
| 85 | + asserts.assert_true(status_ok, "FanMode write did not return a value of Success or InvalidInState") |
| 86 | + |
| 87 | + self.print_step("3c", "After a few seconds, read from the DUT the PercentSetting attribute") |
| 88 | + time.sleep(3) |
| 89 | + |
| 90 | + new_percent_setting = await self.read_percent_setting(endpoint=endpoint) |
| 91 | + |
| 92 | + if status == Status.Success: |
| 93 | + asserts.assert_equal(new_percent_setting, Clusters.FanControl.Enums.FanModeEnum.kOff, "PercentSetting is not Off") |
| 94 | + else: |
| 95 | + asserts.assert_equal(new_percent_setting, existing_percent_setting, "PercentSetting is not unchanged") |
| 96 | + |
| 97 | + self.print_step("3d", "Read from the DUT the PercentCurrent attribute") |
| 98 | + percent_current = await self.read_percent_current(endpoint=endpoint) |
| 99 | + |
| 100 | + if status == Status.Success: |
| 101 | + asserts.assert_equal(percent_current, 0, "PercentCurrent is not 0") |
| 102 | + else: |
| 103 | + asserts.assert_equal(percent_current, existing_percent_setting, "PercentCurrent is not unchanged") |
| 104 | + |
| 105 | + self.print_step("4a", "Read from the DUT the PercentSetting attribute and store") |
| 106 | + existing_percent_setting = await self.read_percent_setting(endpoint=endpoint) |
| 107 | + |
| 108 | + self.print_step("4b", "Write PercentSetting to 30") |
| 109 | + status = await self.write_percent_setting(endpoint=endpoint, percent_setting=30) |
| 110 | + status_ok = (status == Status.Success) or (status == Status.InvalidInState) |
| 111 | + asserts.assert_true(status_ok, "PercentSetting write did not return a value of Success or InvalidInState") |
| 112 | + |
| 113 | + self.print_step("4c", "After a few seconds, read from the DUT the PercentSetting attribute") |
| 114 | + time.sleep(3) |
| 115 | + |
| 116 | + new_percent_setting = await self.read_percent_setting(endpoint=endpoint) |
| 117 | + |
| 118 | + if status == Status.Success: |
| 119 | + asserts.assert_equal(new_percent_setting, 30, "PercentSetting is not 30") |
| 120 | + else: |
| 121 | + asserts.assert_equal(new_percent_setting, existing_percent_setting, "PercentSetting is not unchanged") |
| 122 | + |
| 123 | + self.print_step("4d", "Read from the DUT the PercentCurrent attribute") |
| 124 | + percent_current = await self.read_percent_current(endpoint=endpoint) |
| 125 | + |
| 126 | + if status == Status.Success: |
| 127 | + asserts.assert_equal(percent_current, 30, "PercentCurrent is not 30") |
| 128 | + else: |
| 129 | + asserts.assert_equal(percent_current, existing_percent_setting, "PercentCurrent is not unchanged") |
| 130 | + |
| 131 | + self.print_step("5a", "Read from the DUT the FanMode attribute and store") |
| 132 | + existing_fan_mode = await self.read_fan_mode(endpoint=endpoint) |
| 133 | + |
| 134 | + self.print_step("5b", "Write PercentSetting to 0") |
| 135 | + status = await self.write_percent_setting(endpoint=endpoint, percent_setting=0) |
| 136 | + status_ok = (status == Status.Success) or (status == Status.InvalidInState) |
| 137 | + asserts.assert_true(status_ok, "PercentSetting write did not return a value of Success or InvalidInState") |
| 138 | + |
| 139 | + self.print_step("5c", "After a few seconds, read from the DUT the FanMode attribute") |
| 140 | + time.sleep(3) |
| 141 | + |
| 142 | + new_fan_mode = await self.read_fan_mode(endpoint=endpoint) |
| 143 | + |
| 144 | + if status == Status.Success: |
| 145 | + asserts.assert_equal(new_fan_mode, Clusters.FanControl.Enums.FanModeEnum.kOff, "FanMode is not Off") |
| 146 | + else: |
| 147 | + asserts.assert_equal(new_fan_mode, existing_fan_mode, "FanMode is not unchanged") |
| 148 | + |
| 149 | + |
| 150 | +if __name__ == "__main__": |
| 151 | + default_matter_test_main() |
0 commit comments