tplink: Add Qt6 support

This commit is contained in:
Simon Stürz 2025-08-11 14:46:25 +02:00
parent 1d629d50a6
commit d2593bb465
3 changed files with 25 additions and 19 deletions

View File

@ -38,6 +38,7 @@
#include <QJsonDocument> #include <QJsonDocument>
#include <QTimer> #include <QTimer>
#include <QDataStream> #include <QDataStream>
#include <QRegularExpression>
// Related projects: // Related projects:
@ -138,19 +139,19 @@ void IntegrationPluginTPLink::discoverThings(ThingDiscoveryInfo *info)
qCWarning(dcTplink()) << qUtf8Printable(jsonDoc.toJson(QJsonDocument::Indented)); qCWarning(dcTplink()) << qUtf8Printable(jsonDoc.toJson(QJsonDocument::Indented));
QRegExp modelFilter; QRegularExpression modelFilter;
if (info->thingClassId() == kasaPlug100ThingClassId) { if (info->thingClassId() == kasaPlug100ThingClassId) {
modelFilter = QRegExp("(HS100|HS103|HS105|KP100|KP105).*"); modelFilter = QRegularExpression("(HS100|HS103|HS105|KP100|KP105).*");
} else if (info->thingClassId() == kasaPlug110ThingClassId) { } else if (info->thingClassId() == kasaPlug110ThingClassId) {
modelFilter = QRegExp("(HS110|KP115).*"); modelFilter = QRegularExpression("(HS110|KP115).*");
} else if (info->thingClassId() == kasaSwitch200ThingClassId) { } else if (info->thingClassId() == kasaSwitch200ThingClassId) {
modelFilter = QRegExp("HS200.*"); modelFilter = QRegularExpression("HS200.*");
} else if (info->thingClassId() == kasaPowerStrip300ThingClassId) { } else if (info->thingClassId() == kasaPowerStrip300ThingClassId) {
modelFilter = QRegExp("HS300.*"); modelFilter = QRegularExpression("HS300.*");
} }
QString model = sysInfo.value("model").toString(); QString model = sysInfo.value("model").toString();
if (modelFilter.exactMatch(model)) { if (modelFilter.match(model).hasMatch()) {
ThingDescriptor descriptor(info->thingClassId(), sysInfo.value("alias").toString(), sysInfo.value("dev_name").toString()); ThingDescriptor descriptor(info->thingClassId(), sysInfo.value("alias").toString(), sysInfo.value("dev_name").toString());
Param idParam = Param(idParamTypesMap.value(info->thingClassId()), sysInfo.value("deviceId").toString()); Param idParam = Param(idParamTypesMap.value(info->thingClassId()), sysInfo.value("deviceId").toString());
descriptor.setParams(ParamList() << idParam); descriptor.setParams(ParamList() << idParam);
@ -363,7 +364,7 @@ void IntegrationPluginTPLink::executeAction(ThingActionInfo *info)
job.data = data; job.data = data;
job.actionInfo = info; job.actionInfo = info;
m_jobQueue[targetThing].append(job); m_jobQueue[targetThing].append(job);
connect(info, &ThingActionInfo::aborted, this, [=](){ connect(info, &ThingActionInfo::aborted, targetThing, [this, targetThing, job](){
m_jobQueue[targetThing].removeAll(job); m_jobQueue[targetThing].removeAll(job);
}); });
@ -422,8 +423,12 @@ void IntegrationPluginTPLink::connectToDevice(Thing *thing, const QHostAddress &
fetchState(thing); fetchState(thing);
}); });
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
connect(socket, &QTcpSocket::errorOccurred, this, [](QAbstractSocket::SocketError error){
#else
typedef void (QTcpSocket:: *errorSignal)(QAbstractSocket::SocketError); typedef void (QTcpSocket:: *errorSignal)(QAbstractSocket::SocketError);
connect(socket, static_cast<errorSignal>(&QTcpSocket::error), thing, [](QAbstractSocket::SocketError error) { connect(socket, static_cast<errorSignal>(&QTcpSocket::error), thing, [](QAbstractSocket::SocketError error) {
#endif
qCWarning(dcTplink()) << "Error in device connection:" << error; qCWarning(dcTplink()) << "Error in device connection:" << error;
}); });

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright 2013 - 2020, nymea GmbH * Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io * Contact: contact@nymea.io
* *
* This file is part of nymea. * This file is part of nymea.
@ -31,7 +31,7 @@
#ifndef INTEGRATIONPLUGINTPLINK_H #ifndef INTEGRATIONPLUGINTPLINK_H
#define INTEGRATIONPLUGINTPLINK_H #define INTEGRATIONPLUGINTPLINK_H
#include "integrations/integrationplugin.h" #include <integrations/integrationplugin.h>
#include <QUdpSocket> #include <QUdpSocket>
@ -49,7 +49,7 @@ class IntegrationPluginTPLink: public IntegrationPlugin
public: public:
explicit IntegrationPluginTPLink(); explicit IntegrationPluginTPLink();
~IntegrationPluginTPLink(); ~IntegrationPluginTPLink() override;
void init() override; void init() override;
void discoverThings(ThingDiscoveryInfo *info) override; void discoverThings(ThingDiscoveryInfo *info) override;
@ -73,18 +73,19 @@ private:
int id = 0; int id = 0;
QByteArray data; QByteArray data;
ThingActionInfo *actionInfo = nullptr; ThingActionInfo *actionInfo = nullptr;
bool operator==(const Job &other) { return id == other.id; } bool operator==(const Job &other) const { return id == other.id; }
}; };
QHash<Thing*, Job> m_pendingJobs;
QHash<Thing*, QList<Job>> m_jobQueue; QHash<Thing *, Job> m_pendingJobs;
QHash<Thing*, QTimer*> m_jobTimers; QHash<Thing *, QList<Job>> m_jobQueue;
QHash<Thing *, QTimer *> m_jobTimers;
int m_jobIdx = 0; int m_jobIdx = 0;
QUdpSocket *m_broadcastSocket = nullptr; QUdpSocket *m_broadcastSocket = nullptr;
QHash<Thing*, QTcpSocket*> m_sockets; QHash<Thing *, QTcpSocket *> m_sockets;
QHash<ThingSetupInfo*, int> m_setupRetries; QHash<ThingSetupInfo *, int> m_setupRetries;
QHash<Thing*, QByteArray> m_inputBuffers; QHash<Thing *, QByteArray> m_inputBuffers;
PluginTimer *m_timer = nullptr; PluginTimer *m_timer = nullptr;
}; };

View File

@ -3,10 +3,10 @@ include(../plugins.pri)
QT += network QT += network
SOURCES += \ SOURCES += \
integrationplugintplink.cpp \ integrationplugintplink.cpp
HEADERS += \ HEADERS += \
integrationplugintplink.h \ integrationplugintplink.h
OTHER_FILES += \ OTHER_FILES += \
sampledata/HS200.txt \ sampledata/HS200.txt \