diff --git a/solarlog/integrationpluginsolarlog.cpp b/solarlog/integrationpluginsolarlog.cpp index 5d4ad8b7..6a57d8f3 100644 --- a/solarlog/integrationpluginsolarlog.cpp +++ b/solarlog/integrationpluginsolarlog.cpp @@ -28,10 +28,13 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#include "integrationpluginsolarlog.h".h" +#include "integrationpluginsolarlog.h" #include "plugininfo.h" #include "network/networkaccessmanager.h" +#include +#include +#include IntegrationPluginSolarLog::IntegrationPluginSolarLog() { @@ -59,19 +62,57 @@ void IntegrationPluginSolarLog::thingRemoved(Thing *thing) void IntegrationPluginSolarLog::onRefreshTimer() { - foreach (Thing *, myThings().filterByThingClassId()) { - + foreach (Thing *thing, myThings().filterByThingClassId(solarlogThingClassId)) { + getData(thing); } } -QUuid IntegrationPluginSolarLog::getData(const QHostAddress &address) +void IntegrationPluginSolarLog::getData(Thing *thing) { QUrl url; - url.setHost(address); + url.setHost(thing->paramValue(solarlogThingHostParamTypeId).toString()); url.setPath("/getjp"); url.setScheme("http"); + QNetworkRequest request(url); + request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "text/plain"); + QNetworkReply *reply = hardwareManager()->networkManager()->post(request, QByteArray("{\"801\":{\"170\":null}}")); + connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater); + connect(reply, &QNetworkReply::finished, this, [this, reply, thing]{ - hardwareManager()->networkManager()->post(QNetworkRequest(url), QByteArray("{\"801\":{\"170\":null}}")); + int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + + // Check HTTP status code + if (status != 200 || reply->error() != QNetworkReply::NoError) { + if (reply->error() == QNetworkReply::HostNotFoundError) { + } + qCWarning(dcSolarlog()) << "Request error:" << status << reply->errorString(); + return; + } + + QJsonParseError error; + QJsonDocument data = QJsonDocument::fromJson(reply->readAll(), &error); + if (error.error != QJsonParseError::NoError) { + qDebug(dcSolarlog()) << "Recieved invalide JSON object"; + return; + } + + QVariantMap map = data.toVariant().toMap().value("801").toMap().value("170").toMap(); + thing->setStateValue(solarlogLastupdateStateTypeId, map.value(QString::number(JsonObjectNumbers::LastUpdateTime))); + thing->setStateValue(solarlogPacStateTypeId, map.value(QString::number(JsonObjectNumbers::Pac))); + thing->setStateValue(solarlogPdcStateTypeId, map.value(QString::number(JsonObjectNumbers::Pdc))); + thing->setStateValue(solarlogUacStateTypeId, map.value(QString::number(JsonObjectNumbers::Uac))); + thing->setStateValue(solarlogDcVoltageStateTypeId, map.value(QString::number(JsonObjectNumbers::DCVoltage))); + thing->setStateValue(solarlogYieldDayStateTypeId, map.value(QString::number(JsonObjectNumbers::YieldDay))); + thing->setStateValue(solarlogYieldYesterdayStateTypeId, map.value(QString::number(JsonObjectNumbers::YieldYesterday))); + thing->setStateValue(solarlogYieldMonthStateTypeId, map.value(QString::number(JsonObjectNumbers::YieldMonth))); + thing->setStateValue(solarlogYieldYearStateTypeId, map.value(QString::number(JsonObjectNumbers::YieldYear))); + thing->setStateValue(solarlogYieldTotalStateTypeId, map.value(QString::number(JsonObjectNumbers::YieldTotal))); + thing->setStateValue(solarlogCurrentTotalConsumptionStateTypeId, map.value(QString::number(JsonObjectNumbers::ConsPac))); + thing->setStateValue(solarlogConsYieldDayStateTypeId, map.value(QString::number(JsonObjectNumbers::ConsYieldDay))); + thing->setStateValue(solarlogConsYieldYesterdayStateTypeId, map.value(QString::number(JsonObjectNumbers::ConsYieldYesterday))); + thing->setStateValue(solarlogConsYieldMonthStateTypeId, map.value(QString::number(JsonObjectNumbers::ConsYieldMonth))); + thing->setStateValue(solarlogConsYieldYearStateTypeId, map.value(QString::number(JsonObjectNumbers::ConsYieldYear))); + thing->setStateValue(solarlogConsYieldTotalStateTypeId, map.value(QString::number(JsonObjectNumbers::ConsYieldTotal))); + thing->setStateValue(solarlogTotalPowerStateTypeId, map.value(QString::number(JsonObjectNumbers::TotalPower))); + }); } - - diff --git a/solarlog/integrationpluginsolarlog.h b/solarlog/integrationpluginsolarlog.h index 4ccdcbd3..b0b7a922 100644 --- a/solarlog/integrationpluginsolarlog.h +++ b/solarlog/integrationpluginsolarlog.h @@ -45,6 +45,25 @@ class IntegrationPluginSolarLog: public IntegrationPlugin { Q_INTERFACES(IntegrationPlugin) public: + enum JsonObjectNumbers{ + LastUpdateTime = 100, + Pac, + Pdc, + Uac, + DCVoltage, + YieldDay, + YieldYesterday, + YieldMonth, + YieldYear, + YieldTotal, + ConsPac, + ConsYieldDay, + ConsYieldYesterday, + ConsYieldMonth, + ConsYieldYear, + ConsYieldTotal, + TotalPower + }; explicit IntegrationPluginSolarLog(); ~IntegrationPluginSolarLog() override; @@ -57,7 +76,7 @@ private slots: private: PluginTimer *m_refreshTimer = nullptr; - QUuid getData(const QHostAddress &address); + void getData(Thing *thing); }; #endif // INTEGRATIONPLUGINSOLARLOG_H diff --git a/solarlog/integrationpluginsolarlog.json b/solarlog/integrationpluginsolarlog.json index cea1a6b4..9df383fd 100644 --- a/solarlog/integrationpluginsolarlog.json +++ b/solarlog/integrationpluginsolarlog.json @@ -5,15 +5,15 @@ "vendors": [ { "id": "0cf5f437-abf0-4396-92d4-be94d616c667", - "name": "Solarlog", + "name": "solarlog", "displayName": "Solar-Log", "thingClasses": [ { "id": "1374b47e-5555-4ec1-b2cd-6474048dd30c", - "name": "Solarlog", + "name": "solarlog", "displayName": "Solar-Log", "createMethods": [ "user", "discovery" ], - "interfaces": [ "batterylevel", "connectable" ], + "interfaces": [ "connectable" ], "paramTypes": [ { "id": "84bd8a41-2411-4bb0-87a9-ab7e01044b10", @@ -66,7 +66,7 @@ "displayName": "UAC", "displayNameEvent": "UAC changed", "type": "int", - "unit": "Voltage", + "unit": "Volt", "defaultValue": 0 }, { @@ -75,7 +75,7 @@ "displayName": "DC Voltage", "displayNameEvent": "DC Voltage changed", "type": "int", - "unit": "Voltage", + "unit": "Volt", "defaultValue": 0 }, { @@ -84,7 +84,7 @@ "displayName": "Yield day", "displayNameEvent": "Yield day changed", "type": "int", - "unit": "WattHour", + "unit": "KiloWattHour", "defaultValue": 0 }, { @@ -93,7 +93,7 @@ "displayName": "Yield yesterday", "displayNameEvent": "Yield yesterday changed", "type": "int", - "unit": "WattHour", + "unit": "KiloWattHour", "defaultValue": 0 }, { @@ -102,7 +102,7 @@ "displayName": "Yield month", "displayNameEvent": "Yield month changed", "type": "int", - "unit": "WattHour", + "unit": "KiloWattHour", "defaultValue": 0 }, { @@ -111,7 +111,7 @@ "displayName": "Yield year", "displayNameEvent": "Yield year changed", "type": "int", - "unit": "WattHour", + "unit": "KiloWattHour", "defaultValue": 0 }, { @@ -120,7 +120,7 @@ "displayName": "Yield total", "displayNameEvent": "Yield total changed", "type": "int", - "unit": "WattHour", + "unit": "KiloWattHour", "defaultValue": 0 }, { @@ -138,7 +138,7 @@ "displayName": "consYieldDay", "displayNameEvent": "consYieldDay changed", "type": "int", - "unit": "WattHour", + "unit": "KiloWattHour", "defaultValue": 0 }, { @@ -147,7 +147,7 @@ "displayName": "consYieldYesterday", "displayNameEvent": "consYieldYesterday changed", "type": "int", - "unit": "WattHour", + "unit": "KiloWattHour", "defaultValue": 0 }, { @@ -156,7 +156,7 @@ "displayName": "consYieldMonth", "displayNameEvent": "consYieldMonth changed", "type": "int", - "unit": "WattHour", + "unit": "KiloWattHour", "defaultValue": 0 }, { @@ -165,7 +165,7 @@ "displayName": "consYieldYear", "displayNameEvent": "consYieldYear changed", "type": "int", - "unit": "WattHour", + "unit": "KiloWattHour", "defaultValue": 0 }, { @@ -174,7 +174,7 @@ "displayName": "consYieldTotal", "displayNameEvent": "consYieldTotal changed", "type": "int", - "unit": "WattHour", + "unit": "KiloWattHour", "defaultValue": 0 }, { diff --git a/solarlog/translations/606adc5a-c9a5-45fa-9652-ea385dcb0b81-en_US.ts b/solarlog/translations/606adc5a-c9a5-45fa-9652-ea385dcb0b81-en_US.ts new file mode 100644 index 00000000..24921f36 --- /dev/null +++ b/solarlog/translations/606adc5a-c9a5-45fa-9652-ea385dcb0b81-en_US.ts @@ -0,0 +1,295 @@ + + + + + solarlog + + + Address + The name of the ParamType (ThingClass: solarlog, Type: thing, ID: {84bd8a41-2411-4bb0-87a9-ab7e01044b10}) + + + + + + Connected + The name of the ParamType (ThingClass: solarlog, EventType: connected, ID: {eb9f8575-71e3-42a9-aa4d-ffea9586cc4f}) +---------- +The name of the StateType ({eb9f8575-71e3-42a9-aa4d-ffea9586cc4f}) of ThingClass solarlog + + + + + Connected changed + The name of the EventType ({eb9f8575-71e3-42a9-aa4d-ffea9586cc4f}) of ThingClass solarlog + + + + + + Current total consumption + The name of the ParamType (ThingClass: solarlog, EventType: currentTotalConsumption, ID: {5b665247-278a-4b59-9046-add40763e937}) +---------- +The name of the StateType ({5b665247-278a-4b59-9046-add40763e937}) of ThingClass solarlog + + + + + Current total consumption changed + The name of the EventType ({5b665247-278a-4b59-9046-add40763e937}) of ThingClass solarlog + + + + + + DC Voltage + The name of the ParamType (ThingClass: solarlog, EventType: dcVoltage, ID: {bb891a05-59d8-4a3b-a0ea-b63af58558f7}) +---------- +The name of the StateType ({bb891a05-59d8-4a3b-a0ea-b63af58558f7}) of ThingClass solarlog + + + + + DC Voltage changed + The name of the EventType ({bb891a05-59d8-4a3b-a0ea-b63af58558f7}) of ThingClass solarlog + + + + + + Installed generator power + The name of the ParamType (ThingClass: solarlog, EventType: totalPower, ID: {0aa21401-2a3d-4149-803b-f0ba8c66b2f7}) +---------- +The name of the StateType ({0aa21401-2a3d-4149-803b-f0ba8c66b2f7}) of ThingClass solarlog + + + + + Installed generator power changed + The name of the EventType ({0aa21401-2a3d-4149-803b-f0ba8c66b2f7}) of ThingClass solarlog + + + + + + Last update + The name of the ParamType (ThingClass: solarlog, EventType: lastupdate, ID: {b944c513-a7f0-4bc1-941e-aae9849557fe}) +---------- +The name of the StateType ({b944c513-a7f0-4bc1-941e-aae9849557fe}) of ThingClass solarlog + + + + + Last update changed + The name of the EventType ({b944c513-a7f0-4bc1-941e-aae9849557fe}) of ThingClass solarlog + + + + + + PAC + The name of the ParamType (ThingClass: solarlog, EventType: pac, ID: {0bf515d8-0f48-4eba-9255-f774d68c80fe}) +---------- +The name of the StateType ({0bf515d8-0f48-4eba-9255-f774d68c80fe}) of ThingClass solarlog + + + + + PAC changed + The name of the EventType ({0bf515d8-0f48-4eba-9255-f774d68c80fe}) of ThingClass solarlog + + + + + + PDC + The name of the ParamType (ThingClass: solarlog, EventType: pdc, ID: {e4183a70-c848-447a-962a-f19dc5974140}) +---------- +The name of the StateType ({e4183a70-c848-447a-962a-f19dc5974140}) of ThingClass solarlog + + + + + PDC changed + The name of the EventType ({e4183a70-c848-447a-962a-f19dc5974140}) of ThingClass solarlog + + + + + + + Solar-Log + The name of the ThingClass ({1374b47e-5555-4ec1-b2cd-6474048dd30c}) +---------- +The name of the vendor ({0cf5f437-abf0-4396-92d4-be94d616c667}) +---------- +The name of the plugin solarlog ({606adc5a-c9a5-45fa-9652-ea385dcb0b81}) + + + + + + UAC + The name of the ParamType (ThingClass: solarlog, EventType: uac, ID: {7dc46b2e-5fba-4cc6-a159-09472cdfac62}) +---------- +The name of the StateType ({7dc46b2e-5fba-4cc6-a159-09472cdfac62}) of ThingClass solarlog + + + + + UAC changed + The name of the EventType ({7dc46b2e-5fba-4cc6-a159-09472cdfac62}) of ThingClass solarlog + + + + + + Yield day + The name of the ParamType (ThingClass: solarlog, EventType: yieldDay, ID: {53ed041a-e3c3-4ae5-9a79-1cd7ad82e9a8}) +---------- +The name of the StateType ({53ed041a-e3c3-4ae5-9a79-1cd7ad82e9a8}) of ThingClass solarlog + + + + + Yield day changed + The name of the EventType ({53ed041a-e3c3-4ae5-9a79-1cd7ad82e9a8}) of ThingClass solarlog + + + + + + Yield month + The name of the ParamType (ThingClass: solarlog, EventType: yieldMonth, ID: {9a77662a-2034-4031-8e7a-1e6347089d97}) +---------- +The name of the StateType ({9a77662a-2034-4031-8e7a-1e6347089d97}) of ThingClass solarlog + + + + + Yield month changed + The name of the EventType ({9a77662a-2034-4031-8e7a-1e6347089d97}) of ThingClass solarlog + + + + + + Yield total + The name of the ParamType (ThingClass: solarlog, EventType: yieldTotal, ID: {3afb6ea1-fef8-4c17-8307-c7547a7a6f3c}) +---------- +The name of the StateType ({3afb6ea1-fef8-4c17-8307-c7547a7a6f3c}) of ThingClass solarlog + + + + + Yield total changed + The name of the EventType ({3afb6ea1-fef8-4c17-8307-c7547a7a6f3c}) of ThingClass solarlog + + + + + + Yield year + The name of the ParamType (ThingClass: solarlog, EventType: yieldYear, ID: {d18169ce-deeb-4f7b-b737-818a91760041}) +---------- +The name of the StateType ({d18169ce-deeb-4f7b-b737-818a91760041}) of ThingClass solarlog + + + + + Yield year changed + The name of the EventType ({d18169ce-deeb-4f7b-b737-818a91760041}) of ThingClass solarlog + + + + + + Yield yesterday + The name of the ParamType (ThingClass: solarlog, EventType: yieldYesterday, ID: {bd96d0b3-e921-49eb-8b34-0b3be5bb27fa}) +---------- +The name of the StateType ({bd96d0b3-e921-49eb-8b34-0b3be5bb27fa}) of ThingClass solarlog + + + + + Yield yesterday changed + The name of the EventType ({bd96d0b3-e921-49eb-8b34-0b3be5bb27fa}) of ThingClass solarlog + + + + + + consYieldDay + The name of the ParamType (ThingClass: solarlog, EventType: consYieldDay, ID: {40ff1d14-a5d2-4fdb-919c-58dfbcdca123}) +---------- +The name of the StateType ({40ff1d14-a5d2-4fdb-919c-58dfbcdca123}) of ThingClass solarlog + + + + + consYieldDay changed + The name of the EventType ({40ff1d14-a5d2-4fdb-919c-58dfbcdca123}) of ThingClass solarlog + + + + + + consYieldMonth + The name of the ParamType (ThingClass: solarlog, EventType: consYieldMonth, ID: {a45a557a-a937-4382-8ef5-76f1ff5940e4}) +---------- +The name of the StateType ({a45a557a-a937-4382-8ef5-76f1ff5940e4}) of ThingClass solarlog + + + + + consYieldMonth changed + The name of the EventType ({a45a557a-a937-4382-8ef5-76f1ff5940e4}) of ThingClass solarlog + + + + + + consYieldTotal + The name of the ParamType (ThingClass: solarlog, EventType: consYieldTotal, ID: {34f60062-5dec-45ed-9a27-4fbc083cb36e}) +---------- +The name of the StateType ({34f60062-5dec-45ed-9a27-4fbc083cb36e}) of ThingClass solarlog + + + + + consYieldTotal changed + The name of the EventType ({34f60062-5dec-45ed-9a27-4fbc083cb36e}) of ThingClass solarlog + + + + + + consYieldYear + The name of the ParamType (ThingClass: solarlog, EventType: consYieldYear, ID: {1d42619b-3a50-4bde-b325-67a8014332ef}) +---------- +The name of the StateType ({1d42619b-3a50-4bde-b325-67a8014332ef}) of ThingClass solarlog + + + + + consYieldYear changed + The name of the EventType ({1d42619b-3a50-4bde-b325-67a8014332ef}) of ThingClass solarlog + + + + + + consYieldYesterday + The name of the ParamType (ThingClass: solarlog, EventType: consYieldYesterday, ID: {5d6d5ba5-ebc3-42ce-9d08-802da694b4da}) +---------- +The name of the StateType ({5d6d5ba5-ebc3-42ce-9d08-802da694b4da}) of ThingClass solarlog + + + + + consYieldYesterday changed + The name of the EventType ({5d6d5ba5-ebc3-42ce-9d08-802da694b4da}) of ThingClass solarlog + + + +