Create timer after setup to prevent crash on startup

master
Simon Stürz 2021-03-18 11:19:09 +01:00
parent c1f6e42d9c
commit 05331143dd
1 changed files with 7 additions and 6 deletions

View File

@ -75,12 +75,6 @@ void IntegrationPluginSma::setupThing(ThingSetupInfo *info)
Thing *thing = info->thing();
qCDebug(dcSma()) << "Setup thing" << thing->name();
if (!m_refreshTimer) {
qCDebug(dcSma()) << "Starting refresh timer";
m_refreshTimer = hardwareManager()->pluginTimerManager()->registerTimer(1);
connect(m_refreshTimer, &PluginTimer::timeout, this, &IntegrationPluginSma::onRefreshTimer);
}
if (thing->thingClassId() == sunnyWebBoxThingClassId) {
//check if a Sunny WebBox is already added with this IPv4Address
foreach(SunnyWebBox *sunnyWebBox, m_sunnyWebBoxes.values()) {
@ -106,6 +100,13 @@ void IntegrationPluginSma::setupThing(ThingSetupInfo *info)
connect(sunnyWebBox, &SunnyWebBox::plantOverviewReceived, this, &IntegrationPluginSma::onPlantOverviewReceived);
m_sunnyWebBoxes.insert(info->thing(), sunnyWebBox);
});
if (!m_refreshTimer) {
qCDebug(dcSma()) << "Starting refresh timer";
m_refreshTimer = hardwareManager()->pluginTimerManager()->registerTimer(1);
connect(m_refreshTimer, &PluginTimer::timeout, this, &IntegrationPluginSma::onRefreshTimer);
}
} else {
Q_ASSERT_X(false, "setupThing", QString("Unhandled thingClassId: %1").arg(thing->thingClassId().toString()).toUtf8());
}