def streamed_request(self, command, event_stream_type, message=None):
        """Send command request and collect and return all emitted events.

        :param command: command to send
        :type command: str
        :param event_stream_type: event type emitted on command execution
        :type event_stream_type: str
        :param message: message (optional)
        :type message: str
        :return: a pair of the command result and a list of emitted events
        :rtype: tuple
        """
        result = []

        if message is not None:
            message = Message.serialize(message)

        # subscribe to event stream
        packet = Packet.register_event(event_stream_type)
        response = self._communicate(packet)

        if response.response_type != Packet.EVENT_CONFIRM:
            raise SessionException(
                "Unexpected response type {type}, "
                "expected '{confirm}' (EVENT_CONFIRM)".format(
                    type=response.response_type,
                    confirm=Packet.EVENT_CONFIRM,
                )
            )

        # issue command, and read any event messages
        packet = Packet.request(command, message)
        self.transport.send(packet)
        response = self._read()
        while response.response_type == Packet.EVENT:
            result.append(Message.deserialize(response.payload))
            response = self._read()

        if response.response_type == Packet.CMD_RESPONSE:
            response_message = Message.deserialize(response.payload)
        else:
            raise SessionException(
                "Unexpected response type {type}, "
                "expected '{response}' (CMD_RESPONSE)".format(
                    type=response.response_type,
                    response=Packet.CMD_RESPONSE
                )
            )

        # unsubscribe from event stream
        packet = Packet.unregister_event(event_stream_type)
        response = self._communicate(packet)
        if response.response_type != Packet.EVENT_CONFIRM:
            raise SessionException(
                "Unexpected response type {type}, "
                "expected '{confirm}' (EVENT_CONFIRM)".format(
                    type=response.response_type,
                    confirm=Packet.EVENT_CONFIRM,
                )
            )

        return (response_message, result)
Send command request and collect and return all emitted events.

        :param command: command to send
        :type command: str
        :param event_stream_type: event type emitted on command execution
        :type event_stream_type: str
        :param message: message (optional)
        :type message: str
        :return: a pair of the command result and a list of emitted events
        :rtype: tuple