added userandpassword setup method
This commit is contained in:
parent
ac6dcf0765
commit
275f598f29
@ -52,6 +52,31 @@ void IntegrationPluginNetatmo::init()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IntegrationPluginNetatmo::startPairing(ThingPairingInfo *info)
|
||||||
|
{
|
||||||
|
info->finish(Thing::ThingErrorNoError, QT_TR_NOOP("Please enter the login credentials for your Netatmo account."));
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntegrationPluginNetatmo::confirmPairing(ThingPairingInfo *info, const QString &username, const QString &password)
|
||||||
|
{
|
||||||
|
OAuth2 *authentication = new OAuth2("561c015d49c75f0d1cce6e13", "GuvKkdtu7JQlPD47qTTepRR9hQ0CUPAj4Tae3Ohcq", this);
|
||||||
|
authentication->setUrl(QUrl("https://api.netatmo.net/oauth2/token"));
|
||||||
|
authentication->setUsername(username);
|
||||||
|
authentication->setPassword(password);
|
||||||
|
authentication->setScope("read_station read_thermostat write_thermostat");
|
||||||
|
|
||||||
|
// Update thing connected state based on OAuth connected state
|
||||||
|
connect(authentication, &OAuth2::authenticationChanged, info, [info, authentication](){
|
||||||
|
if (authentication->authenticated()) {
|
||||||
|
info->finish(Thing::ThingErrorNoError);
|
||||||
|
} else {
|
||||||
|
info->finish(Thing::ThingErrorAuthenticationFailure, "Wrong username of password");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
authentication->startAuthentication();
|
||||||
|
connect(info, &QObject::destroyed, authentication, &OAuth2::deleteLater);
|
||||||
|
}
|
||||||
|
|
||||||
void IntegrationPluginNetatmo::setupThing(ThingSetupInfo *info)
|
void IntegrationPluginNetatmo::setupThing(ThingSetupInfo *info)
|
||||||
{
|
{
|
||||||
Thing *thing = info->thing();
|
Thing *thing = info->thing();
|
||||||
@ -64,10 +89,26 @@ void IntegrationPluginNetatmo::setupThing(ThingSetupInfo *info)
|
|||||||
connect(m_pluginTimer, &PluginTimer::timeout, this, &IntegrationPluginNetatmo::onPluginTimer);
|
connect(m_pluginTimer, &PluginTimer::timeout, this, &IntegrationPluginNetatmo::onPluginTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString username;
|
||||||
|
QString password;
|
||||||
|
|
||||||
|
ParamTypeId usernameParamTypeId = ParamTypeId("763c2c10-dee5-41c8-9f7e-ded741945e73");
|
||||||
|
ParamTypeId passwordParamTypeId = ParamTypeId("c0d892d6-f359-4782-9d7d-8f74a3b53e3e");
|
||||||
|
|
||||||
|
if (pluginStorage()->childGroups().contains(thing->id().toString())) {
|
||||||
|
pluginStorage()->beginGroup(thing->id().toString());
|
||||||
|
username = pluginStorage()->value("username").toString();
|
||||||
|
password = pluginStorage()->value("password").toString();
|
||||||
|
pluginStorage()->endGroup();
|
||||||
|
} else {
|
||||||
|
username = thing->paramValue(usernameParamTypeId).toString();
|
||||||
|
password = thing->paramValue(passwordParamTypeId).toString();
|
||||||
|
}
|
||||||
|
|
||||||
OAuth2 *authentication = new OAuth2("561c015d49c75f0d1cce6e13", "GuvKkdtu7JQlPD47qTTepRR9hQ0CUPAj4Tae3Ohcq", this);
|
OAuth2 *authentication = new OAuth2("561c015d49c75f0d1cce6e13", "GuvKkdtu7JQlPD47qTTepRR9hQ0CUPAj4Tae3Ohcq", this);
|
||||||
authentication->setUrl(QUrl("https://api.netatmo.net/oauth2/token"));
|
authentication->setUrl(QUrl("https://api.netatmo.net/oauth2/token"));
|
||||||
authentication->setUsername(thing->paramValue(netatmoConnectionThingUsernameParamTypeId).toString());
|
authentication->setUsername(username);
|
||||||
authentication->setPassword(thing->paramValue(netatmoConnectionThingPasswordParamTypeId).toString());
|
authentication->setPassword(password);
|
||||||
authentication->setScope("read_station read_thermostat write_thermostat");
|
authentication->setScope("read_station read_thermostat write_thermostat");
|
||||||
m_authentications.insert(authentication, thing);
|
m_authentications.insert(authentication, thing);
|
||||||
|
|
||||||
@ -78,7 +119,6 @@ void IntegrationPluginNetatmo::setupThing(ThingSetupInfo *info)
|
|||||||
refreshData(thing, authentication->token());
|
refreshData(thing, authentication->token());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
authentication->startAuthentication();
|
authentication->startAuthentication();
|
||||||
|
|
||||||
// Report thing setup finished when authentication reports success
|
// Report thing setup finished when authentication reports success
|
||||||
|
|||||||
@ -51,6 +51,8 @@ public:
|
|||||||
~IntegrationPluginNetatmo();
|
~IntegrationPluginNetatmo();
|
||||||
|
|
||||||
void init() override;
|
void init() override;
|
||||||
|
void startPairing(ThingPairingInfo *info) override;
|
||||||
|
void confirmPairing(ThingPairingInfo *info, const QString &username, const QString &secret) override;
|
||||||
void setupThing(ThingSetupInfo *info) override;
|
void setupThing(ThingSetupInfo *info) override;
|
||||||
void thingRemoved(Thing *thing) override;
|
void thingRemoved(Thing *thing) override;
|
||||||
void postSetupThing(Thing *thing) override;
|
void postSetupThing(Thing *thing) override;
|
||||||
|
|||||||
@ -13,29 +13,14 @@
|
|||||||
"name": "netatmoConnection",
|
"name": "netatmoConnection",
|
||||||
"displayName": "Netatmo Connection",
|
"displayName": "Netatmo Connection",
|
||||||
"interfaces": ["gateway"],
|
"interfaces": ["gateway"],
|
||||||
|
"setupMethod": "userandpassword",
|
||||||
"createMethods": ["user"],
|
"createMethods": ["user"],
|
||||||
"paramTypes": [
|
|
||||||
{
|
|
||||||
"id": "763c2c10-dee5-41c8-9f7e-ded741945e73",
|
|
||||||
"name": "username",
|
|
||||||
"displayName": "username",
|
|
||||||
"type": "QString",
|
|
||||||
"inputType": "TextLine"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "c0d892d6-f359-4782-9d7d-8f74a3b53e3e",
|
|
||||||
"name": "password",
|
|
||||||
"displayName": "password",
|
|
||||||
"type": "QString",
|
|
||||||
"inputType": "Password"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"stateTypes": [
|
"stateTypes": [
|
||||||
{
|
{
|
||||||
"id": "2f79bc1d-27ed-480a-b583-728363c83ea6",
|
"id": "2f79bc1d-27ed-480a-b583-728363c83ea6",
|
||||||
"name": "connected",
|
"name": "connected",
|
||||||
"displayName": "available",
|
"displayName": "Available",
|
||||||
"displayNameEvent": "available changed",
|
"displayNameEvent": "Available changed",
|
||||||
"type": "bool",
|
"type": "bool",
|
||||||
"defaultValue": false
|
"defaultValue": false
|
||||||
}
|
}
|
||||||
@ -58,7 +43,7 @@
|
|||||||
{
|
{
|
||||||
"id": "157d470a-e579-4d0e-b879-6b5bfa8e34ae",
|
"id": "157d470a-e579-4d0e-b879-6b5bfa8e34ae",
|
||||||
"name": "mac",
|
"name": "mac",
|
||||||
"displayName": "mac address",
|
"displayName": "MAC Address",
|
||||||
"type": "QString",
|
"type": "QString",
|
||||||
"inputType": "TextLine",
|
"inputType": "TextLine",
|
||||||
"readOnly": true
|
"readOnly": true
|
||||||
@ -68,8 +53,8 @@
|
|||||||
{
|
{
|
||||||
"id": "50da9f6b-c350-401c-a72e-2e4036f3975d",
|
"id": "50da9f6b-c350-401c-a72e-2e4036f3975d",
|
||||||
"name": "updateTime",
|
"name": "updateTime",
|
||||||
"displayName": "last update",
|
"displayName": "Last update",
|
||||||
"displayNameEvent": "last update changed",
|
"displayNameEvent": "Last update changed",
|
||||||
"unit": "UnixTime",
|
"unit": "UnixTime",
|
||||||
"type": "int",
|
"type": "int",
|
||||||
"defaultValue": 0
|
"defaultValue": 0
|
||||||
@ -77,8 +62,8 @@
|
|||||||
{
|
{
|
||||||
"id": "3cb25538-e463-40ae-92f9-8f34f0c06b92",
|
"id": "3cb25538-e463-40ae-92f9-8f34f0c06b92",
|
||||||
"name": "temperature",
|
"name": "temperature",
|
||||||
"displayName": "temperature",
|
"displayName": "Temperature",
|
||||||
"displayNameEvent": "temperature changed",
|
"displayNameEvent": "Temperature changed",
|
||||||
"unit": "DegreeCelsius",
|
"unit": "DegreeCelsius",
|
||||||
"type": "double",
|
"type": "double",
|
||||||
"defaultValue": 0
|
"defaultValue": 0
|
||||||
@ -86,8 +71,8 @@
|
|||||||
{
|
{
|
||||||
"id": "ae8bb713-8805-4efd-89a1-bca44a1f1690",
|
"id": "ae8bb713-8805-4efd-89a1-bca44a1f1690",
|
||||||
"name": "temperatureMin",
|
"name": "temperatureMin",
|
||||||
"displayName": "temperature minimum",
|
"displayName": "Temperature minimum",
|
||||||
"displayNameEvent": "temperature minimum changed",
|
"displayNameEvent": "Temperature minimum changed",
|
||||||
"unit": "DegreeCelsius",
|
"unit": "DegreeCelsius",
|
||||||
"type": "double",
|
"type": "double",
|
||||||
"defaultValue": 0
|
"defaultValue": 0
|
||||||
@ -95,8 +80,8 @@
|
|||||||
{
|
{
|
||||||
"id": "dd30507e-037b-4c74-bcca-e04b94c7c5fe",
|
"id": "dd30507e-037b-4c74-bcca-e04b94c7c5fe",
|
||||||
"name": "temperatureMax",
|
"name": "temperatureMax",
|
||||||
"displayName": "temperature maximum",
|
"displayName": "Temperature maximum",
|
||||||
"displayNameEvent": "temperature maximum changed",
|
"displayNameEvent": "Temperature maximum changed",
|
||||||
"unit": "DegreeCelsius",
|
"unit": "DegreeCelsius",
|
||||||
"type": "double",
|
"type": "double",
|
||||||
"defaultValue": 0
|
"defaultValue": 0
|
||||||
@ -104,8 +89,8 @@
|
|||||||
{
|
{
|
||||||
"id": "e2db5f01-196a-48d1-8874-6b8cbfe0d8c9",
|
"id": "e2db5f01-196a-48d1-8874-6b8cbfe0d8c9",
|
||||||
"name": "humidity",
|
"name": "humidity",
|
||||||
"displayName": "humidity",
|
"displayName": "Humidity",
|
||||||
"displayNameEvent": "humidity changed",
|
"displayNameEvent": "Humidity changed",
|
||||||
"unit": "Percentage",
|
"unit": "Percentage",
|
||||||
"type": "double",
|
"type": "double",
|
||||||
"defaultValue": 0,
|
"defaultValue": 0,
|
||||||
@ -115,8 +100,8 @@
|
|||||||
{
|
{
|
||||||
"id": "03b0a7b7-987d-4d3b-b3f0-21d9f92ad326",
|
"id": "03b0a7b7-987d-4d3b-b3f0-21d9f92ad326",
|
||||||
"name": "pressure",
|
"name": "pressure",
|
||||||
"displayName": "pressure",
|
"displayName": "Pressure",
|
||||||
"displayNameEvent": "pressure changed",
|
"displayNameEvent": "Pressure changed",
|
||||||
"unit": "MilliBar",
|
"unit": "MilliBar",
|
||||||
"type": "double",
|
"type": "double",
|
||||||
"defaultValue": 0
|
"defaultValue": 0
|
||||||
@ -124,8 +109,8 @@
|
|||||||
{
|
{
|
||||||
"id": "906cea9d-1daf-4e9c-90b9-e40f43052a34",
|
"id": "906cea9d-1daf-4e9c-90b9-e40f43052a34",
|
||||||
"name": "noise",
|
"name": "noise",
|
||||||
"displayName": "noise",
|
"displayName": "Noise",
|
||||||
"displayNameEvent": "noise changed",
|
"displayNameEvent": "Noise changed",
|
||||||
"unit": "Dezibel",
|
"unit": "Dezibel",
|
||||||
"type": "double",
|
"type": "double",
|
||||||
"defaultValue": 0
|
"defaultValue": 0
|
||||||
@ -133,8 +118,8 @@
|
|||||||
{
|
{
|
||||||
"id": "e5710bd1-79fa-4bd4-9052-8416aae909b9",
|
"id": "e5710bd1-79fa-4bd4-9052-8416aae909b9",
|
||||||
"name": "co2",
|
"name": "co2",
|
||||||
"displayName": "co2",
|
"displayName": "CO2",
|
||||||
"displayNameEvent": "co2 changed",
|
"displayNameEvent": "CO2 changed",
|
||||||
"unit": "PartsPerMillion",
|
"unit": "PartsPerMillion",
|
||||||
"type": "double",
|
"type": "double",
|
||||||
"defaultValue": 0
|
"defaultValue": 0
|
||||||
@ -142,8 +127,8 @@
|
|||||||
{
|
{
|
||||||
"id": "6ea906d4-5740-454d-a730-6fdb9fa0d624",
|
"id": "6ea906d4-5740-454d-a730-6fdb9fa0d624",
|
||||||
"name": "wifiStrength",
|
"name": "wifiStrength",
|
||||||
"displayName": "wifi signal strength",
|
"displayName": "WiFi signal strength",
|
||||||
"displayNameEvent": "wifi signal strength changed",
|
"displayNameEvent": "WiFi signal strength changed",
|
||||||
"unit": "Percentage",
|
"unit": "Percentage",
|
||||||
"type": "int",
|
"type": "int",
|
||||||
"defaultValue": 0
|
"defaultValue": 0
|
||||||
@ -167,7 +152,7 @@
|
|||||||
{
|
{
|
||||||
"id": "73a76c5c-84f5-4e65-8541-457e5aca9bb0",
|
"id": "73a76c5c-84f5-4e65-8541-457e5aca9bb0",
|
||||||
"name": "mac",
|
"name": "mac",
|
||||||
"displayName": "mac address",
|
"displayName": "MAC Address",
|
||||||
"type": "QString",
|
"type": "QString",
|
||||||
"inputType": "TextLine",
|
"inputType": "TextLine",
|
||||||
"readOnly": true
|
"readOnly": true
|
||||||
@ -175,7 +160,7 @@
|
|||||||
{
|
{
|
||||||
"id": "d7a0ec46-760c-4fdc-9753-fe10c86fe1b9",
|
"id": "d7a0ec46-760c-4fdc-9753-fe10c86fe1b9",
|
||||||
"name": "baseStation",
|
"name": "baseStation",
|
||||||
"displayName": "base station",
|
"displayName": "Base station",
|
||||||
"type": "QString",
|
"type": "QString",
|
||||||
"inputType": "TextLine",
|
"inputType": "TextLine",
|
||||||
"readOnly": true
|
"readOnly": true
|
||||||
@ -185,8 +170,8 @@
|
|||||||
{
|
{
|
||||||
"id": "154aad5c-4998-43c2-b9ee-0b997eb6dd69",
|
"id": "154aad5c-4998-43c2-b9ee-0b997eb6dd69",
|
||||||
"name": "updateTime",
|
"name": "updateTime",
|
||||||
"displayName": "last update",
|
"displayName": "Last update",
|
||||||
"displayNameEvent": "last update changed",
|
"displayNameEvent": "Last update changed",
|
||||||
"unit": "UnixTime",
|
"unit": "UnixTime",
|
||||||
"type": "int",
|
"type": "int",
|
||||||
"defaultValue": 0
|
"defaultValue": 0
|
||||||
@ -194,8 +179,8 @@
|
|||||||
{
|
{
|
||||||
"id": "f98776bd-887e-4b01-a87f-3d8224180563",
|
"id": "f98776bd-887e-4b01-a87f-3d8224180563",
|
||||||
"name": "temperature",
|
"name": "temperature",
|
||||||
"displayName": "temperature",
|
"displayName": "Temperature",
|
||||||
"displayNameEvent": "temperature changed",
|
"displayNameEvent": "Temperature changed",
|
||||||
"unit": "DegreeCelsius",
|
"unit": "DegreeCelsius",
|
||||||
"type": "double",
|
"type": "double",
|
||||||
"defaultValue": 0
|
"defaultValue": 0
|
||||||
@ -203,8 +188,8 @@
|
|||||||
{
|
{
|
||||||
"id": "b71e0c8b-3c94-421e-830e-dab97b6c104e",
|
"id": "b71e0c8b-3c94-421e-830e-dab97b6c104e",
|
||||||
"name": "temperatureMin",
|
"name": "temperatureMin",
|
||||||
"displayName": "temperature minimum",
|
"displayName": "Temperature minimum",
|
||||||
"displayNameEvent": "temperature minimum changed",
|
"displayNameEvent": "Temperature minimum changed",
|
||||||
"unit": "DegreeCelsius",
|
"unit": "DegreeCelsius",
|
||||||
"type": "double",
|
"type": "double",
|
||||||
"defaultValue": 0
|
"defaultValue": 0
|
||||||
@ -212,8 +197,8 @@
|
|||||||
{
|
{
|
||||||
"id": "aae071dc-70d5-4a6a-8daa-3dca0d150bd7",
|
"id": "aae071dc-70d5-4a6a-8daa-3dca0d150bd7",
|
||||||
"name": "temperatureMax",
|
"name": "temperatureMax",
|
||||||
"displayName": "temperature maximum",
|
"displayName": "Temperature maximum",
|
||||||
"displayNameEvent": "temperature maximum changed",
|
"displayNameEvent": "Temperature maximum changed",
|
||||||
"unit": "DegreeCelsius",
|
"unit": "DegreeCelsius",
|
||||||
"type": "double",
|
"type": "double",
|
||||||
"defaultValue": 0
|
"defaultValue": 0
|
||||||
@ -221,8 +206,8 @@
|
|||||||
{
|
{
|
||||||
"id": "7ba6ddeb-5142-4b87-9729-487fcda394df",
|
"id": "7ba6ddeb-5142-4b87-9729-487fcda394df",
|
||||||
"name": "humidity",
|
"name": "humidity",
|
||||||
"displayName": "humidity",
|
"displayName": "Humidity",
|
||||||
"displayNameEvent": "humidity changed",
|
"displayNameEvent": "Humidity changed",
|
||||||
"unit": "Percentage",
|
"unit": "Percentage",
|
||||||
"type": "double",
|
"type": "double",
|
||||||
"defaultValue": 0,
|
"defaultValue": 0,
|
||||||
@ -232,8 +217,8 @@
|
|||||||
{
|
{
|
||||||
"id": "0faa3d08-9004-46fb-a5aa-a59b75e454cc",
|
"id": "0faa3d08-9004-46fb-a5aa-a59b75e454cc",
|
||||||
"name": "signalStrength",
|
"name": "signalStrength",
|
||||||
"displayName": "signal strength",
|
"displayName": "Signal strength",
|
||||||
"displayNameEvent": "signal strength changed",
|
"displayNameEvent": "Signal strength changed",
|
||||||
"unit": "Percentage",
|
"unit": "Percentage",
|
||||||
"type": "int",
|
"type": "int",
|
||||||
"defaultValue": 0
|
"defaultValue": 0
|
||||||
@ -241,8 +226,8 @@
|
|||||||
{
|
{
|
||||||
"id": "15d8fae1-ba47-42e1-994d-530e8017c965",
|
"id": "15d8fae1-ba47-42e1-994d-530e8017c965",
|
||||||
"name": "batteryLevel",
|
"name": "batteryLevel",
|
||||||
"displayName": "battery",
|
"displayName": "Battery",
|
||||||
"displayNameEvent": "battery changed",
|
"displayNameEvent": "Battery changed",
|
||||||
"unit": "Percentage",
|
"unit": "Percentage",
|
||||||
"type": "int",
|
"type": "int",
|
||||||
"defaultValue": 0,
|
"defaultValue": 0,
|
||||||
@ -252,8 +237,8 @@
|
|||||||
{
|
{
|
||||||
"id": "f8aeb144-014d-4ccb-81db-64ffc70f1c97",
|
"id": "f8aeb144-014d-4ccb-81db-64ffc70f1c97",
|
||||||
"name": "batteryCritical",
|
"name": "batteryCritical",
|
||||||
"displayName": "battery critical",
|
"displayName": "Battery critical",
|
||||||
"displayNameEvent": "battery critical changed",
|
"displayNameEvent": "Battery critical changed",
|
||||||
"type": "bool",
|
"type": "bool",
|
||||||
"defaultValue": false
|
"defaultValue": false
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user