def register(self, payload=None, callback=None):
        """
        Register to the device provisioning service.
        :param payload: Payload that can be sent with the registration request.
        :param callback: callback which is called when the registration is done.

        The following exceptions are not "raised", but rather returned via the "error" parameter
        when invoking "callback":

        :raises: :class:`azure.iot.device.provisioning.pipeline.exceptions.ConnectionFailedError`
        :raises: :class:`azure.iot.device.provisioning.pipeline.exceptions.ConnectionDroppedError`
        :raises: :class:`azure.iot.device.provisioning.pipeline.exceptions.UnauthorizedError`
        :raises: :class:`azure.iot.device.provisioning.pipeline.exceptions.ProtocolClientError`
        """
        def on_complete(op, error):
            # TODO : Apparently when its failed we can get result as well as error.
            if error:
                callback(error=error, result=None)
            else:
                callback(result=op.registration_result)

        self._pipeline.run_op(
            pipeline_ops_provisioning.RegisterOperation(
                request_payload=payload,
                registration_id=self._registration_id,
                callback=on_complete))
    def op(self, stage, mocker):
        op = pipeline_ops_provisioning.RegisterOperation(
            " ", fake_registration_id, callback=mocker.MagicMock())
        yield op

        # Clean up any timers set on it
        if op.provisioning_timeout_timer:
            op.provisioning_timeout_timer.cancel()
        if op.retry_after_timer:
            op.retry_after_timer.cancel()
        if op.provisioning_timeout_timer:
            op.provisioning_timeout_timer.cancel()
    def send_registration_op(self, mocker, request_payload):
        op = pipeline_ops_provisioning.RegisterOperation(
            request_payload, fake_registration_id, callback=mocker.MagicMock())
        yield op

        # Clean up any timers set on it
        if op.provisioning_timeout_timer:
            op.provisioning_timeout_timer.cancel()
        if op.retry_after_timer:
            op.retry_after_timer.cancel()
        if op.provisioning_timeout_timer:
            op.provisioning_timeout_timer.cancel()
Exemple #4
0
    def register(self, payload=None, callback=None):
        """
        Register to the device provisioning service.
        :param payload: Payload that can be sent with the registration request.
        :param callback: callback which is called when the registration is done.

        :raises: :class:`azure.iot.device.provisioning.pipeline.exceptions.PipelineNotRunning` if the
            pipeline has already been shut down

        The following exceptions are not "raised", but rather returned via the "error" parameter
        when invoking "callback":

        :raises: :class:`azure.iot.device.iothub.pipeline.exceptions.NoConnectionError`
        :raises: :class:`azure.iot.device.provisioning.pipeline.exceptions.ProtocolClientError

        The following exceptions can be returned via the "error" parameter only if auto-connect
        is enabled in the pipeline configuration:

        :raises: :class:`azure.iot.device.provisioning.pipeline.exceptions.ConnectionFailedError`
        :raises: :class:`azure.iot.device.provisioning.pipeline.exceptions.ConnectionDroppedError`
        :raises: :class:`azure.iot.device.provisioning.pipeline.exceptions.UnauthorizedError``
        :raises: :class:`azure.iot.device.iothub.pipeline.exceptions.OperationTimeout`
        """
        self._verify_running()

        def on_complete(op, error):
            # TODO : Apparently when its failed we can get result as well as error.
            if error:
                callback(error=error, result=None)
            else:
                callback(result=op.registration_result)

        self._pipeline.run_op(
            pipeline_ops_provisioning.RegisterOperation(
                request_payload=payload,
                registration_id=self._registration_id,
                callback=on_complete))
 def op(self, stage, mocker):
     op = pipeline_ops_provisioning.RegisterOperation(
         " ", fake_registration_id, callback=mocker.MagicMock())
     return op
 def op(self, stage, mocker, request_payload):
     return pipeline_ops_provisioning.RegisterOperation(
         request_payload, fake_registration_id, callback=mocker.MagicMock())
 def send_registration_op(self, mocker, request_payload):
     op = pipeline_ops_provisioning.RegisterOperation(
         request_payload, fake_registration_id, callback=mocker.MagicMock())
     return op