From 0bdfeb81dca7a4b29dc8192a0015a0982bb51acf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Tue, 30 May 2023 15:12:33 +0200 Subject: [PATCH] SunSpec: Fix autoremove devices if the model does not exist any more --- sunspec/integrationpluginsunspec.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sunspec/integrationpluginsunspec.cpp b/sunspec/integrationpluginsunspec.cpp index 9fad0f0..d427b21 100644 --- a/sunspec/integrationpluginsunspec.cpp +++ b/sunspec/integrationpluginsunspec.cpp @@ -626,12 +626,16 @@ void IntegrationPluginSunSpec::processDiscoveryResult(Thing *thing, SunSpecConne // - Some SunSpec device seem to communicate different model id depending on the startup phase // i.e. they communicate a SinglePhase Meter on register x, few mnutes later it is a 3 phase meter on x // This code should handle such weird setups... + + if (connection->models().isEmpty()) + return; + foreach (Thing *child, myThings().filterByParentId(thing->id())) { - if (!m_modelIdParamTypeIds.contains(child->thingClassId()) || connection->models().isEmpty()) + if (!m_modelIdParamTypeIds.contains(child->thingClassId()) || !m_modbusAddressParamTypeIds.contains(child->thingClassId())) continue; - uint childModelId = child->paramValue(m_modelIdParamTypeIds.value(thing->thingClassId())).toUInt(); - uint childModbusAddress = child->paramValue(m_modbusAddressParamTypeIds.value(thing->thingClassId())).toUInt(); + uint childModelId = child->paramValue(m_modelIdParamTypeIds.value(child->thingClassId())).toUInt(); + uint childModbusAddress = child->paramValue(m_modbusAddressParamTypeIds.value(child->thingClassId())).toUInt(); bool modelFoundForChild = false; foreach (SunSpecModel *model, connection->models()) {