Setup plugin timer

master
Simon Stürz 2021-06-10 09:49:09 +02:00 committed by Michael Zanetti
parent 539133cc26
commit d0d55427c3
2 changed files with 22 additions and 12 deletions

View File

@ -128,7 +128,16 @@ void IntegrationPluginMTec::postSetupThing(Thing *thing)
MTec *mtec = m_mtecConnections.value(thing);
if (mtec) {
update(thing);
//thing->setStateValue(mtecConnectedStateTypeId, true);
}
if (!m_pluginTimer) {
qCDebug(dcMTec()) << "Starting plugin timer...";
m_pluginTimer = hardwareManager()->pluginTimerManager()->registerTimer(10);
connect(m_pluginTimer, &PluginTimer::timeout, this, [this] {
foreach (Thing *thing, myThings().filterByThingClassId(mtecThingClassId)) {
update(thing);
}
});
}
}
}
@ -136,7 +145,16 @@ void IntegrationPluginMTec::postSetupThing(Thing *thing)
void IntegrationPluginMTec::thingRemoved(Thing *thing)
{
if (m_mtecConnections.contains(thing)) {
m_mtecConnections.take(thing)->deleteLater();
MTec *mtec = m_mtecConnections.take(thing);
if (mtec) {
mtec->disconnectDevice();
mtec->deleteLater();
}
}
if (myThings().isEmpty()) {
hardwareManager()->pluginTimerManager()->unregisterTimer(m_pluginTimer);
m_pluginTimer = nullptr;
}
}
@ -181,11 +199,4 @@ void IntegrationPluginMTec::onStatusUpdated(const MTecInfo &info)
thing->setStateValue(mtecRequestExternalHeatSourceStateTypeId, info.requestExternalHeatSource);
}
void IntegrationPluginMTec::onRefreshTimer()
{
foreach (Thing *thing, myThings().filterByThingClassId(mtecThingClassId)) {
update(thing);
}
}

View File

@ -56,12 +56,11 @@ public:
void executeAction(ThingActionInfo *info) override;
private:
PluginTimer *m_pluginTimer = nullptr;
QHash<Thing *, MTec *> m_mtecConnections;
void update(Thing *thing);
private slots:
void onRefreshTimer();
void update(Thing *thing);
void onStatusUpdated(const MTecInfo &info);
};