From 0abc756a3dff3500474e4602752beb4c54d07a9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Fri, 16 Jul 2021 17:09:33 +0200 Subject: [PATCH] Fix set version string for sunspec devices --- sunspec/integrationpluginsunspec.cpp | 12 ----------- sunspec/integrationpluginsunspec.h | 3 --- sunspec/sunspecinverter.cpp | 32 +++++++++++----------------- sunspec/sunspecmeter.cpp | 14 ++++++++++++ sunspec/sunspecstorage.cpp | 2 ++ 5 files changed, 28 insertions(+), 35 deletions(-) diff --git a/sunspec/integrationpluginsunspec.cpp b/sunspec/integrationpluginsunspec.cpp index ee1248d..d72705b 100644 --- a/sunspec/integrationpluginsunspec.cpp +++ b/sunspec/integrationpluginsunspec.cpp @@ -89,15 +89,6 @@ void IntegrationPluginSunSpec::init() m_connectedStateTypeIds.insert(sunspecSplitPhaseMeterThingClassId, sunspecSplitPhaseMeterConnectedStateTypeId); m_connectedStateTypeIds.insert(sunspecThreePhaseMeterThingClassId, sunspecThreePhaseMeterConnectedStateTypeId); - // Version states for all sunspec things - m_versionStateTypeIds.insert(solarEdgeBatteryThingClassId, solarEdgeBatteryVersionStateTypeId); - m_versionStateTypeIds.insert(sunspecSinglePhaseInverterThingClassId, sunspecSinglePhaseInverterVersionStateTypeId); - m_versionStateTypeIds.insert(sunspecThreePhaseInverterThingClassId, sunspecThreePhaseInverterVersionStateTypeId); - m_versionStateTypeIds.insert(sunspecStorageThingClassId, sunspecStorageVersionStateTypeId); - m_versionStateTypeIds.insert(sunspecSinglePhaseMeterThingClassId, sunspecSinglePhaseMeterVersionStateTypeId); - m_versionStateTypeIds.insert(sunspecSplitPhaseMeterThingClassId, sunspecSplitPhaseMeterVersionStateTypeId); - m_versionStateTypeIds.insert(sunspecThreePhaseMeterThingClassId, sunspecThreePhaseMeterVersionStateTypeId); - // Params for sunspec things m_modelIdParamTypeIds.insert(sunspecSinglePhaseInverterThingClassId, sunspecSinglePhaseInverterThingModelIdParamTypeId); m_modelIdParamTypeIds.insert(sunspecSplitPhaseInverterThingClassId, sunspecSplitPhaseInverterThingModelIdParamTypeId); @@ -287,9 +278,6 @@ void IntegrationPluginSunSpec::postSetupThing(Thing *thing) } else if (m_sunspecThings.contains(thing)) { SunSpecThing *sunSpecThing = m_sunspecThings.value(thing); sunSpecThing->readBlockData(); - - // Update the version state - thing->setStateValue(m_versionStateTypeIds.value(thing->thingClassId()), sunSpecThing->model()->commonModelInfo().versionString); } else { Q_ASSERT_X(false, "postSetupThing", QString("Unhandled thingClassId: %1").arg(thing->thingClassId().toString()).toUtf8()); } diff --git a/sunspec/integrationpluginsunspec.h b/sunspec/integrationpluginsunspec.h index bab9f7e..f2710ea 100644 --- a/sunspec/integrationpluginsunspec.h +++ b/sunspec/integrationpluginsunspec.h @@ -69,9 +69,6 @@ private: QHash m_connectionMacAddressParamTypeIds; QHash m_connectionSlaveIdParamTypeIds; - // SunSpec thing common state map - QHash m_versionStateTypeIds; - // SunSpec thing params map QHash m_modelIdParamTypeIds; QHash m_modbusAddressParamTypeIds; diff --git a/sunspec/sunspecinverter.cpp b/sunspec/sunspecinverter.cpp index 8ad23ca..53f386f 100644 --- a/sunspec/sunspecinverter.cpp +++ b/sunspec/sunspecinverter.cpp @@ -56,74 +56,68 @@ void SunSpecInverter::onBlockDataUpdated() SunSpecInverterSinglePhaseModel *inverter = qobject_cast(m_model); qCDebug(dcSunSpec()) << m_thing->name() << "block data updated" << inverter; m_thing->setStateValue(sunspecSinglePhaseInverterConnectedStateTypeId, true); + m_thing->setStateValue(sunspecSinglePhaseInverterVersionStateTypeId, m_model->commonModelInfo().versionString); + m_thing->setStateValue(sunspecSinglePhaseInverterTotalCurrentStateTypeId, inverter->amps()); m_thing->setStateValue(sunspecSinglePhaseInverterCurrentPowerStateTypeId, inverter->watts()); m_thing->setStateValue(sunspecSinglePhaseInverterTotalEnergyProducedStateTypeId, inverter->wattHours() / 1000.0); m_thing->setStateValue(sunspecSinglePhaseInverterFrequencyStateTypeId, inverter->hz()); m_thing->setStateValue(sunspecSinglePhaseInverterCabinetTemperatureStateTypeId, inverter->cabinetTemperature()); - m_thing->setStateValue(sunspecSinglePhaseInverterPhaseVoltageStateTypeId, inverter->phaseVoltageAn()); - m_thing->setStateValue(sunspecSinglePhaseInverterOperatingStateStateTypeId, getStateString(inverter->operatingState())); m_thing->setStateValue(sunspecSinglePhaseInverterErrorStateTypeId, getErrorString(inverter->event1())); - break; } case SunSpecModelFactory::ModelIdInverterSinglePhaseFloat: { SunSpecInverterSinglePhaseFloatModel *inverter = qobject_cast(m_model); qCDebug(dcSunSpec()) << m_thing->name() << "block data updated" << inverter; m_thing->setStateValue(sunspecSinglePhaseInverterConnectedStateTypeId, true); + m_thing->setStateValue(sunspecSinglePhaseInverterVersionStateTypeId, m_model->commonModelInfo().versionString); + m_thing->setStateValue(sunspecSinglePhaseInverterTotalCurrentStateTypeId, inverter->amps()); m_thing->setStateValue(sunspecSinglePhaseInverterCurrentPowerStateTypeId, inverter->watts()); m_thing->setStateValue(sunspecSinglePhaseInverterTotalEnergyProducedStateTypeId, inverter->wattHours() / 1000.0); m_thing->setStateValue(sunspecSinglePhaseInverterFrequencyStateTypeId, inverter->hz()); m_thing->setStateValue(sunspecSinglePhaseInverterCabinetTemperatureStateTypeId, inverter->cabinetTemperature()); - m_thing->setStateValue(sunspecSinglePhaseInverterPhaseVoltageStateTypeId, inverter->phaseVoltageAn()); - m_thing->setStateValue(sunspecSinglePhaseInverterOperatingStateStateTypeId, getStateString(inverter->operatingState())); - m_thing->setStateValue(sunspecSinglePhaseInverterErrorStateTypeId, getErrorString(inverter->event1())); - break; } case SunSpecModelFactory::ModelIdInverterSplitPhase: { SunSpecInverterSplitPhaseModel *inverter = qobject_cast(m_model); qCDebug(dcSunSpec()) << m_thing->name() << "block data updated" << inverter; m_thing->setStateValue(sunspecSplitPhaseInverterConnectedStateTypeId, true); + m_thing->setStateValue(sunspecSplitPhaseInverterVersionStateTypeId, m_model->commonModelInfo().versionString); + m_thing->setStateValue(sunspecSplitPhaseInverterTotalCurrentStateTypeId, inverter->amps()); m_thing->setStateValue(sunspecSplitPhaseInverterCurrentPowerStateTypeId, inverter->watts()); m_thing->setStateValue(sunspecSplitPhaseInverterTotalEnergyProducedStateTypeId, inverter->wattHours() / 1000.0); m_thing->setStateValue(sunspecSplitPhaseInverterFrequencyStateTypeId, inverter->hz()); m_thing->setStateValue(sunspecSplitPhaseInverterCabinetTemperatureStateTypeId, inverter->cabinetTemperature()); - m_thing->setStateValue(sunspecSplitPhaseInverterPhaseANVoltageStateTypeId, inverter->phaseVoltageAn()); m_thing->setStateValue(sunspecSplitPhaseInverterPhaseBNVoltageStateTypeId, inverter->phaseVoltageBn()); - m_thing->setStateValue(sunspecSplitPhaseInverterPhaseACurrentStateTypeId, inverter->ampsPhaseA()); m_thing->setStateValue(sunspecSplitPhaseInverterPhaseBCurrentStateTypeId, inverter->ampsPhaseB()); - m_thing->setStateValue(sunspecSplitPhaseInverterOperatingStateStateTypeId, getStateString(inverter->operatingState())); m_thing->setStateValue(sunspecSplitPhaseInverterErrorStateTypeId, getErrorString(inverter->event1())); - break; } case SunSpecModelFactory::ModelIdInverterSplitPhaseFloat: { SunSpecInverterSplitPhaseFloatModel *inverter = qobject_cast(m_model); qCDebug(dcSunSpec()) << m_thing->name() << "block data updated" << inverter; m_thing->setStateValue(sunspecSplitPhaseInverterConnectedStateTypeId, true); + m_thing->setStateValue(sunspecSplitPhaseInverterVersionStateTypeId, m_model->commonModelInfo().versionString); + m_thing->setStateValue(sunspecSplitPhaseInverterTotalCurrentStateTypeId, inverter->amps()); m_thing->setStateValue(sunspecSplitPhaseInverterCurrentPowerStateTypeId, inverter->watts()); m_thing->setStateValue(sunspecSplitPhaseInverterTotalEnergyProducedStateTypeId, inverter->wattHours() / 1000.0); m_thing->setStateValue(sunspecSplitPhaseInverterFrequencyStateTypeId, inverter->hz()); m_thing->setStateValue(sunspecSplitPhaseInverterCabinetTemperatureStateTypeId, inverter->cabinetTemperature()); - m_thing->setStateValue(sunspecSplitPhaseInverterPhaseANVoltageStateTypeId, inverter->phaseVoltageAn()); m_thing->setStateValue(sunspecSplitPhaseInverterPhaseBNVoltageStateTypeId, inverter->phaseVoltageBn()); - m_thing->setStateValue(sunspecSplitPhaseInverterPhaseACurrentStateTypeId, inverter->ampsPhaseA()); m_thing->setStateValue(sunspecSplitPhaseInverterPhaseBCurrentStateTypeId, inverter->ampsPhaseB()); - m_thing->setStateValue(sunspecSplitPhaseInverterOperatingStateStateTypeId, getStateString(inverter->operatingState())); m_thing->setStateValue(sunspecSplitPhaseInverterErrorStateTypeId, getErrorString(inverter->event1())); break; @@ -132,20 +126,19 @@ void SunSpecInverter::onBlockDataUpdated() SunSpecInverterThreePhaseModel *inverter = qobject_cast(m_model); qCDebug(dcSunSpec()) << m_thing->name() << "block data updated" << inverter; m_thing->setStateValue(sunspecThreePhaseInverterConnectedStateTypeId, true); + m_thing->setStateValue(sunspecThreePhaseInverterVersionStateTypeId, m_model->commonModelInfo().versionString); + m_thing->setStateValue(sunspecThreePhaseInverterTotalCurrentStateTypeId, inverter->amps()); m_thing->setStateValue(sunspecThreePhaseInverterCurrentPowerStateTypeId, inverter->watts()); m_thing->setStateValue(sunspecThreePhaseInverterTotalEnergyProducedStateTypeId, inverter->wattHours() / 1000.0); m_thing->setStateValue(sunspecThreePhaseInverterFrequencyStateTypeId, inverter->hz()); m_thing->setStateValue(sunspecThreePhaseInverterCabinetTemperatureStateTypeId, inverter->cabinetTemperature()); - m_thing->setStateValue(sunspecThreePhaseInverterPhaseANVoltageStateTypeId, inverter->phaseVoltageAn()); m_thing->setStateValue(sunspecThreePhaseInverterPhaseBNVoltageStateTypeId, inverter->phaseVoltageBn()); m_thing->setStateValue(sunspecThreePhaseInverterPhaseCNVoltageStateTypeId, inverter->phaseVoltageCn()); - m_thing->setStateValue(sunspecThreePhaseInverterPhaseACurrentStateTypeId, inverter->ampsPhaseA()); m_thing->setStateValue(sunspecThreePhaseInverterPhaseBCurrentStateTypeId, inverter->ampsPhaseB()); m_thing->setStateValue(sunspecThreePhaseInverterPhaseCCurrentStateTypeId, inverter->ampsPhaseC()); - m_thing->setStateValue(sunspecThreePhaseInverterOperatingStateStateTypeId, getStateString(inverter->operatingState())); m_thing->setStateValue(sunspecThreePhaseInverterErrorStateTypeId, getErrorString(inverter->event1())); break; @@ -154,20 +147,19 @@ void SunSpecInverter::onBlockDataUpdated() SunSpecInverterThreePhaseFloatModel *inverter = qobject_cast(m_model); qCDebug(dcSunSpec()) << m_thing->name() << "block data updated" << inverter; m_thing->setStateValue(sunspecThreePhaseInverterConnectedStateTypeId, true); + m_thing->setStateValue(sunspecThreePhaseInverterVersionStateTypeId, m_model->commonModelInfo().versionString); + m_thing->setStateValue(sunspecThreePhaseInverterTotalCurrentStateTypeId, inverter->amps()); m_thing->setStateValue(sunspecThreePhaseInverterCurrentPowerStateTypeId, inverter->watts()); m_thing->setStateValue(sunspecThreePhaseInverterTotalEnergyProducedStateTypeId, inverter->wattHours() / 1000.0); m_thing->setStateValue(sunspecThreePhaseInverterFrequencyStateTypeId, inverter->hz()); m_thing->setStateValue(sunspecThreePhaseInverterCabinetTemperatureStateTypeId, inverter->cabinetTemperature()); - m_thing->setStateValue(sunspecThreePhaseInverterPhaseANVoltageStateTypeId, inverter->phaseVoltageAn()); m_thing->setStateValue(sunspecThreePhaseInverterPhaseBNVoltageStateTypeId, inverter->phaseVoltageBn()); m_thing->setStateValue(sunspecThreePhaseInverterPhaseCNVoltageStateTypeId, inverter->phaseVoltageCn()); - m_thing->setStateValue(sunspecThreePhaseInverterPhaseACurrentStateTypeId, inverter->ampsPhaseA()); m_thing->setStateValue(sunspecThreePhaseInverterPhaseBCurrentStateTypeId, inverter->ampsPhaseB()); m_thing->setStateValue(sunspecThreePhaseInverterPhaseCCurrentStateTypeId, inverter->ampsPhaseC()); - m_thing->setStateValue(sunspecThreePhaseInverterOperatingStateStateTypeId, getStateString(inverter->operatingState())); m_thing->setStateValue(sunspecThreePhaseInverterErrorStateTypeId, getErrorString(inverter->event1())); break; diff --git a/sunspec/sunspecmeter.cpp b/sunspec/sunspecmeter.cpp index 4ba6cbe..581c5dd 100644 --- a/sunspec/sunspecmeter.cpp +++ b/sunspec/sunspecmeter.cpp @@ -73,6 +73,8 @@ void SunSpecMeter::onBlockDataUpdated() SunSpecMeterSinglePhaseFloatModel *meter = qobject_cast(m_model); qCDebug(dcSunSpec()) << m_thing->name() << "block data updated" << meter; m_thing->setStateValue(sunspecSinglePhaseMeterConnectedStateTypeId, true); + m_thing->setStateValue(sunspecSinglePhaseMeterVersionStateTypeId, m_model->commonModelInfo().versionString); + m_thing->setStateValue(sunspecSinglePhaseMeterPhaseACurrentStateTypeId, meter->ampsPhaseA()); m_thing->setStateValue(sunspecSinglePhaseMeterLnACVoltageStateTypeId, meter->voltageLn()); m_thing->setStateValue(sunspecSinglePhaseMeterPhaseANVoltageStateTypeId, meter->phaseVoltageAn()); @@ -86,6 +88,8 @@ void SunSpecMeter::onBlockDataUpdated() SunSpecMeterSplitSinglePhaseAbnModel *meter = qobject_cast(m_model); qCDebug(dcSunSpec()) << m_thing->name() << "block data updated" << meter; m_thing->setStateValue(sunspecSplitPhaseMeterConnectedStateTypeId, true); + m_thing->setStateValue(sunspecSplitPhaseMeterVersionStateTypeId, m_model->commonModelInfo().versionString); + m_thing->setStateValue(sunspecSplitPhaseMeterTotalCurrentStateTypeId, meter->amps()); m_thing->setStateValue(sunspecSplitPhaseMeterPhaseACurrentStateTypeId, meter->ampsPhaseA()); m_thing->setStateValue(sunspecSplitPhaseMeterPhaseBCurrentStateTypeId, meter->ampsPhaseB()); @@ -102,6 +106,8 @@ void SunSpecMeter::onBlockDataUpdated() SunSpecMeterSplitSinglePhaseFloatModel *meter = qobject_cast(m_model); qCDebug(dcSunSpec()) << m_thing->name() << "block data updated" << meter; m_thing->setStateValue(sunspecSplitPhaseMeterConnectedStateTypeId, true); + m_thing->setStateValue(sunspecSplitPhaseMeterVersionStateTypeId, m_model->commonModelInfo().versionString); + m_thing->setStateValue(sunspecSplitPhaseMeterTotalCurrentStateTypeId, meter->amps()); m_thing->setStateValue(sunspecSplitPhaseMeterPhaseACurrentStateTypeId, meter->ampsPhaseA()); m_thing->setStateValue(sunspecSplitPhaseMeterPhaseBCurrentStateTypeId, meter->ampsPhaseB()); @@ -118,6 +124,8 @@ void SunSpecMeter::onBlockDataUpdated() SunSpecMeterThreePhaseModel *meter = qobject_cast(m_model); qCDebug(dcSunSpec()) << m_thing->name() << "block data updated" << meter; m_thing->setStateValue(sunspecThreePhaseMeterConnectedStateTypeId, true); + m_thing->setStateValue(sunspecThreePhaseMeterVersionStateTypeId, m_model->commonModelInfo().versionString); + m_thing->setStateValue(sunspecThreePhaseMeterTotalCurrentStateTypeId, meter->amps()); m_thing->setStateValue(sunspecThreePhaseMeterPhaseACurrentStateTypeId, meter->ampsPhaseA()); m_thing->setStateValue(sunspecThreePhaseMeterPhaseBCurrentStateTypeId, meter->ampsPhaseB()); @@ -136,6 +144,8 @@ void SunSpecMeter::onBlockDataUpdated() SunSpecDeltaConnectThreePhaseAbcMeterModel *meter = qobject_cast(m_model); qCDebug(dcSunSpec()) << m_thing->name() << "block data updated" << meter; m_thing->setStateValue(sunspecThreePhaseMeterConnectedStateTypeId, true); + m_thing->setStateValue(sunspecThreePhaseMeterVersionStateTypeId, m_model->commonModelInfo().versionString); + m_thing->setStateValue(sunspecThreePhaseMeterTotalCurrentStateTypeId, meter->amps()); m_thing->setStateValue(sunspecThreePhaseMeterPhaseACurrentStateTypeId, meter->ampsPhaseA()); m_thing->setStateValue(sunspecThreePhaseMeterPhaseBCurrentStateTypeId, meter->ampsPhaseB()); @@ -154,6 +164,8 @@ void SunSpecMeter::onBlockDataUpdated() SunSpecMeterThreePhaseWyeConnectModel *meter = qobject_cast(m_model); qCDebug(dcSunSpec()) << m_thing->name() << "block data updated" << meter; m_thing->setStateValue(sunspecThreePhaseMeterConnectedStateTypeId, true); + m_thing->setStateValue(sunspecThreePhaseMeterVersionStateTypeId, m_model->commonModelInfo().versionString); + m_thing->setStateValue(sunspecThreePhaseMeterTotalCurrentStateTypeId, meter->amps()); m_thing->setStateValue(sunspecThreePhaseMeterPhaseACurrentStateTypeId, meter->ampsPhaseA()); m_thing->setStateValue(sunspecThreePhaseMeterPhaseBCurrentStateTypeId, meter->ampsPhaseB()); @@ -172,6 +184,8 @@ void SunSpecMeter::onBlockDataUpdated() SunSpecMeterThreePhaseDeltaConnectModel *meter = qobject_cast(m_model); qCDebug(dcSunSpec()) << m_thing->name() << "block data updated" << meter; m_thing->setStateValue(sunspecThreePhaseMeterConnectedStateTypeId, true); + m_thing->setStateValue(sunspecThreePhaseMeterVersionStateTypeId, m_model->commonModelInfo().versionString); + m_thing->setStateValue(sunspecThreePhaseMeterTotalCurrentStateTypeId, meter->amps()); m_thing->setStateValue(sunspecThreePhaseMeterPhaseACurrentStateTypeId, meter->ampsPhaseA()); m_thing->setStateValue(sunspecThreePhaseMeterPhaseBCurrentStateTypeId, meter->ampsPhaseB()); diff --git a/sunspec/sunspecstorage.cpp b/sunspec/sunspecstorage.cpp index 81b241d..79de4f4 100644 --- a/sunspec/sunspecstorage.cpp +++ b/sunspec/sunspecstorage.cpp @@ -126,6 +126,8 @@ void SunSpecStorage::onBlockDataUpdated() qCDebug(dcSunSpec()) << m_thing->name() << "block data updated" << storage; m_thing->setStateValue(sunspecStorageConnectedStateTypeId, true); + m_thing->setStateValue(sunspecStorageVersionStateTypeId, m_model->commonModelInfo().versionString); + m_thing->setStateValue(sunspecStorageBatteryCriticalStateTypeId, storage->chaState() < 5); m_thing->setStateValue(sunspecStorageBatteryLevelStateTypeId, qRound(storage->chaState())); m_thing->setStateValue(sunspecStorageGridChargingStateTypeId, storage->chaGriSet() == SunSpecStorageModel::ChagrisetGrid);