-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR #202: SunSpec: Update to networkdevice intrface
- Loading branch information
Showing
5 changed files
with
122 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | ||
* | ||
* Copyright 2013 - 2023, nymea GmbH | ||
* Copyright 2013 - 2024, nymea GmbH | ||
* Contact: [email protected] | ||
* | ||
* This file is part of nymea. | ||
|
@@ -70,12 +70,18 @@ IntegrationPluginSunSpec::IntegrationPluginSunSpec() | |
void IntegrationPluginSunSpec::init() | ||
{ | ||
// SunSpec connection params | ||
m_connectionPortParamTypeIds.insert(sunspecConnectionThingClassId, sunspecConnectionThingPortParamTypeId); | ||
m_connectionPortParamTypeIds.insert(solarEdgeConnectionThingClassId, solarEdgeConnectionThingPortParamTypeId); | ||
|
||
m_connectionMacAddressParamTypeIds.insert(sunspecConnectionThingClassId, sunspecConnectionThingMacAddressParamTypeId); | ||
m_connectionMacAddressParamTypeIds.insert(solarEdgeConnectionThingClassId, solarEdgeConnectionThingMacAddressParamTypeId); | ||
|
||
m_connectionHostNameParamTypeIds.insert(sunspecConnectionThingClassId, sunspecConnectionThingHostNameParamTypeId); | ||
m_connectionHostNameParamTypeIds.insert(solarEdgeConnectionThingClassId, solarEdgeConnectionThingHostNameParamTypeId); | ||
|
||
m_connectionAddressParamTypeIds.insert(sunspecConnectionThingClassId, sunspecConnectionThingAddressParamTypeId); | ||
m_connectionAddressParamTypeIds.insert(solarEdgeConnectionThingClassId, solarEdgeConnectionThingAddressParamTypeId); | ||
|
||
m_connectionPortParamTypeIds.insert(sunspecConnectionThingClassId, sunspecConnectionThingPortParamTypeId); | ||
m_connectionPortParamTypeIds.insert(solarEdgeConnectionThingClassId, solarEdgeConnectionThingPortParamTypeId); | ||
|
||
m_connectionSlaveIdParamTypeIds.insert(sunspecConnectionThingClassId, sunspecConnectionThingSlaveIdParamTypeId); | ||
m_connectionSlaveIdParamTypeIds.insert(solarEdgeConnectionThingClassId, solarEdgeConnectionThingSlaveIdParamTypeId); | ||
|
||
|
@@ -141,7 +147,7 @@ void IntegrationPluginSunSpec::discoverThings(ThingDiscoveryInfo *info) | |
|
||
SunSpecDiscovery *discovery = new SunSpecDiscovery(hardwareManager()->networkDeviceDiscovery(), slaveIds, byteOrder, info); | ||
// Note: we could add here more | ||
connect(discovery, &SunSpecDiscovery::discoveryFinished, info, [=](){ | ||
connect(discovery, &SunSpecDiscovery::discoveryFinished, info, [this, info, discovery](){ | ||
foreach (const SunSpecDiscovery::Result &result, discovery->results()) { | ||
|
||
// Extract the manufacturer: we pick the first manufacturer name of the first common model having a manufacturer name for now | ||
|
@@ -166,6 +172,7 @@ void IntegrationPluginSunSpec::discoverThings(ThingDiscoveryInfo *info) | |
// Full support of meter, inverter and storage will be provided in the kostal plugin which makes | ||
// use of the native modbus communication from kostal. | ||
if (hasManufacturer(result.modelManufacturers, "kostal")) { | ||
qCWarning(dcSunSpec()) << "Skipping Kostal manufacturer on SunSpec. Please use the native kostal integration plugin in order to add it to the system."; | ||
continue; | ||
} | ||
} | ||
|
@@ -177,26 +184,40 @@ void IntegrationPluginSunSpec::discoverThings(ThingDiscoveryInfo *info) | |
title.append("SunSpec connection"); | ||
|
||
QString description; | ||
if (result.networkDeviceInfo.macAddressManufacturer().isEmpty()) { | ||
description = result.networkDeviceInfo.macAddress(); | ||
} else { | ||
description = result.networkDeviceInfo.macAddress() + " (" + result.networkDeviceInfo.macAddressManufacturer() + ")"; | ||
MacAddressInfo macInfo; | ||
switch (result.networkDeviceInfo.monitorMode()) { | ||
case NetworkDeviceInfo::MonitorModeMac: | ||
macInfo = result.networkDeviceInfo.macAddressInfos().constFirst(); | ||
description = result.networkDeviceInfo.address().toString(); | ||
if (!macInfo.vendorName().isEmpty()) | ||
description += " - " + result.networkDeviceInfo.macAddressInfos().constFirst().vendorName(); | ||
|
||
break; | ||
case NetworkDeviceInfo::MonitorModeHostName: | ||
description = result.networkDeviceInfo.hostName(); | ||
break; | ||
case NetworkDeviceInfo::MonitorModeIp: | ||
description = "Interface: " + result.networkDeviceInfo.networkInterface().name(); | ||
break; | ||
} | ||
|
||
ThingDescriptor descriptor(info->thingClassId(), title, description); | ||
|
||
// Check if we already have set up this device | ||
Things existingThings = myThings().filterByParam(m_connectionMacAddressParamTypeIds.value(info->thingClassId()), result.networkDeviceInfo.macAddress()); | ||
if (existingThings.count() == 1) { | ||
qCDebug(dcSunSpec()) << "This thing already exists in the system." << existingThings.first() << result.networkDeviceInfo; | ||
descriptor.setThingId(existingThings.first()->id()); | ||
} | ||
|
||
ParamList params; | ||
params << Param(m_connectionMacAddressParamTypeIds.value(info->thingClassId()), result.networkDeviceInfo.thingParamValueMacAddress()); | ||
params << Param(m_connectionHostNameParamTypeIds.value(info->thingClassId()), result.networkDeviceInfo.thingParamValueHostName()); | ||
params << Param(m_connectionAddressParamTypeIds.value(info->thingClassId()), result.networkDeviceInfo.thingParamValueAddress()); | ||
params << Param(m_connectionPortParamTypeIds.value(info->thingClassId()), result.port); | ||
params << Param(m_connectionMacAddressParamTypeIds.value(info->thingClassId()), result.networkDeviceInfo.macAddress()); | ||
params << Param(m_connectionSlaveIdParamTypeIds.value(info->thingClassId()), result.slaveId); | ||
descriptor.setParams(params); | ||
|
||
// Check if we already have set up this device | ||
Thing *existingThing = myThings().findByParams(params); | ||
if (existingThing) { | ||
qCDebug(dcSunSpec()) << "This thing already exists in the system:" << result.networkDeviceInfo; | ||
descriptor.setThingId(existingThing->id()); | ||
} | ||
|
||
info->addThingDescriptor(descriptor); | ||
} | ||
|
||
|
@@ -213,7 +234,8 @@ void IntegrationPluginSunSpec::setupThing(ThingSetupInfo *info) | |
qCDebug(dcSunSpec()) << "Setup thing" << thing; | ||
qCDebug(dcSunSpec()) << thing->params(); | ||
|
||
if (thing->thingClassId() == sunspecConnectionThingClassId || thing->thingClassId() == solarEdgeConnectionThingClassId) { | ||
if (thing->thingClassId() == sunspecConnectionThingClassId || | ||
thing->thingClassId() == solarEdgeConnectionThingClassId) { | ||
|
||
// Handle reconfigure | ||
if (m_sunSpecConnections.contains(thing->id())) { | ||
|
@@ -225,16 +247,17 @@ void IntegrationPluginSunSpec::setupThing(ThingSetupInfo *info) | |
} | ||
} | ||
|
||
MacAddress macAddress = MacAddress(thing->paramValue(m_connectionMacAddressParamTypeIds.value(thing->thingClassId())).toString()); | ||
if (!macAddress.isValid()) { | ||
qCWarning(dcSunSpec()) << "The configured mac address is not valid" << thing->params(); | ||
info->finish(Thing::ThingErrorInvalidParameter, QT_TR_NOOP("The MAC address is not known. Please reconfigure the connection.")); | ||
|
||
// Create the monitor | ||
NetworkDeviceMonitor *monitor = hardwareManager()->networkDeviceDiscovery()->registerMonitor(thing); | ||
if (!monitor) { | ||
qCWarning(dcSunSpec()) << "Unable to register monitor with the given params" << thing->params(); | ||
info->finish(Thing::ThingErrorInvalidParameter, QT_TR_NOOP("Unable to set up the connection with this configuration, please reconfigure the connection.")); | ||
return; | ||
} | ||
|
||
// Create the monitor | ||
NetworkDeviceMonitor *monitor = hardwareManager()->networkDeviceDiscovery()->registerMonitor(macAddress); | ||
m_monitors.insert(thing, monitor); | ||
|
||
QHostAddress address = monitor->networkDeviceInfo().address(); | ||
if (address.isNull() && info->isInitialSetup()) { | ||
qCWarning(dcSunSpec()) << "Cannot set up thing. The host address is not known and this is an initial setup"; | ||
|
@@ -305,9 +328,9 @@ void IntegrationPluginSunSpec::setupThing(ThingSetupInfo *info) | |
} | ||
} | ||
|
||
} else if (thing->thingClassId() == sunspecThreePhaseInverterThingClassId | ||
|| thing->thingClassId() == sunspecSplitPhaseInverterThingClassId | ||
|| thing->thingClassId() == sunspecSinglePhaseInverterThingClassId ) { | ||
} else if (thing->thingClassId() == sunspecThreePhaseInverterThingClassId || | ||
thing->thingClassId() == sunspecSplitPhaseInverterThingClassId || | ||
thing->thingClassId() == sunspecSinglePhaseInverterThingClassId ) { | ||
|
||
Thing *thing = info->thing(); | ||
uint modelId = thing->paramValue(m_modelIdParamTypeIds.value(thing->thingClassId())).toInt(); | ||
|
@@ -420,9 +443,8 @@ void IntegrationPluginSunSpec::thingRemoved(Thing *thing) | |
Q_ASSERT_X(false, "thingRemoved", QString("Unhandled thingClassId: %1").arg(thing->thingClassId().toString()).toUtf8()); | ||
} | ||
|
||
if (m_monitors.contains(thing)) { | ||
if (m_monitors.contains(thing)) | ||
hardwareManager()->networkDeviceDiscovery()->unregisterMonitor(m_monitors.take(thing)); | ||
} | ||
|
||
if (myThings().isEmpty()) { | ||
qCDebug(dcSunSpec()) << "Stopping refresh timer"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | ||
* | ||
* Copyright 2013 - 2023, nymea GmbH | ||
* Copyright 2013 - 2024, nymea GmbH | ||
* Contact: [email protected] | ||
* | ||
* This file is part of nymea. | ||
|
@@ -62,9 +62,10 @@ class IntegrationPluginSunSpec: public IntegrationPlugin | |
|
||
private: | ||
// SunSpec Connection params map | ||
QHash<ThingClassId, ParamTypeId> m_connectionIpParamTypeIds; | ||
QHash<ThingClassId, ParamTypeId> m_connectionPortParamTypeIds; | ||
QHash<ThingClassId, ParamTypeId> m_connectionMacAddressParamTypeIds; | ||
QHash<ThingClassId, ParamTypeId> m_connectionAddressParamTypeIds; | ||
QHash<ThingClassId, ParamTypeId> m_connectionHostNameParamTypeIds; | ||
QHash<ThingClassId, ParamTypeId> m_connectionPortParamTypeIds; | ||
QHash<ThingClassId, ParamTypeId> m_connectionSlaveIdParamTypeIds; | ||
|
||
// SunSpec thing params map | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.