somfytahoma: Use single param for identifying the gateway

The single unique identifier of Somfy Gateways is the Gateway PIN that
the device announces via zeroconf (txt + hostname). There's no point in
setting two params to the same value.

Note that due to a previous mistake this fixes also getting the IP
via zeroconf, because the old code was comparing against an incorrect
identifier.
master
Christian Fetzer 2022-05-29 14:01:21 +02:00
parent 8955a84f26
commit 3f526cbf21
2 changed files with 4 additions and 14 deletions

View File

@ -53,11 +53,10 @@ void IntegrationPluginSomfyTahoma::discoverThings(ThingDiscoveryInfo *info)
ThingDescriptor descriptor(info->thingClassId(), "Somfy TaHoma Gateway", entry.hostAddress().toString()); ThingDescriptor descriptor(info->thingClassId(), "Somfy TaHoma Gateway", entry.hostAddress().toString());
ParamList params; ParamList params;
params << Param(gatewayThingGatewayIdParamTypeId, entry.name());
params << Param(gatewayThingGatewayPinParamTypeId, entry.txt("gateway_pin")); params << Param(gatewayThingGatewayPinParamTypeId, entry.txt("gateway_pin"));
descriptor.setParams(params); descriptor.setParams(params);
Things existingThings = myThings().filterByParam(gatewayThingGatewayIdParamTypeId, entry.name()); Things existingThings = myThings().filterByParam(gatewayThingGatewayPinParamTypeId, entry.txt("gateway_pin"));
if (existingThings.count() == 1) { if (existingThings.count() == 1) {
qCDebug(dcSomfyTahoma()) << "This gateway already exists in the system!"; qCDebug(dcSomfyTahoma()) << "This gateway already exists in the system!";
descriptor.setThingId(existingThings.first()->id()); descriptor.setThingId(existingThings.first()->id());
@ -128,8 +127,6 @@ void IntegrationPluginSomfyTahoma::setupThing(ThingSetupInfo *info)
QList<ThingDescriptor> unknownDevices; QList<ThingDescriptor> unknownDevices;
QUuid gatewayId = info->thing()->id(); QUuid gatewayId = info->thing()->id();
info->thing()->setParamValue(gatewayThingGatewayIdParamTypeId, result.toMap()["gateways"].toList().first().toMap().value("gatewayId").toString());
foreach (const QVariant &deviceVariant, result.toMap()["devices"].toList()) { foreach (const QVariant &deviceVariant, result.toMap()["devices"].toList()) {
QVariantMap deviceMap = deviceVariant.toMap(); QVariantMap deviceMap = deviceVariant.toMap();
QString type = deviceMap.value("controllableName").toString(); QString type = deviceMap.value("controllableName").toString();
@ -628,10 +625,10 @@ QString IntegrationPluginSomfyTahoma::getHost(Thing *thing) const
gateway = myThings().findById(thing->parentId()); gateway = myThings().findById(thing->parentId());
} }
QString gatewayId = gateway->paramValue(gatewayThingGatewayIdParamTypeId).toString(); QString gatewayPin = gateway->paramValue(gatewayThingGatewayPinParamTypeId).toString();
ZeroConfServiceEntry zeroConfEntry; ZeroConfServiceEntry zeroConfEntry;
foreach (const ZeroConfServiceEntry &entry, m_zeroConfBrowser->serviceEntries()) { foreach (const ZeroConfServiceEntry &entry, m_zeroConfBrowser->serviceEntries()) {
if (entry.name() == gatewayId) { if (gatewayPin == entry.txt("gateway_pin")) {
zeroConfEntry = entry; zeroConfEntry = entry;
} }
} }
@ -643,7 +640,7 @@ QString IntegrationPluginSomfyTahoma::getHost(Thing *thing) const
} else if (pluginStorage()->contains("cachedAddress")){ } else if (pluginStorage()->contains("cachedAddress")){
host = pluginStorage()->value("cachedAddress").toString(); host = pluginStorage()->value("cachedAddress").toString();
} else { } else {
qCWarning(dcSomfyTahoma()) << "Unable to determine IP address for:" << gatewayId; qCWarning(dcSomfyTahoma()) << "Unable to determine IP address for:" << gatewayPin;
} }
pluginStorage()->endGroup(); pluginStorage()->endGroup();

View File

@ -49,13 +49,6 @@
"setupMethod": "userandpassword", "setupMethod": "userandpassword",
"interfaces": ["gateway"], "interfaces": ["gateway"],
"paramTypes": [ "paramTypes": [
{
"id": "e321a7d6-6dcb-4a37-baf1-c7008f2d5bdb",
"displayName": "Gateway Id",
"name": "gatewayId",
"type": "QString",
"readOnly": true
},
{ {
"id": "30b73244-e5bb-4c00-9332-702a60c03420", "id": "30b73244-e5bb-4c00-9332-702a60c03420",
"displayName": "Gateway pin", "displayName": "Gateway pin",