update openweathermap api changes
small changes in the plugin json
This commit is contained in:
parent
4e7dc321ae
commit
46f77cd67a
@ -25,14 +25,15 @@
|
|||||||
\ingroup plugins
|
\ingroup plugins
|
||||||
\ingroup services
|
\ingroup services
|
||||||
|
|
||||||
This plugin alows you to get the current weather data from \l{http://www.openweathermap.org}.
|
This plugin allows to get the current weather data from \l{http://www.openweathermap.org}{OpenWeatherMap}.
|
||||||
The plugin offers two different search methods: if the user searches for a empty string,
|
The weather data will be refreshed every 15 minutes automatically, but can also refreshed manually.
|
||||||
the plugin makes an autodetction with the WAN ip and offers the user the found autodetectresult.
|
The plugin offers two different search methods for the location: if the user searches for a empty string,
|
||||||
|
the plugin makes an autodetction with the WAN ip and offers the user the found weather stations.
|
||||||
The autodetection function uses the geolocation of your WAN ip and searches all available weather
|
The autodetection function uses the geolocation of your WAN ip and searches all available weather
|
||||||
stations in a radius of 1.5 km. Otherwise the plugin returns the list of the found search results
|
stations in a radius of 1.5 km. Otherwise the plugin returns the list of the found search results
|
||||||
from the search string.
|
from the search string.
|
||||||
|
|
||||||
\underline{NOTE}: If you are using a VPN connection, the autodetection will show the results around of your VPN location.
|
\underline{NOTE}: If you are using a VPN connection, the autodetection will show the results around your VPN location.
|
||||||
|
|
||||||
\chapter Plugin properties
|
\chapter Plugin properties
|
||||||
Following JSON file contains the definition and the description of all available \l{DeviceClass}{DeviceClasses}
|
Following JSON file contains the definition and the description of all available \l{DeviceClass}{DeviceClasses}
|
||||||
@ -64,9 +65,18 @@
|
|||||||
#include <QUrlQuery>
|
#include <QUrlQuery>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
|
||||||
|
|
||||||
DevicePluginOpenweathermap::DevicePluginOpenweathermap()
|
DevicePluginOpenweathermap::DevicePluginOpenweathermap()
|
||||||
{
|
{
|
||||||
|
// max 60 calls/minute
|
||||||
|
// max 50000 calls/day
|
||||||
|
m_apiKey = "c1b9d5584bb740804871583f6c62744f";
|
||||||
|
|
||||||
|
// update every 15 minutes
|
||||||
|
m_timer = new QTimer(this);
|
||||||
|
m_timer->setSingleShot(false);
|
||||||
|
m_timer->setInterval(900000);
|
||||||
|
|
||||||
|
connect(m_timer, SIGNAL(timeout()), this, SLOT(onTimeout()));
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceManager::DeviceError DevicePluginOpenweathermap::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
DeviceManager::DeviceError DevicePluginOpenweathermap::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
||||||
@ -103,12 +113,12 @@ DeviceManager::DeviceSetupStatus DevicePluginOpenweathermap::setupDevice(Device
|
|||||||
|
|
||||||
DeviceManager::HardwareResources DevicePluginOpenweathermap::requiredHardware() const
|
DeviceManager::HardwareResources DevicePluginOpenweathermap::requiredHardware() const
|
||||||
{
|
{
|
||||||
return DeviceManager::HardwareResourceTimer | DeviceManager::HardwareResourceNetworkManager;
|
return DeviceManager::HardwareResourceNetworkManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceManager::DeviceError DevicePluginOpenweathermap::executeAction(Device *device, const Action &action)
|
DeviceManager::DeviceError DevicePluginOpenweathermap::executeAction(Device *device, const Action &action)
|
||||||
{
|
{
|
||||||
if(action.actionTypeId() == updateWeatherActionTypeId){
|
if(action.actionTypeId() == refreshWeatherActionTypeId){
|
||||||
update(device);
|
update(device);
|
||||||
return DeviceManager::DeviceErrorNoError;
|
return DeviceManager::DeviceErrorNoError;
|
||||||
}
|
}
|
||||||
@ -155,26 +165,6 @@ void DevicePluginOpenweathermap::networkManagerReplyReady(QNetworkReply *reply)
|
|||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginOpenweathermap::guhTimer()
|
|
||||||
{
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DevicePluginOpenweathermap::update()
|
|
||||||
{
|
|
||||||
foreach (Device *device, myDevices()) {
|
|
||||||
QUrl url("http://api.openweathermap.org/data/2.5/weather");
|
|
||||||
QUrlQuery query;
|
|
||||||
query.addQueryItem("id", device->paramValue("id").toString());
|
|
||||||
query.addQueryItem("mode", "json");
|
|
||||||
query.addQueryItem("units", "metric");
|
|
||||||
url.setQuery(query);
|
|
||||||
|
|
||||||
QNetworkReply *reply = networkManagerGet(QNetworkRequest(url));
|
|
||||||
m_weatherReplies.insert(reply, device);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DevicePluginOpenweathermap::update(Device *device)
|
void DevicePluginOpenweathermap::update(Device *device)
|
||||||
{
|
{
|
||||||
QUrl url("http://api.openweathermap.org/data/2.5/weather");
|
QUrl url("http://api.openweathermap.org/data/2.5/weather");
|
||||||
@ -182,6 +172,7 @@ void DevicePluginOpenweathermap::update(Device *device)
|
|||||||
query.addQueryItem("id", device->paramValue("id").toString());
|
query.addQueryItem("id", device->paramValue("id").toString());
|
||||||
query.addQueryItem("mode", "json");
|
query.addQueryItem("mode", "json");
|
||||||
query.addQueryItem("units", "metric");
|
query.addQueryItem("units", "metric");
|
||||||
|
query.addQueryItem("appid", m_apiKey);
|
||||||
url.setQuery(query);
|
url.setQuery(query);
|
||||||
|
|
||||||
QNetworkReply *reply = networkManagerGet(QNetworkRequest(url));
|
QNetworkReply *reply = networkManagerGet(QNetworkRequest(url));
|
||||||
@ -202,6 +193,7 @@ void DevicePluginOpenweathermap::search(QString searchString)
|
|||||||
query.addQueryItem("type", "like");
|
query.addQueryItem("type", "like");
|
||||||
query.addQueryItem("mode", "json");
|
query.addQueryItem("mode", "json");
|
||||||
query.addQueryItem("units", "metric");
|
query.addQueryItem("units", "metric");
|
||||||
|
query.addQueryItem("appid", m_apiKey);
|
||||||
url.setQuery(query);
|
url.setQuery(query);
|
||||||
|
|
||||||
QNetworkReply *reply = networkManagerGet(QNetworkRequest(url));
|
QNetworkReply *reply = networkManagerGet(QNetworkRequest(url));
|
||||||
@ -218,6 +210,7 @@ void DevicePluginOpenweathermap::searchGeoLocation(double lat, double lon)
|
|||||||
query.addQueryItem("type", "like");
|
query.addQueryItem("type", "like");
|
||||||
query.addQueryItem("mode", "json");
|
query.addQueryItem("mode", "json");
|
||||||
query.addQueryItem("units", "metric");
|
query.addQueryItem("units", "metric");
|
||||||
|
query.addQueryItem("appid", m_apiKey);
|
||||||
url.setQuery(query);
|
url.setQuery(query);
|
||||||
|
|
||||||
QNetworkReply *reply = networkManagerGet(QNetworkRequest(url));
|
QNetworkReply *reply = networkManagerGet(QNetworkRequest(url));
|
||||||
@ -403,4 +396,10 @@ void DevicePluginOpenweathermap::processWeatherData(const QByteArray &data, Devi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DevicePluginOpenweathermap::onTimeout()
|
||||||
|
{
|
||||||
|
foreach (Device *device, myDevices()) {
|
||||||
|
update(device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
#include "plugin/deviceplugin.h"
|
#include "plugin/deviceplugin.h"
|
||||||
|
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
class DevicePluginOpenweathermap : public DevicePlugin
|
class DevicePluginOpenweathermap : public DevicePlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -40,7 +42,7 @@ public:
|
|||||||
|
|
||||||
void deviceRemoved(Device *device) override;
|
void deviceRemoved(Device *device) override;
|
||||||
void networkManagerReplyReady(QNetworkReply *reply) override;
|
void networkManagerReplyReady(QNetworkReply *reply) override;
|
||||||
void guhTimer() override;
|
//void guhTimer() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<QNetworkReply *> m_autodetectionReplies;
|
QList<QNetworkReply *> m_autodetectionReplies;
|
||||||
@ -55,7 +57,9 @@ private:
|
|||||||
double m_longitude;
|
double m_longitude;
|
||||||
double m_latitude;
|
double m_latitude;
|
||||||
|
|
||||||
void update();
|
QTimer *m_timer;
|
||||||
|
QString m_apiKey;
|
||||||
|
|
||||||
void update(Device *device);
|
void update(Device *device);
|
||||||
void searchAutodetect();
|
void searchAutodetect();
|
||||||
void search(QString searchString);
|
void search(QString searchString);
|
||||||
@ -68,6 +72,8 @@ private:
|
|||||||
void processSearchResults(const QList<QVariantMap> &cityList);
|
void processSearchResults(const QList<QVariantMap> &cityList);
|
||||||
void processWeatherData(const QByteArray &data, Device *device);
|
void processWeatherData(const QByteArray &data, Device *device);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onTimeout();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
{
|
{
|
||||||
"deviceClassId": "985195aa-17ad-4530-88a4-cdd753d747d7",
|
"deviceClassId": "985195aa-17ad-4530-88a4-cdd753d747d7",
|
||||||
"idName": "openweathermap",
|
"idName": "openweathermap",
|
||||||
"name": "Weather from OpenWeatherMap",
|
"name": "Weather",
|
||||||
"createMethods": ["discovery"],
|
"createMethods": ["discovery"],
|
||||||
"discoveryParamTypes": [
|
"discoveryParamTypes": [
|
||||||
{
|
{
|
||||||
@ -41,8 +41,8 @@
|
|||||||
"actionTypes": [
|
"actionTypes": [
|
||||||
{
|
{
|
||||||
"id": "cfbc6504-d86f-4856-8dfa-97b6fbb385e4",
|
"id": "cfbc6504-d86f-4856-8dfa-97b6fbb385e4",
|
||||||
"idName": "updateWeather",
|
"idName": "refreshWeather",
|
||||||
"name": "update"
|
"name": "refresh"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"stateTypes": [
|
"stateTypes": [
|
||||||
|
|||||||
Reference in New Issue
Block a user