fixed uuid bug
parent
ebd094c57b
commit
66bce1b1ab
|
|
@ -1,13 +1,29 @@
|
||||||
|
|
||||||
# Air Quality Index
|
# Air Quality Index
|
||||||
|
|
||||||
This plug-in gets the air quality information from http://aqicn.org.
|
This plug-in gets air quality information from http://aqicn.org.
|
||||||
Through your IP address the next nearby sensor station will be discovered.
|
Through the WAN IP address the next nearby sensor station will be discovered.
|
||||||
|
The geo location can also be set manually.
|
||||||
|
|
||||||
## Supported Things
|
## Supported Things
|
||||||
|
|
||||||
If you encounter that a value stays to zero, it means the sensor station
|
* Air Quality Index
|
||||||
|
* Location discovery
|
||||||
|
* Manually location set
|
||||||
|
* Air Quality
|
||||||
|
* Cautionary statement
|
||||||
|
* PM2.5 pollution level
|
||||||
|
* PM10 pollution lebel
|
||||||
|
* Ozone level
|
||||||
|
* Nitrogen dioxide level
|
||||||
|
* Carbon monoxide level
|
||||||
|
* Sulfur dioxide level
|
||||||
|
* Temperature
|
||||||
|
* Humidity
|
||||||
|
* Pressure
|
||||||
|
* Wind speed
|
||||||
|
|
||||||
|
NOTE: If you encounter that a value stays to zero, it means the sensor station
|
||||||
doesn't support that value.
|
doesn't support that value.
|
||||||
|
|
||||||
Besides the air pollution level the plug-in also states a cautionary statement.
|
Besides the air pollution level the plug-in also states a cautionary statement.
|
||||||
|
|
@ -16,6 +32,10 @@ inform you what precautions should be taken.
|
||||||
|
|
||||||
## Requirments
|
## Requirments
|
||||||
|
|
||||||
|
* Valid "Air Quality Index" API Key
|
||||||
|
* The package "nymea-plugin-airqualityindex" must be installed
|
||||||
|
* Intenet connection
|
||||||
|
|
||||||
## More
|
## More
|
||||||
|
|
||||||
More about the different Air Quality Levels: https://www.airnow.gov/index.cfm?action=aqibasics.aqi
|
More about the different Air Quality Levels: https://www.airnow.gov/index.cfm?action=aqibasics.aqi
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ QUuid AirQualityIndex::searchByName(const QString &name)
|
||||||
if (m_apiKey.isEmpty())
|
if (m_apiKey.isEmpty())
|
||||||
qCWarning(dcAirQualityIndex()) << "API key is not set";
|
qCWarning(dcAirQualityIndex()) << "API key is not set";
|
||||||
|
|
||||||
QUuid requestId;
|
QUuid requestId = QUuid::createUuid();;
|
||||||
QUrl url;
|
QUrl url;
|
||||||
url.setUrl(m_baseUrl);
|
url.setUrl(m_baseUrl);
|
||||||
url.setPath("/search/");
|
url.setPath("/search/");
|
||||||
|
|
@ -118,7 +118,7 @@ QUuid AirQualityIndex::getDataByIp()
|
||||||
if (m_apiKey.isEmpty())
|
if (m_apiKey.isEmpty())
|
||||||
qCWarning(dcAirQualityIndex()) << "API key is not set";
|
qCWarning(dcAirQualityIndex()) << "API key is not set";
|
||||||
|
|
||||||
QUuid requestId;
|
QUuid requestId = QUuid::createUuid();;
|
||||||
QUrl url;
|
QUrl url;
|
||||||
url.setUrl(m_baseUrl);
|
url.setUrl(m_baseUrl);
|
||||||
url.setPath("/feed/here/");
|
url.setPath("/feed/here/");
|
||||||
|
|
@ -153,7 +153,7 @@ QUuid AirQualityIndex::getDataByGeolocation(const QString &lat, const QString &l
|
||||||
if (m_apiKey.isEmpty())
|
if (m_apiKey.isEmpty())
|
||||||
qCWarning(dcAirQualityIndex()) << "API key is not set";
|
qCWarning(dcAirQualityIndex()) << "API key is not set";
|
||||||
|
|
||||||
QUuid requestId;
|
QUuid requestId = QUuid::createUuid();
|
||||||
QUrl url;
|
QUrl url;
|
||||||
url.setUrl(m_baseUrl);
|
url.setUrl(m_baseUrl);
|
||||||
url.setPath("/feed/geo:"+lat+";"+lng+"/");
|
url.setPath("/feed/geo:"+lat+";"+lng+"/");
|
||||||
|
|
|
||||||
|
|
@ -45,27 +45,27 @@ void IntegrationPluginAqi::startPairing(ThingPairingInfo *info)
|
||||||
|
|
||||||
void IntegrationPluginAqi::confirmPairing(ThingPairingInfo *info, const QString &username, const QString &secret)
|
void IntegrationPluginAqi::confirmPairing(ThingPairingInfo *info, const QString &username, const QString &secret)
|
||||||
{
|
{
|
||||||
Q_UNUSED(username)
|
Q_UNUSED(username)
|
||||||
|
|
||||||
QNetworkRequest request(QUrl("https://api.waqi.info/feed/here/?token="+secret));
|
QNetworkRequest request(QUrl("https://api.waqi.info/feed/here/?token="+secret));
|
||||||
QNetworkReply *reply = hardwareManager()->networkManager()->get(request);
|
QNetworkReply *reply = hardwareManager()->networkManager()->get(request);
|
||||||
connect(reply, &QNetworkReply::finished, info, [this, reply, info, secret](){
|
connect(reply, &QNetworkReply::finished, info, [this, reply, info, secret](){
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
||||||
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||||
|
|
||||||
// check HTTP status code
|
// check HTTP status code
|
||||||
if (status != 200) {
|
if (status != 200) {
|
||||||
//: Error setting up device with invalid token
|
//: Error setting up device with invalid token
|
||||||
info->finish(Thing::ThingErrorAuthenticationFailure, QT_TR_NOOP("This token is not valid."));
|
info->finish(Thing::ThingErrorAuthenticationFailure, QT_TR_NOOP("This token is not valid."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginStorage()->beginGroup(info->thingId().toString());
|
pluginStorage()->beginGroup(info->thingId().toString());
|
||||||
pluginStorage()->setValue("apiKey", secret);
|
pluginStorage()->setValue("apiKey", secret);
|
||||||
pluginStorage()->endGroup();
|
pluginStorage()->endGroup();
|
||||||
info->finish(Thing::ThingErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntegrationPluginAqi::discoverThings(ThingDiscoveryInfo *info)
|
void IntegrationPluginAqi::discoverThings(ThingDiscoveryInfo *info)
|
||||||
|
|
@ -78,8 +78,10 @@ void IntegrationPluginAqi::discoverThings(ThingDiscoveryInfo *info)
|
||||||
connect(m_aqiConnection, &AirQualityIndex::stationsReceived, this, &IntegrationPluginAqi::onAirQualityStationsReceived);
|
connect(m_aqiConnection, &AirQualityIndex::stationsReceived, this, &IntegrationPluginAqi::onAirQualityStationsReceived);
|
||||||
|
|
||||||
connect(info, &ThingDiscoveryInfo::aborted, [this] {
|
connect(info, &ThingDiscoveryInfo::aborted, [this] {
|
||||||
m_aqiConnection->deleteLater();
|
if (myThings().filterByThingClassId(airQualityIndexThingClassId).isEmpty()) {
|
||||||
m_aqiConnection = nullptr;
|
m_aqiConnection->deleteLater();
|
||||||
|
m_aqiConnection = nullptr;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
qCDebug(dcAirQualityIndex()) << "AQI connection alread created";
|
qCDebug(dcAirQualityIndex()) << "AQI connection alread created";
|
||||||
|
|
@ -107,8 +109,10 @@ void IntegrationPluginAqi::setupThing(ThingSetupInfo *info)
|
||||||
|
|
||||||
connect(info, &ThingSetupInfo::aborted, [requestId, this] {
|
connect(info, &ThingSetupInfo::aborted, [requestId, this] {
|
||||||
m_asyncSetups.remove(requestId);
|
m_asyncSetups.remove(requestId);
|
||||||
//m_aqiConnection->deleteLater();
|
if (myThings().filterByThingClassId(airQualityIndexThingClassId).isEmpty()) {
|
||||||
//m_aqiConnection = nullptr;
|
m_aqiConnection->deleteLater();
|
||||||
|
m_aqiConnection = nullptr;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
info->finish(Thing::ThingErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
|
|
@ -120,6 +124,7 @@ void IntegrationPluginAqi::setupThing(ThingSetupInfo *info)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void IntegrationPluginAqi::postSetupThing(Thing *thing)
|
void IntegrationPluginAqi::postSetupThing(Thing *thing)
|
||||||
{
|
{
|
||||||
if (thing->thingClassId() == airQualityIndexThingClassId) {
|
if (thing->thingClassId() == airQualityIndexThingClassId) {
|
||||||
|
|
@ -162,7 +167,7 @@ void IntegrationPluginAqi::thingRemoved(Thing *thing)
|
||||||
void IntegrationPluginAqi::onAirQualityDataReceived(QUuid requestId, AirQualityIndex::AirQualityData data)
|
void IntegrationPluginAqi::onAirQualityDataReceived(QUuid requestId, AirQualityIndex::AirQualityData data)
|
||||||
{
|
{
|
||||||
if (m_asyncSetups.contains(requestId)) {
|
if (m_asyncSetups.contains(requestId)) {
|
||||||
ThingSetupInfo *info = m_asyncSetups.value(requestId);
|
ThingSetupInfo *info = m_asyncSetups.take(requestId);
|
||||||
return info->finish(Thing::ThingErrorNoError);
|
return info->finish(Thing::ThingErrorNoError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -171,7 +176,6 @@ void IntegrationPluginAqi::onAirQualityDataReceived(QUuid requestId, AirQualityI
|
||||||
if (!thing)
|
if (!thing)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//thing->setStateValue(airQualityIndexStationNameStateTypeId, data);
|
|
||||||
thing->setStateValue(airQualityIndexConnectedStateTypeId, true);
|
thing->setStateValue(airQualityIndexConnectedStateTypeId, true);
|
||||||
thing->setStateValue(airQualityIndexCoStateTypeId, data.co);
|
thing->setStateValue(airQualityIndexCoStateTypeId, data.co);
|
||||||
thing->setStateValue(airQualityIndexHumidityStateTypeId, data.humidity);
|
thing->setStateValue(airQualityIndexHumidityStateTypeId, data.humidity);
|
||||||
|
|
@ -221,11 +225,14 @@ void IntegrationPluginAqi::onAirQualityStationsReceived(QUuid requestId, QList<A
|
||||||
info->finish(Thing::ThingErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (m_asyncRequests.contains(requestId)) {
|
if (m_asyncRequests.contains(requestId)) {
|
||||||
Thing *thing = myThings().findById(m_asyncRequests.take(requestId));
|
Thing * thing = myThings().findById(m_asyncRequests.take(requestId));
|
||||||
if (!thing)
|
if (!thing)
|
||||||
return;
|
return;
|
||||||
thing->setStateValue(airQualityIndexConnectedStateTypeId, true);
|
if (stations.length() != 0) {
|
||||||
|
thing->setStateValue(airQualityIndexStationNameStateTypeId, stations.first().name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue