From a89e442835c38f916dc79a74eea3b976dea36991 Mon Sep 17 00:00:00 2001 From: Boernsman Date: Wed, 21 Oct 2020 16:34:27 +0200 Subject: [PATCH 1/7] switched aqi to api key provider --- aqi/integrationpluginaqi.cpp | 54 ++++------------------------------- aqi/integrationpluginaqi.h | 2 -- aqi/integrationpluginaqi.json | 2 +- 3 files changed, 6 insertions(+), 52 deletions(-) diff --git a/aqi/integrationpluginaqi.cpp b/aqi/integrationpluginaqi.cpp index f6a21a77..88414e90 100644 --- a/aqi/integrationpluginaqi.cpp +++ b/aqi/integrationpluginaqi.cpp @@ -38,50 +38,13 @@ IntegrationPluginAqi::IntegrationPluginAqi() } -void IntegrationPluginAqi::startPairing(ThingPairingInfo *info) -{ - NetworkAccessManager *network = hardwareManager()->networkManager(); - QNetworkReply *reply = network->get(QNetworkRequest(QUrl("https://api.waqi.info"))); - connect(reply, &QNetworkReply::finished, this, [reply, info] { - reply->deleteLater(); - - if (reply->error() == QNetworkReply::NetworkError::HostNotFoundError) { - info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("Air quality index server is not reachable.")); - } else { - info->finish(Thing::ThingErrorNoError, QT_TR_NOOP("Please enter your API token for Air Quality Index")); - } - }); -} - -void IntegrationPluginAqi::confirmPairing(ThingPairingInfo *info, const QString &username, const QString &secret) -{ - Q_UNUSED(username) - - QNetworkRequest request(QUrl("https://api.waqi.info/feed/here/?token="+secret)); - QNetworkReply *reply = hardwareManager()->networkManager()->get(request); - connect(reply, &QNetworkReply::finished, info, [this, reply, info, secret](){ - reply->deleteLater(); - - int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - - // check HTTP status code - if (status != 200) { - //: Error setting up device with invalid token - info->finish(Thing::ThingErrorAuthenticationFailure, QT_TR_NOOP("This token is not valid.")); - return; - } - - pluginStorage()->beginGroup(info->thingId().toString()); - pluginStorage()->setValue("apiKey", secret); - pluginStorage()->endGroup(); - info->finish(Thing::ThingErrorNoError); - }); -} - void IntegrationPluginAqi::discoverThings(ThingDiscoveryInfo *info) { if (!m_aqiConnection) { - QString apiKey = "74d31bb5ad9bcdeaed48097418b55188cb56d450"; //temporary key for discovery + QString apiKey = apiKeyStorage()->requestKey("aqi").data("apiKey"); + if (apiKey.isEmpty()) { + return info->finish(Thing::ThingErrorHardwareNotAvailable, tr("No API key is set.")); + } m_aqiConnection = new AirQualityIndex(hardwareManager()->networkManager(), apiKey, this); connect(m_aqiConnection, &AirQualityIndex::requestExecuted, this, &IntegrationPluginAqi::onRequestExecuted); connect(m_aqiConnection, &AirQualityIndex::dataReceived, this, &IntegrationPluginAqi::onAirQualityDataReceived); @@ -105,9 +68,7 @@ void IntegrationPluginAqi::setupThing(ThingSetupInfo *info) { if (info->thing()->thingClassId() == airQualityIndexThingClassId) { if (!m_aqiConnection) { - pluginStorage()->beginGroup(info->thing()->id().toString()); - QString apiKey = pluginStorage()->value("apiKey").toString(); - pluginStorage()->endGroup(); + QString apiKey = apiKeyStorage()->requestKey("aqi").data("apiKey"); m_aqiConnection = new AirQualityIndex(hardwareManager()->networkManager(), apiKey, this); connect(m_aqiConnection, &AirQualityIndex::requestExecuted, this, &IntegrationPluginAqi::onRequestExecuted); connect(m_aqiConnection, &AirQualityIndex::dataReceived, this, &IntegrationPluginAqi::onAirQualityDataReceived); @@ -128,11 +89,6 @@ void IntegrationPluginAqi::setupThing(ThingSetupInfo *info) } else { // An AQI connection might be setup because of an discovery request // or because there is already another thing using the connection - // In any case the API key is being updated to avoid using the discovery key. - pluginStorage()->beginGroup(info->thing()->id().toString()); - QString apiKey = pluginStorage()->value("apiKey").toString(); - pluginStorage()->endGroup(); - m_aqiConnection->setApiKey(apiKey); info->finish(Thing::ThingErrorNoError); } } else { diff --git a/aqi/integrationpluginaqi.h b/aqi/integrationpluginaqi.h index 14808bfd..16799917 100644 --- a/aqi/integrationpluginaqi.h +++ b/aqi/integrationpluginaqi.h @@ -50,8 +50,6 @@ class IntegrationPluginAqi : public IntegrationPlugin public: explicit IntegrationPluginAqi(); - void startPairing(ThingPairingInfo *info) override; - void confirmPairing(ThingPairingInfo *info, const QString &username, const QString &secret) override; void discoverThings(ThingDiscoveryInfo *info) override; void setupThing(ThingSetupInfo *info) override; void thingRemoved(Thing *thing) override; diff --git a/aqi/integrationpluginaqi.json b/aqi/integrationpluginaqi.json index 85d2c9e9..43ffc42c 100644 --- a/aqi/integrationpluginaqi.json +++ b/aqi/integrationpluginaqi.json @@ -2,6 +2,7 @@ "name": "AirQualityIndex", "displayName": "AirQualityIndex", "id": "57d69b76-4d2d-41ec-bef6-949a79ffbe6b", + "apiKeys": ["aqi"], "vendors": [ { "name": "airQualityIndex", @@ -14,7 +15,6 @@ "displayName": "Air quality index", "interfaces": ["windspeedsensor", "humiditysensor", "pressuresensor", "temperaturesensor", "connectable"], "createMethods": ["discovery", "user"], - "setupMethod": "displaypin", "paramTypes": [ { "id": "afd5803b-6c98-44d7-9f4a-45e91cfb062e", From 602c4e66149a895925f892022f0af1a23e38c68c Mon Sep 17 00:00:00 2001 From: Boernsman Date: Thu, 22 Oct 2020 09:36:11 +0200 Subject: [PATCH 2/7] added option for private api keys --- aqi/README.md | 8 +++++++- aqi/integrationpluginaqi.cpp | 33 ++++++++++++++++++++++++++++----- aqi/integrationpluginaqi.h | 1 + 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/aqi/README.md b/aqi/README.md index d940e9d5..a58e3a2e 100644 --- a/aqi/README.md +++ b/aqi/README.md @@ -29,9 +29,10 @@ Besides the air pollution level the plug-in also states a cautionary statement. Both states can be used to let nymea notify you about the pollution level and inform you what precautions should be taken. -## Requirments +## Requirements * Valid "Air Quality Index" API Key + * This might be provided through the nymea community API Key provider or an own key in the nymead.conf file. * The package "nymea-plugin-airqualityindex" must be installed * Internet connection @@ -39,3 +40,8 @@ inform you what precautions should be taken. More about the different Air Quality Levels: https://www.airnow.gov/index.cfm?action=aqibasics.aqi +Personal API Key settings in 'nymead.conf': +''' +[aqi] +apiKey="123456789abcdfgh" +''' diff --git a/aqi/integrationpluginaqi.cpp b/aqi/integrationpluginaqi.cpp index 88414e90..04bfa517 100644 --- a/aqi/integrationpluginaqi.cpp +++ b/aqi/integrationpluginaqi.cpp @@ -30,6 +30,7 @@ #include "integrationpluginaqi.h" #include "plugininfo.h" +#include "nymeasettings.h" #include @@ -41,10 +42,9 @@ IntegrationPluginAqi::IntegrationPluginAqi() void IntegrationPluginAqi::discoverThings(ThingDiscoveryInfo *info) { if (!m_aqiConnection) { - QString apiKey = apiKeyStorage()->requestKey("aqi").data("apiKey"); - if (apiKey.isEmpty()) { - return info->finish(Thing::ThingErrorHardwareNotAvailable, tr("No API key is set.")); - } + QString apiKey = getApiKey(); + if (apiKey.isEmpty()) + return info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("API key is not available.")); m_aqiConnection = new AirQualityIndex(hardwareManager()->networkManager(), apiKey, this); connect(m_aqiConnection, &AirQualityIndex::requestExecuted, this, &IntegrationPluginAqi::onRequestExecuted); connect(m_aqiConnection, &AirQualityIndex::dataReceived, this, &IntegrationPluginAqi::onAirQualityDataReceived); @@ -68,7 +68,9 @@ void IntegrationPluginAqi::setupThing(ThingSetupInfo *info) { if (info->thing()->thingClassId() == airQualityIndexThingClassId) { if (!m_aqiConnection) { - QString apiKey = apiKeyStorage()->requestKey("aqi").data("apiKey"); + QString apiKey = getApiKey(); + if (apiKey.isEmpty()) + return info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("API key is not available.")); m_aqiConnection = new AirQualityIndex(hardwareManager()->networkManager(), apiKey, this); connect(m_aqiConnection, &AirQualityIndex::requestExecuted, this, &IntegrationPluginAqi::onRequestExecuted); connect(m_aqiConnection, &AirQualityIndex::dataReceived, this, &IntegrationPluginAqi::onAirQualityDataReceived); @@ -118,6 +120,27 @@ void IntegrationPluginAqi::postSetupThing(Thing *thing) } } +QString IntegrationPluginAqi::getApiKey() +{ + QString apiKey; + QSettings settings(NymeaSettings::settingsPath() + "/nymead.conf", QSettings::IniFormat); + settings.beginGroup("aqi"); + if (settings.contains("apiKey")) { + apiKey = settings.value("apiKey").toString(); + QString printedCopy = apiKey; + qCDebug(dcAirQualityIndex()) << "Using custom API key:" << printedCopy.replace(printedCopy.length() - 10, 10, "**********"); + } + settings.endGroup(); + + if (apiKey.isEmpty()) { + apiKey = apiKeyStorage()->requestKey("aqi").data("apiKey"); + } + if (apiKey.isEmpty()) { + qCWarning(dcAirQualityIndex()) << "Could not find any API key for AQI"; + } + return apiKey; +} + void IntegrationPluginAqi::thingRemoved(Thing *thing) { Q_UNUSED(thing) diff --git a/aqi/integrationpluginaqi.h b/aqi/integrationpluginaqi.h index 16799917..dbda5269 100644 --- a/aqi/integrationpluginaqi.h +++ b/aqi/integrationpluginaqi.h @@ -62,6 +62,7 @@ private: QHash m_asyncDiscovery; QHash m_asyncSetups; QHash m_asyncRequests; + QString getApiKey(); private slots: void onPluginTimer(); From fced2b9fe9adf4725e19545d1dd29f97854d6e38 Mon Sep 17 00:00:00 2001 From: Boernsman Date: Thu, 22 Oct 2020 11:14:34 +0200 Subject: [PATCH 3/7] added german translation --- aqi/integrationpluginaqi.json | 4 +- ...57d69b76-4d2d-41ec-bef6-949a79ffbe6b-de.ts | 276 ++++++++++++++++++ ...69b76-4d2d-41ec-bef6-949a79ffbe6b-en_US.ts | 45 ++- 3 files changed, 295 insertions(+), 30 deletions(-) create mode 100644 aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-de.ts diff --git a/aqi/integrationpluginaqi.json b/aqi/integrationpluginaqi.json index 43ffc42c..7f8dc6b3 100644 --- a/aqi/integrationpluginaqi.json +++ b/aqi/integrationpluginaqi.json @@ -1,12 +1,12 @@ { "name": "AirQualityIndex", - "displayName": "AirQualityIndex", + "displayName": "Air quality index", "id": "57d69b76-4d2d-41ec-bef6-949a79ffbe6b", "apiKeys": ["aqi"], "vendors": [ { "name": "airQualityIndex", - "displayName": "Air Quality Index", + "displayName": "Air quality index", "id": "6c8e2ded-0a33-4e77-b76c-ea02168741ec", "thingClasses": [ { diff --git a/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-de.ts b/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-de.ts new file mode 100644 index 00000000..9e4cb02e --- /dev/null +++ b/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-de.ts @@ -0,0 +1,276 @@ + + + + + AirQualityIndex + + + + Air quality + The name of the ParamType (ThingClass: airQualityIndex, EventType: airQuality, ID: {33a3329a-4117-4488-aa18-91c76056ed6e}) +---------- +The name of the StateType ({33a3329a-4117-4488-aa18-91c76056ed6e}) of ThingClass airQualityIndex + Luftqualität + + + + Air quality changed + The name of the EventType ({33a3329a-4117-4488-aa18-91c76056ed6e}) of ThingClass airQualityIndex + Luftqualität geändert + + + + + + Air quality index + The name of the ThingClass ({23ea32c9-38b0-4155-bacc-3afa8c09f6ee}) +---------- +The name of the vendor ({6c8e2ded-0a33-4e77-b76c-ea02168741ec}) +---------- +The name of the plugin AirQualityIndex ({57d69b76-4d2d-41ec-bef6-949a79ffbe6b}) + Air quality index + + + + + Carbon monoxide level (CO) + The name of the ParamType (ThingClass: airQualityIndex, EventType: co, ID: {54ac72f3-6444-46a8-a43d-210c2a6fbfb5}) +---------- +The name of the StateType ({54ac72f3-6444-46a8-a43d-210c2a6fbfb5}) of ThingClass airQualityIndex + Kohlenmonoxidgehalt (CO) + + + + Carbon monoxide level (CO) changed + The name of the EventType ({54ac72f3-6444-46a8-a43d-210c2a6fbfb5}) of ThingClass airQualityIndex + Kohlenmonoxidgehalt (CO) geändert + + + + + Cautionary statement + The name of the ParamType (ThingClass: airQualityIndex, EventType: cautionaryStatement, ID: {cfece671-4e88-4c49-9456-e3f8f7c79ab3}) +---------- +The name of the StateType ({cfece671-4e88-4c49-9456-e3f8f7c79ab3}) of ThingClass airQualityIndex + Warnhinweis + + + + Cautionary statement changed + The name of the EventType ({cfece671-4e88-4c49-9456-e3f8f7c79ab3}) of ThingClass airQualityIndex + Warnhinweis geändert + + + + + Coarse dust particles pollution level (PM10) + The name of the ParamType (ThingClass: airQualityIndex, EventType: pm10, ID: {24b41ec4-e26b-4dfb-b52c-8e2b1bbdafc6}) +---------- +The name of the StateType ({24b41ec4-e26b-4dfb-b52c-8e2b1bbdafc6}) of ThingClass airQualityIndex + Verschmutzungsgrad der groben Staubpartikel (PM10) + + + + Coarse dust particles pollution level (PM10) changed + The name of the EventType ({24b41ec4-e26b-4dfb-b52c-8e2b1bbdafc6}) of ThingClass airQualityIndex + Verschmutzungsgrad der groben Staubpartikel (PM10) geändert + + + + + Connected + The name of the ParamType (ThingClass: airQualityIndex, EventType: connected, ID: {7b9135cd-2461-4d33-b2b3-3dc600983895}) +---------- +The name of the StateType ({7b9135cd-2461-4d33-b2b3-3dc600983895}) of ThingClass airQualityIndex + Verbunden + + + + Connected changed + The name of the EventType ({7b9135cd-2461-4d33-b2b3-3dc600983895}) of ThingClass airQualityIndex + Verbunden geändert + + + + + Fine particles pollution level (PM2.5) + The name of the ParamType (ThingClass: airQualityIndex, EventType: pm25, ID: {bc8c4c83-d229-4be4-8732-bc4f2390f399}) +---------- +The name of the StateType ({bc8c4c83-d229-4be4-8732-bc4f2390f399}) of ThingClass airQualityIndex + Verschmutzungsgrad der Feinstaubpartikel (PM2,5) + + + + Fine particles pollution level (PM2.5) changed + The name of the EventType ({bc8c4c83-d229-4be4-8732-bc4f2390f399}) of ThingClass airQualityIndex + Verschmutzungsgrad der Feinstaubpartikel (PM2,5) geändert + + + + + Humidity + The name of the ParamType (ThingClass: airQualityIndex, EventType: humidity, ID: {4fc45fca-25ab-45a0-b862-817eea1f51e3}) +---------- +The name of the StateType ({4fc45fca-25ab-45a0-b862-817eea1f51e3}) of ThingClass airQualityIndex + Luftfeuchtigkeit + + + + Humidity changed + The name of the EventType ({4fc45fca-25ab-45a0-b862-817eea1f51e3}) of ThingClass airQualityIndex + Luftfeuchtigkeit geändert + + + + Latitude + The name of the ParamType (ThingClass: airQualityIndex, Type: thing, ID: {afd5803b-6c98-44d7-9f4a-45e91cfb062e}) + Breitengrad + + + + Longitude + The name of the ParamType (ThingClass: airQualityIndex, Type: thing, ID: {4800d78e-a367-41f7-9bf6-7c81d40ce19a}) + Längengrad + + + + + Nitrogen Dioxide level (NO2) + The name of the ParamType (ThingClass: airQualityIndex, EventType: no2, ID: {6ed6c505-f36e-44c4-a982-f395b04e539b}) +---------- +The name of the StateType ({6ed6c505-f36e-44c4-a982-f395b04e539b}) of ThingClass airQualityIndex + Stickstoffdioxidgehalt (NO2) + + + + Nitrogen Dioxide level (NO2) changed + The name of the EventType ({6ed6c505-f36e-44c4-a982-f395b04e539b}) of ThingClass airQualityIndex + Stickstoffdioxidgehalt (NO2) geändert + + + + + Ozone level (O3) + The name of the ParamType (ThingClass: airQualityIndex, EventType: o3, ID: {4e88526d-009f-4820-9a84-09b3646d23c9}) +---------- +The name of the StateType ({4e88526d-009f-4820-9a84-09b3646d23c9}) of ThingClass airQualityIndex + Ozongehalt (O3) + + + + Ozone level (O3) changed + The name of the EventType ({4e88526d-009f-4820-9a84-09b3646d23c9}) of ThingClass airQualityIndex + Ozongehalt (O3) geändert + + + + + Pressure + The name of the ParamType (ThingClass: airQualityIndex, EventType: pressure, ID: {5f799040-08f8-44d1-aa0a-4cab7caad839}) +---------- +The name of the StateType ({5f799040-08f8-44d1-aa0a-4cab7caad839}) of ThingClass airQualityIndex + Luftdruck + + + + Pressure changed + The name of the EventType ({5f799040-08f8-44d1-aa0a-4cab7caad839}) of ThingClass airQualityIndex + Luftdruck + + + + + Station name + The name of the ParamType (ThingClass: airQualityIndex, EventType: stationName, ID: {8385f3d5-62f7-482e-927c-b5d61a70d607}) +---------- +The name of the StateType ({8385f3d5-62f7-482e-927c-b5d61a70d607}) of ThingClass airQualityIndex + Stationsname + + + + Station name changed + The name of the EventType ({8385f3d5-62f7-482e-927c-b5d61a70d607}) of ThingClass airQualityIndex + Stationsname geändert + + + + + Sulfur dioxide level (SO2) + The name of the ParamType (ThingClass: airQualityIndex, EventType: so2, ID: {f3a05e65-a9b3-48fd-be43-688d4c293cc9}) +---------- +The name of the StateType ({f3a05e65-a9b3-48fd-be43-688d4c293cc9}) of ThingClass airQualityIndex + Schwefeldioxidgehalt (SO2) + + + + Sulfur dioxide level (SO2) changed + The name of the EventType ({f3a05e65-a9b3-48fd-be43-688d4c293cc9}) of ThingClass airQualityIndex + Schwefeldioxidgehalt (SO2) geändert + + + + + Temperature + The name of the ParamType (ThingClass: airQualityIndex, EventType: temperature, ID: {94219802-0a82-4761-99b3-c6b6dfc096db}) +---------- +The name of the StateType ({94219802-0a82-4761-99b3-c6b6dfc096db}) of ThingClass airQualityIndex + Temperatur + + + + Temperature changed + The name of the EventType ({94219802-0a82-4761-99b3-c6b6dfc096db}) of ThingClass airQualityIndex + Temperatur geändert + + + + + Wind speed + The name of the ParamType (ThingClass: airQualityIndex, EventType: windSpeed, ID: {c4366608-2511-428b-964e-2ad9e37f8f3c}) +---------- +The name of the StateType ({c4366608-2511-428b-964e-2ad9e37f8f3c}) of ThingClass airQualityIndex + Windgeschwindigkeit + + + + Wind speed changed + The name of the EventType ({c4366608-2511-428b-964e-2ad9e37f8f3c}) of ThingClass airQualityIndex + Windgeschwindigkeit geändert + + + + IntegrationPluginAqi + + + + API key is not available. + API-Key ist nicht verfügbar. + + + + None + Keine + + + + + Active children and adults, and people with respiratory disease, such as asthma, should limit prolonged outdoor exertion. + Aktive Kinder und Erwachsene sowie Menschen mit Atemwegserkrankungen wie Asthma sollten eine längere Belastung im Freien begrenzen. + + + + Active children and adults, and people with respiratory disease, such as asthma, should avoid prolonged outdoor exertion; everyone else, especially children, should limit prolonged outdoor exertion + Aktive Kinder und Erwachsene sowie Menschen mit Atemwegserkrankungen wie Asthma sollten eine längere Anstrengung im Freien vermeiden. Alle anderen, insbesondere Kinder, sollten längere Belastungen im Freien begrenzen + + + + Active children and adults, and people with respiratory disease, such as asthma, should avoid all outdoor exertion; everyone else, especially children, should limit outdoor exertion. + Aktive Kinder und Erwachsene sowie Menschen mit Atemwegserkrankungen wie Asthma sollten jede Anstrengung im Freien vermeiden. Alle anderen, insbesondere Kinder, sollten die Anstrengung im Freien einschränken. + + + + Everyone should avoid all outdoor exertion + Jeder sollte jede Anstrengung im Freien vermeiden. + + + diff --git a/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-en_US.ts b/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-en_US.ts index a7e01783..53ea90f7 100644 --- a/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-en_US.ts +++ b/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-en_US.ts @@ -5,13 +5,7 @@ AirQualityIndex - Air Quality Index - The name of the vendor ({6c8e2ded-0a33-4e77-b76c-ea02168741ec}) - - - - Air quality The name of the ParamType (ThingClass: airQualityIndex, EventType: airQuality, ID: {33a3329a-4117-4488-aa18-91c76056ed6e}) ---------- @@ -19,21 +13,21 @@ The name of the StateType ({33a3329a-4117-4488-aa18-91c76056ed6e}) of ThingClass - + Air quality changed The name of the EventType ({33a3329a-4117-4488-aa18-91c76056ed6e}) of ThingClass airQualityIndex + - Air quality index - The name of the ThingClass ({23ea32c9-38b0-4155-bacc-3afa8c09f6ee}) - - - - AirQualityIndex - The name of the plugin AirQualityIndex ({57d69b76-4d2d-41ec-bef6-949a79ffbe6b}) + Air quality index + The name of the ThingClass ({23ea32c9-38b0-4155-bacc-3afa8c09f6ee}) +---------- +The name of the vendor ({6c8e2ded-0a33-4e77-b76c-ea02168741ec}) +---------- +The name of the plugin AirQualityIndex ({57d69b76-4d2d-41ec-bef6-949a79ffbe6b}) @@ -247,39 +241,34 @@ The name of the StateType ({c4366608-2511-428b-964e-2ad9e37f8f3c}) of ThingClass IntegrationPluginAqi - - Please enter your API token for Air Quality Index + + + API key is not available. - - This token is not valid. - Error setting up device with invalid token - - - - + None - - + + Active children and adults, and people with respiratory disease, such as asthma, should limit prolonged outdoor exertion. - + Active children and adults, and people with respiratory disease, such as asthma, should avoid prolonged outdoor exertion; everyone else, especially children, should limit prolonged outdoor exertion - + Active children and adults, and people with respiratory disease, such as asthma, should avoid all outdoor exertion; everyone else, especially children, should limit outdoor exertion. - + Everyone should avoid all outdoor exertion From f7eef285dd1ad5ea9485cee912ab90bde70bc34a Mon Sep 17 00:00:00 2001 From: Boernsman Date: Thu, 22 Oct 2020 11:25:54 +0200 Subject: [PATCH 4/7] improved discovery error repsonse --- aqi/integrationpluginaqi.cpp | 7 ++++++- .../57d69b76-4d2d-41ec-bef6-949a79ffbe6b-de.ts | 5 +++++ .../57d69b76-4d2d-41ec-bef6-949a79ffbe6b-en_US.ts | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/aqi/integrationpluginaqi.cpp b/aqi/integrationpluginaqi.cpp index 04bfa517..a4283a3e 100644 --- a/aqi/integrationpluginaqi.cpp +++ b/aqi/integrationpluginaqi.cpp @@ -248,7 +248,12 @@ void IntegrationPluginAqi::onPluginTimer() void IntegrationPluginAqi::onRequestExecuted(QUuid requestId, bool success) { - qCDebug(dcAirQualityIndex()) << "Request executd, requestId:" << requestId << "Success:" << success << "is an async request:" << m_asyncRequests.contains(requestId); + qCDebug(dcAirQualityIndex()) << "Request executed, requestId:" << requestId << "Success:" << success << "is an async request:" << m_asyncRequests.contains(requestId); + if (m_asyncDiscovery.contains(requestId) && !success) { + ThingDiscoveryInfo *info = m_asyncDiscovery.take(requestId); + info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("Air quality index server not available, please check your internet connection.")); + } + if (m_asyncRequests.contains(requestId)) { Thing *thing = myThings().findById(m_asyncRequests.value(requestId)); diff --git a/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-de.ts b/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-de.ts index 9e4cb02e..52781677 100644 --- a/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-de.ts +++ b/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-de.ts @@ -272,5 +272,10 @@ The name of the StateType ({c4366608-2511-428b-964e-2ad9e37f8f3c}) of ThingClass Everyone should avoid all outdoor exertion Jeder sollte jede Anstrengung im Freien vermeiden. + + + Air quality index server not available, please check your internet connection. + Air quality index Server nicht verfügbar, bitte überprüfe die Internetverbindung. + diff --git a/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-en_US.ts b/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-en_US.ts index 53ea90f7..97117c6f 100644 --- a/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-en_US.ts +++ b/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-en_US.ts @@ -272,5 +272,10 @@ The name of the StateType ({c4366608-2511-428b-964e-2ad9e37f8f3c}) of ThingClass Everyone should avoid all outdoor exertion + + + Air quality index server not available, please check your internet connection. + + From 4e8f1a68a0cb9b6130c9781c56654e6d027c7278 Mon Sep 17 00:00:00 2001 From: Boernsman Date: Thu, 22 Oct 2020 12:58:57 +0200 Subject: [PATCH 5/7] moved api key to plug-in setting --- aqi/airqualityindex.cpp | 26 ++-- aqi/airqualityindex.h | 2 +- aqi/integrationpluginaqi.cpp | 55 ++++----- aqi/integrationpluginaqi.h | 1 + aqi/integrationpluginaqi.json | 37 +++--- ...57d69b76-4d2d-41ec-bef6-949a79ffbe6b-de.ts | 116 +++++++++--------- ...69b76-4d2d-41ec-bef6-949a79ffbe6b-en_US.ts | 116 +++++++++--------- 7 files changed, 186 insertions(+), 167 deletions(-) diff --git a/aqi/airqualityindex.cpp b/aqi/airqualityindex.cpp index 9373a2c8..de4481f2 100644 --- a/aqi/airqualityindex.cpp +++ b/aqi/airqualityindex.cpp @@ -52,9 +52,10 @@ void AirQualityIndex::setApiKey(const QString &apiKey) QUuid AirQualityIndex::searchByName(const QString &name) { - if (m_apiKey.isEmpty()) - qCWarning(dcAirQualityIndex()) << "API key is not set"; - + if (m_apiKey.isEmpty()) { + qCWarning(dcAirQualityIndex()) << "API key is not set, not sending request"; + return ""; + } QUuid requestId = QUuid::createUuid();; QUrl url; url.setUrl(m_baseUrl); @@ -116,10 +117,11 @@ QUuid AirQualityIndex::searchByName(const QString &name) QUuid AirQualityIndex::getDataByIp() { - if (m_apiKey.isEmpty()) - qCWarning(dcAirQualityIndex()) << "API key is not set"; - - QUuid requestId = QUuid::createUuid();; + if (m_apiKey.isEmpty()) { + qCWarning(dcAirQualityIndex()) << "API key is not set, not sending request"; + return ""; + } + QUuid requestId = QUuid::createUuid(); QUrl url; url.setUrl(m_baseUrl); url.setPath("/feed/here/"); @@ -151,15 +153,17 @@ QUuid AirQualityIndex::getDataByIp() return requestId; } -QUuid AirQualityIndex::getDataByGeolocation(const QString &lat, const QString &lng) +QUuid AirQualityIndex::getDataByGeolocation(double lat, double lng) { - if (m_apiKey.isEmpty()) - qCWarning(dcAirQualityIndex()) << "API key is not set"; + if (m_apiKey.isEmpty()) { + qCWarning(dcAirQualityIndex()) << "API key is not set, not sending request"; + return ""; + } QUuid requestId = QUuid::createUuid(); QUrl url; url.setUrl(m_baseUrl); - url.setPath("/feed/geo:"+lat+";"+lng+"/"); + url.setPath(QString("/feed/geo:%1;%2/").arg(lat).arg(lng)); QUrlQuery query; query.addQueryItem("token", m_apiKey); url.setQuery(query); diff --git a/aqi/airqualityindex.h b/aqi/airqualityindex.h index fd332c42..79cd1393 100644 --- a/aqi/airqualityindex.h +++ b/aqi/airqualityindex.h @@ -73,7 +73,7 @@ public: void setApiKey(const QString &apiKey); QUuid searchByName(const QString &name); QUuid getDataByIp(); - QUuid getDataByGeolocation(const QString &lat, const QString &lng); + QUuid getDataByGeolocation(double lat, double lng); private: NetworkAccessManager *m_networkAccessManager; diff --git a/aqi/integrationpluginaqi.cpp b/aqi/integrationpluginaqi.cpp index a4283a3e..5c0c836d 100644 --- a/aqi/integrationpluginaqi.cpp +++ b/aqi/integrationpluginaqi.cpp @@ -36,20 +36,21 @@ IntegrationPluginAqi::IntegrationPluginAqi() { + connect(this, &IntegrationPluginAqi::configValueChanged, this, [this] (const ParamTypeId ¶mTypeId, const QVariant &value) { + if (paramTypeId == airQualityIndexPluginApiKeyParamTypeId && m_aqiConnection) { + if (!value.toString().isEmpty()) + m_aqiConnection->setApiKey(value.toString()); + } + }); } void IntegrationPluginAqi::discoverThings(ThingDiscoveryInfo *info) { if (!m_aqiConnection) { - QString apiKey = getApiKey(); - if (apiKey.isEmpty()) + if(createAqiConnection()) { return info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("API key is not available.")); - m_aqiConnection = new AirQualityIndex(hardwareManager()->networkManager(), apiKey, this); - connect(m_aqiConnection, &AirQualityIndex::requestExecuted, this, &IntegrationPluginAqi::onRequestExecuted); - connect(m_aqiConnection, &AirQualityIndex::dataReceived, this, &IntegrationPluginAqi::onAirQualityDataReceived); - connect(m_aqiConnection, &AirQualityIndex::stationsReceived, this, &IntegrationPluginAqi::onAirQualityStationsReceived); - + } connect(info, &ThingDiscoveryInfo::aborted, [this] { if (myThings().filterByThingClassId(airQualityIndexThingClassId).isEmpty()) { m_aqiConnection->deleteLater(); @@ -68,16 +69,11 @@ void IntegrationPluginAqi::setupThing(ThingSetupInfo *info) { if (info->thing()->thingClassId() == airQualityIndexThingClassId) { if (!m_aqiConnection) { - QString apiKey = getApiKey(); - if (apiKey.isEmpty()) + if(createAqiConnection()) { return info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("API key is not available.")); - m_aqiConnection = new AirQualityIndex(hardwareManager()->networkManager(), apiKey, this); - connect(m_aqiConnection, &AirQualityIndex::requestExecuted, this, &IntegrationPluginAqi::onRequestExecuted); - connect(m_aqiConnection, &AirQualityIndex::dataReceived, this, &IntegrationPluginAqi::onAirQualityDataReceived); - connect(m_aqiConnection, &AirQualityIndex::stationsReceived, this, &IntegrationPluginAqi::onAirQualityStationsReceived); - - QString longitude = info->thing()->paramValue(airQualityIndexThingLongitudeParamTypeId).toString(); - QString latitude = info->thing()->paramValue(airQualityIndexThingLatitudeParamTypeId).toString(); + } + double longitude = info->thing()->paramValue(airQualityIndexThingLongitudeParamTypeId).toDouble(); + double latitude = info->thing()->paramValue(airQualityIndexThingLatitudeParamTypeId).toDouble(); QUuid requestId = m_aqiConnection->getDataByGeolocation(latitude, longitude); m_asyncSetups.insert(requestId, info); @@ -108,8 +104,8 @@ void IntegrationPluginAqi::postSetupThing(Thing *thing) return; } - QString longitude = thing->paramValue(airQualityIndexThingLongitudeParamTypeId).toString(); - QString latitude = thing->paramValue(airQualityIndexThingLatitudeParamTypeId).toString(); + double longitude = thing->paramValue(airQualityIndexThingLongitudeParamTypeId).toDouble(); + double latitude = thing->paramValue(airQualityIndexThingLatitudeParamTypeId).toDouble(); QUuid requestId = m_aqiConnection->getDataByGeolocation(latitude, longitude); m_asyncRequests.insert(requestId, thing->id()); } @@ -120,25 +116,22 @@ void IntegrationPluginAqi::postSetupThing(Thing *thing) } } -QString IntegrationPluginAqi::getApiKey() +bool IntegrationPluginAqi::createAqiConnection() { - QString apiKey; - QSettings settings(NymeaSettings::settingsPath() + "/nymead.conf", QSettings::IniFormat); - settings.beginGroup("aqi"); - if (settings.contains("apiKey")) { - apiKey = settings.value("apiKey").toString(); - QString printedCopy = apiKey; - qCDebug(dcAirQualityIndex()) << "Using custom API key:" << printedCopy.replace(printedCopy.length() - 10, 10, "**********"); - } - settings.endGroup(); + QString apiKey = configValue(airQualityIndexPluginApiKeyParamTypeId).toString(); if (apiKey.isEmpty()) { apiKey = apiKeyStorage()->requestKey("aqi").data("apiKey"); } if (apiKey.isEmpty()) { qCWarning(dcAirQualityIndex()) << "Could not find any API key for AQI"; + return false; } - return apiKey; + m_aqiConnection = new AirQualityIndex(hardwareManager()->networkManager(), apiKey, this); + connect(m_aqiConnection, &AirQualityIndex::requestExecuted, this, &IntegrationPluginAqi::onRequestExecuted); + connect(m_aqiConnection, &AirQualityIndex::dataReceived, this, &IntegrationPluginAqi::onAirQualityDataReceived); + connect(m_aqiConnection, &AirQualityIndex::stationsReceived, this, &IntegrationPluginAqi::onAirQualityStationsReceived); + return true; } void IntegrationPluginAqi::thingRemoved(Thing *thing) @@ -239,8 +232,8 @@ void IntegrationPluginAqi::onPluginTimer() foreach (Thing *thing, myThings().filterByThingClassId(airQualityIndexThingClassId)) { - QString longitude = thing->paramValue(airQualityIndexThingLongitudeParamTypeId).toString(); - QString latitude = thing->paramValue(airQualityIndexThingLatitudeParamTypeId).toString(); + double longitude = thing->paramValue(airQualityIndexThingLongitudeParamTypeId).toDouble(); + double latitude = thing->paramValue(airQualityIndexThingLatitudeParamTypeId).toDouble(); QUuid requestId = m_aqiConnection->getDataByGeolocation(latitude, longitude); m_asyncRequests.insert(requestId, thing->id()); } diff --git a/aqi/integrationpluginaqi.h b/aqi/integrationpluginaqi.h index dbda5269..8ca2c2c9 100644 --- a/aqi/integrationpluginaqi.h +++ b/aqi/integrationpluginaqi.h @@ -63,6 +63,7 @@ private: QHash m_asyncSetups; QHash m_asyncRequests; QString getApiKey(); + bool createAqiConnection(); private slots: void onPluginTimer(); diff --git a/aqi/integrationpluginaqi.json b/aqi/integrationpluginaqi.json index 7f8dc6b3..d2f9c138 100644 --- a/aqi/integrationpluginaqi.json +++ b/aqi/integrationpluginaqi.json @@ -2,6 +2,15 @@ "name": "AirQualityIndex", "displayName": "Air quality index", "id": "57d69b76-4d2d-41ec-bef6-949a79ffbe6b", + "paramTypes": [ + { + "id": "b6861adb-7ed5-445f-b500-4df9eab866ef", + "name": "apiKey", + "displayName": "API key", + "type": "QString", + "defaultValue": "" + } + ], "apiKeys": ["aqi"], "vendors": [ { @@ -16,20 +25,20 @@ "interfaces": ["windspeedsensor", "humiditysensor", "pressuresensor", "temperaturesensor", "connectable"], "createMethods": ["discovery", "user"], "paramTypes": [ - { - "id": "afd5803b-6c98-44d7-9f4a-45e91cfb062e", - "name": "latitude", - "displayName": "Latitude", - "type": "QString", - "inputType": "TextLine" - }, - { - "id": "4800d78e-a367-41f7-9bf6-7c81d40ce19a", - "name": "longitude", - "displayName": "Longitude", - "type": "QString", - "inputType": "TextLine" - } + { + "id": "afd5803b-6c98-44d7-9f4a-45e91cfb062e", + "name": "latitude", + "displayName": "Latitude", + "type": "double", + "defaultValue": 0.00 + }, + { + "id": "4800d78e-a367-41f7-9bf6-7c81d40ce19a", + "name": "longitude", + "displayName": "Longitude", + "type": "double", + "defaultValue": 0.00 + } ], "stateTypes": [ { diff --git a/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-de.ts b/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-de.ts index 52781677..b9c20e05 100644 --- a/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-de.ts +++ b/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-de.ts @@ -4,8 +4,14 @@ AirQualityIndex - - + + API key + The name of the ParamType (ThingClass: airQualityIndex, Type: plugin, ID: {b6861adb-7ed5-445f-b500-4df9eab866ef}) + API-Key + + + + Air quality The name of the ParamType (ThingClass: airQualityIndex, EventType: airQuality, ID: {33a3329a-4117-4488-aa18-91c76056ed6e}) ---------- @@ -13,15 +19,15 @@ The name of the StateType ({33a3329a-4117-4488-aa18-91c76056ed6e}) of ThingClass Luftqualität - + Air quality changed The name of the EventType ({33a3329a-4117-4488-aa18-91c76056ed6e}) of ThingClass airQualityIndex Luftqualität geändert - - - + + + Air quality index The name of the ThingClass ({23ea32c9-38b0-4155-bacc-3afa8c09f6ee}) ---------- @@ -31,8 +37,8 @@ The name of the plugin AirQualityIndex ({57d69b76-4d2d-41ec-bef6-949a79ffbe6b})< Air quality index - - + + Carbon monoxide level (CO) The name of the ParamType (ThingClass: airQualityIndex, EventType: co, ID: {54ac72f3-6444-46a8-a43d-210c2a6fbfb5}) ---------- @@ -40,14 +46,14 @@ The name of the StateType ({54ac72f3-6444-46a8-a43d-210c2a6fbfb5}) of ThingClass Kohlenmonoxidgehalt (CO) - + Carbon monoxide level (CO) changed The name of the EventType ({54ac72f3-6444-46a8-a43d-210c2a6fbfb5}) of ThingClass airQualityIndex Kohlenmonoxidgehalt (CO) geändert - - + + Cautionary statement The name of the ParamType (ThingClass: airQualityIndex, EventType: cautionaryStatement, ID: {cfece671-4e88-4c49-9456-e3f8f7c79ab3}) ---------- @@ -55,14 +61,14 @@ The name of the StateType ({cfece671-4e88-4c49-9456-e3f8f7c79ab3}) of ThingClass Warnhinweis - + Cautionary statement changed The name of the EventType ({cfece671-4e88-4c49-9456-e3f8f7c79ab3}) of ThingClass airQualityIndex Warnhinweis geändert - - + + Coarse dust particles pollution level (PM10) The name of the ParamType (ThingClass: airQualityIndex, EventType: pm10, ID: {24b41ec4-e26b-4dfb-b52c-8e2b1bbdafc6}) ---------- @@ -70,14 +76,14 @@ The name of the StateType ({24b41ec4-e26b-4dfb-b52c-8e2b1bbdafc6}) of ThingClass Verschmutzungsgrad der groben Staubpartikel (PM10) - + Coarse dust particles pollution level (PM10) changed The name of the EventType ({24b41ec4-e26b-4dfb-b52c-8e2b1bbdafc6}) of ThingClass airQualityIndex Verschmutzungsgrad der groben Staubpartikel (PM10) geändert - - + + Connected The name of the ParamType (ThingClass: airQualityIndex, EventType: connected, ID: {7b9135cd-2461-4d33-b2b3-3dc600983895}) ---------- @@ -85,14 +91,14 @@ The name of the StateType ({7b9135cd-2461-4d33-b2b3-3dc600983895}) of ThingClass Verbunden - + Connected changed The name of the EventType ({7b9135cd-2461-4d33-b2b3-3dc600983895}) of ThingClass airQualityIndex Verbunden geändert - - + + Fine particles pollution level (PM2.5) The name of the ParamType (ThingClass: airQualityIndex, EventType: pm25, ID: {bc8c4c83-d229-4be4-8732-bc4f2390f399}) ---------- @@ -100,14 +106,14 @@ The name of the StateType ({bc8c4c83-d229-4be4-8732-bc4f2390f399}) of ThingClass Verschmutzungsgrad der Feinstaubpartikel (PM2,5) - + Fine particles pollution level (PM2.5) changed The name of the EventType ({bc8c4c83-d229-4be4-8732-bc4f2390f399}) of ThingClass airQualityIndex Verschmutzungsgrad der Feinstaubpartikel (PM2,5) geändert - - + + Humidity The name of the ParamType (ThingClass: airQualityIndex, EventType: humidity, ID: {4fc45fca-25ab-45a0-b862-817eea1f51e3}) ---------- @@ -115,26 +121,26 @@ The name of the StateType ({4fc45fca-25ab-45a0-b862-817eea1f51e3}) of ThingClass Luftfeuchtigkeit - + Humidity changed The name of the EventType ({4fc45fca-25ab-45a0-b862-817eea1f51e3}) of ThingClass airQualityIndex Luftfeuchtigkeit geändert - + Latitude The name of the ParamType (ThingClass: airQualityIndex, Type: thing, ID: {afd5803b-6c98-44d7-9f4a-45e91cfb062e}) Breitengrad - + Longitude The name of the ParamType (ThingClass: airQualityIndex, Type: thing, ID: {4800d78e-a367-41f7-9bf6-7c81d40ce19a}) Längengrad - - + + Nitrogen Dioxide level (NO2) The name of the ParamType (ThingClass: airQualityIndex, EventType: no2, ID: {6ed6c505-f36e-44c4-a982-f395b04e539b}) ---------- @@ -142,14 +148,14 @@ The name of the StateType ({6ed6c505-f36e-44c4-a982-f395b04e539b}) of ThingClass Stickstoffdioxidgehalt (NO2) - + Nitrogen Dioxide level (NO2) changed The name of the EventType ({6ed6c505-f36e-44c4-a982-f395b04e539b}) of ThingClass airQualityIndex Stickstoffdioxidgehalt (NO2) geändert - - + + Ozone level (O3) The name of the ParamType (ThingClass: airQualityIndex, EventType: o3, ID: {4e88526d-009f-4820-9a84-09b3646d23c9}) ---------- @@ -157,14 +163,14 @@ The name of the StateType ({4e88526d-009f-4820-9a84-09b3646d23c9}) of ThingClass Ozongehalt (O3) - + Ozone level (O3) changed The name of the EventType ({4e88526d-009f-4820-9a84-09b3646d23c9}) of ThingClass airQualityIndex Ozongehalt (O3) geändert - - + + Pressure The name of the ParamType (ThingClass: airQualityIndex, EventType: pressure, ID: {5f799040-08f8-44d1-aa0a-4cab7caad839}) ---------- @@ -172,14 +178,14 @@ The name of the StateType ({5f799040-08f8-44d1-aa0a-4cab7caad839}) of ThingClass Luftdruck - + Pressure changed The name of the EventType ({5f799040-08f8-44d1-aa0a-4cab7caad839}) of ThingClass airQualityIndex Luftdruck - - + + Station name The name of the ParamType (ThingClass: airQualityIndex, EventType: stationName, ID: {8385f3d5-62f7-482e-927c-b5d61a70d607}) ---------- @@ -187,14 +193,14 @@ The name of the StateType ({8385f3d5-62f7-482e-927c-b5d61a70d607}) of ThingClass Stationsname - + Station name changed The name of the EventType ({8385f3d5-62f7-482e-927c-b5d61a70d607}) of ThingClass airQualityIndex Stationsname geändert - - + + Sulfur dioxide level (SO2) The name of the ParamType (ThingClass: airQualityIndex, EventType: so2, ID: {f3a05e65-a9b3-48fd-be43-688d4c293cc9}) ---------- @@ -202,14 +208,14 @@ The name of the StateType ({f3a05e65-a9b3-48fd-be43-688d4c293cc9}) of ThingClass Schwefeldioxidgehalt (SO2) - + Sulfur dioxide level (SO2) changed The name of the EventType ({f3a05e65-a9b3-48fd-be43-688d4c293cc9}) of ThingClass airQualityIndex Schwefeldioxidgehalt (SO2) geändert - - + + Temperature The name of the ParamType (ThingClass: airQualityIndex, EventType: temperature, ID: {94219802-0a82-4761-99b3-c6b6dfc096db}) ---------- @@ -217,14 +223,14 @@ The name of the StateType ({94219802-0a82-4761-99b3-c6b6dfc096db}) of ThingClass Temperatur - + Temperature changed The name of the EventType ({94219802-0a82-4761-99b3-c6b6dfc096db}) of ThingClass airQualityIndex Temperatur geändert - - + + Wind speed The name of the ParamType (ThingClass: airQualityIndex, EventType: windSpeed, ID: {c4366608-2511-428b-964e-2ad9e37f8f3c}) ---------- @@ -232,7 +238,7 @@ The name of the StateType ({c4366608-2511-428b-964e-2ad9e37f8f3c}) of ThingClass Windgeschwindigkeit - + Wind speed changed The name of the EventType ({c4366608-2511-428b-964e-2ad9e37f8f3c}) of ThingClass airQualityIndex Windgeschwindigkeit geändert @@ -241,39 +247,39 @@ The name of the StateType ({c4366608-2511-428b-964e-2ad9e37f8f3c}) of ThingClass IntegrationPluginAqi - + API key is not available. API-Key ist nicht verfügbar. - + None Keine - - + + Active children and adults, and people with respiratory disease, such as asthma, should limit prolonged outdoor exertion. Aktive Kinder und Erwachsene sowie Menschen mit Atemwegserkrankungen wie Asthma sollten eine längere Belastung im Freien begrenzen. - + Active children and adults, and people with respiratory disease, such as asthma, should avoid prolonged outdoor exertion; everyone else, especially children, should limit prolonged outdoor exertion Aktive Kinder und Erwachsene sowie Menschen mit Atemwegserkrankungen wie Asthma sollten eine längere Anstrengung im Freien vermeiden. Alle anderen, insbesondere Kinder, sollten längere Belastungen im Freien begrenzen - + Active children and adults, and people with respiratory disease, such as asthma, should avoid all outdoor exertion; everyone else, especially children, should limit outdoor exertion. Aktive Kinder und Erwachsene sowie Menschen mit Atemwegserkrankungen wie Asthma sollten jede Anstrengung im Freien vermeiden. Alle anderen, insbesondere Kinder, sollten die Anstrengung im Freien einschränken. - + Everyone should avoid all outdoor exertion Jeder sollte jede Anstrengung im Freien vermeiden. - + Air quality index server not available, please check your internet connection. Air quality index Server nicht verfügbar, bitte überprüfe die Internetverbindung. diff --git a/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-en_US.ts b/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-en_US.ts index 97117c6f..5676866d 100644 --- a/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-en_US.ts +++ b/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-en_US.ts @@ -4,8 +4,14 @@ AirQualityIndex - - + + API key + The name of the ParamType (ThingClass: airQualityIndex, Type: plugin, ID: {b6861adb-7ed5-445f-b500-4df9eab866ef}) + + + + + Air quality The name of the ParamType (ThingClass: airQualityIndex, EventType: airQuality, ID: {33a3329a-4117-4488-aa18-91c76056ed6e}) ---------- @@ -13,15 +19,15 @@ The name of the StateType ({33a3329a-4117-4488-aa18-91c76056ed6e}) of ThingClass - + Air quality changed The name of the EventType ({33a3329a-4117-4488-aa18-91c76056ed6e}) of ThingClass airQualityIndex - - - + + + Air quality index The name of the ThingClass ({23ea32c9-38b0-4155-bacc-3afa8c09f6ee}) ---------- @@ -31,8 +37,8 @@ The name of the plugin AirQualityIndex ({57d69b76-4d2d-41ec-bef6-949a79ffbe6b})< - - + + Carbon monoxide level (CO) The name of the ParamType (ThingClass: airQualityIndex, EventType: co, ID: {54ac72f3-6444-46a8-a43d-210c2a6fbfb5}) ---------- @@ -40,14 +46,14 @@ The name of the StateType ({54ac72f3-6444-46a8-a43d-210c2a6fbfb5}) of ThingClass - + Carbon monoxide level (CO) changed The name of the EventType ({54ac72f3-6444-46a8-a43d-210c2a6fbfb5}) of ThingClass airQualityIndex - - + + Cautionary statement The name of the ParamType (ThingClass: airQualityIndex, EventType: cautionaryStatement, ID: {cfece671-4e88-4c49-9456-e3f8f7c79ab3}) ---------- @@ -55,14 +61,14 @@ The name of the StateType ({cfece671-4e88-4c49-9456-e3f8f7c79ab3}) of ThingClass - + Cautionary statement changed The name of the EventType ({cfece671-4e88-4c49-9456-e3f8f7c79ab3}) of ThingClass airQualityIndex - - + + Coarse dust particles pollution level (PM10) The name of the ParamType (ThingClass: airQualityIndex, EventType: pm10, ID: {24b41ec4-e26b-4dfb-b52c-8e2b1bbdafc6}) ---------- @@ -70,14 +76,14 @@ The name of the StateType ({24b41ec4-e26b-4dfb-b52c-8e2b1bbdafc6}) of ThingClass - + Coarse dust particles pollution level (PM10) changed The name of the EventType ({24b41ec4-e26b-4dfb-b52c-8e2b1bbdafc6}) of ThingClass airQualityIndex - - + + Connected The name of the ParamType (ThingClass: airQualityIndex, EventType: connected, ID: {7b9135cd-2461-4d33-b2b3-3dc600983895}) ---------- @@ -85,14 +91,14 @@ The name of the StateType ({7b9135cd-2461-4d33-b2b3-3dc600983895}) of ThingClass - + Connected changed The name of the EventType ({7b9135cd-2461-4d33-b2b3-3dc600983895}) of ThingClass airQualityIndex - - + + Fine particles pollution level (PM2.5) The name of the ParamType (ThingClass: airQualityIndex, EventType: pm25, ID: {bc8c4c83-d229-4be4-8732-bc4f2390f399}) ---------- @@ -100,14 +106,14 @@ The name of the StateType ({bc8c4c83-d229-4be4-8732-bc4f2390f399}) of ThingClass - + Fine particles pollution level (PM2.5) changed The name of the EventType ({bc8c4c83-d229-4be4-8732-bc4f2390f399}) of ThingClass airQualityIndex - - + + Humidity The name of the ParamType (ThingClass: airQualityIndex, EventType: humidity, ID: {4fc45fca-25ab-45a0-b862-817eea1f51e3}) ---------- @@ -115,26 +121,26 @@ The name of the StateType ({4fc45fca-25ab-45a0-b862-817eea1f51e3}) of ThingClass - + Humidity changed The name of the EventType ({4fc45fca-25ab-45a0-b862-817eea1f51e3}) of ThingClass airQualityIndex - + Latitude The name of the ParamType (ThingClass: airQualityIndex, Type: thing, ID: {afd5803b-6c98-44d7-9f4a-45e91cfb062e}) - + Longitude The name of the ParamType (ThingClass: airQualityIndex, Type: thing, ID: {4800d78e-a367-41f7-9bf6-7c81d40ce19a}) - - + + Nitrogen Dioxide level (NO2) The name of the ParamType (ThingClass: airQualityIndex, EventType: no2, ID: {6ed6c505-f36e-44c4-a982-f395b04e539b}) ---------- @@ -142,14 +148,14 @@ The name of the StateType ({6ed6c505-f36e-44c4-a982-f395b04e539b}) of ThingClass - + Nitrogen Dioxide level (NO2) changed The name of the EventType ({6ed6c505-f36e-44c4-a982-f395b04e539b}) of ThingClass airQualityIndex - - + + Ozone level (O3) The name of the ParamType (ThingClass: airQualityIndex, EventType: o3, ID: {4e88526d-009f-4820-9a84-09b3646d23c9}) ---------- @@ -157,14 +163,14 @@ The name of the StateType ({4e88526d-009f-4820-9a84-09b3646d23c9}) of ThingClass - + Ozone level (O3) changed The name of the EventType ({4e88526d-009f-4820-9a84-09b3646d23c9}) of ThingClass airQualityIndex - - + + Pressure The name of the ParamType (ThingClass: airQualityIndex, EventType: pressure, ID: {5f799040-08f8-44d1-aa0a-4cab7caad839}) ---------- @@ -172,14 +178,14 @@ The name of the StateType ({5f799040-08f8-44d1-aa0a-4cab7caad839}) of ThingClass - + Pressure changed The name of the EventType ({5f799040-08f8-44d1-aa0a-4cab7caad839}) of ThingClass airQualityIndex - - + + Station name The name of the ParamType (ThingClass: airQualityIndex, EventType: stationName, ID: {8385f3d5-62f7-482e-927c-b5d61a70d607}) ---------- @@ -187,14 +193,14 @@ The name of the StateType ({8385f3d5-62f7-482e-927c-b5d61a70d607}) of ThingClass - + Station name changed The name of the EventType ({8385f3d5-62f7-482e-927c-b5d61a70d607}) of ThingClass airQualityIndex - - + + Sulfur dioxide level (SO2) The name of the ParamType (ThingClass: airQualityIndex, EventType: so2, ID: {f3a05e65-a9b3-48fd-be43-688d4c293cc9}) ---------- @@ -202,14 +208,14 @@ The name of the StateType ({f3a05e65-a9b3-48fd-be43-688d4c293cc9}) of ThingClass - + Sulfur dioxide level (SO2) changed The name of the EventType ({f3a05e65-a9b3-48fd-be43-688d4c293cc9}) of ThingClass airQualityIndex - - + + Temperature The name of the ParamType (ThingClass: airQualityIndex, EventType: temperature, ID: {94219802-0a82-4761-99b3-c6b6dfc096db}) ---------- @@ -217,14 +223,14 @@ The name of the StateType ({94219802-0a82-4761-99b3-c6b6dfc096db}) of ThingClass - + Temperature changed The name of the EventType ({94219802-0a82-4761-99b3-c6b6dfc096db}) of ThingClass airQualityIndex - - + + Wind speed The name of the ParamType (ThingClass: airQualityIndex, EventType: windSpeed, ID: {c4366608-2511-428b-964e-2ad9e37f8f3c}) ---------- @@ -232,7 +238,7 @@ The name of the StateType ({c4366608-2511-428b-964e-2ad9e37f8f3c}) of ThingClass - + Wind speed changed The name of the EventType ({c4366608-2511-428b-964e-2ad9e37f8f3c}) of ThingClass airQualityIndex @@ -241,39 +247,39 @@ The name of the StateType ({c4366608-2511-428b-964e-2ad9e37f8f3c}) of ThingClass IntegrationPluginAqi - + API key is not available. - + None - - + + Active children and adults, and people with respiratory disease, such as asthma, should limit prolonged outdoor exertion. - + Active children and adults, and people with respiratory disease, such as asthma, should avoid prolonged outdoor exertion; everyone else, especially children, should limit prolonged outdoor exertion - + Active children and adults, and people with respiratory disease, such as asthma, should avoid all outdoor exertion; everyone else, especially children, should limit outdoor exertion. - + Everyone should avoid all outdoor exertion - + Air quality index server not available, please check your internet connection. From 5ffe1000dcb7372242c9eee3733985552e91e16c Mon Sep 17 00:00:00 2001 From: Boernsman Date: Fri, 23 Oct 2020 10:37:28 +0200 Subject: [PATCH 6/7] fixed error with first thing setup --- aqi/README.md | 8 +-- aqi/airqualityindex.cpp | 8 +++ aqi/integrationpluginaqi.cpp | 8 +-- aqi/integrationpluginaqi.json | 2 +- ...57d69b76-4d2d-41ec-bef6-949a79ffbe6b-de.ts | 50 +++++++++---------- ...69b76-4d2d-41ec-bef6-949a79ffbe6b-en_US.ts | 50 +++++++++---------- 6 files changed, 65 insertions(+), 61 deletions(-) diff --git a/aqi/README.md b/aqi/README.md index a58e3a2e..4f75693a 100644 --- a/aqi/README.md +++ b/aqi/README.md @@ -32,16 +32,10 @@ inform you what precautions should be taken. ## Requirements * Valid "Air Quality Index" API Key - * This might be provided through the nymea community API Key provider or an own key in the nymead.conf file. + * This might be provided through the nymea community API Key provider or by setting a custom API Key in the plug-in settings. * The package "nymea-plugin-airqualityindex" must be installed * Internet connection ## More More about the different Air Quality Levels: https://www.airnow.gov/index.cfm?action=aqibasics.aqi - -Personal API Key settings in 'nymead.conf': -''' -[aqi] -apiKey="123456789abcdfgh" -''' diff --git a/aqi/airqualityindex.cpp b/aqi/airqualityindex.cpp index de4481f2..c7837e92 100644 --- a/aqi/airqualityindex.cpp +++ b/aqi/airqualityindex.cpp @@ -202,6 +202,14 @@ bool AirQualityIndex::parseData(QUuid requestId, const QByteArray &data) qCWarning(dcAirQualityIndex()) << "Received invalide JSON object"; return false; } + + if (doc.toVariant().toMap().contains("status")) { + if (doc.toVariant().toMap().value("status") == "error") { + qCWarning(dcAirQualityIndex()) << "Server responded with error:" << doc.toVariant().toMap().value("data").toString(); + return false; + } + } + Station station; station.aqi = doc.toVariant().toMap().value("data").toMap().value("aqi").toInt(); station.idx = doc.toVariant().toMap().value("data").toMap().value("idx").toInt(); diff --git a/aqi/integrationpluginaqi.cpp b/aqi/integrationpluginaqi.cpp index 5c0c836d..a8682103 100644 --- a/aqi/integrationpluginaqi.cpp +++ b/aqi/integrationpluginaqi.cpp @@ -39,8 +39,10 @@ IntegrationPluginAqi::IntegrationPluginAqi() connect(this, &IntegrationPluginAqi::configValueChanged, this, [this] (const ParamTypeId ¶mTypeId, const QVariant &value) { if (paramTypeId == airQualityIndexPluginApiKeyParamTypeId && m_aqiConnection) { - if (!value.toString().isEmpty()) + if (!value.toString().isEmpty()) { + qCDebug(dcAirQualityIndex()) << "Custom API key updated"; m_aqiConnection->setApiKey(value.toString()); + } } }); } @@ -48,7 +50,7 @@ IntegrationPluginAqi::IntegrationPluginAqi() void IntegrationPluginAqi::discoverThings(ThingDiscoveryInfo *info) { if (!m_aqiConnection) { - if(createAqiConnection()) { + if(!createAqiConnection()) { return info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("API key is not available.")); } connect(info, &ThingDiscoveryInfo::aborted, [this] { @@ -69,7 +71,7 @@ void IntegrationPluginAqi::setupThing(ThingSetupInfo *info) { if (info->thing()->thingClassId() == airQualityIndexThingClassId) { if (!m_aqiConnection) { - if(createAqiConnection()) { + if(!createAqiConnection()) { return info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("API key is not available.")); } double longitude = info->thing()->paramValue(airQualityIndexThingLongitudeParamTypeId).toDouble(); diff --git a/aqi/integrationpluginaqi.json b/aqi/integrationpluginaqi.json index d2f9c138..349b79ab 100644 --- a/aqi/integrationpluginaqi.json +++ b/aqi/integrationpluginaqi.json @@ -6,7 +6,7 @@ { "id": "b6861adb-7ed5-445f-b500-4df9eab866ef", "name": "apiKey", - "displayName": "API key", + "displayName": "Custom API key", "type": "QString", "defaultValue": "" } diff --git a/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-de.ts b/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-de.ts index b9c20e05..1a8522dd 100644 --- a/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-de.ts +++ b/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-de.ts @@ -5,13 +5,7 @@ AirQualityIndex - API key - The name of the ParamType (ThingClass: airQualityIndex, Type: plugin, ID: {b6861adb-7ed5-445f-b500-4df9eab866ef}) - API-Key - - - Air quality The name of the ParamType (ThingClass: airQualityIndex, EventType: airQuality, ID: {33a3329a-4117-4488-aa18-91c76056ed6e}) ---------- @@ -19,15 +13,15 @@ The name of the StateType ({33a3329a-4117-4488-aa18-91c76056ed6e}) of ThingClass Luftqualität - + Air quality changed The name of the EventType ({33a3329a-4117-4488-aa18-91c76056ed6e}) of ThingClass airQualityIndex Luftqualität geändert + - Air quality index The name of the ThingClass ({23ea32c9-38b0-4155-bacc-3afa8c09f6ee}) ---------- @@ -37,8 +31,8 @@ The name of the plugin AirQualityIndex ({57d69b76-4d2d-41ec-bef6-949a79ffbe6b})< Air quality index + - Carbon monoxide level (CO) The name of the ParamType (ThingClass: airQualityIndex, EventType: co, ID: {54ac72f3-6444-46a8-a43d-210c2a6fbfb5}) ---------- @@ -46,14 +40,14 @@ The name of the StateType ({54ac72f3-6444-46a8-a43d-210c2a6fbfb5}) of ThingClass Kohlenmonoxidgehalt (CO) - + Carbon monoxide level (CO) changed The name of the EventType ({54ac72f3-6444-46a8-a43d-210c2a6fbfb5}) of ThingClass airQualityIndex Kohlenmonoxidgehalt (CO) geändert + - Cautionary statement The name of the ParamType (ThingClass: airQualityIndex, EventType: cautionaryStatement, ID: {cfece671-4e88-4c49-9456-e3f8f7c79ab3}) ---------- @@ -61,14 +55,14 @@ The name of the StateType ({cfece671-4e88-4c49-9456-e3f8f7c79ab3}) of ThingClass Warnhinweis - + Cautionary statement changed The name of the EventType ({cfece671-4e88-4c49-9456-e3f8f7c79ab3}) of ThingClass airQualityIndex Warnhinweis geändert + - Coarse dust particles pollution level (PM10) The name of the ParamType (ThingClass: airQualityIndex, EventType: pm10, ID: {24b41ec4-e26b-4dfb-b52c-8e2b1bbdafc6}) ---------- @@ -76,14 +70,14 @@ The name of the StateType ({24b41ec4-e26b-4dfb-b52c-8e2b1bbdafc6}) of ThingClass Verschmutzungsgrad der groben Staubpartikel (PM10) - + Coarse dust particles pollution level (PM10) changed The name of the EventType ({24b41ec4-e26b-4dfb-b52c-8e2b1bbdafc6}) of ThingClass airQualityIndex Verschmutzungsgrad der groben Staubpartikel (PM10) geändert + - Connected The name of the ParamType (ThingClass: airQualityIndex, EventType: connected, ID: {7b9135cd-2461-4d33-b2b3-3dc600983895}) ---------- @@ -91,11 +85,17 @@ The name of the StateType ({7b9135cd-2461-4d33-b2b3-3dc600983895}) of ThingClass Verbunden - + Connected changed The name of the EventType ({7b9135cd-2461-4d33-b2b3-3dc600983895}) of ThingClass airQualityIndex Verbunden geändert + + + Custom API key + The name of the ParamType (ThingClass: airQualityIndex, Type: plugin, ID: {b6861adb-7ed5-445f-b500-4df9eab866ef}) + Benutzerdefinierter API Key + @@ -247,39 +247,39 @@ The name of the StateType ({c4366608-2511-428b-964e-2ad9e37f8f3c}) of ThingClass IntegrationPluginAqi - - + + API key is not available. API-Key ist nicht verfügbar. - + None Keine - - + + Active children and adults, and people with respiratory disease, such as asthma, should limit prolonged outdoor exertion. Aktive Kinder und Erwachsene sowie Menschen mit Atemwegserkrankungen wie Asthma sollten eine längere Belastung im Freien begrenzen. - + Active children and adults, and people with respiratory disease, such as asthma, should avoid prolonged outdoor exertion; everyone else, especially children, should limit prolonged outdoor exertion Aktive Kinder und Erwachsene sowie Menschen mit Atemwegserkrankungen wie Asthma sollten eine längere Anstrengung im Freien vermeiden. Alle anderen, insbesondere Kinder, sollten längere Belastungen im Freien begrenzen - + Active children and adults, and people with respiratory disease, such as asthma, should avoid all outdoor exertion; everyone else, especially children, should limit outdoor exertion. Aktive Kinder und Erwachsene sowie Menschen mit Atemwegserkrankungen wie Asthma sollten jede Anstrengung im Freien vermeiden. Alle anderen, insbesondere Kinder, sollten die Anstrengung im Freien einschränken. - + Everyone should avoid all outdoor exertion Jeder sollte jede Anstrengung im Freien vermeiden. - + Air quality index server not available, please check your internet connection. Air quality index Server nicht verfügbar, bitte überprüfe die Internetverbindung. diff --git a/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-en_US.ts b/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-en_US.ts index 5676866d..dee39a99 100644 --- a/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-en_US.ts +++ b/aqi/translations/57d69b76-4d2d-41ec-bef6-949a79ffbe6b-en_US.ts @@ -5,13 +5,7 @@ AirQualityIndex - API key - The name of the ParamType (ThingClass: airQualityIndex, Type: plugin, ID: {b6861adb-7ed5-445f-b500-4df9eab866ef}) - - - - Air quality The name of the ParamType (ThingClass: airQualityIndex, EventType: airQuality, ID: {33a3329a-4117-4488-aa18-91c76056ed6e}) ---------- @@ -19,15 +13,15 @@ The name of the StateType ({33a3329a-4117-4488-aa18-91c76056ed6e}) of ThingClass - + Air quality changed The name of the EventType ({33a3329a-4117-4488-aa18-91c76056ed6e}) of ThingClass airQualityIndex + - Air quality index The name of the ThingClass ({23ea32c9-38b0-4155-bacc-3afa8c09f6ee}) ---------- @@ -37,8 +31,8 @@ The name of the plugin AirQualityIndex ({57d69b76-4d2d-41ec-bef6-949a79ffbe6b})< + - Carbon monoxide level (CO) The name of the ParamType (ThingClass: airQualityIndex, EventType: co, ID: {54ac72f3-6444-46a8-a43d-210c2a6fbfb5}) ---------- @@ -46,14 +40,14 @@ The name of the StateType ({54ac72f3-6444-46a8-a43d-210c2a6fbfb5}) of ThingClass - + Carbon monoxide level (CO) changed The name of the EventType ({54ac72f3-6444-46a8-a43d-210c2a6fbfb5}) of ThingClass airQualityIndex + - Cautionary statement The name of the ParamType (ThingClass: airQualityIndex, EventType: cautionaryStatement, ID: {cfece671-4e88-4c49-9456-e3f8f7c79ab3}) ---------- @@ -61,14 +55,14 @@ The name of the StateType ({cfece671-4e88-4c49-9456-e3f8f7c79ab3}) of ThingClass - + Cautionary statement changed The name of the EventType ({cfece671-4e88-4c49-9456-e3f8f7c79ab3}) of ThingClass airQualityIndex + - Coarse dust particles pollution level (PM10) The name of the ParamType (ThingClass: airQualityIndex, EventType: pm10, ID: {24b41ec4-e26b-4dfb-b52c-8e2b1bbdafc6}) ---------- @@ -76,14 +70,14 @@ The name of the StateType ({24b41ec4-e26b-4dfb-b52c-8e2b1bbdafc6}) of ThingClass - + Coarse dust particles pollution level (PM10) changed The name of the EventType ({24b41ec4-e26b-4dfb-b52c-8e2b1bbdafc6}) of ThingClass airQualityIndex + - Connected The name of the ParamType (ThingClass: airQualityIndex, EventType: connected, ID: {7b9135cd-2461-4d33-b2b3-3dc600983895}) ---------- @@ -91,11 +85,17 @@ The name of the StateType ({7b9135cd-2461-4d33-b2b3-3dc600983895}) of ThingClass - + Connected changed The name of the EventType ({7b9135cd-2461-4d33-b2b3-3dc600983895}) of ThingClass airQualityIndex + + + Custom API key + The name of the ParamType (ThingClass: airQualityIndex, Type: plugin, ID: {b6861adb-7ed5-445f-b500-4df9eab866ef}) + + @@ -247,39 +247,39 @@ The name of the StateType ({c4366608-2511-428b-964e-2ad9e37f8f3c}) of ThingClass IntegrationPluginAqi - - + + API key is not available. - + None - - + + Active children and adults, and people with respiratory disease, such as asthma, should limit prolonged outdoor exertion. - + Active children and adults, and people with respiratory disease, such as asthma, should avoid prolonged outdoor exertion; everyone else, especially children, should limit prolonged outdoor exertion - + Active children and adults, and people with respiratory disease, such as asthma, should avoid all outdoor exertion; everyone else, especially children, should limit outdoor exertion. - + Everyone should avoid all outdoor exertion - + Air quality index server not available, please check your internet connection. From 33a254df9cae2a31d221ed43721f4e0c66574836 Mon Sep 17 00:00:00 2001 From: Boernsman Date: Mon, 2 Nov 2020 12:12:41 +0100 Subject: [PATCH 7/7] fixed custom key removal --- aqi/integrationpluginaqi.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/aqi/integrationpluginaqi.cpp b/aqi/integrationpluginaqi.cpp index a8682103..4acb1528 100644 --- a/aqi/integrationpluginaqi.cpp +++ b/aqi/integrationpluginaqi.cpp @@ -42,6 +42,14 @@ IntegrationPluginAqi::IntegrationPluginAqi() if (!value.toString().isEmpty()) { qCDebug(dcAirQualityIndex()) << "Custom API key updated"; m_aqiConnection->setApiKey(value.toString()); + } else { + qCDebug(dcAirQualityIndex()) << "Custom API key has been deleted"; + QString apiKey = apiKeyStorage()->requestKey("aqi").data("apiKey"); + if (apiKey.isEmpty()) { + qCWarning(dcApiKeys()) << "No API Key is available, keeping the AQI connection as it is"; + } else { + m_aqiConnection->setApiKey(apiKey); + } } } }); @@ -233,7 +241,6 @@ void IntegrationPluginAqi::onPluginTimer() return; foreach (Thing *thing, myThings().filterByThingClassId(airQualityIndexThingClassId)) { - double longitude = thing->paramValue(airQualityIndexThingLongitudeParamTypeId).toDouble(); double latitude = thing->paramValue(airQualityIndexThingLatitudeParamTypeId).toDouble(); QUuid requestId = m_aqiConnection->getDataByGeolocation(latitude, longitude); @@ -247,6 +254,10 @@ void IntegrationPluginAqi::onRequestExecuted(QUuid requestId, bool success) if (m_asyncDiscovery.contains(requestId) && !success) { ThingDiscoveryInfo *info = m_asyncDiscovery.take(requestId); info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("Air quality index server not available, please check your internet connection.")); + if (myThings().filterByThingClassId(airQualityIndexThingClassId).isEmpty() && m_aqiConnection) { + m_aqiConnection->deleteLater(); + m_aqiConnection = nullptr; + } } if (m_asyncRequests.contains(requestId)) {