From e300ac974e40ac13c36709424b2d001fbd7908a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Fri, 17 Feb 2023 14:28:27 +0100 Subject: [PATCH] huawei: Set energy states to 0 if not connected --- huawei/integrationpluginhuawei.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/huawei/integrationpluginhuawei.cpp b/huawei/integrationpluginhuawei.cpp index 1785611..68ebe37 100644 --- a/huawei/integrationpluginhuawei.cpp +++ b/huawei/integrationpluginhuawei.cpp @@ -121,7 +121,6 @@ void IntegrationPluginHuawei::setupThing(ThingSetupInfo *info) if (m_monitors.contains(thing)) hardwareManager()->networkDeviceDiscovery()->unregisterMonitor(m_monitors.take(thing)); - // Make sure we have a valid mac address, otherwise no monitor and not auto searching is possible MacAddress macAddress = MacAddress(thing->paramValue(huaweiFusionSolarInverterThingMacAddressParamTypeId).toString()); if (macAddress.isNull()) { @@ -441,6 +440,21 @@ void IntegrationPluginHuawei::setupFusionSolar(ThingSetupInfo *info) thing->setStateValue("connected", reachable); foreach (Thing *childThing, myThings().filterByParentId(thing->id())) { childThing->setStateValue("connected", reachable); + + if (!reachable) { + // Set power values to 0 since we don't know what the current value is + if (childThing->thingClassId() == huaweiFusionSolarInverterThingClassId) { + thing->setStateValue(huaweiFusionSolarInverterCurrentPowerStateTypeId, 0); + } + + if (childThing->thingClassId() == huaweiMeterThingClassId) { + thing->setStateValue(huaweiMeterCurrentPowerStateTypeId, 0); + } + + if (childThing->thingClassId() == huaweiBatteryThingClassId) { + thing->setStateValue(huaweiBatteryCurrentPowerStateTypeId, 0); + } + } } });