def __init__(self, rendezvousAddr=None):
        self.lastNetworkId = None

        Cmd.__init__(self)

        Cmd.identchars = string.ascii_letters + string.digits + "-"

        if sys.stdin.isatty():
            self.prompt = "chip-device-ctrl > "
        else:
            self.use_rawinput = 0
            self.prompt = ""

        DeviceMgrCmd.command_names.sort()

        self.bleMgr = None

        self.devCtrl = ChipDeviceCtrl.ChipDeviceController()

        self.historyFileName = os.path.expanduser(
            "~/.chip-device-ctrl-history")

        try:
            import readline

            if "libedit" in readline.__doc__:
                readline.parse_and_bind("bind ^I rl_complete")
            readline.set_completer_delims(" ")
            try:
                readline.read_history_file(self.historyFileName)
            except IOError:
                pass
        except ImportError:
            pass
Пример #2
0
    def __init__(self,
                 rendezvousAddr=None,
                 controllerNodeId=0,
                 bluetoothAdapter=None):
        self.lastNetworkId = None

        Cmd.__init__(self)

        Cmd.identchars = string.ascii_letters + string.digits + "-"

        if sys.stdin.isatty():
            self.prompt = "chip-device-ctrl > "
        else:
            self.use_rawinput = 0
            self.prompt = ""

        DeviceMgrCmd.command_names.sort()

        self.bleMgr = None

        self.devCtrl = ChipDeviceCtrl.ChipDeviceController(
            controllerNodeId=controllerNodeId,
            bluetoothAdapter=bluetoothAdapter)

        self.commissionableNodeCtrl = ChipCommissionableNodeCtrl.ChipCommissionableNodeController(
        )

        # If we are on Linux and user selects non-default bluetooth adapter.
        if sys.platform.startswith("linux") and (bluetoothAdapter is not None):
            try:
                self.bleMgr = BleManager(self.devCtrl)
                self.bleMgr.ble_adapter_select(
                    "hci{}".format(bluetoothAdapter))
            except Exception as ex:
                traceback.print_exc()
                print(
                    "Failed to initialize BLE, if you don't have BLE, run chip-device-ctrl with --no-ble"
                )
                raise ex

        self.historyFileName = os.path.expanduser(
            "~/.chip-device-ctrl-history")

        try:
            import readline

            if "libedit" in readline.__doc__:
                readline.parse_and_bind("bind ^I rl_complete")
            readline.set_completer_delims(" ")
            try:
                readline.read_history_file(self.historyFileName)
            except IOError:
                pass
        except ImportError:
            pass
Пример #3
0
    def NewController(self,
                      nodeId: int = None,
                      paaTrustStorePath: str = "",
                      useTestCommissioner: bool = False,
                      catTags: List[int] = []):
        ''' Create a new chip.ChipDeviceCtrl.ChipDeviceController instance on this fabric.

            When vending ChipDeviceController instances on a given fabric, each controller instance
            is associated with a unique fabric index local to the running process. In the underlying FabricTable, each FabricInfo
            instance can be treated as unique identities that can collide on the same logical fabric.

            nodeId:                 NodeID to be assigned to the controller. Automatically allocates one starting from 112233 if one
                                    is not provided.

            paaTrustStorePath:      Path to the PAA trust store. If one isn't provided, a suitable default is selected.
            useTestCommissioner:    If a test commmisioner is to be created.
            catTags:			    A list of 32-bit CAT tags that will added to the NOC generated for this controller.
        '''
        if (not (self._isActive)):
            raise RuntimeError(
                f"FabricAdmin object was previously shutdown and is no longer valid!"
            )

        nodeIdList = [
            controller.nodeId for controller in self._activeControllers
            if controller.isActive
        ]
        if (nodeId is None):
            if (len(nodeIdList) != 0):
                nodeId = max(nodeIdList) + 1
            else:
                nodeId = 112233
        else:
            if (nodeId in nodeIdList):
                raise RuntimeError(
                    f"Provided NodeId {nodeId} collides with an existing controller instance!"
                )

        self.logger().warning(
            f"Allocating new controller with CaIndex: {self._certificateAuthority.caIndex}, FabricId: 0x{self._fabricId:016X}, NodeId: 0x{nodeId:016X}, CatTags: {catTags}"
        )

        controller = ChipDeviceCtrl.ChipDeviceController(
            opCredsContext=self._certificateAuthority.GetOpCredsContext(),
            fabricId=self._fabricId,
            nodeId=nodeId,
            adminVendorId=self._vendorId,
            paaTrustStorePath=paaTrustStorePath,
            useTestCommissioner=useTestCommissioner,
            fabricAdmin=self,
            catTags=catTags)

        self._activeControllers.append(controller)
        return controller
