private function getWrappedDevice($deviceId, Request\GenericRequest $request = null)
    {
        $modelDevices = $this->getCacheStorage()->load('DEVS_' . $deviceId);

        if (empty($modelDevices)) {
            $modelDevices = $this->getDeviceRepository()->getDeviceHierarchy($deviceId);
        }

        $this->getCacheStorage()->save('DEVS_' . $deviceId, $modelDevices);

        if ($request === null) {
            // If a request was not provided, we generate one from the WURFL entry itself
            // to help resolve the virtual capabilities
            $requestFactory    = new GenericRequestFactory();
            $request           = $requestFactory->createRequestForUserAgent($modelDevices[0]->userAgent);
            $genericNormalizer = UserAgentHandlerChainFactory::createGenericNormalizers();

            $request->setUserAgentNormalized($genericNormalizer->normalize($request->getUserAgent()));
        }

        // The CustomDevice is not cached since virtual capabilities must be recalculated
        // for every different request.
        return new CustomDevice($modelDevices, $request);
    }