remove typeutils.cpp and improve lgsmarttv

This commit is contained in:
Simon Stürz 2015-06-12 14:44:30 +02:00 committed by Michael Zanetti
parent 3c6daeded9
commit 3be9de549a
2 changed files with 23 additions and 24 deletions

View File

@ -37,7 +37,6 @@ SOURCES += plugin/device.cpp \
types/ruleaction.cpp \ types/ruleaction.cpp \
types/ruleactionparam.cpp \ types/ruleactionparam.cpp \
types/statedescriptor.cpp \ types/statedescriptor.cpp \
typeutils.cpp \
HEADERS += plugin/device.h \ HEADERS += plugin/device.h \
plugin/deviceclass.h \ plugin/deviceclass.h \

View File

@ -103,14 +103,6 @@ DeviceManager::DeviceError DevicePluginLgSmartTv::discoverDevices(const DeviceCl
DeviceManager::DeviceSetupStatus DevicePluginLgSmartTv::setupDevice(Device *device) DeviceManager::DeviceSetupStatus DevicePluginLgSmartTv::setupDevice(Device *device)
{ {
qDebug() << "setup tv";
qDebug() << device->params();
QString key = m_tvKeys.value(device->paramValue("uuid").toString());
qDebug() << "key for this device" << key;
device->setParamValue("key", key);
UpnpDeviceDescriptor upnpDeviceDescriptor; UpnpDeviceDescriptor upnpDeviceDescriptor;
upnpDeviceDescriptor.setFriendlyName(device->paramValue("name").toString()); upnpDeviceDescriptor.setFriendlyName(device->paramValue("name").toString());
upnpDeviceDescriptor.setUuid(device->paramValue("uuid").toString()); upnpDeviceDescriptor.setUuid(device->paramValue("uuid").toString());
@ -120,15 +112,34 @@ DeviceManager::DeviceSetupStatus DevicePluginLgSmartTv::setupDevice(Device *devi
upnpDeviceDescriptor.setLocation(QUrl(device->paramValue("location").toString())); upnpDeviceDescriptor.setLocation(QUrl(device->paramValue("location").toString()));
TvDevice *tvDevice = new TvDevice(this, upnpDeviceDescriptor); TvDevice *tvDevice = new TvDevice(this, upnpDeviceDescriptor);
tvDevice->setKey(key);
// check if the key wasn't loaded
if (device->paramValue("key") == QString()) {
// check if we know the key from the pairing procedure
if (!m_tvKeys.contains(device->paramValue("uuid").toString())) {
qWarning() << "could not find any pairing key";
return DeviceManager::DeviceSetupStatusFailure;
}
// use the key from the pairing procedure
tvDevice->endPairing();
QString key = m_tvKeys.value(device->paramValue("uuid").toString());
tvDevice->setKey(key);
device->setParamValue("key", key);
} else {
// add the key for editing
if (!m_tvKeys.contains(device->paramValue("uuid").toString())) {
m_tvKeys.insert(tvDevice->uuid(), tvDevice->key());
}
}
connect(tvDevice, &TvDevice::pairingFinished, this, &DevicePluginLgSmartTv::slotPairingFinished); connect(tvDevice, &TvDevice::pairingFinished, this, &DevicePluginLgSmartTv::slotPairingFinished);
connect(tvDevice, &TvDevice::sendCommandFinished, this, &DevicePluginLgSmartTv::sendingCommandFinished); connect(tvDevice, &TvDevice::sendCommandFinished, this, &DevicePluginLgSmartTv::sendingCommandFinished);
connect(tvDevice, &TvDevice::statusChanged, this, &DevicePluginLgSmartTv::statusChanged); connect(tvDevice, &TvDevice::statusChanged, this, &DevicePluginLgSmartTv::statusChanged);
m_tvList.insert(tvDevice, device); m_tvList.insert(tvDevice, device);
tvDevice->requestPairing();
return DeviceManager::DeviceSetupStatusSuccess; return DeviceManager::DeviceSetupStatusAsync;
} }
DeviceManager::HardwareResources DevicePluginLgSmartTv::requiredHardware() const DeviceManager::HardwareResources DevicePluginLgSmartTv::requiredHardware() const
@ -264,19 +275,8 @@ void DevicePluginLgSmartTv::networkManagerReplyReady(QNetworkReply *reply)
qWarning() << "Could not pair: please check the key and retry"; qWarning() << "Could not pair: please check the key and retry";
emit pairingFinished(pairingTransactionId, DeviceManager::DeviceSetupStatusFailure); emit pairingFinished(pairingTransactionId, DeviceManager::DeviceSetupStatusFailure);
} else { } else {
qWarning() << "Paired successfully"; qDebug() << "Paired tv successfully";
// now unpair the device, because setupdevice will try that again emit pairingFinished(pairingTransactionId, DeviceManager::DeviceSetupStatusSuccess);
QString urlString = "http://" + hostAddress().toString() + ":" + QString::number(port()) + "/udap/api/pairing";
QNetworkRequest request;
request.setUrl(QUrl(urlString));
request.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("text/xml; charset=utf-8"));
request.setHeader(QNetworkRequest::UserAgentHeader,QVariant("UDAP/2.0 guh"));
request.setRawHeader("Connection", "Close");
QByteArray data = "<?xml version=\"1.0\" encoding=\"utf-8\"?><envelope><api type=\"pairing\"><name>byebye</name><port>8080</port></api></envelope>";
m_finishingPairingReplay = m_manager->post(request,data);
} }
reply->deleteLater(); reply->deleteLater();
} }