pytest_esp_zigbee.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
  2. # SPDX-License-Identifier: Apache-2.0
  3. # !/usr/bin/env python3
  4. import pathlib
  5. import time
  6. from typing import Tuple
  7. import pytest
  8. from pytest_embedded import Dut
  9. CURRENT_DIR_LIGHT = str(pathlib.Path(__file__).parent / 'HA_on_off_light')
  10. CURRENT_DIR_SWITCH = str(pathlib.Path(__file__).parent / 'HA_on_off_switch')
  11. pytest_build_dir = CURRENT_DIR_LIGHT + '|' + CURRENT_DIR_SWITCH
  12. @pytest.mark.esp32h2
  13. @pytest.mark.zigbee_multi_dut
  14. @pytest.mark.parametrize(
  15. ' count, app_path, erase_all', [
  16. (2, pytest_build_dir, 'y'),
  17. ],
  18. indirect=True,
  19. )
  20. # config Zigbee network
  21. def test_config_zigbee_network(dut:Tuple[Dut, Dut]) -> None:
  22. light = dut[0]
  23. switch = dut[1]
  24. time.sleep(3)
  25. switch.expect('ESP_ZB_ON_OFF_SWITCH: Formed network successfully',timeout=30)
  26. # get the switch extpanid
  27. switch_node_expanid = switch.expect(r'Extended PAN ID: (([a-z0-9]{2}:?){8})',timeout=3)[1].decode()
  28. switch_node_expanid = switch_node_expanid.replace(':','')
  29. # get the switch panid
  30. switch_node_panid = switch.expect(r'PAN ID: 0x([a-z0-9]+:?)',timeout=2)[1].decode()
  31. # new device commissioned successfully
  32. switch.expect(r'New device commissioned or rejoined \(short: 0x([a-z0-9]+)[^a-z0-9]',timeout=30)[1].decode()
  33. # get the light node extpanid
  34. light.expect('ESP_ZB_ON_OFF_LIGHT: Joined network successfully',timeout=20)
  35. light_node_expanid = light.expect(r'Extended PAN ID: (([a-z0-9]{2}:?){8})',timeout=3)[1].decode()
  36. light_node_expanid = light_node_expanid.replace(':','')
  37. # get the light panid
  38. light_node_panid = light.expect(r'PAN ID: 0x([a-z0-9]+:?)',timeout=2)[1].decode()
  39. # make sure the light node join the network that switch node formed (same expanid)
  40. if ((light_node_expanid != switch_node_expanid) or (light_node_panid != switch_node_panid)):
  41. assert False