mirror of
https://github.com/nymea/nymea-plugins.git
synced 2026-07-18 00:43:48 +02:00
Offer possibility to use a manual URL for connection
This commit is contained in:
parent
68e9cd8c01
commit
c08b38e4cf
@ -33,17 +33,17 @@
|
||||
|
||||
#include <QUrlQuery>
|
||||
|
||||
FroniusSolarConnection::FroniusSolarConnection(NetworkAccessManager *networkManager, const QHostAddress &address, QObject *parent) :
|
||||
FroniusSolarConnection::FroniusSolarConnection(NetworkAccessManager *networkManager, const QUrl &baseUrl, QObject *parent) :
|
||||
QObject(parent),
|
||||
m_networkManager(networkManager),
|
||||
m_address(address)
|
||||
m_baseUrl(baseUrl)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QHostAddress FroniusSolarConnection::address() const
|
||||
QUrl FroniusSolarConnection::baseUrl() const
|
||||
{
|
||||
return m_address;
|
||||
return m_baseUrl;
|
||||
}
|
||||
|
||||
bool FroniusSolarConnection::available() const
|
||||
@ -58,9 +58,7 @@ bool FroniusSolarConnection::busy() const
|
||||
|
||||
FroniusNetworkReply *FroniusSolarConnection::getVersion()
|
||||
{
|
||||
QUrl requestUrl;
|
||||
requestUrl.setScheme("http");
|
||||
requestUrl.setHost(m_address.toString());
|
||||
QUrl requestUrl = m_baseUrl;
|
||||
requestUrl.setPath("/solar_api/GetAPIVersion.cgi");
|
||||
|
||||
FroniusNetworkReply *reply = new FroniusNetworkReply(QNetworkRequest(requestUrl), this);
|
||||
@ -71,9 +69,7 @@ FroniusNetworkReply *FroniusSolarConnection::getVersion()
|
||||
|
||||
FroniusNetworkReply *FroniusSolarConnection::getActiveDevices()
|
||||
{
|
||||
QUrl requestUrl;
|
||||
requestUrl.setScheme("http");
|
||||
requestUrl.setHost(m_address.toString());
|
||||
QUrl requestUrl = m_baseUrl;
|
||||
requestUrl.setPath("/solar_api/v1/GetActiveDeviceInfo.cgi");
|
||||
|
||||
QUrlQuery query;
|
||||
@ -112,9 +108,7 @@ FroniusNetworkReply *FroniusSolarConnection::getActiveDevices()
|
||||
|
||||
FroniusNetworkReply *FroniusSolarConnection::getPowerFlowRealtimeData()
|
||||
{
|
||||
QUrl requestUrl;
|
||||
requestUrl.setScheme("http");
|
||||
requestUrl.setHost(m_address.toString());
|
||||
QUrl requestUrl = m_baseUrl;
|
||||
requestUrl.setPath("/solar_api/v1/GetPowerFlowRealtimeData.fcgi");
|
||||
|
||||
FroniusNetworkReply *reply = new FroniusNetworkReply(QNetworkRequest(requestUrl), this);
|
||||
@ -125,9 +119,7 @@ FroniusNetworkReply *FroniusSolarConnection::getPowerFlowRealtimeData()
|
||||
|
||||
FroniusNetworkReply *FroniusSolarConnection::getInverterRealtimeData(int inverterId)
|
||||
{
|
||||
QUrl requestUrl;
|
||||
requestUrl.setScheme("http");
|
||||
requestUrl.setHost(m_address.toString());
|
||||
QUrl requestUrl = m_baseUrl;
|
||||
requestUrl.setPath("/solar_api/v1/GetInverterRealtimeData.cgi");
|
||||
|
||||
QUrlQuery query;
|
||||
@ -144,9 +136,7 @@ FroniusNetworkReply *FroniusSolarConnection::getInverterRealtimeData(int inverte
|
||||
|
||||
FroniusNetworkReply *FroniusSolarConnection::getMeterRealtimeData(int meterId)
|
||||
{
|
||||
QUrl requestUrl;
|
||||
requestUrl.setScheme("http");
|
||||
requestUrl.setHost(m_address.toString());
|
||||
QUrl requestUrl = m_baseUrl;
|
||||
requestUrl.setPath("/solar_api/v1/GetMeterRealtimeData.cgi");
|
||||
|
||||
QUrlQuery query;
|
||||
@ -162,9 +152,7 @@ FroniusNetworkReply *FroniusSolarConnection::getMeterRealtimeData(int meterId)
|
||||
|
||||
FroniusNetworkReply *FroniusSolarConnection::getStorageRealtimeData(int meterId)
|
||||
{
|
||||
QUrl requestUrl;
|
||||
requestUrl.setScheme("http");
|
||||
requestUrl.setHost(m_address.toString());
|
||||
QUrl requestUrl = m_baseUrl;
|
||||
requestUrl.setPath("/solar_api/v1/GetStorageRealtimeData.cgi");
|
||||
|
||||
QUrlQuery query;
|
||||
|
||||
@ -33,6 +33,7 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <QUrl>
|
||||
#include <QQueue>
|
||||
#include <QHostAddress>
|
||||
|
||||
@ -44,12 +45,10 @@ class FroniusSolarConnection : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FroniusSolarConnection(NetworkAccessManager *networkManager, const QHostAddress &address, QObject *parent = nullptr);
|
||||
|
||||
QHostAddress address() const;
|
||||
explicit FroniusSolarConnection(NetworkAccessManager *networkManager, const QUrl &baseUrl, QObject *parent = nullptr);
|
||||
|
||||
QUrl baseUrl() const;
|
||||
bool available() const;
|
||||
|
||||
bool busy() const;
|
||||
|
||||
FroniusNetworkReply *getVersion();
|
||||
@ -66,6 +65,7 @@ signals:
|
||||
private:
|
||||
NetworkAccessManager *m_networkManager = nullptr;
|
||||
QHostAddress m_address;
|
||||
QUrl m_baseUrl;
|
||||
|
||||
bool m_available = false;
|
||||
|
||||
|
||||
@ -110,8 +110,6 @@ void IntegrationPluginFronius::setupThing(ThingSetupInfo *info)
|
||||
|
||||
if (thing->thingClassId() == connectionThingClassId) {
|
||||
|
||||
QHostAddress address(thing->paramValue(connectionThingAddressParamTypeId).toString());
|
||||
|
||||
// Handle reconfigure
|
||||
if (m_froniusConnections.values().contains(thing)) {
|
||||
FroniusSolarConnection *connection = m_froniusConnections.key(thing);
|
||||
@ -119,8 +117,16 @@ void IntegrationPluginFronius::setupThing(ThingSetupInfo *info)
|
||||
connection->deleteLater();
|
||||
}
|
||||
|
||||
QHostAddress address(thing->paramValue(connectionThingAddressParamTypeId).toString());
|
||||
QUrl baseUrl = QUrl(thing->paramValue(connectionThingUrlParamTypeId).toString());
|
||||
if (!baseUrl.isValid()) {
|
||||
baseUrl.setScheme("http");
|
||||
baseUrl.setHost(address.toString());
|
||||
}
|
||||
|
||||
|
||||
// Create the connection
|
||||
FroniusSolarConnection *connection = new FroniusSolarConnection(hardwareManager()->networkManager(), address, thing);
|
||||
FroniusSolarConnection *connection = new FroniusSolarConnection(hardwareManager()->networkManager(), baseUrl, thing);
|
||||
|
||||
// Verify the version
|
||||
FroniusNetworkReply *reply = connection->getVersion();
|
||||
@ -250,7 +256,7 @@ void IntegrationPluginFronius::executeAction(ThingActionInfo *info)
|
||||
void IntegrationPluginFronius::refreshConnection(FroniusSolarConnection *connection)
|
||||
{
|
||||
if (connection->busy()) {
|
||||
qCWarning(dcFronius()) << "Connection busy. Skipping refresh cycle for host" << connection->address().toString();
|
||||
qCWarning(dcFronius()) << "Connection busy. Skipping refresh cycle for host" << connection->baseUrl().toString();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -24,6 +24,13 @@
|
||||
"inputType": "IPv4Address",
|
||||
"defaultValue": "88.117.152.99"
|
||||
},
|
||||
{
|
||||
"id": "2345715c-77db-47f9-adf7-9f2d265c0099",
|
||||
"name": "url",
|
||||
"displayName": "Connection URL",
|
||||
"type": "QString",
|
||||
"defaultValue": "http://hackaton-linz.doesntexist.org:21080"
|
||||
},
|
||||
{
|
||||
"id": "2237972e-385b-4458-b5d3-1d1fb4ae8756",
|
||||
"name": "mac",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user