Merge PR #611: Add information for initialSetup and reconfigure to ThingSetupInfo

This commit is contained in:
jenkins 2023-02-21 17:43:23 +01:00
commit e248bffcf2
7 changed files with 72 additions and 40 deletions

View File

@ -346,7 +346,7 @@ ThingSetupInfo *ThingManagerImplementation::addConfiguredThing(const ThingDescri
ThingDescriptor descriptor = m_discoveredThings.value(thingDescriptorId);
if (!descriptor.isValid()) {
qCWarning(dcThingManager()) << "Cannot add thing. ThingDescriptor" << thingDescriptorId << "not found.";
ThingSetupInfo *info = new ThingSetupInfo(nullptr, this);
ThingSetupInfo *info = new ThingSetupInfo(this);
info->finish(Thing::ThingErrorThingDescriptorNotFound);
return info;
}
@ -354,13 +354,13 @@ ThingSetupInfo *ThingManagerImplementation::addConfiguredThing(const ThingDescri
ThingClass thingClass = findThingClass(descriptor.thingClassId());
if (!thingClass.isValid()) {
qCWarning(dcThingManager()) << "Cannot add thing. ThingClass" << descriptor.thingClassId() << "not found.";
ThingSetupInfo *info = new ThingSetupInfo(nullptr, this);
ThingSetupInfo *info = new ThingSetupInfo(this);
info->finish(Thing::ThingErrorThingClassNotFound);
return info;
}
if (!thingClass.createMethods().testFlag(ThingClass::CreateMethodDiscovery)) {
qCWarning(dcThingManager()) << "Cannot add thing. This thing of" << thingClass << "cannot be added via discovery.";
ThingSetupInfo *info = new ThingSetupInfo(nullptr, this);
ThingSetupInfo *info = new ThingSetupInfo(this);
info->finish(Thing::ThingErrorCreationMethodNotSupported);
return info;
}
@ -376,7 +376,7 @@ ThingSetupInfo* ThingManagerImplementation::reconfigureThing(const ThingId &thin
Thing *thing = findConfiguredThing(thingId);
if (!thing) {
qCWarning(dcThingManager()) << "Cannot reconfigure thing. Thing with id" << thingId.toString() << "not found.";
ThingSetupInfo *info = new ThingSetupInfo(nullptr, this);
ThingSetupInfo *info = new ThingSetupInfo(this);
info->finish(Thing::ThingErrorThingNotFound);
return info;
}
@ -384,14 +384,14 @@ ThingSetupInfo* ThingManagerImplementation::reconfigureThing(const ThingId &thin
ThingClass thingClass = findThingClass(thing->thingClassId());
if (thingClass.id().isNull()) {
qCWarning(dcThingManager()) << "Cannot reconfigure thing. ThingClass for thing" << thing->name() << thingId.toString() << "not found.";
ThingSetupInfo *info = new ThingSetupInfo(nullptr, this);
ThingSetupInfo *info = new ThingSetupInfo(this);
info->finish(Thing::ThingErrorThingClassNotFound);
return info;
}
foreach (const ParamType &paramType, thingClass.paramTypes()) {
if (paramType.readOnly() && params.hasParam(paramType.id())) {
ThingSetupInfo *info = new ThingSetupInfo(nullptr, this);
ThingSetupInfo *info = new ThingSetupInfo(this);
qCWarning(dcThingManager()) << "Cannot reconfigure thing" << thing << "because the parameter" << paramType.name() << paramType.id().toString() << "is not writable";
info->finish(Thing::ThingErrorParameterNotWritable);
return info;
@ -408,14 +408,14 @@ ThingSetupInfo *ThingManagerImplementation::reconfigureThing(const ThingDescript
ThingDescriptor descriptor = m_discoveredThings.value(thingDescriptorId);
if (!descriptor.isValid()) {
qCWarning(dcThingManager()) << "Cannot reconfigure thing. No thing descriptor with ID" << thingDescriptorId << "found.";
ThingSetupInfo *info = new ThingSetupInfo(nullptr, this);
ThingSetupInfo *info = new ThingSetupInfo(this);
info->finish(Thing::ThingErrorThingDescriptorNotFound);
return info;
}
Thing *thing = findConfiguredThing(descriptor.thingId());
if (!thing) {
ThingSetupInfo *info = new ThingSetupInfo(nullptr, this);
ThingSetupInfo *info = new ThingSetupInfo(this);
qCWarning(dcThingManager()) << "Cannot reconfigure thing. No thing with ID" << descriptor.thingId() << "found.";
info->finish(Thing::ThingErrorThingNotFound);
return info;
@ -424,7 +424,7 @@ ThingSetupInfo *ThingManagerImplementation::reconfigureThing(const ThingDescript
ThingClass thingClass = findThingClass(thing->thingClassId());
if (!thingClass.isValid()) {
qCWarning(dcThingManager()) << "Cannot reconfigure thing. No ThingClass with ID" << thing->thingClassId() << "found.";
ThingSetupInfo *info = new ThingSetupInfo(nullptr, this);
ThingSetupInfo *info = new ThingSetupInfo(this);
info->finish(Thing::ThingErrorThingClassNotFound);
return info;
}
@ -438,7 +438,7 @@ ThingSetupInfo *ThingManagerImplementation::reconfigureThingInternal(Thing *thin
IntegrationPlugin *plugin = m_integrationPlugins.value(thing->thingClass().pluginId());
if (!plugin) {
qCWarning(dcThingManager()) << "Cannot reconfigure thing. Plugin for ThingClass" << thing->thingClassId().toString() << "not found.";
ThingSetupInfo *info = new ThingSetupInfo(nullptr, this);
ThingSetupInfo *info = new ThingSetupInfo(this);
info->finish(Thing::ThingErrorPluginNotFound);
return info;
}
@ -446,7 +446,7 @@ ThingSetupInfo *ThingManagerImplementation::reconfigureThingInternal(Thing *thin
Thing::ThingError result = ThingUtils::verifyParams(thing->thingClass().paramTypes(), params);
if (result != Thing::ThingErrorNoError) {
qCWarning(dcThingManager()) << "Cannot reconfigure" << thing << "from" << plugin << "because the param verification failed with error" << result;
ThingSetupInfo *info = new ThingSetupInfo(nullptr, this);
ThingSetupInfo *info = new ThingSetupInfo(this);
info->finish(result);
return info;
}
@ -465,7 +465,7 @@ ThingSetupInfo *ThingManagerImplementation::reconfigureThingInternal(Thing *thin
}
// try to setup the thing with the new params
ThingSetupInfo *info = new ThingSetupInfo(thing, this, 30000);
ThingSetupInfo *info = new ThingSetupInfo(thing, this, true, true, 30000);
plugin->setupThing(info);
connect(info, &ThingSetupInfo::destroyed, thing, [=](){
m_pendingSetups.remove(thing->id());
@ -594,7 +594,7 @@ ThingPairingInfo* ThingManagerImplementation::pairThing(const ThingClassId &thin
ThingClass thingClass = m_supportedThings.value(thingClassId);
if (!thingClass.isValid()) {
qCWarning(dcThingManager) << "Cannot find a ThingClass with ID" << thingClassId.toString();
ThingPairingInfo *info = new ThingPairingInfo(transactionId, thingClassId, ThingId(), name, ParamList(), ThingId(), this);
ThingPairingInfo *info = new ThingPairingInfo(transactionId, thingClassId, ThingId(), name, ParamList(), ThingId(), this, false);
info->finish(Thing::ThingErrorThingClassNotFound);
return info;
}
@ -605,7 +605,7 @@ ThingPairingInfo* ThingManagerImplementation::pairThing(const ThingClassId &thin
// Use given params, if there are missing some, use the defaults ones.
ParamList finalParams = buildParams(thingClass.paramTypes(), params);
ThingPairingInfo *info = new ThingPairingInfo(transactionId, thingClassId, newThingId, name, finalParams, ThingId(), this, 30000);
ThingPairingInfo *info = new ThingPairingInfo(transactionId, thingClassId, newThingId, name, finalParams, ThingId(), this, false, 30000);
pairThingInternal(info);
return info;
}
@ -616,7 +616,7 @@ ThingPairingInfo* ThingManagerImplementation::pairThing(const ThingDescriptorId
ThingDescriptor descriptor = m_discoveredThings.value(thingDescriptorId);
if (!descriptor.isValid()) {
qCWarning(dcThingManager) << "Cannot find a ThingDescriptor with ID" << thingDescriptorId.toString();
ThingPairingInfo *info = new ThingPairingInfo(pairingTransactionId, ThingClassId(), ThingId(), name, ParamList(), ThingId(), this);
ThingPairingInfo *info = new ThingPairingInfo(pairingTransactionId, ThingClassId(), ThingId(), name, ParamList(), ThingId(), this, false);
info->finish(Thing::ThingErrorThingDescriptorNotFound);
return info;
}
@ -624,7 +624,7 @@ ThingPairingInfo* ThingManagerImplementation::pairThing(const ThingDescriptorId
ThingClass thingClass = m_supportedThings.value(descriptor.thingClassId());
if (!thingClass.isValid()) {
qCWarning(dcThingManager) << "Cannot find a ThingClass with ID" << descriptor.thingClassId().toString();
ThingPairingInfo *info = new ThingPairingInfo(pairingTransactionId, descriptor.thingClassId(), ThingId(), name, ParamList(), ThingId(), this);
ThingPairingInfo *info = new ThingPairingInfo(pairingTransactionId, descriptor.thingClassId(), ThingId(), name, ParamList(), ThingId(), this, false);
info->finish(Thing::ThingErrorThingClassNotFound);
return info;
}
@ -638,7 +638,7 @@ ThingPairingInfo* ThingManagerImplementation::pairThing(const ThingDescriptorId
// Use given params, if there are missing some, use the discovered ones.
ParamList finalParams = buildParams(thingClass.paramTypes(), params, descriptor.params());
ThingPairingInfo *info = new ThingPairingInfo(pairingTransactionId, descriptor.thingClassId(), thingId, name, finalParams, descriptor.parentId(), this, 30000);
ThingPairingInfo *info = new ThingPairingInfo(pairingTransactionId, descriptor.thingClassId(), thingId, name, finalParams, descriptor.parentId(), this, false, 30000);
pairThingInternal(info);
return info;
}
@ -650,7 +650,7 @@ ThingPairingInfo *ThingManagerImplementation::pairThing(const ThingId &thingId,
Thing *thing = findConfiguredThing(thingId);
if (!thing) {
qCWarning(dcThingManager) << "Cannot find a thing with ID" << thingId.toString();
ThingPairingInfo *info = new ThingPairingInfo(pairingTransactionId, ThingClassId(), thingId, name, ParamList(), ThingId(), this);
ThingPairingInfo *info = new ThingPairingInfo(pairingTransactionId, ThingClassId(), thingId, name, ParamList(), ThingId(), this, true);
info->finish(Thing::ThingErrorThingDescriptorNotFound);
return info;
}
@ -658,7 +658,7 @@ ThingPairingInfo *ThingManagerImplementation::pairThing(const ThingId &thingId,
// Use new params, if there are missing some, use the existing ones.
ParamList finalParams = buildParams(thing->thingClass().paramTypes(), params, thing->params());
ThingPairingInfo *info = new ThingPairingInfo(pairingTransactionId, thing->thingClassId(), thingId, name, finalParams, ThingId(), this, 30000);
ThingPairingInfo *info = new ThingPairingInfo(pairingTransactionId, thing->thingClassId(), thingId, name, finalParams, ThingId(), this, true, 30000);
pairThingInternal(info);
return info;
}
@ -667,7 +667,7 @@ ThingPairingInfo *ThingManagerImplementation::confirmPairing(const PairingTransa
{
if (!m_pendingPairings.contains(pairingTransactionId)) {
qCWarning(dcThingManager()) << "No pairing transaction with id" << pairingTransactionId.toString();
ThingPairingInfo *info = new ThingPairingInfo(pairingTransactionId, ThingClassId(), ThingId(), QString(), ParamList(), ThingId(), this);
ThingPairingInfo *info = new ThingPairingInfo(pairingTransactionId, ThingClassId(), ThingId(), QString(), ParamList(), ThingId(), this, false);
info->finish(Thing::ThingErrorPairingTransactionIdNotFound);
return info;
}
@ -679,7 +679,7 @@ ThingPairingInfo *ThingManagerImplementation::confirmPairing(const PairingTransa
IntegrationPlugin *plugin = m_integrationPlugins.value(thingClass.pluginId());
if (!plugin) {
qCWarning(dcThingManager) << "Can't find a plugin for this" << thingClass;
ThingPairingInfo *info = new ThingPairingInfo(pairingTransactionId, thingClassId, context.thingId, context.thingName, context.params, context.parentId, this);
ThingPairingInfo *info = new ThingPairingInfo(pairingTransactionId, thingClassId, context.thingId, context.thingName, context.params, context.parentId, this, false);
info->finish(Thing::ThingErrorPluginNotFound);
return info;
}
@ -691,8 +691,8 @@ ThingPairingInfo *ThingManagerImplementation::confirmPairing(const PairingTransa
// We're using two different info objects here, one to hand over to the plugin for the pairing, the other we give out
// to the user. After the internal one has finished, we'll start a setupThing job and finish the external pairingInfo only after
// both, the internal pairing and the setup have completed.
ThingPairingInfo *internalInfo = new ThingPairingInfo(pairingTransactionId, thingClassId, thingId, context.thingName, context.params, context.parentId, this);
ThingPairingInfo *externalInfo = new ThingPairingInfo(pairingTransactionId, thingClassId, thingId, context.thingName, context.params, context.parentId, this);
ThingPairingInfo *internalInfo = new ThingPairingInfo(pairingTransactionId, thingClassId, thingId, context.thingName, context.params, context.parentId, this, false);
ThingPairingInfo *externalInfo = new ThingPairingInfo(pairingTransactionId, thingClassId, thingId, context.thingName, context.params, context.parentId, this, false);
plugin->confirmPairing(internalInfo, username, secret);
connect(internalInfo, &ThingPairingInfo::finished, this, [this, internalInfo, externalInfo, plugin, addNewThing](){
@ -733,7 +733,7 @@ ThingPairingInfo *ThingManagerImplementation::confirmPairing(const PairingTransa
initThing(thing);
ThingSetupInfo *info = setupThing(thing);
ThingSetupInfo *info = setupThing(thing, true);
connect(info, &ThingSetupInfo::finished, thing, [this, info, externalInfo, addNewThing](){
externalInfo->finish(info->status(), info->displayMessage());
@ -780,14 +780,14 @@ ThingSetupInfo* ThingManagerImplementation::addConfiguredThingInternal(const Thi
ThingClass thingClass = findThingClass(thingClassId);
if (thingClass.id().isNull()) {
qCWarning(dcThingManager()) << "Cannot add thing. The ThingClass ID" << thingClassId.toString() << "could not be found.";
ThingSetupInfo *info = new ThingSetupInfo(nullptr, this);
ThingSetupInfo *info = new ThingSetupInfo(this);
info->finish(Thing::ThingErrorThingClassNotFound);
return info;
}
if (thingClass.setupMethod() != ThingClass::SetupMethodJustAdd) {
qCWarning(dcThingManager()) << "Cannot add thing of" << thingClass << "this way. (SetupMethodJustAdd)";
ThingSetupInfo *info = new ThingSetupInfo(nullptr, this);
ThingSetupInfo *info = new ThingSetupInfo(this);
info->finish(Thing::ThingErrorCreationMethodNotSupported);
return info;
}
@ -801,7 +801,7 @@ ThingSetupInfo* ThingManagerImplementation::addConfiguredThingInternal(const Thi
IntegrationPlugin *plugin = m_integrationPlugins.value(thingClass.pluginId());
if (!plugin) {
qCWarning(dcThingManager()) << "Cannot add thing. Plugin for thing class" << thingClass << "not found.";
ThingSetupInfo *info = new ThingSetupInfo(nullptr, this);
ThingSetupInfo *info = new ThingSetupInfo(this);
info->finish(Thing::ThingErrorPluginNotFound);
return info;
}
@ -810,7 +810,7 @@ ThingSetupInfo* ThingManagerImplementation::addConfiguredThingInternal(const Thi
Thing::ThingError paramsResult = ThingUtils::verifyParams(thingClass.paramTypes(), params);
if (paramsResult != Thing::ThingErrorNoError) {
qCWarning(dcThingManager()) << "Cannot add thing of" << thingClass << "from" << plugin << "because the param verification failed with error" << paramsResult;
ThingSetupInfo *info = new ThingSetupInfo(nullptr, this);
ThingSetupInfo *info = new ThingSetupInfo(this);
info->finish(paramsResult);
return info;
}
@ -832,7 +832,7 @@ ThingSetupInfo* ThingManagerImplementation::addConfiguredThingInternal(const Thi
initThing(thing);
ThingSetupInfo *info = setupThing(thing);
ThingSetupInfo *info = setupThing(thing, true);
connect(info, &ThingSetupInfo::finished, this, [this, info](){
if (info->status() != Thing::ThingErrorNoError) {
qCWarning(dcThingManager) << "Thing setup failed for" << info->thing() << "Not adding thing to system.";
@ -1770,7 +1770,7 @@ void ThingManagerImplementation::onAutoThingsAppeared(const ThingDescriptors &th
qCDebug(dcThingManager()) << "Setting up auto thing:" << thing;
ThingSetupInfo *info = setupThing(thing);
ThingSetupInfo *info = setupThing(thing, true);
connect(info, &ThingSetupInfo::finished, thing, [this, info](){
if (info->status() != Thing::ThingErrorNoError) {
@ -2078,12 +2078,12 @@ void ThingManagerImplementation::pairThingInternal(ThingPairingInfo *info)
});
}
ThingSetupInfo* ThingManagerImplementation::setupThing(Thing *thing)
ThingSetupInfo* ThingManagerImplementation::setupThing(Thing *thing, bool initialSetup)
{
ThingClass thingClass = findThingClass(thing->thingClassId());
IntegrationPlugin *plugin = m_integrationPlugins.value(thingClass.pluginId());
ThingSetupInfo *info = new ThingSetupInfo(thing, this, 30000);
ThingSetupInfo *info = new ThingSetupInfo(thing, this, initialSetup, false, 30000);
if (!plugin) {
qCWarning(dcThingManager) << "Can't find a plugin for this thing" << thing;
@ -2240,7 +2240,7 @@ QVariant ThingManagerImplementation::mapValue(const QVariant &value, const State
void ThingManagerImplementation::trySetupThing(Thing *thing)
{
thing->setSetupStatus(Thing::ThingSetupStatusInProgress, Thing::ThingErrorNoError);
ThingSetupInfo *info = setupThing(thing);
ThingSetupInfo *info = setupThing(thing, false);
// 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.

View File

@ -158,7 +158,7 @@ private:
void pairThingInternal(ThingPairingInfo *info);
ThingSetupInfo *addConfiguredThingInternal(const ThingClassId &thingClassId, const QString &name, const ParamList &params, const ThingId &parentId = ThingId());
ThingSetupInfo *reconfigureThingInternal(Thing *thing, const ParamList &params, const QString &name = QString());
ThingSetupInfo *setupThing(Thing *thing);
ThingSetupInfo *setupThing(Thing *thing, bool initialSetup);
void initThing(Thing *thing);
void trySetupThing(Thing *thing);
void registerThing(Thing *thing);

View File

@ -35,14 +35,15 @@
Q_DECLARE_LOGGING_CATEGORY(dcIntegrations)
ThingPairingInfo::ThingPairingInfo(const PairingTransactionId &pairingTransactionId, const ThingClassId &thingClassId, const ThingId &thingId, const QString &deviceName, const ParamList &params, const ThingId &parentId, ThingManager *parent, quint32 timeout):
ThingPairingInfo::ThingPairingInfo(const PairingTransactionId &pairingTransactionId, const ThingClassId &thingClassId, const ThingId &thingId, const QString &deviceName, const ParamList &params, const ThingId &parentId, ThingManager *parent, bool reconfigure, quint32 timeout):
QObject(parent),
m_transactionId(pairingTransactionId),
m_thingClassId(thingClassId),
m_thingId(thingId),
m_thingName(deviceName),
m_params(params),
m_parentId(parentId)
m_parentId(parentId),
m_reconfigure(reconfigure)
{
connect(this, &ThingPairingInfo::finished, this, &ThingPairingInfo::deleteLater, Qt::QueuedConnection);
@ -102,6 +103,11 @@ QUrl ThingPairingInfo::oAuthUrl() const
return m_oAuthUrl;
}
bool ThingPairingInfo::isReconfigure() const
{
return m_reconfigure;
}
void ThingPairingInfo::setOAuthUrl(const QUrl &oAuthUrl)
{
m_oAuthUrl = oAuthUrl;

View File

@ -42,7 +42,7 @@ class LIBNYMEA_EXPORT ThingPairingInfo: public QObject
{
Q_OBJECT
public:
ThingPairingInfo(const PairingTransactionId &pairingTransactionId, const ThingClassId &thingClassId, const ThingId &thingId, const QString &thingName, const ParamList &params, const ThingId &parentId, ThingManager *parent, quint32 timeout = 0);
ThingPairingInfo(const PairingTransactionId &pairingTransactionId, const ThingClassId &thingClassId, const ThingId &thingId, const QString &thingName, const ParamList &params, const ThingId &parentId, ThingManager *parent, bool reconfigure, quint32 timeout = 0);
PairingTransactionId transactionId() const;
@ -54,6 +54,8 @@ public:
QUrl oAuthUrl() const;
bool isReconfigure() const;
Thing::ThingError status() const;
QString displayMessage() const;
QString translatedDisplayMessage(const QLocale &locale) const;
@ -76,6 +78,7 @@ private:
QUrl m_oAuthUrl;
bool m_reconfigure = false;
bool m_finished = false;
Thing::ThingError m_status = Thing::ThingErrorNoError;
QString m_displayMessage;

View File

@ -37,9 +37,17 @@
Q_DECLARE_LOGGING_CATEGORY(dcIntegrations)
ThingSetupInfo::ThingSetupInfo(Thing *thing, ThingManager *thingManager, quint32 timeout):
ThingSetupInfo::ThingSetupInfo(QObject *parent):
QObject(parent)
{
}
ThingSetupInfo::ThingSetupInfo(Thing *thing, ThingManager *thingManager, bool initialSetup, bool reconfigure, quint32 timeout):
QObject(thingManager),
m_thing(thing),
m_initialSetup(initialSetup),
m_reconfigure(reconfigure),
m_thingManager(thingManager)
{
connect(this, &ThingSetupInfo::finished, this, &ThingSetupInfo::deleteLater, Qt::QueuedConnection);
@ -70,6 +78,16 @@ Thing *ThingSetupInfo::thing() const
return m_thing;
}
bool ThingSetupInfo::isInitialSetup() const
{
return m_initialSetup;
}
bool ThingSetupInfo::isReconfigure() const
{
return m_reconfigure;
}
bool ThingSetupInfo::isFinished() const
{
return m_finished;

View File

@ -42,10 +42,13 @@ class LIBNYMEA_EXPORT ThingSetupInfo : public QObject
Q_OBJECT
Q_PROPERTY(Thing* thing READ thing CONSTANT)
public:
explicit ThingSetupInfo(Thing *thing, ThingManager *thingManager, quint32 timeout = 0);
explicit ThingSetupInfo(QObject *parent);
explicit ThingSetupInfo(Thing *thing, ThingManager *thingManager, bool initialSetup, bool reconfigure, quint32 timeout = 0);
Thing *thing() const;
bool isInitialSetup() const;
bool isReconfigure() const;
bool isFinished() const;
Thing::ThingError status() const;
@ -62,6 +65,8 @@ signals:
private:
Thing *m_thing = nullptr;
bool m_initialSetup = true;
bool m_reconfigure = false;
bool m_finished = false;
Thing::ThingError m_status = Thing::ThingErrorNoError;
QString m_displayMessage;

View File

@ -8,7 +8,7 @@ JSON_PROTOCOL_VERSION_MAJOR=7
JSON_PROTOCOL_VERSION_MINOR=0
JSON_PROTOCOL_VERSION="$${JSON_PROTOCOL_VERSION_MAJOR}.$${JSON_PROTOCOL_VERSION_MINOR}"
LIBNYMEA_API_VERSION_MAJOR=7
LIBNYMEA_API_VERSION_MINOR=3
LIBNYMEA_API_VERSION_MINOR=4
LIBNYMEA_API_VERSION_PATCH=0
LIBNYMEA_API_VERSION="$${LIBNYMEA_API_VERSION_MAJOR}.$${LIBNYMEA_API_VERSION_MINOR}.$${LIBNYMEA_API_VERSION_PATCH}"