Пример #4
0
def test_lock_ctrl(device, network):
    network_ssid = network[0]
    network_pass = network[1]

    devCtrl = ChipDeviceCtrl.ChipDeviceController()

    device_details = get_device_details(device)
    assert device_details != None and len(device_details) != 0

    assert check_chip_ble_devices_advertising(devCtrl, BLE_DEVICE_NAME,
                                              device_details)

    ret = connect_device_over_ble(devCtrl,
                                  int(device_details["Discriminator"]),
                                  int(device_details["SetUpPINCode"]),
                                  DEVICE_NODE_ID)
    assert ret != None and ret == DEVICE_NODE_ID

    ret = device.wait_for_output("Device completed Rendezvous process")
    assert ret != None and len(ret) > 0

    ret = commissioning_wifi(devCtrl, network_ssid, network_pass,
                             DEVICE_NODE_ID)
    assert ret == 0

    ret = resolve_device(devCtrl, DEVICE_NODE_ID)
    assert ret != None and len(ret) == 2

    err, res = send_zcl_command(devCtrl,
                                "OnOff Off {} 1 0".format(DEVICE_NODE_ID))
    assert err == 0

    ret = device.wait_for_output("Unlock Action has been completed", 20)
    assert ret != None and len(ret) > 0

    err, res = send_zcl_command(devCtrl,
                                "OnOff On {} 1 0".format(DEVICE_NODE_ID))
    assert err == 0

    ret = device.wait_for_output("Lock Action has been completed", 20)
    assert ret != None and len(ret) > 0

    err, res = send_zcl_command(devCtrl,
                                "OnOff Toggle {} 1 0".format(DEVICE_NODE_ID))
    assert err == 0

    ret = device.wait_for_output("Unlock Action has been completed", 20)
    assert ret != None and len(ret) > 0

    assert close_connection(devCtrl, DEVICE_NODE_ID)
    assert close_ble(devCtrl)
Пример #5
0
def test_wifi_provisioning(device, network):
    network_ssid = network[0]
    network_pass = network[1]

    devCtrl = ChipDeviceCtrl.ChipDeviceController()

    device_details = get_device_details(device)
    assert device_details != None and len(device_details) != 0

    assert check_chip_ble_devices_advertising(devCtrl, BLE_DEVICE_NAME,
                                              device_details)

    ret = connect_device_over_ble(devCtrl,
                                  int(device_details["Discriminator"]),
                                  int(device_details["SetUpPINCode"]),
                                  DEVICE_NODE_ID)
    assert ret != None and ret == DEVICE_NODE_ID

    ret = device.wait_for_output("Device completed Rendezvous process")
    assert ret != None and len(ret) > 0

    ret = commissioning_wifi(devCtrl, network_ssid, network_pass,
                             DEVICE_NODE_ID)
    assert ret == 0

    ret = device.wait_for_output("StationConnected")
    assert ret != None and len(ret) > 0

    ret = device.wait_for_output("address set")
    assert ret != None and len(ret) > 0

    device_ip_address = ret[-1].partition("address set:")[2].strip()

    ret = resolve_device(devCtrl, DEVICE_NODE_ID)
    assert ret != None and len(ret) == 2

    ip_address = ret[0]
    port = ret[1]

    assert device_ip_address == ip_address

    assert close_connection(devCtrl, DEVICE_NODE_ID)
    assert close_ble(devCtrl)
Пример #6
0
    def NewController(self,
                      nodeId: int = None,
                      useTestCommissioner: bool = False):
        ''' Vend a new controller on this fabric seeded with the right fabric details.
        '''
        if (not (self._isActive)):
            raise RuntimeError(
                f"FabricAdmin object was previously shutdown and is no longer valid!"
            )

        if (nodeId is None):
            nodeId = self.nextControllerId
            self.nextControllerId = self.nextControllerId + 1

        print(
            f"Allocating new controller with FabricId: {self._fabricId}({self._fabricIndex}), NodeId: {nodeId}"
        )
        controller = ChipDeviceCtrl.ChipDeviceController(
            self.closure, self._fabricId, self._fabricIndex, nodeId,
            useTestCommissioner)
        return controller
