start zone setup after parent setup has been completed
This commit is contained in:
parent
bc2ff5b7be
commit
b9cd18a45e
@ -100,7 +100,7 @@ void IntegrationPluginTado::setupThing(ThingSetupInfo *info)
|
|||||||
{
|
{
|
||||||
Thing *thing = info->thing();
|
Thing *thing = info->thing();
|
||||||
|
|
||||||
if (thing->thingClassId() == tadoConnectionThingClassId) {
|
if (thing->thingClassId() == tadoAccountThingClassId) {
|
||||||
|
|
||||||
qCDebug(dcTado) << "Setup tado connection" << thing->name() << thing->params();
|
qCDebug(dcTado) << "Setup tado connection" << thing->name() << thing->params();
|
||||||
Tado *tado;
|
Tado *tado;
|
||||||
@ -155,8 +155,18 @@ void IntegrationPluginTado::setupThing(ThingSetupInfo *info)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
} else if (thing->thingClassId() == zoneThingClassId) {
|
} else if (thing->thingClassId() == zoneThingClassId) {
|
||||||
qCDebug(dcTado) << "Setup tado thermostat" << thing->params();
|
qCDebug(dcTado) << "Setup Tado zone" << thing->params();
|
||||||
return info->finish(Thing::ThingErrorNoError);
|
Thing *parentThing = myThings().findById(thing->parentId());
|
||||||
|
if(parentThing->setupComplete()) {
|
||||||
|
return info->finish(Thing::ThingErrorNoError);
|
||||||
|
} else {
|
||||||
|
connect(parentThing, &Thing::setupStatusChanged, info, [parentThing, info]{
|
||||||
|
if (parentThing->setupComplete()) {
|
||||||
|
info->finish(Thing::ThingErrorNoError);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
qCWarning(dcTado()) << "Unhandled thing class in setupDevice";
|
qCWarning(dcTado()) << "Unhandled thing class in setupDevice";
|
||||||
return info->finish(Thing::ThingErrorThingClassNotFound);
|
return info->finish(Thing::ThingErrorThingClassNotFound);
|
||||||
@ -165,7 +175,7 @@ void IntegrationPluginTado::setupThing(ThingSetupInfo *info)
|
|||||||
|
|
||||||
void IntegrationPluginTado::thingRemoved(Thing *thing)
|
void IntegrationPluginTado::thingRemoved(Thing *thing)
|
||||||
{
|
{
|
||||||
if (thing->thingClassId() == tadoConnectionThingClassId) {
|
if (thing->thingClassId() == tadoAccountThingClassId) {
|
||||||
Tado *tado = m_tadoAccounts.take(thing->id());
|
Tado *tado = m_tadoAccounts.take(thing->id());
|
||||||
tado->deleteLater();
|
tado->deleteLater();
|
||||||
}
|
}
|
||||||
@ -183,11 +193,11 @@ void IntegrationPluginTado::postSetupThing(Thing *thing)
|
|||||||
connect(m_pluginTimer, &PluginTimer::timeout, this, &IntegrationPluginTado::onPluginTimer);
|
connect(m_pluginTimer, &PluginTimer::timeout, this, &IntegrationPluginTado::onPluginTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (thing->thingClassId() == tadoConnectionThingClassId) {
|
if (thing->thingClassId() == tadoAccountThingClassId) {
|
||||||
Tado *tado = m_tadoAccounts.value(thing->id());
|
Tado *tado = m_tadoAccounts.value(thing->id());
|
||||||
thing->setStateValue(tadoConnectionUserDisplayNameStateTypeId, tado->username());
|
thing->setStateValue(tadoAccountUserDisplayNameStateTypeId, tado->username());
|
||||||
thing->setStateValue(tadoConnectionLoggedInStateTypeId, true);
|
thing->setStateValue(tadoAccountLoggedInStateTypeId, true);
|
||||||
thing->setStateValue(tadoConnectionConnectedStateTypeId, true);
|
thing->setStateValue(tadoAccountConnectedStateTypeId, true);
|
||||||
tado->getHomes();
|
tado->getHomes();
|
||||||
|
|
||||||
} else if (thing->thingClassId() == zoneThingClassId) {
|
} else if (thing->thingClassId() == zoneThingClassId) {
|
||||||
@ -261,16 +271,22 @@ void IntegrationPluginTado::executeAction(ThingActionInfo *info)
|
|||||||
|
|
||||||
void IntegrationPluginTado::onPluginTimer()
|
void IntegrationPluginTado::onPluginTimer()
|
||||||
{
|
{
|
||||||
foreach (Thing *thing, myThings().filterByThingClassId(zoneThingClassId)) {
|
Q_FOREACH(Tado *tado, m_tadoAccounts){
|
||||||
Tado *tado = m_tadoAccounts.value(thing->parentId());
|
ThingId accountThingId = m_tadoAccounts.key(tado);
|
||||||
if (!tado){
|
if (!tado->authenticated()) {
|
||||||
qCWarning(dcTado()) << "Could not find any Tado connection to Zone" << thing->name();
|
pluginStorage()->beginGroup(accountThingId.toString());
|
||||||
continue;
|
QString password = pluginStorage()->value("password").toString();
|
||||||
|
pluginStorage()->endGroup();
|
||||||
|
tado->getToken(password);
|
||||||
|
} else {
|
||||||
|
Q_FOREACH(Thing *thing, myThings().filterByParentId(accountThingId)) {
|
||||||
|
if (thing->thingClassId() == zoneThingClassId) {
|
||||||
|
QString homeId = thing->paramValue(zoneThingHomeIdParamTypeId).toString();
|
||||||
|
QString zoneId = thing->paramValue(zoneThingZoneIdParamTypeId).toString();
|
||||||
|
tado->getZoneState(homeId, zoneId);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString homeId = thing->paramValue(zoneThingHomeIdParamTypeId).toString();
|
|
||||||
QString zoneId = thing->paramValue(zoneThingZoneIdParamTypeId).toString();
|
|
||||||
tado->getZoneState(homeId, zoneId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,10 +298,14 @@ void IntegrationPluginTado::onConnectionChanged(bool connected)
|
|||||||
Thing *thing = myThings().findById(m_tadoAccounts.key(tado));
|
Thing *thing = myThings().findById(m_tadoAccounts.key(tado));
|
||||||
if (!thing)
|
if (!thing)
|
||||||
return;
|
return;
|
||||||
thing->setStateValue(tadoConnectionConnectedStateTypeId, connected);
|
thing->setStateValue(tadoAccountConnectedStateTypeId, connected);
|
||||||
|
|
||||||
foreach(Thing *zoneThing, myThings().filterByParentId(thing->id())) {
|
if (!connected) {
|
||||||
zoneThing->setStateValue(zoneConnectedStateTypeId, connected);
|
Q_FOREACH(Thing *child, myThings().filterByParentId(thing->id())) {
|
||||||
|
if (child->thingClassId() == zoneThingClassId) {
|
||||||
|
child->setStateValue(zoneConnectedStateTypeId, connected);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -300,17 +320,13 @@ void IntegrationPluginTado::onAuthenticationStatusChanged(bool authenticated)
|
|||||||
qCWarning(dcTado()) << "OnAuthenticationChanged no thing found by ID" << m_tadoAccounts.key(tado);
|
qCWarning(dcTado()) << "OnAuthenticationChanged no thing found by ID" << m_tadoAccounts.key(tado);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
thing->setStateValue(tadoConnectionLoggedInStateTypeId, authenticated);
|
thing->setStateValue(tadoAccountLoggedInStateTypeId, authenticated);
|
||||||
|
|
||||||
if (!authenticated) {
|
if (!authenticated) {
|
||||||
QTimer::singleShot(5000, tado, [this, tado, thing] {
|
Q_FOREACH(Thing *child, myThings().filterByParentId(thing->id())) {
|
||||||
if (!tado->connected()) {
|
if (child->thingClassId() == zoneThingClassId) {
|
||||||
pluginStorage()->beginGroup(thing->id().toString());
|
child->setStateValue(zoneConnectedStateTypeId, authenticated);
|
||||||
QString password = pluginStorage()->value("password").toString();
|
|
||||||
pluginStorage()->endGroup();
|
|
||||||
tado->getToken(password);
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,8 +10,8 @@
|
|||||||
"thingClasses": [
|
"thingClasses": [
|
||||||
{
|
{
|
||||||
"id": "69be7d15-5658-4442-872e-42abbd8bff81",
|
"id": "69be7d15-5658-4442-872e-42abbd8bff81",
|
||||||
"name": "tadoConnection",
|
"name": "tadoAccount",
|
||||||
"displayName": "Tado Connection",
|
"displayName": "Tado account",
|
||||||
"interfaces": ["account"],
|
"interfaces": ["account"],
|
||||||
"createMethods": ["user"],
|
"createMethods": ["user"],
|
||||||
"setupMethod": "userandpassword",
|
"setupMethod": "userandpassword",
|
||||||
@ -19,8 +19,8 @@
|
|||||||
{
|
{
|
||||||
"id": "2f79bc1d-27ed-480a-b583-728363c83ea6",
|
"id": "2f79bc1d-27ed-480a-b583-728363c83ea6",
|
||||||
"name": "connected",
|
"name": "connected",
|
||||||
"displayName": "Available",
|
"displayName": "Connected",
|
||||||
"displayNameEvent": "Available changed",
|
"displayNameEvent": "Connected changed",
|
||||||
"type": "bool",
|
"type": "bool",
|
||||||
"defaultValue": false
|
"defaultValue": false
|
||||||
},
|
},
|
||||||
@ -77,8 +77,8 @@
|
|||||||
{
|
{
|
||||||
"id": "9f45a703-6a15-447c-a77a-0df731cda48e",
|
"id": "9f45a703-6a15-447c-a77a-0df731cda48e",
|
||||||
"name": "connected",
|
"name": "connected",
|
||||||
"displayName": "Available",
|
"displayName": "Connected",
|
||||||
"displayNameEvent": "Available changed",
|
"displayNameEvent": "Connected changed",
|
||||||
"type": "bool",
|
"type": "bool",
|
||||||
"defaultValue": false
|
"defaultValue": false
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user