Patrick Schurig a598544712 sunspec: open a second connection for the Fronius Smart Meter
A GEN24 answers for the inverter on unit ID 1 and for its Smart Meter on
unit ID 200 by default, behind the same host and port. One thing now
carries two SunSpecConnection objects, the second one driven by the
meterSlaveId parameter that until now no line of C++ ever read.

The meter connection is created during setup but left idle: it is only
brought up once the primary connection has finished discovering, so the
two never handshake at the same time towards the same inverter. An
absent meter never fails the pairing, since a GEN24 without a Smart
Meter is a legitimate installation and the parameter has a non zero
default the user did not choose.

thingRemoved() and the reconfigure path now dispose of both connections
through a single entry point. Their else if chain used to stop at the
primary one, which left the meter connection outliving its thing with an
open socket and signals pointing at a destroyed Thing.

Child things look their model up across every connection of their
parent. The two connections of a GEN24 never announce the same model ID,
so no discriminator has to be persisted.

Adds a test suite instantiating the plugin behind a real ThingManager
with two connections. It lives in its own binary because the F1 suite
checks global call counters that extra configured things would falsify.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-02 09:00:27 +02:00

65 lines
2.2 KiB
Prolog

include(../../../sunspec.pri)
QT += testlib network serialbus
QT -= gui
CONFIG += console testcase c++17
CONFIG -= app_bundle
TEMPLATE = app
TARGET = tst_sunspecmultiunit
# Suite F3 : un thing froniusConnection porte deux SunSpecConnection, une par
# unit ID, sur le meme host:port.
#
# Binaire separe de ../plugin plutot que tests ajoutes a celui-la : les things
# deja configures sont ecrits dans les reglages avant le demarrage du
# ThingManager, donc en ajouter ferait mentir les compteurs d'appels que la
# suite F1 verifie. Chaque binaire a son propre nom d'organisation, donc son
# propre fichier de reglages, et n'interfere pas avec l'autre.
CONFIG += link_pkgconfig
PKGCONFIG += nymea nymea-core
PLUGIN_DIR = $$PWD/../..
INCLUDEPATH += $$PLUGIN_DIR
# Accesseurs reserves aux tests : voir integrationpluginsunspec.h. Sans eux, le
# nombre de connexions d'un thing n'est pas observable, les deux vivant derriere
# le meme moniteur reseau et le meme host:port.
DEFINES += SUNSPEC_PLUGIN_TEST_ACCESS
JSONFILE = $$PLUGIN_DIR/integrationpluginsunspec.json
OTHER_FILES += $$JSONFILE
plugininfo.input = JSONFILE
plugininfo.output = plugininfo.h
plugininfo.commands = nymea-plugininfocompiler ${QMAKE_FILE_NAME} --output ${QMAKE_FILE_OUT}
plugininfo.dependency_type = TYPE_C
plugininfo.CONFIG += no_link combine
QMAKE_EXTRA_COMPILERS += plugininfo
extern_plugininfo.input = JSONFILE
extern_plugininfo.output = extern-plugininfo.h
extern_plugininfo.commands = nymea-plugininfocompiler ${QMAKE_FILE_NAME} --extern ${QMAKE_FILE_OUT}
extern_plugininfo.dependency_type = TYPE_C
extern_plugininfo.CONFIG += no_link combine
QMAKE_EXTRA_COMPILERS += extern_plugininfo
DEFINES += PLUGIN_JSON_PATH=\\\"$$JSONFILE\\\"
SOURCES += \
tst_sunspecmultiunit.cpp \
$$PLUGIN_DIR/integrationpluginsunspec.cpp \
$$PLUGIN_DIR/froniusrules.cpp \
$$PLUGIN_DIR/solaredgebattery.cpp \
$$PLUGIN_DIR/sunspecdiscovery.cpp \
$$PLUGIN_DIR/sunspecstoragelogic.cpp \
$$PLUGIN_DIR/sunspecthing.cpp
HEADERS += \
$$PLUGIN_DIR/integrationpluginsunspec.h \
$$PLUGIN_DIR/froniusrules.h \
$$PLUGIN_DIR/solaredgebattery.h \
$$PLUGIN_DIR/sunspecdiscovery.h \
$$PLUGIN_DIR/sunspecstoragelogic.h \
$$PLUGIN_DIR/sunspecthing.h