From 05194f95ec1ea4d561bfa166202654596cccfd07 Mon Sep 17 00:00:00 2001 From: Boernsman Date: Tue, 31 Dec 2019 00:48:23 +0100 Subject: [PATCH 1/3] added OpenUV --- debian/control | 16 +++ debian/nymea-plugin-openuv.install.in | 1 + nymea-plugins.pro | 1 + openuv/README.md | 6 + openuv/devicepluginopenuv.cpp | 173 ++++++++++++++++++++++++++ openuv/devicepluginopenuv.h | 60 +++++++++ openuv/devicepluginopenuv.json | 162 ++++++++++++++++++++++++ openuv/openuv.pro | 13 ++ 8 files changed, 432 insertions(+) create mode 100644 debian/nymea-plugin-openuv.install.in create mode 100644 openuv/README.md create mode 100644 openuv/devicepluginopenuv.cpp create mode 100644 openuv/devicepluginopenuv.h create mode 100644 openuv/devicepluginopenuv.json create mode 100644 openuv/openuv.pro diff --git a/debian/control b/debian/control index 1840e055..a37571ab 100644 --- a/debian/control +++ b/debian/control @@ -469,6 +469,21 @@ Description: nymea.io plugin for one wire devices This package will install the nymea.io plugin for one wire devices +Package: nymea-plugin-openuv +Architecture: any +Depends: ${shlibs:Depends}, + ${misc:Depends}, + nymea-plugins-translations, +Description: nymea.io plugin for OpenUV + The nymea daemon is a plugin based IoT (Internet of Things) server. The + server works like a translator for devices, things and services and + allows them to interact. + With the powerful rule engine you are able to connect any device available + in the system and create individual scenes and behaviors for your environment. + . + This package will install the nymea.io plugin for OpenUV + + Package: nymea-plugin-openweathermap Architecture: any Depends: ${shlibs:Depends}, @@ -847,6 +862,7 @@ Depends: nymea-plugin-anel, nymea-plugin-texasinstruments, nymea-plugin-netatmo, nymea-plugin-networkdetector, + nymea-plugin-openuv, nymea-plugin-openweathermap, nymea-plugin-philipshue, nymea-plugin-pushbullet, diff --git a/debian/nymea-plugin-openuv.install.in b/debian/nymea-plugin-openuv.install.in new file mode 100644 index 00000000..63b20ffc --- /dev/null +++ b/debian/nymea-plugin-openuv.install.in @@ -0,0 +1 @@ +usr/lib/@DEB_HOST_MULTIARCH@/nymea/plugins/libnymea_devicepluginopenuv.so diff --git a/nymea-plugins.pro b/nymea-plugins.pro index 9e1177a0..ba6ef519 100644 --- a/nymea-plugins.pro +++ b/nymea-plugins.pro @@ -31,6 +31,7 @@ PLUGIN_DIRS = \ netatmo \ networkdetector \ onewire \ + openuv \ openweathermap \ osdomotics \ philipshue \ diff --git a/openuv/README.md b/openuv/README.md new file mode 100644 index 00000000..30524675 --- /dev/null +++ b/openuv/README.md @@ -0,0 +1,6 @@ +# OpenUV + +Get the current UV index for your location. + + +The save exposure time is not available for all regions. If all save exposure times are zero it due to unavailability of this information diff --git a/openuv/devicepluginopenuv.cpp b/openuv/devicepluginopenuv.cpp new file mode 100644 index 00000000..c385f681 --- /dev/null +++ b/openuv/devicepluginopenuv.cpp @@ -0,0 +1,173 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2020 Berhard Trinnes * + * * + * This file is part of nymea. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; If not, see * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "devicepluginopenuv.h" +#include "devices/device.h" +#include "plugininfo.h" + +#include +#include +#include +#include +#include +#include +#include + +DevicePluginOpenUv::DevicePluginOpenUv() +{ +} + +void DevicePluginOpenUv::init() +{ + m_apiKey = configValue(openUvPluginApiKeyParamTypeId).toByteArray(); + + connect(this, &DevicePluginOpenUv::configValueChanged, this, [this]{ + m_apiKey = configValue(openUvPluginApiKeyParamTypeId).toByteArray(); + }); +} + + +void DevicePluginOpenUv::discoverDevices(DeviceDiscoveryInfo *info) +{ + QNetworkRequest request(QUrl("http://ip-api.com/json")); + QNetworkReply* reply = hardwareManager()->networkManager()->get(request); + connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater); + connect(reply, &QNetworkReply::finished, info, [this, reply, info]() { + if (reply->error() != QNetworkReply::NoError) { + qCWarning(dcOpenUv()) << "Error fetching geolocation from ip-api:" << reply->error() << reply->errorString(); + info->finish(Device::DeviceErrorHardwareFailure, QT_TR_NOOP("Failed to fetch data from the internet.")); + return; + } + QJsonParseError error; + QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error); + if (error.error != QJsonParseError::NoError) { + qCWarning(dcOpenUv()) << "Failed to parse json from ip-api:" << error.error << error.errorString(); + info->finish(Device::DeviceErrorHardwareFailure, QT_TR_NOOP("The server returned unexpected data.")); + return; + } + if (!jsonDoc.toVariant().toMap().contains("lat") || !jsonDoc.toVariant().toMap().contains("lon")) { + qCWarning(dcOpenUv()) << "Reply missing geolocation info" << qUtf8Printable(jsonDoc.toJson(QJsonDocument::Indented)); + info->finish(Device::DeviceErrorHardwareFailure, QT_TR_NOOP("The server returned unexpected data.")); + return; + } + qreal lat = jsonDoc.toVariant().toMap().value("lat").toDouble(); + qreal lon = jsonDoc.toVariant().toMap().value("lon").toDouble(); + + DeviceDescriptor descriptor(info->deviceClassId(), tr("OpenUV location"), jsonDoc.toVariant().toMap().value("city").toString()); + ParamList params; + params.append(Param(openUvDeviceLatitudeParamTypeId, lat)); + params.append(Param(openUvDeviceLongitudeParamTypeId, lon)); + descriptor.setParams(params); + info->addDeviceDescriptor(descriptor); + info->finish(Device::DeviceErrorNoError); + }); +} + +void DevicePluginOpenUv::setupDevice(DeviceSetupInfo *info) +{ + if (m_apiKey.isEmpty() || m_apiKey == "-") { + info->finish(Device::DeviceErrorSetupFailed, tr("API key is missing, add your OpenUV API key in the plug-in configs")); + return; + } + + if (!m_pluginTimer) { + m_pluginTimer = hardwareManager()->pluginTimerManager()->registerTimer(60 * 60); + connect(m_pluginTimer, &PluginTimer::timeout, this, &DevicePluginOpenUv::onPluginTimer); + } + info->finish(Device::DeviceErrorNoError); +} + +void DevicePluginOpenUv::postSetupDevice(Device *device) +{ + getUvIndex(device); +} + + +void DevicePluginOpenUv::deviceRemoved(Device *device) +{ + Q_UNUSED(device); + + if (myDevices().isEmpty()) { + hardwareManager()->pluginTimerManager()->unregisterTimer(m_pluginTimer); + m_pluginTimer = nullptr; + } +} + +void DevicePluginOpenUv::getUvIndex(Device *device) +{ + qCDebug(dcOpenUv()) << "Refresh data for" << device->name(); + QUrl url("https://api.openuv.io/api/v1/uv"); + QUrlQuery query; + query.addQueryItem("lat", device->paramValue(openUvDeviceLatitudeParamTypeId).toString()); + query.addQueryItem("lng", device->paramValue(openUvDeviceLongitudeParamTypeId).toString()); + url.setQuery(query); + QNetworkRequest request; + request.setUrl(url); + request.setRawHeader("x-access-token", m_apiKey); + + QNetworkReply *reply = hardwareManager()->networkManager()->get(request); + connect(reply, &QNetworkReply::finished, this, [reply, device, this] { + reply->deleteLater(); + int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + + // Check HTTP status code + if (status != 200 || reply->error() != QNetworkReply::NoError) { + if (reply->error() == QNetworkReply::HostNotFoundError) { + device->setStateValue(openUvConnectedStateTypeId, false); + } + qCWarning(dcOpenUv()) << "Request error:" << status << reply->errorString(); + return; + } + device->setStateValue(openUvConnectedStateTypeId, true); + + QJsonParseError error; + QJsonDocument data = QJsonDocument::fromJson(reply->readAll(), &error); + if (error.error != QJsonParseError::NoError) { + qDebug(dcOpenUv()) << "Recieved invalide JSON object"; + return; + } + QVariantMap result = data.toVariant().toMap().value("result").toMap(); + device->setStateValue(openUvUvStateTypeId, result["uv"].toDouble()); + device->setStateValue(openUvUvMaxStateTypeId, result["uv_max"].toDouble()); + device->setStateValue(openUvOzoneStateTypeId, result["ozone"].toDouble()); + + device->setStateValue(openUvUvTimeStateTypeId, QDateTime::fromString(result["uv_time"].toString(),Qt::DateFormat::ISODateWithMs).toSecsSinceEpoch()); + device->setStateValue(openUvOzoneTimeStateTypeId, QDateTime::fromString(result["ozone_time"].toString(),Qt::DateFormat::ISODateWithMs).toSecsSinceEpoch()); + device->setStateValue(openUvUvMaxTimeStateTypeId, QDateTime::fromString(result["uv_max_time"].toString(),Qt::DateFormat::ISODateWithMs).toSecsSinceEpoch()); + + QVariantMap safeExposureTimes = result["safe_exposure_time"].toMap(); + device->setStateValue(openUvSafeExposureTimeSt1StateTypeId, safeExposureTimes["st1"].toInt()); + device->setStateValue(openUvSafeExposureTimeSt2StateTypeId, safeExposureTimes["st2"].toInt()); + device->setStateValue(openUvSafeExposureTimeSt3StateTypeId, safeExposureTimes["st3"].toInt()); + device->setStateValue(openUvSafeExposureTimeSt4StateTypeId, safeExposureTimes["st4"].toInt()); + device->setStateValue(openUvSafeExposureTimeSt5StateTypeId, safeExposureTimes["st5"].toInt()); + device->setStateValue(openUvSafeExposureTimeSt6StateTypeId, safeExposureTimes["st6"].toInt()); + }); +} + +void DevicePluginOpenUv::onPluginTimer() +{ + foreach (Device *device, myDevices()) { + getUvIndex(device); + } +} + diff --git a/openuv/devicepluginopenuv.h b/openuv/devicepluginopenuv.h new file mode 100644 index 00000000..19e7aa9c --- /dev/null +++ b/openuv/devicepluginopenuv.h @@ -0,0 +1,60 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2020 Bernhard Trinnes * + * * + * This file is part of nymea. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; If not, see * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef DEVICEPLUGINOPENUV_H +#define DEVICEPLUGINOPENUV_H + +#include "plugintimer.h" +#include "devices/deviceplugin.h" +#include "network/networkaccessmanager.h" + +#include +#include + +class DevicePluginOpenUv : public DevicePlugin +{ + Q_OBJECT + + Q_PLUGIN_METADATA(IID "io.nymea.DevicePlugin" FILE "devicepluginopenuv.json") + Q_INTERFACES(DevicePlugin) + +public: + explicit DevicePluginOpenUv(); + + void init() override; + void discoverDevices(DeviceDiscoveryInfo *info) override; + void setupDevice(DeviceSetupInfo *info) override; + void postSetupDevice(Device *device)override; + void deviceRemoved(Device *device) override; + + void getUvIndex(Device *device); +private: + PluginTimer *m_pluginTimer = nullptr; + QByteArray m_apiKey; + + void searchGeoLocation(double lat, double lon, const QString &country, DeviceDiscoveryInfo *info); + +private slots: + void onPluginTimer(); +}; + +#endif // DEVICEPLUGINOPENUV_H diff --git a/openuv/devicepluginopenuv.json b/openuv/devicepluginopenuv.json new file mode 100644 index 00000000..c0853152 --- /dev/null +++ b/openuv/devicepluginopenuv.json @@ -0,0 +1,162 @@ +{ + "name": "OpenUv", + "displayName": "OpenUV", + "id": "9b7d9cc8-77df-4197-a6fc-8a365747a3b1", + "paramTypes": [ + { + "id": "cbb8e9d1-22b6-40ab-bbff-26abb2ed416f", + "name": "apiKey", + "displayName": "API key", + "type": "QString", + "inputType": "TextLine", + "defaultValue": "-" + } + ], + "vendors": [ + { + "name": "openUv", + "displayName": "OpenUV", + "id": "73560db6-af79-41f0-85a8-e9c9907647c8", + "deviceClasses": [ + { + "id": "37e17c00-91e1-4276-a1e3-12283d2cae4c", + "name": "openUv", + "displayName": "UV Index", + "interfaces": ["connectable"], + "createMethods": ["discovery", "user"], + "paramTypes": [ + { + "id": "35869967-20f2-4106-ba2e-90293bd460db", + "name": "latitude", + "displayName": "Latitude", + "type": "QString", + "inputType": "TextLine" + }, + { + "id": "b97dfec9-f9e7-489d-b3db-7e70938def1a", + "name": "longitude", + "displayName": "Longitude", + "type": "QString", + "inputType": "TextLine" + } + ], + "stateTypes": [ + { + "id": "47c7dd57-3592-4d05-af4c-1034268223e1", + "name": "connected", + "displayName": "Connected", + "displayNameEvent": "Connected changed", + "type": "bool", + "defaultValue": false + }, + { + "id": "1d63cee1-3e28-4e90-ad4f-acbc2081ea8c", + "name": "uv", + "displayName": "UV index", + "displayNameEvent": "UV index changed", + "type": "int", + "defaultValue": 0 + }, + { + "id": "35c799a1-d4b5-4d26-8b63-d884cf96ff2c", + "name": "uvTime", + "displayName": "UV time", + "displayNameEvent": "UV time changed", + "unit": "UnixTime", + "type": "int", + "defaultValue": 0 + }, + { + "id": "59fe2255-3b61-44f0-84eb-afa6eea838c2", + "name": "uvMax", + "displayName": "UV day max index", + "displayNameEvent": "UV day max index changed", + "type": "int", + "defaultValue": 0 + }, + { + "id": "4abd1745-c290-4685-bed4-108d31721b67", + "name": "uvMaxTime", + "displayName": "UV maximum time", + "displayNameEvent": "UV maximum time changed", + "unit": "UnixTime", + "type": "int", + "defaultValue": 0 + }, + { + "id": "48e51a7c-edbb-499e-95a0-6789bf51437c", + "name": "ozone", + "displayName": "Ozone", + "displayNameEvent": "Ozone changed", + "type": "int", + "defaultValue": 0 + }, + { + "id": "27a48154-218f-4a27-aefb-41d943ecf7e8", + "name": "ozoneTime", + "displayName": "Ozone time", + "displayNameEvent": "Ozone time changed", + "unit": "UnixTime", + "type": "int", + "defaultValue": 0 + }, + { + "id": "13bc0387-acfe-4461-85c8-46f5e93ee0aa", + "name": "safeExposureTimeSt1", + "displayName": "Safe exposure time skin type 1", + "displayNameEvent": "Safe exposure time skin type 1 changed", + "unit": "Minutes", + "type": "int", + "defaultValue": 0 + }, + { + "id": "0a60b028-97c9-4231-90a4-95ace8c6cf28", + "name": "safeExposureTimeSt2", + "displayName": "Safe exposure time skin type 2", + "displayNameEvent": "Safe exposure time skin type 2 changed", + "unit": "Minutes", + "type": "int", + "defaultValue": 0 + }, + { + "id": "fb9c63aa-8ec6-479d-bd87-75865b8fcd77", + "name": "safeExposureTimeSt3", + "displayName": "Safe exposure time skin type 3", + "displayNameEvent": "Safe exposure time skin type 3 changed", + "unit": "Minutes", + "type": "int", + "defaultValue": 0 + }, + { + "id": "31fc498f-1f17-4443-b0f8-65aff70bbf1c", + "name": "safeExposureTimeSt4", + "displayName": "Safe exposure time skin type 4", + "displayNameEvent": "Safe exposure time skin type 4 changed", + "unit": "Minutes", + "type": "int", + "defaultValue": 0 + }, + { + "id": "268637f0-73a9-4945-ace9-fc2bfc250675", + "name": "safeExposureTimeSt5", + "displayName": "Safe exposure time skin type 5", + "displayNameEvent": "Safe exposure time skin type 5 changed", + "unit": "Minutes", + "type": "int", + "defaultValue": 0 + }, + { + "id": "fd98313c-a6fb-4cff-8478-7399d33e7794", + "name": "safeExposureTimeSt6", + "displayName": "Safe exposure time skin type 6", + "displayNameEvent": "Safe exposure time skin type 6 changed", + "unit": "Minutes", + "type": "int", + "defaultValue": 0 + } + ] + } + ] + } + ] +} diff --git a/openuv/openuv.pro b/openuv/openuv.pro new file mode 100644 index 00000000..bdedf434 --- /dev/null +++ b/openuv/openuv.pro @@ -0,0 +1,13 @@ +include(../plugins.pri) + +TARGET = $$qtLibraryTarget(nymea_devicepluginopenuv) + +QT+= network + +SOURCES += \ + devicepluginopenuv.cpp \ + +HEADERS += \ + devicepluginopenuv.h \ + + From 028e99539fee29504e52e9ca16f9e193ed7eced6 Mon Sep 17 00:00:00 2001 From: Boernsman Date: Tue, 31 Dec 2019 00:49:51 +0100 Subject: [PATCH 2/3] added translation file --- ...d9cc8-77df-4197-a6fc-8a365747a3b1-en_US.ts | 259 ++++++++++++++++++ 1 file changed, 259 insertions(+) create mode 100644 openuv/translations/9b7d9cc8-77df-4197-a6fc-8a365747a3b1-en_US.ts diff --git a/openuv/translations/9b7d9cc8-77df-4197-a6fc-8a365747a3b1-en_US.ts b/openuv/translations/9b7d9cc8-77df-4197-a6fc-8a365747a3b1-en_US.ts new file mode 100644 index 00000000..e6cc971b --- /dev/null +++ b/openuv/translations/9b7d9cc8-77df-4197-a6fc-8a365747a3b1-en_US.ts @@ -0,0 +1,259 @@ + + + + + DevicePluginOpenUv + + + Failed to fetch data from the internet. + + + + + + The server returned unexpected data. + + + + + OpenUV location + + + + + API key is missing, add your OpenUV API key in the plug-in configs + + + + + OpenUv + + + API key + The name of the ParamType (DeviceClass: openUv, Type: plugin, ID: {cbb8e9d1-22b6-40ab-bbff-26abb2ed416f}) + + + + + + Connected + The name of the ParamType (DeviceClass: openUv, EventType: connected, ID: {47c7dd57-3592-4d05-af4c-1034268223e1}) +---------- +The name of the StateType ({47c7dd57-3592-4d05-af4c-1034268223e1}) of DeviceClass openUv + + + + + Connected changed + The name of the EventType ({47c7dd57-3592-4d05-af4c-1034268223e1}) of DeviceClass openUv + + + + + Latitude + The name of the ParamType (DeviceClass: openUv, Type: device, ID: {35869967-20f2-4106-ba2e-90293bd460db}) + + + + + Longitude + The name of the ParamType (DeviceClass: openUv, Type: device, ID: {b97dfec9-f9e7-489d-b3db-7e70938def1a}) + + + + + + OpenUV + The name of the vendor ({73560db6-af79-41f0-85a8-e9c9907647c8}) +---------- +The name of the plugin OpenUv ({9b7d9cc8-77df-4197-a6fc-8a365747a3b1}) + + + + + + Ozone + The name of the ParamType (DeviceClass: openUv, EventType: ozone, ID: {48e51a7c-edbb-499e-95a0-6789bf51437c}) +---------- +The name of the StateType ({48e51a7c-edbb-499e-95a0-6789bf51437c}) of DeviceClass openUv + + + + + Ozone changed + The name of the EventType ({48e51a7c-edbb-499e-95a0-6789bf51437c}) of DeviceClass openUv + + + + + + Ozone time + The name of the ParamType (DeviceClass: openUv, EventType: ozoneTime, ID: {27a48154-218f-4a27-aefb-41d943ecf7e8}) +---------- +The name of the StateType ({27a48154-218f-4a27-aefb-41d943ecf7e8}) of DeviceClass openUv + + + + + Ozone time changed + The name of the EventType ({27a48154-218f-4a27-aefb-41d943ecf7e8}) of DeviceClass openUv + + + + + + Safe exposure time skin type 1 + The name of the ParamType (DeviceClass: openUv, EventType: safeExposureTimeSt1, ID: {13bc0387-acfe-4461-85c8-46f5e93ee0aa}) +---------- +The name of the StateType ({13bc0387-acfe-4461-85c8-46f5e93ee0aa}) of DeviceClass openUv + + + + + Safe exposure time skin type 1 changed + The name of the EventType ({13bc0387-acfe-4461-85c8-46f5e93ee0aa}) of DeviceClass openUv + + + + + + Safe exposure time skin type 2 + The name of the ParamType (DeviceClass: openUv, EventType: safeExposureTimeSt2, ID: {0a60b028-97c9-4231-90a4-95ace8c6cf28}) +---------- +The name of the StateType ({0a60b028-97c9-4231-90a4-95ace8c6cf28}) of DeviceClass openUv + + + + + Safe exposure time skin type 2 changed + The name of the EventType ({0a60b028-97c9-4231-90a4-95ace8c6cf28}) of DeviceClass openUv + + + + + + Safe exposure time skin type 3 + The name of the ParamType (DeviceClass: openUv, EventType: safeExposureTimeSt3, ID: {fb9c63aa-8ec6-479d-bd87-75865b8fcd77}) +---------- +The name of the StateType ({fb9c63aa-8ec6-479d-bd87-75865b8fcd77}) of DeviceClass openUv + + + + + Safe exposure time skin type 3 changed + The name of the EventType ({fb9c63aa-8ec6-479d-bd87-75865b8fcd77}) of DeviceClass openUv + + + + + + Safe exposure time skin type 4 + The name of the ParamType (DeviceClass: openUv, EventType: safeExposureTimeSt4, ID: {31fc498f-1f17-4443-b0f8-65aff70bbf1c}) +---------- +The name of the StateType ({31fc498f-1f17-4443-b0f8-65aff70bbf1c}) of DeviceClass openUv + + + + + Safe exposure time skin type 4 changed + The name of the EventType ({31fc498f-1f17-4443-b0f8-65aff70bbf1c}) of DeviceClass openUv + + + + + + Safe exposure time skin type 5 + The name of the ParamType (DeviceClass: openUv, EventType: safeExposureTimeSt5, ID: {268637f0-73a9-4945-ace9-fc2bfc250675}) +---------- +The name of the StateType ({268637f0-73a9-4945-ace9-fc2bfc250675}) of DeviceClass openUv + + + + + Safe exposure time skin type 5 changed + The name of the EventType ({268637f0-73a9-4945-ace9-fc2bfc250675}) of DeviceClass openUv + + + + + + Safe exposure time skin type 6 + The name of the ParamType (DeviceClass: openUv, EventType: safeExposureTimeSt6, ID: {fd98313c-a6fb-4cff-8478-7399d33e7794}) +---------- +The name of the StateType ({fd98313c-a6fb-4cff-8478-7399d33e7794}) of DeviceClass openUv + + + + + Safe exposure time skin type 6 changed + The name of the EventType ({fd98313c-a6fb-4cff-8478-7399d33e7794}) of DeviceClass openUv + + + + + UV Index + The name of the DeviceClass ({37e17c00-91e1-4276-a1e3-12283d2cae4c}) + + + + + + UV day max index + The name of the ParamType (DeviceClass: openUv, EventType: uvMax, ID: {59fe2255-3b61-44f0-84eb-afa6eea838c2}) +---------- +The name of the StateType ({59fe2255-3b61-44f0-84eb-afa6eea838c2}) of DeviceClass openUv + + + + + UV day max index changed + The name of the EventType ({59fe2255-3b61-44f0-84eb-afa6eea838c2}) of DeviceClass openUv + + + + + + UV index + The name of the ParamType (DeviceClass: openUv, EventType: uv, ID: {1d63cee1-3e28-4e90-ad4f-acbc2081ea8c}) +---------- +The name of the StateType ({1d63cee1-3e28-4e90-ad4f-acbc2081ea8c}) of DeviceClass openUv + + + + + UV index changed + The name of the EventType ({1d63cee1-3e28-4e90-ad4f-acbc2081ea8c}) of DeviceClass openUv + + + + + + UV maximum time + The name of the ParamType (DeviceClass: openUv, EventType: uvMaxTime, ID: {4abd1745-c290-4685-bed4-108d31721b67}) +---------- +The name of the StateType ({4abd1745-c290-4685-bed4-108d31721b67}) of DeviceClass openUv + + + + + UV maximum time changed + The name of the EventType ({4abd1745-c290-4685-bed4-108d31721b67}) of DeviceClass openUv + + + + + + UV time + The name of the ParamType (DeviceClass: openUv, EventType: uvTime, ID: {35c799a1-d4b5-4d26-8b63-d884cf96ff2c}) +---------- +The name of the StateType ({35c799a1-d4b5-4d26-8b63-d884cf96ff2c}) of DeviceClass openUv + + + + + UV time changed + The name of the EventType ({35c799a1-d4b5-4d26-8b63-d884cf96ff2c}) of DeviceClass openUv + + + + From becd2b58d59e048a4c5c324514f5219fa46bea34 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Thu, 16 Jan 2020 16:35:47 +0100 Subject: [PATCH 3/3] Make it build with older Qt versions. Qt::ISODateWithMs and toSecsSinceEpoch() are only available with Qt 5.8. However, seems parsing already works fine with ISODate too even if milliseconds are included in the string. --- openuv/devicepluginopenuv.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openuv/devicepluginopenuv.cpp b/openuv/devicepluginopenuv.cpp index c385f681..09ad0adf 100644 --- a/openuv/devicepluginopenuv.cpp +++ b/openuv/devicepluginopenuv.cpp @@ -150,9 +150,9 @@ void DevicePluginOpenUv::getUvIndex(Device *device) device->setStateValue(openUvUvMaxStateTypeId, result["uv_max"].toDouble()); device->setStateValue(openUvOzoneStateTypeId, result["ozone"].toDouble()); - device->setStateValue(openUvUvTimeStateTypeId, QDateTime::fromString(result["uv_time"].toString(),Qt::DateFormat::ISODateWithMs).toSecsSinceEpoch()); - device->setStateValue(openUvOzoneTimeStateTypeId, QDateTime::fromString(result["ozone_time"].toString(),Qt::DateFormat::ISODateWithMs).toSecsSinceEpoch()); - device->setStateValue(openUvUvMaxTimeStateTypeId, QDateTime::fromString(result["uv_max_time"].toString(),Qt::DateFormat::ISODateWithMs).toSecsSinceEpoch()); + device->setStateValue(openUvUvTimeStateTypeId, QDateTime::fromString(result["uv_time"].toString(),Qt::DateFormat::ISODate).toMSecsSinceEpoch() / 1000); + device->setStateValue(openUvOzoneTimeStateTypeId, QDateTime::fromString(result["ozone_time"].toString(),Qt::DateFormat::ISODate).toMSecsSinceEpoch() / 1000); + device->setStateValue(openUvUvMaxTimeStateTypeId, QDateTime::fromString(result["uv_max_time"].toString(),Qt::DateFormat::ISODate).toMSecsSinceEpoch() / 100); QVariantMap safeExposureTimes = result["safe_exposure_time"].toMap(); device->setStateValue(openUvSafeExposureTimeSt1StateTypeId, safeExposureTimes["st1"].toInt());