Пример #7
0
def test_ble_adv_check(device):
    devCtrl = ChipDeviceCtrl.ChipDeviceController()

    ret = device.send(command="ble adv start", expected_output="Done")
    assert ret != None and len(ret) > 0
    ret = device.send(command="ble adv state", expected_output="Done")
    assert ret != None and len(ret) > 1
    assert "enabled" in ret[-2].split()[-1]

    sleep(1)

    assert check_chip_ble_devices_advertising(devCtrl, BLE_DEVICE_NAME)

    ret = device.send(command="ble adv stop", expected_output="Done")
    assert ret != None and len(ret) > 0
    ret = device.send(command="ble adv state", expected_output="Done")
    assert ret != None and len(ret) > 1
    assert "disabled" in ret[-2].split()[-1]

    sleep(1)

    assert not check_chip_ble_devices_advertising(devCtrl, BLE_DEVICE_NAME)
Пример #8
0
 def __init__(self, nodeid: int):
     self.devCtrl = ChipDeviceCtrl.ChipDeviceController(
         controllerNodeId=nodeid)
     self.logger = logger
     self.commissionableNodeCtrl = ChipCommissionableNodeCtrl.ChipCommissionableNodeController(
     )
Пример #9
0
def test_light_ctrl(device, network):
    network_ssid = network[0]
    network_pass = network[1]

    devCtrl = ChipDeviceCtrl.ChipDeviceController()

    device_details = get_device_details(device)
    assert device_details != None and len(device_details) != 0

    assert check_chip_ble_devices_advertising(devCtrl, BLE_DEVICE_NAME,
                                              device_details)

    ret = connect_device_over_ble(devCtrl,
                                  int(device_details["Discriminator"]),
                                  int(device_details["SetUpPINCode"]),
                                  DEVICE_NODE_ID)
    assert ret != None and ret == DEVICE_NODE_ID

    ret = device.wait_for_output("Device completed Rendezvous process")
    assert ret != None and len(ret) > 0

    ret = commissioning_wifi(devCtrl, network_ssid, network_pass,
                             DEVICE_NODE_ID)
    assert ret == 0

    ret = resolve_device(devCtrl, DEVICE_NODE_ID)
    assert ret != None and len(ret) == 2

    err, res = send_zcl_command(devCtrl,
                                "OnOff On {} 1 0".format(DEVICE_NODE_ID))
    assert err == 0

    ret = device.wait_for_output("Turn On Action has been completed", 20)
    assert ret != None and len(ret) > 0

    err, res = send_zcl_command(devCtrl,
                                "OnOff Off {} 1 0".format(DEVICE_NODE_ID))
    assert err == 0

    ret = device.wait_for_output("Turn Off Action has been completed", 20)
    assert ret != None and len(ret) > 0

    err, res = send_zcl_command(devCtrl,
                                "OnOff Toggle {} 1 0".format(DEVICE_NODE_ID))
    assert err == 0

    ret = device.wait_for_output("Turn On Action has been completed", 20)
    assert ret != None and len(ret) > 0

    err, res = send_zcl_command(
        devCtrl,
        "LevelControl MoveToLevel {} 1 0 level={} transitionTime=1 optionMask=0 optionOverride=0"
        .format(DEVICE_NODE_ID, TEST_BRIGHTNESS_LEVEL))
    assert err == 0

    ret = device.wait_for_output(
        "Setting brightness level to {}".format(TEST_BRIGHTNESS_LEVEL), 20)
    assert ret != None and len(ret) > 0

    assert close_connection(devCtrl, DEVICE_NODE_ID)
    assert close_ble(devCtrl)
 def __init__(self, nodeid: int):
     self.devCtrl = ChipDeviceCtrl.ChipDeviceController(
         controllerNodeId=nodeid)
     self.logger = logger
Пример #11
0
 def deviceController(self):
     if self._deviceController is None:
         self._deviceController = ChipDeviceCtrl.ChipDeviceController()
     return self._deviceController