added api key provider and custom api key plugin settings
This commit is contained in:
parent
78b0e9a047
commit
fba67dbd3b
@ -42,6 +42,15 @@ IntegrationPluginNetatmo::IntegrationPluginNetatmo()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IntegrationPluginNetatmo::init()
|
||||||
|
{
|
||||||
|
updateClientCredentials();
|
||||||
|
|
||||||
|
connect(this, &IntegrationPlugin::configValueChanged, this, &IntegrationPluginNetatmo::updateClientCredentials);
|
||||||
|
connect(apiKeyStorage(), &ApiKeyStorage::keyAdded, this, &IntegrationPluginNetatmo::updateClientCredentials);
|
||||||
|
connect(apiKeyStorage(), &ApiKeyStorage::keyUpdated, this, &IntegrationPluginNetatmo::updateClientCredentials);
|
||||||
|
}
|
||||||
|
|
||||||
void IntegrationPluginNetatmo::startPairing(ThingPairingInfo *info)
|
void IntegrationPluginNetatmo::startPairing(ThingPairingInfo *info)
|
||||||
{
|
{
|
||||||
// Checking the internet connection
|
// Checking the internet connection
|
||||||
@ -61,7 +70,11 @@ void IntegrationPluginNetatmo::startPairing(ThingPairingInfo *info)
|
|||||||
|
|
||||||
void IntegrationPluginNetatmo::confirmPairing(ThingPairingInfo *info, const QString &username, const QString &password)
|
void IntegrationPluginNetatmo::confirmPairing(ThingPairingInfo *info, const QString &username, const QString &password)
|
||||||
{
|
{
|
||||||
OAuth2 *authentication = new OAuth2("561c015d49c75f0d1cce6e13", "GuvKkdtu7JQlPD47qTTepRR9hQ0CUPAj4Tae3Ohcq", this);
|
if (m_clientId.isEmpty() || m_clientSecret.isEmpty()) {
|
||||||
|
info->finish(Thing::ThingErrorAuthenticationFailure, QT_TR_NOOP("Error, client credentials are not set."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
OAuth2 *authentication = new OAuth2(m_clientId, m_clientSecret, this);
|
||||||
authentication->setUrl(QUrl("https://api.netatmo.net/oauth2/token"));
|
authentication->setUrl(QUrl("https://api.netatmo.net/oauth2/token"));
|
||||||
authentication->setUsername(username);
|
authentication->setUsername(username);
|
||||||
authentication->setPassword(password);
|
authentication->setPassword(password);
|
||||||
@ -124,7 +137,11 @@ void IntegrationPluginNetatmo::setupThing(ThingSetupInfo *info)
|
|||||||
authentication->setUsername(username);
|
authentication->setUsername(username);
|
||||||
authentication->setPassword(password);
|
authentication->setPassword(password);
|
||||||
} else {
|
} else {
|
||||||
authentication = new OAuth2("561c015d49c75f0d1cce6e13", "GuvKkdtu7JQlPD47qTTepRR9hQ0CUPAj4Tae3Ohcq", this);
|
if (m_clientId.isEmpty() || m_clientSecret.isEmpty()) {
|
||||||
|
info->finish(Thing::ThingErrorAuthenticationFailure, QT_TR_NOOP("Error, client credentials are not set."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
authentication = new OAuth2(m_clientId, m_clientSecret, this);
|
||||||
authentication->setUrl(QUrl("https://api.netatmo.net/oauth2/token"));
|
authentication->setUrl(QUrl("https://api.netatmo.net/oauth2/token"));
|
||||||
authentication->setUsername(username);
|
authentication->setUsername(username);
|
||||||
authentication->setPassword(password);
|
authentication->setPassword(password);
|
||||||
@ -410,3 +427,25 @@ void IntegrationPluginNetatmo::onOutdoorStatesChanged()
|
|||||||
thing->setStateValue(outdoorBatteryLevelStateTypeId, outdoor->battery());
|
thing->setStateValue(outdoorBatteryLevelStateTypeId, outdoor->battery());
|
||||||
thing->setStateValue(outdoorBatteryCriticalStateTypeId, outdoor->battery() < 10);
|
thing->setStateValue(outdoorBatteryCriticalStateTypeId, outdoor->battery() < 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IntegrationPluginNetatmo::updateClientCredentials()
|
||||||
|
{
|
||||||
|
QString clientId = configValue(netatmoPluginCustomClientIdParamTypeId).toString();
|
||||||
|
QString clientSecret = configValue(netatmoPluginCustomClientSecretParamTypeId).toString();
|
||||||
|
if (!clientId.isEmpty() && !clientSecret.isEmpty()) {
|
||||||
|
qCDebug(dcNetatmo()) << "Using API key from plugin settings.";
|
||||||
|
m_clientId = clientId;
|
||||||
|
m_clientSecret = clientSecret;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
clientId = apiKeyStorage()->requestKey("netatmo").data("clientId");
|
||||||
|
clientId = apiKeyStorage()->requestKey("netatmo").data("clientSecret");
|
||||||
|
if (!clientId.isEmpty() && !clientSecret.isEmpty()) {
|
||||||
|
qCDebug(dcNetatmo()) << "Using API key from nymea API keys provider";
|
||||||
|
m_clientId = clientId;
|
||||||
|
m_clientSecret = clientSecret;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
qCWarning(dcNetatmo()) << "No API key set.";
|
||||||
|
qCWarning(dcNetatmo()) << "Either install an API key pacakge (nymea-apikeysprovider-plugin-*) or provide a key in the plugin settings.";
|
||||||
|
}
|
||||||
|
|||||||
@ -48,7 +48,7 @@ class IntegrationPluginNetatmo : public IntegrationPlugin
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit IntegrationPluginNetatmo();
|
explicit IntegrationPluginNetatmo();
|
||||||
|
void init() override;
|
||||||
void startPairing(ThingPairingInfo *info) override;
|
void startPairing(ThingPairingInfo *info) override;
|
||||||
void confirmPairing(ThingPairingInfo *info, const QString &username, const QString &secret) override;
|
void confirmPairing(ThingPairingInfo *info, const QString &username, const QString &secret) override;
|
||||||
void setupThing(ThingSetupInfo *info) override;
|
void setupThing(ThingSetupInfo *info) override;
|
||||||
@ -73,10 +73,14 @@ private:
|
|||||||
Thing *findIndoorDevice(const QString &macAddress);
|
Thing *findIndoorDevice(const QString &macAddress);
|
||||||
Thing *findOutdoorDevice(const QString &macAddress);
|
Thing *findOutdoorDevice(const QString &macAddress);
|
||||||
|
|
||||||
|
QString m_clientId;
|
||||||
|
QString m_clientSecret;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onPluginTimer();
|
void onPluginTimer();
|
||||||
void onIndoorStatesChanged();
|
void onIndoorStatesChanged();
|
||||||
void onOutdoorStatesChanged();
|
void onOutdoorStatesChanged();
|
||||||
|
void updateClientCredentials();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // INTEGRATIONPLUGINNETATMO_H
|
#endif // INTEGRATIONPLUGINNETATMO_H
|
||||||
|
|||||||
@ -2,6 +2,23 @@
|
|||||||
"displayName": "Netatmo",
|
"displayName": "Netatmo",
|
||||||
"name": "Netatmo",
|
"name": "Netatmo",
|
||||||
"id": "69d14951-0c02-4877-bcef-dffdf48b7ccb",
|
"id": "69d14951-0c02-4877-bcef-dffdf48b7ccb",
|
||||||
|
"apiKeys": ["netatmo"],
|
||||||
|
"paramTypes": [
|
||||||
|
{
|
||||||
|
"id": "fbda653d-d59e-438c-a70c-0ccbe8080215",
|
||||||
|
"name": "customClientId",
|
||||||
|
"displayName": "Custom client id",
|
||||||
|
"type": "QString",
|
||||||
|
"defaultValue": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "06439e1e-da15-4483-8737-0a6aa967c479",
|
||||||
|
"name": "customClientSecret",
|
||||||
|
"displayName": "Custom client secret",
|
||||||
|
"type": "QString",
|
||||||
|
"defaultValue": ""
|
||||||
|
}
|
||||||
|
],
|
||||||
"vendors": [
|
"vendors": [
|
||||||
{
|
{
|
||||||
"displayName": "Netatmo",
|
"displayName": "Netatmo",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user