3 Copyright (c) 2020 Project CHIP Authors
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
9 http://www.apache.org/licenses/LICENSE-2.0
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.
23 from helper.CHIPTestBase import CHIPVirtualHome
25 logger = logging.getLogger('CHIPOnOffTest')
26 logger.setLevel(logging.INFO)
28 sh = logging.StreamHandler()
31 '%(asctime)s [%(name)s] %(levelname)s %(message)s'))
36 'type': 'CHIP-Server',
37 'base_image': 'chip_server',
38 'capability': ['Thread', 'Interactive'],
43 'base_image': 'chip_tool',
44 'capability': ['Thread', 'Interactive'],
49 SETUPPINCODE = 12345678
50 DISCRIMINATOR = 1 # Randomw number, not used
53 CIRQUE_URL = "http://localhost:5000"
56 class TestOnOffCluster(CHIPVirtualHome):
57 def __init__(self, device_config):
58 super().__init__(CIRQUE_URL, device_config)
62 self.initialize_home()
63 self.connect_to_thread_network()
65 def test_routine(self):
66 self.run_data_model_test()
68 def run_data_model_test(self):
69 server_ip_address = set()
72 server_ids = [device['id'] for device in self.non_ap_devices
73 if device['type'] == 'CHIP-Server']
74 tool_ids = [device['id'] for device in self.non_ap_devices
75 if device['type'] == 'CHIP-Tool']
77 tool_device_id = tool_ids[0]
79 for device_id in server_ids:
80 server_ip_address.add(self.get_device_thread_ip(device_id))
82 command = "chip-tool onoff {} 1"
84 for ip in server_ip_address:
85 ret = self.execute_device_cmd(
86 tool_device_id, "chip-tool pairing softap {} {} {} {}".format(SETUPPINCODE, DISCRIMINATOR, ip, CHIP_PORT))
87 self.assertEqual(ret['return_code'], '0', "{} command failure: {}".format(
88 "pairing softap", ret['output']))
90 ret = self.execute_device_cmd(tool_device_id, command.format("on"))
92 ret['return_code'], '0', "{} command failure: {}".format("on", ret['output']))
94 ret = self.execute_device_cmd(
95 tool_device_id, command.format("off"))
97 ret['return_code'], '0', "{} command failure: {}".format("off", ret['output']))
99 ret = self.execute_device_cmd(
100 tool_device_id, "chip-tool pairing unpair")
101 self.assertEqual(ret['return_code'], '0', "{} command failure: {}".format(
102 "pairing unpair", ret['output']))
106 for device_id in server_ids:
107 self.logger.info("checking device log for {}".format(
108 self.get_device_pretty_id(device_id)))
109 self.assertTrue(self.sequenceMatch(self.get_device_log(device_id).decode('utf-8'), ["Thread initialized.", "LightingManager::InitiateAction(ON_ACTION)", "LightingManager::InitiateAction(OFF_ACTION)"]),
110 "Datamodel test failed: cannot find matching string from device {}".format(device_id))
113 if __name__ == "__main__":
114 sys.exit(TestOnOffCluster(DEVICE_CONFIG).run_test())