search emit discovered devices
This commit is contained in:
parent
dde0bcc868
commit
e7a726733b
@ -151,10 +151,11 @@
|
||||
|
||||
|
||||
VendorId openweathermapVendorId = VendorId("bf1e96f0-9650-4e7c-a56c-916d54d18e7a");
|
||||
|
||||
DeviceClassId deviceClassId = DeviceClassId("985195aa-17ad-4530-88a4-cdd753d747d7");
|
||||
DevicePluginOpenweathermap::DevicePluginOpenweathermap()
|
||||
{
|
||||
m_openweaher = new OpenWeatherMap(this);
|
||||
connect(m_openweaher, SIGNAL(searchResultReady(QList<QVariantMap>)), this, SLOT(searchResultsReady(QList<QVariantMap>)));
|
||||
}
|
||||
|
||||
QList<Vendor> DevicePluginOpenweathermap::supportedVendors() const
|
||||
@ -292,6 +293,10 @@ QList<DeviceClass> DevicePluginOpenweathermap::supportedDevices() const
|
||||
DeviceManager::DeviceError DevicePluginOpenweathermap::discoverDevices(const DeviceClassId &deviceClassId, const QVariantMap ¶ms) const
|
||||
{
|
||||
qDebug() << "should discover divces for" << deviceClassId << params;
|
||||
if(params.value("location").toString() == ""){
|
||||
m_openweaher->update();
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}
|
||||
m_openweaher->search(params.value("location").toString());
|
||||
return DeviceManager::DeviceErrorNoError;
|
||||
}
|
||||
@ -315,4 +320,18 @@ void DevicePluginOpenweathermap::guhTimer()
|
||||
{
|
||||
}
|
||||
|
||||
void DevicePluginOpenweathermap::searchResultsReady(const QList<QVariantMap> &cityList)
|
||||
{
|
||||
QList<DeviceDescriptor> retList;
|
||||
foreach (QVariantMap elemant, cityList) {
|
||||
QVariantMap params;
|
||||
params.insert("location", elemant.value("name"));
|
||||
params.insert("country", elemant.value("country"));
|
||||
params.insert("id", elemant.value("id"));
|
||||
retList.append(DeviceDescriptor(deviceClassId, params));
|
||||
}
|
||||
|
||||
emit discoverDevices(deviceClassId,retList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -48,6 +48,7 @@ public:
|
||||
void guhTimer() override;
|
||||
|
||||
private slots:
|
||||
void searchResultsReady(const QList<QVariantMap> &cityList);
|
||||
|
||||
public slots:
|
||||
|
||||
|
||||
@ -124,16 +124,22 @@ void OpenWeatherMap::processSearchLocationResponse(QByteArray data)
|
||||
}
|
||||
//qDebug() << jsonDoc.toJson();
|
||||
|
||||
QList<QVariantMap> cityList;
|
||||
QVariantMap dataMap = jsonDoc.toVariant().toMap();
|
||||
if(dataMap.contains("list")){
|
||||
QVariantList list = dataMap.value("list").toList();
|
||||
foreach (QVariant key, list) {
|
||||
QVariantMap elemant = key.toMap();
|
||||
if(elemant.contains("id")){
|
||||
m_cityId = elemant.value("id").toString();
|
||||
updateWeatherData();
|
||||
return;
|
||||
}
|
||||
|
||||
QVariantMap city;
|
||||
city.insert("name",elemant.value("name").toString());
|
||||
city.insert("country", elemant.value("sys").toMap().value("country").toString());
|
||||
city.insert("id",elemant.value("id").toString());
|
||||
cityList.append(city);
|
||||
|
||||
m_cityId = elemant.value("id").toString();
|
||||
updateWeatherData();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user