mirror of https://github.com/nymea/nymea.git
add getsupportedvendors
parent
415a48d659
commit
76bf703fc5
|
|
@ -133,8 +133,8 @@ bool DevicePluginMock::deviceCreated(Device *device)
|
|||
return false;
|
||||
}
|
||||
|
||||
connect(daemon, SIGNAL(triggerEvent(QUuid)), SLOT(triggerEvent(QUuid)));
|
||||
connect(daemon, SIGNAL(setState(QUuid, QVariant)), SLOT(setState(QUuid,QVariant)));
|
||||
connect(daemon, &HttpDaemon::triggerEvent, this, &DevicePluginMock::triggerEvent);
|
||||
connect(daemon, &HttpDaemon::setState, this, &DevicePluginMock::setState);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,10 +58,10 @@ void HttpDaemon::readClient()
|
|||
QUrlQuery query(url);
|
||||
qDebug() << "query is" << url.path();
|
||||
if (url.path() == "/setstate") {
|
||||
emit setState(QUuid(query.queryItems().first().first), QVariant(query.queryItems().first().second));
|
||||
emit setState(StateTypeId(query.queryItems().first().first), QVariant(query.queryItems().first().second));
|
||||
} else if (url.path() == "/generateevent") {
|
||||
qDebug() << "got generateevent" << query.queryItemValue("eventid");
|
||||
emit triggerEvent(QUuid(query.queryItemValue("eventid")));
|
||||
emit triggerEvent(EventTypeId(query.queryItemValue("eventid")));
|
||||
}
|
||||
}
|
||||
if (tokens[0] == "GET") {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef HTTPDAEMON_H
|
||||
#define HTTPDAEMON_H
|
||||
|
||||
#include "typeutils.h"
|
||||
|
||||
#include <QTcpServer>
|
||||
#include <QUuid>
|
||||
#include <QDateTime>
|
||||
|
|
@ -19,8 +21,8 @@ public:
|
|||
void actionExecuted(const QUuid&actionTypeId);
|
||||
|
||||
signals:
|
||||
void setState(const QUuid &stateTypeId, const QVariant &value);
|
||||
void triggerEvent(const QUuid &eventTypeId);
|
||||
void setState(const StateTypeId &stateTypeId, const QVariant &value);
|
||||
void triggerEvent(const EventTypeId &eventTypeId);
|
||||
|
||||
private slots:
|
||||
void readClient();
|
||||
|
|
|
|||
|
|
@ -31,6 +31,14 @@ DeviceHandler::DeviceHandler(QObject *parent) :
|
|||
QVariantMap returns;
|
||||
QVariantMap params;
|
||||
|
||||
params.clear(); returns.clear();
|
||||
setDescription("GetSupportedVendors", "Returns a list of supported Vendors.");
|
||||
setParams("GetSupportedVendors", params);
|
||||
QVariantList vendors;
|
||||
vendors.append(JsonTypes::vendorRef());
|
||||
returns.insert("vendors", vendors);
|
||||
setReturns("GetSupportedVendors", returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
setDescription("GetSupportedDevices", "Returns a list of supported Device classes.");
|
||||
setParams("GetSupportedDevices", params);
|
||||
|
|
@ -39,7 +47,6 @@ DeviceHandler::DeviceHandler(QObject *parent) :
|
|||
returns.insert("deviceClasses", deviceClasses);
|
||||
setReturns("GetSupportedDevices", returns);
|
||||
|
||||
|
||||
params.clear(); returns.clear();
|
||||
setDescription("GetPlugins", "Returns a list of loaded plugins.");
|
||||
setParams("GetPlugins", params);
|
||||
|
|
@ -138,6 +145,17 @@ QString DeviceHandler::name() const
|
|||
return "Devices";
|
||||
}
|
||||
|
||||
QVariantMap DeviceHandler::GetSupportedVendors(const QVariantMap ¶ms) const
|
||||
{
|
||||
QVariantMap returns;
|
||||
QVariantList supportedVendors;
|
||||
foreach (const Vendor &vendor, GuhCore::instance()->deviceManager()->supportedVendors()) {
|
||||
supportedVendors.append(JsonTypes::packVendor(vendor));
|
||||
}
|
||||
returns.insert("vendors", supportedVendors);
|
||||
return returns;
|
||||
}
|
||||
|
||||
QVariantMap DeviceHandler::GetSupportedDevices(const QVariantMap ¶ms) const
|
||||
{
|
||||
Q_UNUSED(params)
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ public:
|
|||
|
||||
QString name() const override;
|
||||
|
||||
Q_INVOKABLE QVariantMap GetSupportedVendors(const QVariantMap ¶ms) const;
|
||||
|
||||
Q_INVOKABLE QVariantMap GetSupportedDevices(const QVariantMap ¶ms) const;
|
||||
|
||||
Q_INVOKABLE QVariantMap GetPlugins(const QVariantMap ¶ms) const;
|
||||
|
|
|
|||
|
|
@ -189,6 +189,14 @@ QVariantMap JsonTypes::packStateType(const StateType &stateType)
|
|||
return variantMap;
|
||||
}
|
||||
|
||||
QVariantMap JsonTypes::packVendor(const Vendor &vendor)
|
||||
{
|
||||
QVariantMap variantMap;
|
||||
variantMap.insert("id", vendor.id());
|
||||
variantMap.insert("name", vendor.name());
|
||||
return variantMap;
|
||||
}
|
||||
|
||||
QVariantMap JsonTypes::packDeviceClass(const DeviceClass &deviceClass)
|
||||
{
|
||||
QVariantMap variant;
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ public:
|
|||
DECLARE_OBJECT(actionType, "ActionType")
|
||||
DECLARE_OBJECT(action, "Action")
|
||||
DECLARE_OBJECT(plugin, "Plugin")
|
||||
DECLARE_OBJECT(vendor, "Vendor")
|
||||
DECLARE_OBJECT(deviceClass, "DeviceClass")
|
||||
DECLARE_OBJECT(device, "Device")
|
||||
DECLARE_OBJECT(rule, "Rule")
|
||||
|
|
@ -81,6 +82,7 @@ public:
|
|||
static QVariantMap packActionType(const ActionType &actionType);
|
||||
static QVariantMap packAction(const Action &action);
|
||||
static QVariantMap packStateType(const StateType &stateType);
|
||||
static QVariantMap packVendor(const Vendor &vendor);
|
||||
static QVariantMap packDeviceClass(const DeviceClass &deviceClass);
|
||||
static QVariantMap packPlugin(DevicePlugin *plugin);
|
||||
static QVariantMap packDevice(Device *device);
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ Q_IMPORT_PLUGIN(DevicePluginMock)
|
|||
int mockDevice1Port = 1337;
|
||||
int mockDevice2Port = 7331;
|
||||
|
||||
extern VendorId guhVendorId;
|
||||
|
||||
class TestJSONRPC: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
@ -42,6 +44,7 @@ private slots:
|
|||
void introspect();
|
||||
void version();
|
||||
|
||||
void getSupportedVendors();
|
||||
void getSupportedDevices();
|
||||
|
||||
void enableDisableNotifications_data();
|
||||
|
|
@ -147,6 +150,18 @@ void TestJSONRPC::introspect()
|
|||
QCOMPARE(jsonDoc.toVariant().toMap().value("id").toInt(), 42);
|
||||
}
|
||||
|
||||
void TestJSONRPC::getSupportedVendors()
|
||||
{
|
||||
QVariant supportedVendors = injectAndWait("Devices.GetSupportedVendors");
|
||||
qDebug() << "response" << supportedVendors;
|
||||
|
||||
// Make sure there is exactly 1 supported Vendor named "guh"
|
||||
QVariantList vendorList = supportedVendors.toMap().value("params").toMap().value("vendors").toList();
|
||||
QCOMPARE(vendorList.count(), 1);
|
||||
VendorId vendorId = VendorId(vendorList.first().toMap().value("id").toString());
|
||||
QCOMPARE(vendorId, guhVendorId);
|
||||
}
|
||||
|
||||
void TestJSONRPC::getSupportedDevices()
|
||||
{
|
||||
QVariant supportedDevices = injectAndWait("Devices.GetSupportedDevices");
|
||||
|
|
@ -195,7 +210,6 @@ void TestJSONRPC::stateChangeEmitsNotifications()
|
|||
// Setup connection to mock client
|
||||
QNetworkAccessManager nam;
|
||||
|
||||
QSignalSpy mockSpy(&nam, SIGNAL(finished()));
|
||||
QSignalSpy clientSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray)));
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue