From 3f526cbf2179da6cf69cb61fca98ad87d834d333 Mon Sep 17 00:00:00 2001 From: Christian Fetzer Date: Sun, 29 May 2022 14:01:21 +0200 Subject: [PATCH] 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. --- somfytahoma/integrationpluginsomfytahoma.cpp | 11 ++++------- somfytahoma/integrationpluginsomfytahoma.json | 7 ------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/somfytahoma/integrationpluginsomfytahoma.cpp b/somfytahoma/integrationpluginsomfytahoma.cpp index a687d280..6e0ad1b3 100644 --- a/somfytahoma/integrationpluginsomfytahoma.cpp +++ b/somfytahoma/integrationpluginsomfytahoma.cpp @@ -53,11 +53,10 @@ void IntegrationPluginSomfyTahoma::discoverThings(ThingDiscoveryInfo *info) ThingDescriptor descriptor(info->thingClassId(), "Somfy TaHoma Gateway", entry.hostAddress().toString()); ParamList params; - params << Param(gatewayThingGatewayIdParamTypeId, entry.name()); params << Param(gatewayThingGatewayPinParamTypeId, entry.txt("gateway_pin")); descriptor.setParams(params); - Things existingThings = myThings().filterByParam(gatewayThingGatewayIdParamTypeId, entry.name()); + Things existingThings = myThings().filterByParam(gatewayThingGatewayPinParamTypeId, entry.txt("gateway_pin")); if (existingThings.count() == 1) { qCDebug(dcSomfyTahoma()) << "This gateway already exists in the system!"; descriptor.setThingId(existingThings.first()->id()); @@ -128,8 +127,6 @@ void IntegrationPluginSomfyTahoma::setupThing(ThingSetupInfo *info) QList unknownDevices; 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()) { QVariantMap deviceMap = deviceVariant.toMap(); QString type = deviceMap.value("controllableName").toString(); @@ -628,10 +625,10 @@ QString IntegrationPluginSomfyTahoma::getHost(Thing *thing) const gateway = myThings().findById(thing->parentId()); } - QString gatewayId = gateway->paramValue(gatewayThingGatewayIdParamTypeId).toString(); + QString gatewayPin = gateway->paramValue(gatewayThingGatewayPinParamTypeId).toString(); ZeroConfServiceEntry zeroConfEntry; foreach (const ZeroConfServiceEntry &entry, m_zeroConfBrowser->serviceEntries()) { - if (entry.name() == gatewayId) { + if (gatewayPin == entry.txt("gateway_pin")) { zeroConfEntry = entry; } } @@ -643,7 +640,7 @@ QString IntegrationPluginSomfyTahoma::getHost(Thing *thing) const } else if (pluginStorage()->contains("cachedAddress")){ host = pluginStorage()->value("cachedAddress").toString(); } else { - qCWarning(dcSomfyTahoma()) << "Unable to determine IP address for:" << gatewayId; + qCWarning(dcSomfyTahoma()) << "Unable to determine IP address for:" << gatewayPin; } pluginStorage()->endGroup(); diff --git a/somfytahoma/integrationpluginsomfytahoma.json b/somfytahoma/integrationpluginsomfytahoma.json index e7f2488f..49ca2dea 100644 --- a/somfytahoma/integrationpluginsomfytahoma.json +++ b/somfytahoma/integrationpluginsomfytahoma.json @@ -49,13 +49,6 @@ "setupMethod": "userandpassword", "interfaces": ["gateway"], "paramTypes": [ - { - "id": "e321a7d6-6dcb-4a37-baf1-c7008f2d5bdb", - "displayName": "Gateway Id", - "name": "gatewayId", - "type": "QString", - "readOnly": true - }, { "id": "30b73244-e5bb-4c00-9332-702a60c03420", "displayName": "Gateway pin",