Netatmo: fixed plugin storage
This commit is contained in:
parent
55ce83011f
commit
395ed511cf
@ -66,8 +66,12 @@ void IntegrationPluginNetatmo::confirmPairing(ThingPairingInfo *info, const QStr
|
|||||||
authentication->setScope("read_station read_thermostat write_thermostat");
|
authentication->setScope("read_station read_thermostat write_thermostat");
|
||||||
|
|
||||||
// Update thing connected state based on OAuth connected state
|
// Update thing connected state based on OAuth connected state
|
||||||
connect(authentication, &OAuth2::authenticationChanged, info, [info, authentication](){
|
connect(authentication, &OAuth2::authenticationChanged, info, [this, info, username, password, authentication](){
|
||||||
if (authentication->authenticated()) {
|
if (authentication->authenticated()) {
|
||||||
|
pluginStorage()->beginGroup(info->thingId().toString());
|
||||||
|
pluginStorage()->setValue("username", username);
|
||||||
|
pluginStorage()->setValue("password", password);
|
||||||
|
pluginStorage()->endGroup();
|
||||||
info->finish(Thing::ThingErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
} else {
|
} else {
|
||||||
info->finish(Thing::ThingErrorAuthenticationFailure, "Wrong username of password");
|
info->finish(Thing::ThingErrorAuthenticationFailure, "Wrong username of password");
|
||||||
@ -92,17 +96,28 @@ void IntegrationPluginNetatmo::setupThing(ThingSetupInfo *info)
|
|||||||
QString username;
|
QString username;
|
||||||
QString password;
|
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())) {
|
if (pluginStorage()->childGroups().contains(thing->id().toString())) {
|
||||||
pluginStorage()->beginGroup(thing->id().toString());
|
pluginStorage()->beginGroup(thing->id().toString());
|
||||||
username = pluginStorage()->value("username").toString();
|
username = pluginStorage()->value("username").toString();
|
||||||
password = pluginStorage()->value("password").toString();
|
password = pluginStorage()->value("password").toString();
|
||||||
pluginStorage()->endGroup();
|
pluginStorage()->endGroup();
|
||||||
} else {
|
} else {
|
||||||
|
/* username and password have been stored as thingParams,
|
||||||
|
* this is to migrate the params to plug-in storage. */
|
||||||
|
ParamTypeId usernameParamTypeId = ParamTypeId("763c2c10-dee5-41c8-9f7e-ded741945e73");
|
||||||
|
ParamTypeId passwordParamTypeId = ParamTypeId("c0d892d6-f359-4782-9d7d-8f74a3b53e3e");
|
||||||
|
|
||||||
username = thing->paramValue(usernameParamTypeId).toString();
|
username = thing->paramValue(usernameParamTypeId).toString();
|
||||||
password = thing->paramValue(passwordParamTypeId).toString();
|
password = thing->paramValue(passwordParamTypeId).toString();
|
||||||
|
|
||||||
|
pluginStorage()->beginGroup(info->thing()->id().toString());
|
||||||
|
pluginStorage()->setValue("username", username);
|
||||||
|
pluginStorage()->setValue("password", password);
|
||||||
|
pluginStorage()->endGroup();
|
||||||
|
|
||||||
|
// Delete username and password so it wont be visible in the things.conf file.
|
||||||
|
thing->setParamValue(ParamTypeId("763c2c10-dee5-41c8-9f7e-ded741945e73"), "");
|
||||||
|
thing->setParamValue(ParamTypeId("c0d892d6-f359-4782-9d7d-8f74a3b53e3e"), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
OAuth2 *authentication = new OAuth2("561c015d49c75f0d1cce6e13", "GuvKkdtu7JQlPD47qTTepRR9hQ0CUPAj4Tae3Ohcq", this);
|
OAuth2 *authentication = new OAuth2("561c015d49c75f0d1cce6e13", "GuvKkdtu7JQlPD47qTTepRR9hQ0CUPAj4Tae3Ohcq", this);
|
||||||
@ -170,7 +185,6 @@ void IntegrationPluginNetatmo::setupThing(ThingSetupInfo *info)
|
|||||||
thing->setParams(migratedParams);
|
thing->setParams(migratedParams);
|
||||||
// Migration done
|
// Migration done
|
||||||
|
|
||||||
|
|
||||||
NetatmoOutdoorModule *outdoor = new NetatmoOutdoorModule(thing->paramValue(outdoorThingNameParamTypeId).toString(),
|
NetatmoOutdoorModule *outdoor = new NetatmoOutdoorModule(thing->paramValue(outdoorThingNameParamTypeId).toString(),
|
||||||
thing->paramValue(outdoorThingMacParamTypeId).toString(),
|
thing->paramValue(outdoorThingMacParamTypeId).toString(),
|
||||||
thing->paramValue(outdoorThingBaseStationParamTypeId).toString(),
|
thing->paramValue(outdoorThingBaseStationParamTypeId).toString(),
|
||||||
@ -181,7 +195,6 @@ void IntegrationPluginNetatmo::setupThing(ThingSetupInfo *info)
|
|||||||
|
|
||||||
return info->finish(Thing::ThingErrorNoError);
|
return info->finish(Thing::ThingErrorNoError);
|
||||||
}
|
}
|
||||||
|
|
||||||
qCWarning(dcNetatmo()) << "Unhandled thing class in setupDevice";
|
qCWarning(dcNetatmo()) << "Unhandled thing class in setupDevice";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,11 +375,6 @@ void IntegrationPluginNetatmo::onNetworkReplyFinished()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntegrationPluginNetatmo::onAuthenticationChanged()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void IntegrationPluginNetatmo::onIndoorStatesChanged()
|
void IntegrationPluginNetatmo::onIndoorStatesChanged()
|
||||||
{
|
{
|
||||||
NetatmoBaseStation *indoor = static_cast<NetatmoBaseStation *>(sender());
|
NetatmoBaseStation *indoor = static_cast<NetatmoBaseStation *>(sender());
|
||||||
|
|||||||
@ -78,7 +78,6 @@ private:
|
|||||||
private slots:
|
private slots:
|
||||||
void onPluginTimer();
|
void onPluginTimer();
|
||||||
void onNetworkReplyFinished();
|
void onNetworkReplyFinished();
|
||||||
void onAuthenticationChanged();
|
|
||||||
void onIndoorStatesChanged();
|
void onIndoorStatesChanged();
|
||||||
void onOutdoorStatesChanged();
|
void onOutdoorStatesChanged();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user