Retry setup if it fails at startup (e.g. network isn't up yet or similar)
This commit is contained in:
parent
a0add78af0
commit
6aaab68cdc
@ -1565,25 +1565,7 @@ void ThingManagerImplementation::loadConfiguredThings()
|
|||||||
}
|
}
|
||||||
Q_ASSERT(thing != nullptr);
|
Q_ASSERT(thing != nullptr);
|
||||||
|
|
||||||
thing->setSetupStatus(Thing::ThingSetupStatusInProgress, Thing::ThingErrorNoError);
|
trySetupThing(thing);
|
||||||
ThingSetupInfo *info = setupThing(thing);
|
|
||||||
// Set receiving object to "thing" because at startup we load it in any case, knowing that it worked at
|
|
||||||
// some point. However, it'll be marked as non-working until the setup succeeds so the user might delete
|
|
||||||
// it in the meantime... In that case we don't want to call postsetup on it.
|
|
||||||
connect(info, &ThingSetupInfo::finished, thing, [this, info](){
|
|
||||||
|
|
||||||
if (info->status() != Thing::ThingErrorNoError) {
|
|
||||||
qCWarning(dcThingManager()) << "Error setting up thing" << info->thing()->name() << info->thing()->id().toString() << info->status() << info->displayMessage();
|
|
||||||
info->thing()->setSetupStatus(Thing::ThingSetupStatusFailed, info->status(), info->displayMessage());
|
|
||||||
emit thingChanged(info->thing());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
qCDebug(dcThingManager()) << "Setup complete for thing" << info->thing();
|
|
||||||
info->thing()->setSetupStatus(Thing::ThingSetupStatusComplete, Thing::ThingErrorNoError);
|
|
||||||
emit thingChanged(info->thing());
|
|
||||||
postSetupThing(info->thing());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loadIOConnections();
|
loadIOConnections();
|
||||||
@ -2101,6 +2083,37 @@ QVariant ThingManagerImplementation::mapValue(const QVariant &value, const State
|
|||||||
return toValue;
|
return toValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ThingManagerImplementation::trySetupThing(Thing *thing)
|
||||||
|
{
|
||||||
|
thing->setSetupStatus(Thing::ThingSetupStatusInProgress, Thing::ThingErrorNoError);
|
||||||
|
ThingSetupInfo *info = setupThing(thing);
|
||||||
|
// Set receiving object to "thing" because at startup we load it in any case, knowing that it worked at
|
||||||
|
// some point. However, it'll be marked as non-working until the setup succeeds so the user might delete
|
||||||
|
// it in the meantime... In that case we don't want to call postsetup on it.
|
||||||
|
connect(info, &ThingSetupInfo::finished, thing, [this, info, thing](){
|
||||||
|
|
||||||
|
if (info->status() != Thing::ThingErrorNoError) {
|
||||||
|
qCWarning(dcThingManager()) << "Error setting up thing" << info->thing()->name() << info->thing()->id().toString() << info->status() << info->displayMessage();
|
||||||
|
info->thing()->setSetupStatus(Thing::ThingSetupStatusFailed, info->status(), info->displayMessage());
|
||||||
|
emit thingChanged(info->thing());
|
||||||
|
|
||||||
|
// We know this used to work at some point... try again in a bit unless we don't have a plugin for it...
|
||||||
|
if (info->status() != Thing::ThingErrorPluginNotFound) {
|
||||||
|
QTimer::singleShot(10000, thing, [this, thing]() {
|
||||||
|
trySetupThing(thing);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
qCDebug(dcThingManager()) << "Setup complete for thing" << info->thing();
|
||||||
|
info->thing()->setSetupStatus(Thing::ThingSetupStatusComplete, Thing::ThingErrorNoError);
|
||||||
|
emit thingChanged(info->thing());
|
||||||
|
postSetupThing(info->thing());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void ThingManagerImplementation::storeThingStates(Thing *thing)
|
void ThingManagerImplementation::storeThingStates(Thing *thing)
|
||||||
{
|
{
|
||||||
NymeaSettings settings(NymeaSettings::SettingsRoleThingStates);
|
NymeaSettings settings(NymeaSettings::SettingsRoleThingStates);
|
||||||
|
|||||||
@ -155,11 +155,11 @@ private:
|
|||||||
ThingSetupInfo *reconfigureThingInternal(Thing *thing, const ParamList ¶ms, const QString &name = QString());
|
ThingSetupInfo *reconfigureThingInternal(Thing *thing, const ParamList ¶ms, const QString &name = QString());
|
||||||
ThingSetupInfo *setupThing(Thing *thing);
|
ThingSetupInfo *setupThing(Thing *thing);
|
||||||
void postSetupThing(Thing *thing);
|
void postSetupThing(Thing *thing);
|
||||||
|
void trySetupThing(Thing *thing);
|
||||||
void storeThingStates(Thing *thing);
|
void storeThingStates(Thing *thing);
|
||||||
void loadThingStates(Thing *thing);
|
void loadThingStates(Thing *thing);
|
||||||
void storeIOConnections();
|
void storeIOConnections();
|
||||||
void loadIOConnections();
|
void loadIOConnections();
|
||||||
|
|
||||||
void syncIOConnection(Thing *inputThing, const StateTypeId &stateTypeId);
|
void syncIOConnection(Thing *inputThing, const StateTypeId &stateTypeId);
|
||||||
QVariant mapValue(const QVariant &value, const StateType &fromStateType, const StateType &toStateType, bool inverted) const;
|
QVariant mapValue(const QVariant &value, const StateType &fromStateType, const StateType &toStateType, bool inverted) const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user