Fix erraneous state changes during thing setup
This commit is contained in:
parent
be68d925be
commit
1e008fd60d
@ -694,13 +694,7 @@ ThingPairingInfo *ThingManagerImplementation::confirmPairing(const PairingTransa
|
|||||||
ParamList settings = buildParams(thingClass.settingsTypes(), ParamList());
|
ParamList settings = buildParams(thingClass.settingsTypes(), ParamList());
|
||||||
thing->setSettings(settings);
|
thing->setSettings(settings);
|
||||||
|
|
||||||
QList<EventTypeId> loggedEventTypeIds;
|
initThing(thing);
|
||||||
foreach (const EventType &eventType, thingClass.eventTypes()) {
|
|
||||||
if (eventType.suggestLogging()) {
|
|
||||||
loggedEventTypeIds.append(eventType.id());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
thing->setLoggedEventTypeIds(loggedEventTypeIds);
|
|
||||||
|
|
||||||
ThingSetupInfo *info = setupThing(thing);
|
ThingSetupInfo *info = setupThing(thing);
|
||||||
connect(info, &ThingSetupInfo::finished, thing, [this, info, externalInfo, addNewThing](){
|
connect(info, &ThingSetupInfo::finished, thing, [this, info, externalInfo, addNewThing](){
|
||||||
@ -798,13 +792,8 @@ ThingSetupInfo* ThingManagerImplementation::addConfiguredThingInternal(const Thi
|
|||||||
ParamList settings = buildParams(thingClass.settingsTypes(), ParamList());
|
ParamList settings = buildParams(thingClass.settingsTypes(), ParamList());
|
||||||
thing->setSettings(settings);
|
thing->setSettings(settings);
|
||||||
|
|
||||||
QList<EventTypeId> loggedEventTypeIds;
|
|
||||||
foreach (const EventType &eventType, thingClass.eventTypes()) {
|
initThing(thing);
|
||||||
if (eventType.suggestLogging()) {
|
|
||||||
loggedEventTypeIds.append(eventType.id());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
thing->setLoggedEventTypeIds(loggedEventTypeIds);
|
|
||||||
|
|
||||||
ThingSetupInfo *info = setupThing(thing);
|
ThingSetupInfo *info = setupThing(thing);
|
||||||
connect(info, &ThingSetupInfo::finished, this, [this, info](){
|
connect(info, &ThingSetupInfo::finished, this, [this, info](){
|
||||||
@ -1614,13 +1603,7 @@ void ThingManagerImplementation::loadConfiguredThings()
|
|||||||
|
|
||||||
thing->setSettings(thingSettings);
|
thing->setSettings(thingSettings);
|
||||||
|
|
||||||
QList<EventTypeId> loggedEventTypeIds;
|
initThing(thing);
|
||||||
foreach (const EventType &eventType, thingClass.eventTypes()) {
|
|
||||||
if (eventType.suggestLogging()) {
|
|
||||||
loggedEventTypeIds.append(eventType.id());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
thing->setLoggedEventTypeIds(loggedEventTypeIds);
|
|
||||||
|
|
||||||
settings.endGroup(); // ThingId
|
settings.endGroup(); // ThingId
|
||||||
|
|
||||||
@ -1740,13 +1723,7 @@ void ThingManagerImplementation::onAutoThingsAppeared(const ThingDescriptors &th
|
|||||||
thing->setSettings(settings);
|
thing->setSettings(settings);
|
||||||
thing->setParentId(thingDescriptor.parentId());
|
thing->setParentId(thingDescriptor.parentId());
|
||||||
|
|
||||||
QList<EventTypeId> loggedEventTypeIds;
|
initThing(thing);
|
||||||
foreach (const EventType &eventType, thingClass.eventTypes()) {
|
|
||||||
if (eventType.suggestLogging()) {
|
|
||||||
loggedEventTypeIds.append(eventType.id());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
thing->setLoggedEventTypeIds(loggedEventTypeIds);
|
|
||||||
|
|
||||||
qCDebug(dcThingManager()) << "Setting up auto thing:" << thing->name() << thing->id().toString();
|
qCDebug(dcThingManager()) << "Setting up auto thing:" << thing->name() << thing->id().toString();
|
||||||
|
|
||||||
@ -2065,14 +2042,6 @@ ThingSetupInfo* ThingManagerImplementation::setupThing(Thing *thing)
|
|||||||
ThingClass thingClass = findThingClass(thing->thingClassId());
|
ThingClass thingClass = findThingClass(thing->thingClassId());
|
||||||
IntegrationPlugin *plugin = m_integrationPlugins.value(thingClass.pluginId());
|
IntegrationPlugin *plugin = m_integrationPlugins.value(thingClass.pluginId());
|
||||||
|
|
||||||
QList<State> states;
|
|
||||||
foreach (const StateType &stateType, thingClass.stateTypes()) {
|
|
||||||
State state(stateType.id(), thing->id());
|
|
||||||
states.append(state);
|
|
||||||
}
|
|
||||||
thing->setStates(states);
|
|
||||||
loadThingStates(thing);
|
|
||||||
|
|
||||||
ThingSetupInfo *info = new ThingSetupInfo(thing, this, 30000);
|
ThingSetupInfo *info = new ThingSetupInfo(thing, this, 30000);
|
||||||
|
|
||||||
if (!plugin) {
|
if (!plugin) {
|
||||||
@ -2091,6 +2060,27 @@ ThingSetupInfo* ThingManagerImplementation::setupThing(Thing *thing)
|
|||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ThingManagerImplementation::initThing(Thing *thing)
|
||||||
|
{
|
||||||
|
ThingClass thingClass = findThingClass(thing->thingClassId());
|
||||||
|
|
||||||
|
QList<State> states;
|
||||||
|
foreach (const StateType &stateType, thingClass.stateTypes()) {
|
||||||
|
State state(stateType.id(), thing->id());
|
||||||
|
states.append(state);
|
||||||
|
}
|
||||||
|
thing->setStates(states);
|
||||||
|
loadThingStates(thing);
|
||||||
|
|
||||||
|
QList<EventTypeId> loggedEventTypeIds;
|
||||||
|
foreach (const EventType &eventType, thingClass.eventTypes()) {
|
||||||
|
if (eventType.suggestLogging()) {
|
||||||
|
loggedEventTypeIds.append(eventType.id());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
thing->setLoggedEventTypeIds(loggedEventTypeIds);
|
||||||
|
}
|
||||||
|
|
||||||
void ThingManagerImplementation::postSetupThing(Thing *thing)
|
void ThingManagerImplementation::postSetupThing(Thing *thing)
|
||||||
{
|
{
|
||||||
ThingClass thingClass = findThingClass(thing->thingClassId());
|
ThingClass thingClass = findThingClass(thing->thingClassId());
|
||||||
|
|||||||
@ -158,6 +158,7 @@ private:
|
|||||||
ThingSetupInfo *addConfiguredThingInternal(const ThingClassId &thingClassId, const QString &name, const ParamList ¶ms, const ThingId &parentId = ThingId());
|
ThingSetupInfo *addConfiguredThingInternal(const ThingClassId &thingClassId, const QString &name, const ParamList ¶ms, const ThingId &parentId = ThingId());
|
||||||
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 initThing(Thing *thing);
|
||||||
void trySetupThing(Thing *thing);
|
void trySetupThing(Thing *thing);
|
||||||
void registerThing(Thing *thing);
|
void registerThing(Thing *thing);
|
||||||
void postSetupThing(Thing *thing);
|
void postSetupThing(Thing *thing);
|
||||||
|
|||||||
@ -612,6 +612,8 @@ void TestIntegrations::storedThings()
|
|||||||
ThingId addedThingId = ThingId(response.toMap().value("params").toMap().value("thingId").toString());
|
ThingId addedThingId = ThingId(response.toMap().value("params").toMap().value("thingId").toString());
|
||||||
QVERIFY(!addedThingId.isNull());
|
QVERIFY(!addedThingId.isNull());
|
||||||
|
|
||||||
|
clearLoggingDatabase();
|
||||||
|
|
||||||
// Restart the core instance to check if settings are loaded at startup
|
// Restart the core instance to check if settings are loaded at startup
|
||||||
restartServer();
|
restartServer();
|
||||||
|
|
||||||
@ -620,8 +622,8 @@ void TestIntegrations::storedThings()
|
|||||||
bool found = false;
|
bool found = false;
|
||||||
foreach (const QVariant &thing, response.toMap().value("params").toMap().value("things").toList()) {
|
foreach (const QVariant &thing, response.toMap().value("params").toMap().value("things").toList()) {
|
||||||
if (ThingId(thing.toMap().value("id").toString()) == addedThingId) {
|
if (ThingId(thing.toMap().value("id").toString()) == addedThingId) {
|
||||||
qDebug() << "found added thing" << thing.toMap().value("params");
|
qCDebug(dcTests()) << "found added thing" << thing.toMap().value("params");
|
||||||
qDebug() << "expected thingParams:" << thingParams;
|
qCDebug(dcTests()) << "expected thingParams:" << thingParams;
|
||||||
verifyParams(thingParams, thing.toMap().value("params").toList());
|
verifyParams(thingParams, thing.toMap().value("params").toList());
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
@ -629,6 +631,17 @@ void TestIntegrations::storedThings()
|
|||||||
}
|
}
|
||||||
QVERIFY2(found, "thing missing in config!");
|
QVERIFY2(found, "thing missing in config!");
|
||||||
|
|
||||||
|
// Wait for the DB to sync up and then verify that just restarting did not add state changes for this thing
|
||||||
|
waitForDBSync();
|
||||||
|
|
||||||
|
params.clear();
|
||||||
|
params.insert("thingIds", QVariantList() << addedThingId);
|
||||||
|
params.insert("loggingSources", QVariantList() << "LoggingSourceStates");
|
||||||
|
response = injectAndWait("Logging.GetLogEntries", params);
|
||||||
|
QVERIFY2(response.toMap().value("params").toMap().contains("logEntries"), "Huh? GetLogEntries failed!");
|
||||||
|
qCDebug(dcTests()) << "log response:" << response.toMap().value("params").toMap().value("logEntries");
|
||||||
|
QVERIFY2(response.toMap().value("params").toMap().value("logEntries").toList().isEmpty(), "There are state changed events after a core restart even though states did not change!");
|
||||||
|
|
||||||
params.clear();
|
params.clear();
|
||||||
params.insert("thingId", addedThingId);
|
params.insert("thingId", addedThingId);
|
||||||
response = injectAndWait("Integrations.RemoveThing", params);
|
response = injectAndWait("Integrations.RemoveThing", params);
|
||||||
|
|||||||
Reference in New Issue
Block a user