Remove deprecated Devices, Action, Events, States namespaces from JSONRPC
This commit is contained in:
parent
28d2f53261
commit
717b4f33cc
@ -1,187 +0,0 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2020, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
* This project including source code and documentation is protected by
|
||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
||||
* reproduction, publication, editing and translation, are reserved. The use of
|
||||
* this project is subject to the terms of a license agreement to be concluded
|
||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
||||
* under https://nymea.io/license
|
||||
*
|
||||
* GNU General Public License Usage
|
||||
* Alternatively, this project may be redistributed and/or modified under the
|
||||
* terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, GNU version 3. This project 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 General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For any further details and any questions please contact us under
|
||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
||||
* https://nymea.io/license/faq
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#include "actionhandler.h"
|
||||
#include "devicehandler.h"
|
||||
|
||||
#include "nymeacore.h"
|
||||
#include "integrations/thingmanager.h"
|
||||
#include "integrations/thingactioninfo.h"
|
||||
#include "integrations/browseractioninfo.h"
|
||||
#include "integrations/browseritemactioninfo.h"
|
||||
#include "types/action.h"
|
||||
#include "types/actiontype.h"
|
||||
#include "loggingcategories.h"
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
ActionHandler::ActionHandler(QObject *parent) :
|
||||
JsonHandler(parent)
|
||||
{
|
||||
// Enums
|
||||
registerEnum<Types::InputType>();
|
||||
registerEnum<Types::Unit>();
|
||||
|
||||
// Objects
|
||||
registerObject<ParamType, ParamTypes>();
|
||||
registerObject<Param, ParamList>();
|
||||
registerObject<ActionType>();
|
||||
registerObject<Action>();
|
||||
|
||||
// Methods
|
||||
QString description; QVariantMap params; QVariantMap returns;
|
||||
description = "Execute a single action.";
|
||||
params.insert("actionTypeId", enumValueName(Uuid));
|
||||
params.insert("deviceId", enumValueName(Uuid));
|
||||
params.insert("o:params", objectRef<ParamList>());
|
||||
returns.insert("deviceError", enumRef<Device::DeviceError>());
|
||||
returns.insert("o:displayMessage", enumValueName(String));
|
||||
registerMethod("ExecuteAction", description, params, returns, "Please use Integrations.ExecuteAction instead.");
|
||||
|
||||
params.clear(); returns.clear();
|
||||
description = "Get the ActionType for the given ActionTypeId.";
|
||||
params.insert("actionTypeId", enumValueName(Uuid));
|
||||
returns.insert("deviceError", enumRef<Device::DeviceError>());
|
||||
returns.insert("o:actionType", objectRef<ActionType>());
|
||||
registerMethod("GetActionType", description, params, returns, "Please use the Integrations namespace instead.");
|
||||
|
||||
params.clear(); returns.clear();
|
||||
description = "Execute the item identified by itemId on the given device.";
|
||||
params.insert("deviceId", enumValueName(Uuid));
|
||||
params.insert("itemId", enumValueName(String));
|
||||
returns.insert("deviceError", enumRef<Device::DeviceError>());
|
||||
registerMethod("ExecuteBrowserItem", description, params, returns, "Please use Integrations.ExecuteBrowserItem instead.");
|
||||
|
||||
params.clear(); returns.clear();
|
||||
description = "Execute the action for the browser item identified by actionTypeId and the itemId on the given device.";
|
||||
params.insert("deviceId", enumValueName(Uuid));
|
||||
params.insert("itemId", enumValueName(String));
|
||||
params.insert("actionTypeId", enumValueName(Uuid));
|
||||
params.insert("o:params", objectRef<ParamList>());
|
||||
returns.insert("deviceError", enumRef<Device::DeviceError>());
|
||||
registerMethod("ExecuteBrowserItemAction", description, params, returns, "Please use Integrations.ExecuteBrowserItem instead.");
|
||||
|
||||
}
|
||||
|
||||
QString ActionHandler::name() const
|
||||
{
|
||||
return "Actions";
|
||||
}
|
||||
|
||||
JsonReply* ActionHandler::ExecuteAction(const QVariantMap ¶ms, const JsonContext &context)
|
||||
{
|
||||
ThingId thingId(params.value("deviceId").toString());
|
||||
ActionTypeId actionTypeId(params.value("actionTypeId").toString());
|
||||
ParamList actionParams = unpack<ParamList>(params.value("params"));
|
||||
QLocale locale = context.locale();
|
||||
|
||||
Action action(actionTypeId, thingId);
|
||||
action.setParams(actionParams);
|
||||
|
||||
JsonReply *jsonReply = createAsyncReply("ExecuteAction");
|
||||
|
||||
ThingActionInfo *info = NymeaCore::instance()->thingManager()->executeAction(action);
|
||||
connect(info, &ThingActionInfo::finished, jsonReply, [info, jsonReply, locale](){
|
||||
QVariantMap data;
|
||||
data.insert("deviceError", enumValueName(info->status()).replace("Thing", "Device"));
|
||||
if (!info->displayMessage().isEmpty()) {
|
||||
data.insert("displayMessage", info->translatedDisplayMessage(locale));
|
||||
}
|
||||
jsonReply->setData(data);
|
||||
jsonReply->finished();
|
||||
});
|
||||
|
||||
return jsonReply;
|
||||
}
|
||||
|
||||
JsonReply *ActionHandler::GetActionType(const QVariantMap ¶ms, const JsonContext &context) const
|
||||
{
|
||||
QLocale locale = context.locale();
|
||||
qCDebug(dcJsonRpc) << "asked for action type" << params;
|
||||
ActionTypeId actionTypeId(params.value("actionTypeId").toString());
|
||||
foreach (const ThingClass &deviceClass, NymeaCore::instance()->thingManager()->supportedThings()) {
|
||||
foreach (const ActionType &actionType, deviceClass.actionTypes()) {
|
||||
if (actionType.id() == actionTypeId) {
|
||||
ActionType translatedActionType = actionType;
|
||||
translatedActionType.setDisplayName(NymeaCore::instance()->thingManager()->translate(deviceClass.pluginId(), actionType.displayName(), locale));
|
||||
|
||||
QVariantMap data;
|
||||
data.insert("deviceError", enumValueName<Thing::ThingError>(Thing::ThingErrorNoError).replace("ThingError", "DeviceError"));
|
||||
data.insert("actionType", pack(translatedActionType));
|
||||
return createReply(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
QVariantMap data;
|
||||
data.insert("deviceError", enumValueName<Thing::ThingError>(Thing::ThingErrorActionTypeNotFound).replace("ThingError", "DeviceError"));
|
||||
return createReply(data);
|
||||
}
|
||||
|
||||
JsonReply *ActionHandler::ExecuteBrowserItem(const QVariantMap ¶ms)
|
||||
{
|
||||
ThingId thingId = ThingId(params.value("deviceId").toString());
|
||||
QString itemId = params.value("itemId").toString();
|
||||
BrowserAction action(thingId, itemId);
|
||||
|
||||
JsonReply *jsonReply = createAsyncReply("ExecuteBrowserItem");
|
||||
|
||||
BrowserActionInfo *info = NymeaCore::instance()->executeBrowserItem(action);
|
||||
connect(info, &BrowserActionInfo::finished, jsonReply, [info, jsonReply](){
|
||||
QVariantMap data;
|
||||
data.insert("deviceError", enumValueName<Thing::ThingError>(info->status()).replace("ThingError", "DeviceError"));
|
||||
jsonReply->setData(data);
|
||||
jsonReply->finished();
|
||||
});
|
||||
|
||||
return jsonReply;
|
||||
}
|
||||
|
||||
JsonReply *ActionHandler::ExecuteBrowserItemAction(const QVariantMap ¶ms)
|
||||
{
|
||||
ThingId thingId = ThingId(params.value("deviceId").toString());
|
||||
QString itemId = params.value("itemId").toString();
|
||||
ActionTypeId actionTypeId = ActionTypeId(params.value("actionTypeId").toString());
|
||||
ParamList paramList = unpack<ParamList>(params.value("params"));
|
||||
BrowserItemAction browserItemAction(thingId, itemId, actionTypeId, paramList);
|
||||
|
||||
JsonReply *jsonReply = createAsyncReply("ExecuteBrowserItemAction");
|
||||
|
||||
BrowserItemActionInfo *info = NymeaCore::instance()->executeBrowserItemAction(browserItemAction);
|
||||
connect(info, &BrowserItemActionInfo::finished, jsonReply, [info, jsonReply](){
|
||||
QVariantMap data;
|
||||
data.insert("deviceError", enumValueName<Thing::ThingError>(info->status()).replace("Thing", "Device"));
|
||||
jsonReply->setData(data);
|
||||
jsonReply->finished();
|
||||
});
|
||||
|
||||
return jsonReply;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,57 +0,0 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2020, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
* This project including source code and documentation is protected by
|
||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
||||
* reproduction, publication, editing and translation, are reserved. The use of
|
||||
* this project is subject to the terms of a license agreement to be concluded
|
||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
||||
* under https://nymea.io/license
|
||||
*
|
||||
* GNU General Public License Usage
|
||||
* Alternatively, this project may be redistributed and/or modified under the
|
||||
* terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, GNU version 3. This project 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 General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For any further details and any questions please contact us under
|
||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
||||
* https://nymea.io/license/faq
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#ifndef ACTIONHANDLER_H
|
||||
#define ACTIONHANDLER_H
|
||||
|
||||
#include "jsonrpc/jsonhandler.h"
|
||||
#include "integrations/thingmanager.h"
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
class ActionHandler : public JsonHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ActionHandler(QObject *parent = nullptr);
|
||||
|
||||
QString name() const override;
|
||||
|
||||
Q_INVOKABLE JsonReply *ExecuteAction(const QVariantMap ¶ms, const JsonContext &context);
|
||||
Q_INVOKABLE JsonReply *GetActionType(const QVariantMap ¶ms, const JsonContext &context) const;
|
||||
|
||||
Q_INVOKABLE JsonReply *ExecuteBrowserItem(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply *ExecuteBrowserItemAction(const QVariantMap ¶ms);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // ACTIONHANDLER_H
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,210 +0,0 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2020, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
* This project including source code and documentation is protected by
|
||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
||||
* reproduction, publication, editing and translation, are reserved. The use of
|
||||
* this project is subject to the terms of a license agreement to be concluded
|
||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
||||
* under https://nymea.io/license
|
||||
*
|
||||
* GNU General Public License Usage
|
||||
* Alternatively, this project may be redistributed and/or modified under the
|
||||
* terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, GNU version 3. This project 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 General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For any further details and any questions please contact us under
|
||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
||||
* https://nymea.io/license/faq
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#ifndef DEVICEHANDLER_H
|
||||
#define DEVICEHANDLER_H
|
||||
|
||||
#include "jsonrpc/jsonhandler.h"
|
||||
#include "integrations/thingmanager.h"
|
||||
#include "integrations/thing.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
DECLARE_TYPE_ID(DeviceClass)
|
||||
DECLARE_TYPE_ID(Device)
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
// Device has been renamed to Thing. As we need to keep compatibility with the Devices API for a bit,
|
||||
// let's create them here
|
||||
|
||||
class DevicePlugin: public IntegrationPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
};
|
||||
|
||||
class DevicePlugins: public IntegrationPlugins
|
||||
{
|
||||
Q_GADGET
|
||||
};
|
||||
|
||||
class DeviceClass: public ThingClass
|
||||
{
|
||||
Q_GADGET
|
||||
|
||||
public:
|
||||
DeviceClass(): ThingClass() {}
|
||||
DeviceClass(const ThingClass &other);
|
||||
};
|
||||
|
||||
class DeviceClasses: public ThingClasses
|
||||
{
|
||||
Q_GADGET
|
||||
};
|
||||
|
||||
class Device: public Thing
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QUuid deviceClassId READ deviceClassId)
|
||||
public:
|
||||
enum DeviceError {
|
||||
DeviceErrorNoError,
|
||||
DeviceErrorPluginNotFound,
|
||||
DeviceErrorVendorNotFound,
|
||||
DeviceErrorDeviceNotFound,
|
||||
DeviceErrorDeviceClassNotFound,
|
||||
DeviceErrorActionTypeNotFound,
|
||||
DeviceErrorStateTypeNotFound,
|
||||
DeviceErrorEventTypeNotFound,
|
||||
DeviceErrorDeviceDescriptorNotFound,
|
||||
DeviceErrorMissingParameter,
|
||||
DeviceErrorInvalidParameter,
|
||||
DeviceErrorSetupFailed,
|
||||
DeviceErrorDuplicateUuid,
|
||||
DeviceErrorCreationMethodNotSupported,
|
||||
DeviceErrorSetupMethodNotSupported,
|
||||
DeviceErrorHardwareNotAvailable,
|
||||
DeviceErrorHardwareFailure,
|
||||
DeviceErrorAuthenticationFailure,
|
||||
DeviceErrorDeviceInUse,
|
||||
DeviceErrorDeviceInRule,
|
||||
DeviceErrorDeviceIsChild,
|
||||
DeviceErrorPairingTransactionIdNotFound,
|
||||
DeviceErrorParameterNotWritable,
|
||||
DeviceErrorItemNotFound,
|
||||
DeviceErrorItemNotExecutable,
|
||||
DeviceErrorUnsupportedFeature,
|
||||
DeviceErrorTimeout,
|
||||
};
|
||||
Q_ENUM(DeviceError)
|
||||
|
||||
enum DeviceSetupStatus {
|
||||
DeviceSetupStatusNone,
|
||||
DeviceSetupStatusInProgress,
|
||||
DeviceSetupStatusComplete,
|
||||
DeviceSetupStatusFailed,
|
||||
};
|
||||
Q_ENUM(DeviceSetupStatus)
|
||||
|
||||
DeviceClassId deviceClassId() const;
|
||||
};
|
||||
|
||||
class Devices: public Things
|
||||
{
|
||||
Q_GADGET
|
||||
};
|
||||
|
||||
class DeviceDescriptor: public ThingDescriptor
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(QUuid deviceId READ thingId USER true)
|
||||
Q_PROPERTY(ParamList deviceParams READ params)
|
||||
};
|
||||
|
||||
class DeviceDescriptors: public ThingDescriptors
|
||||
{
|
||||
Q_GADGET
|
||||
};
|
||||
|
||||
class DeviceHandler : public JsonHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DeviceHandler(QObject *parent = nullptr);
|
||||
|
||||
QString name() const override;
|
||||
QHash<QString, QString> cacheHashes() const override;
|
||||
|
||||
QVariantMap translateNotification(const QString ¬ification, const QVariantMap ¶ms, const QLocale &locale) override;
|
||||
|
||||
Q_INVOKABLE JsonReply *GetSupportedVendors(const QVariantMap ¶ms, const JsonContext &context) const;
|
||||
Q_INVOKABLE JsonReply *GetSupportedDevices(const QVariantMap ¶ms, const JsonContext &context) const;
|
||||
Q_INVOKABLE JsonReply *GetDiscoveredDevices(const QVariantMap ¶ms, const JsonContext &context) const;
|
||||
Q_INVOKABLE JsonReply *GetPlugins(const QVariantMap ¶ms, const JsonContext &context) const;
|
||||
Q_INVOKABLE JsonReply *GetPluginConfiguration(const QVariantMap ¶ms) const;
|
||||
Q_INVOKABLE JsonReply *SetPluginConfiguration(const QVariantMap ¶ms);
|
||||
|
||||
Q_INVOKABLE JsonReply *AddConfiguredDevice(const QVariantMap ¶ms, const JsonContext &context);
|
||||
Q_INVOKABLE JsonReply *PairDevice(const QVariantMap ¶ms, const JsonContext &context);
|
||||
Q_INVOKABLE JsonReply *ConfirmPairing(const QVariantMap ¶ms, const JsonContext &context);
|
||||
Q_INVOKABLE JsonReply *GetConfiguredDevices(const QVariantMap ¶ms, const JsonContext &context) const;
|
||||
Q_INVOKABLE JsonReply *ReconfigureDevice(const QVariantMap ¶ms, const JsonContext &context);
|
||||
Q_INVOKABLE JsonReply *EditDevice(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply *RemoveConfiguredDevice(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply *SetDeviceSettings(const QVariantMap ¶ms);
|
||||
|
||||
Q_INVOKABLE JsonReply *GetEventTypes(const QVariantMap ¶ms, const JsonContext &context) const;
|
||||
Q_INVOKABLE JsonReply *GetActionTypes(const QVariantMap ¶ms, const JsonContext &context) const;
|
||||
Q_INVOKABLE JsonReply *GetStateTypes(const QVariantMap ¶ms, const JsonContext &context) const;
|
||||
Q_INVOKABLE JsonReply *GetStateValue(const QVariantMap ¶ms) const;
|
||||
Q_INVOKABLE JsonReply *GetStateValues(const QVariantMap ¶ms) const;
|
||||
|
||||
Q_INVOKABLE JsonReply *BrowseDevice(const QVariantMap ¶ms, const JsonContext &context) const;
|
||||
Q_INVOKABLE JsonReply *GetBrowserItem(const QVariantMap ¶ms, const JsonContext &context) const;
|
||||
|
||||
Q_INVOKABLE JsonReply *ExecuteAction(const QVariantMap ¶ms, const JsonContext &context);
|
||||
Q_INVOKABLE JsonReply *ExecuteBrowserItem(const QVariantMap ¶ms, const JsonContext &context);
|
||||
Q_INVOKABLE JsonReply *ExecuteBrowserItemAction(const QVariantMap ¶ms, const JsonContext &context);
|
||||
|
||||
static QVariantMap packBrowserItem(const BrowserItem &item);
|
||||
|
||||
signals:
|
||||
void PluginConfigurationChanged(const QVariantMap ¶ms);
|
||||
void StateChanged(const QVariantMap ¶ms);
|
||||
void DeviceRemoved(const QVariantMap ¶ms);
|
||||
void DeviceAdded(const QVariantMap ¶ms);
|
||||
void DeviceChanged(const QVariantMap ¶ms);
|
||||
void DeviceSettingChanged(const QVariantMap ¶ms);
|
||||
void EventTriggered(const QVariantMap ¶ms);
|
||||
|
||||
private slots:
|
||||
void pluginConfigChanged(const PluginId &id, const ParamList &config);
|
||||
|
||||
void deviceStateChanged(Thing *device, const QUuid &stateTypeId, const QVariant &value);
|
||||
|
||||
void deviceRemovedNotification(const QUuid &deviceId);
|
||||
|
||||
void deviceAddedNotification(Thing *thing);
|
||||
|
||||
void deviceChangedNotification(Thing *thing);
|
||||
|
||||
void deviceSettingChangedNotification(const ThingId &thingId, const ParamTypeId ¶mTypeId, const QVariant &value);
|
||||
|
||||
private:
|
||||
QVariantMap statusToReply(Device::ThingError status) const;
|
||||
|
||||
QHash<QString, QString> m_cacheHashes;
|
||||
};
|
||||
|
||||
}
|
||||
Q_DECLARE_METATYPE(nymeaserver::DeviceClass)
|
||||
Q_DECLARE_METATYPE(nymeaserver::Device::DeviceError)
|
||||
|
||||
#endif // DEVICEHANDLER_H
|
||||
@ -1,100 +0,0 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2020, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
* This project including source code and documentation is protected by
|
||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
||||
* reproduction, publication, editing and translation, are reserved. The use of
|
||||
* this project is subject to the terms of a license agreement to be concluded
|
||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
||||
* under https://nymea.io/license
|
||||
*
|
||||
* GNU General Public License Usage
|
||||
* Alternatively, this project may be redistributed and/or modified under the
|
||||
* terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, GNU version 3. This project 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 General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For any further details and any questions please contact us under
|
||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
||||
* https://nymea.io/license/faq
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#include "eventhandler.h"
|
||||
#include "nymeacore.h"
|
||||
#include "loggingcategories.h"
|
||||
#include "devicehandler.h"
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
/*! Constructs a new \l EventHandler with the given \a parent. */
|
||||
EventHandler::EventHandler(QObject *parent) :
|
||||
JsonHandler(parent)
|
||||
{
|
||||
registerEnum<Types::InputType>();
|
||||
registerEnum<Types::Unit>();
|
||||
// Objects
|
||||
registerObject<Param, ParamList>();
|
||||
registerObject<Event>();
|
||||
registerObject<ParamType, ParamTypes>();
|
||||
registerObject<EventType>();
|
||||
|
||||
// Methods
|
||||
QString description; QVariantMap params; QVariantMap returns;
|
||||
description = "Get the EventType for the given eventTypeId.";
|
||||
params.insert("eventTypeId", enumValueName(Uuid));
|
||||
returns.insert("deviceError", enumRef<Device::DeviceError>());
|
||||
returns.insert("o:eventType", objectRef<EventType>());
|
||||
registerMethod("GetEventType", description, params, returns, "Please use the Devices namespace instead.");
|
||||
|
||||
// Notifications
|
||||
params.clear(); returns.clear();
|
||||
description = "Emitted whenever an Event is triggered.";
|
||||
params.insert("event", objectRef<Event>());
|
||||
registerNotification("EventTriggered", description, params, "Please use Devices.EventTriggered instead.");
|
||||
connect(NymeaCore::instance(), &NymeaCore::eventTriggered, this, &EventHandler::eventTriggered);
|
||||
}
|
||||
|
||||
/*! Returns the name of the \l{EventHandler}. In this case \b Events.*/
|
||||
QString EventHandler::name() const
|
||||
{
|
||||
return "Events";
|
||||
}
|
||||
|
||||
void EventHandler::eventTriggered(const Event &event)
|
||||
{
|
||||
QVariantMap params;
|
||||
params.insert("event", pack(event));
|
||||
emit EventTriggered(params);
|
||||
}
|
||||
|
||||
JsonReply* EventHandler::GetEventType(const QVariantMap ¶ms, const JsonContext &context) const
|
||||
{
|
||||
qCDebug(dcJsonRpc) << "asked for event type" << params;
|
||||
EventTypeId eventTypeId(params.value("eventTypeId").toString());
|
||||
foreach (const ThingClass &deviceClass, NymeaCore::instance()->thingManager()->supportedThings()) {
|
||||
foreach (const EventType &eventType, deviceClass.eventTypes()) {
|
||||
if (eventType.id() == eventTypeId) {
|
||||
EventType translatedEventType = eventType;
|
||||
translatedEventType.setDisplayName(NymeaCore::instance()->thingManager()->translate(deviceClass.pluginId(), eventType.displayName(), context.locale()));
|
||||
QVariantMap data;
|
||||
data.insert("deviceError", enumValueName<Thing::ThingError>(Thing::ThingErrorNoError).replace("ThingError", "DeviceError"));
|
||||
data.insert("eventType", pack(translatedEventType));
|
||||
return createReply(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
QVariantMap data;
|
||||
data.insert("deviceError", enumValueName<Thing::ThingError>(Thing::ThingErrorEventTypeNotFound).replace("ThingError", "DeviceError"));
|
||||
return createReply(data);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,58 +0,0 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2020, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
* This project including source code and documentation is protected by
|
||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
||||
* reproduction, publication, editing and translation, are reserved. The use of
|
||||
* this project is subject to the terms of a license agreement to be concluded
|
||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
||||
* under https://nymea.io/license
|
||||
*
|
||||
* GNU General Public License Usage
|
||||
* Alternatively, this project may be redistributed and/or modified under the
|
||||
* terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, GNU version 3. This project 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 General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For any further details and any questions please contact us under
|
||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
||||
* https://nymea.io/license/faq
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#ifndef EVENTHANDLER_H
|
||||
#define EVENTHANDLER_H
|
||||
|
||||
#include "jsonrpc/jsonhandler.h"
|
||||
|
||||
#include "types/event.h"
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
class EventHandler : public JsonHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit EventHandler(QObject *parent = nullptr);
|
||||
QString name() const override;
|
||||
|
||||
Q_INVOKABLE JsonReply *GetEventType(const QVariantMap ¶ms, const JsonContext &context) const;
|
||||
|
||||
signals:
|
||||
void EventTriggered(const QVariantMap ¶ms);
|
||||
|
||||
private slots:
|
||||
void eventTriggered(const Event &event);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // EVENTHANDLER_H
|
||||
@ -60,14 +60,10 @@
|
||||
#include "version.h"
|
||||
#include "cloud/cloudmanager.h"
|
||||
|
||||
#include "devicehandler.h"
|
||||
#include "integrationshandler.h"
|
||||
#include "actionhandler.h"
|
||||
#include "ruleshandler.h"
|
||||
#include "scriptshandler.h"
|
||||
#include "eventhandler.h"
|
||||
#include "logginghandler.h"
|
||||
#include "statehandler.h"
|
||||
#include "configurationhandler.h"
|
||||
#include "networkmanagerhandler.h"
|
||||
#include "tagshandler.h"
|
||||
@ -587,12 +583,8 @@ void JsonRPCServerImplementation::setup()
|
||||
{
|
||||
registerHandler(this);
|
||||
registerHandler(new IntegrationsHandler(NymeaCore::instance()->thingManager(), this));
|
||||
registerHandler(new DeviceHandler(this));
|
||||
registerHandler(new ActionHandler(this));
|
||||
registerHandler(new RulesHandler(this));
|
||||
registerHandler(new EventHandler(this));
|
||||
registerHandler(new LoggingHandler(this));
|
||||
registerHandler(new StateHandler(this));
|
||||
registerHandler(new ConfigurationHandler(this));
|
||||
registerHandler(new NetworkManagerHandler(NymeaCore::instance()->networkManager(), this));
|
||||
registerHandler(new TagsHandler(this));
|
||||
|
||||
@ -76,7 +76,6 @@ LoggingHandler::LoggingHandler(QObject *parent) :
|
||||
params.insert("o:eventTypes", QVariantList() << enumRef<Logging::LoggingEventType>());
|
||||
params.insert("o:typeIds", QVariantList() << enumValueName(Uuid));
|
||||
params.insert("o:thingIds", QVariantList() << enumValueName(Uuid));
|
||||
params.insert("d:o:deviceIds", QVariantList() << enumValueName(Uuid));
|
||||
params.insert("o:values", QVariantList() << enumValueName(Variant));
|
||||
params.insert("o:limit", enumValueName(Int));
|
||||
params.insert("o:offset", enumValueName(Int));
|
||||
@ -189,7 +188,6 @@ QVariantMap LoggingHandler::packLogEntry(const LogEntry &logEntry)
|
||||
logEntryMap.insert("typeId", logEntry.typeId());
|
||||
}
|
||||
logEntryMap.insert("thingId", logEntry.thingId());
|
||||
logEntryMap.insert("deviceId", logEntry.thingId()); // DEPRECATED
|
||||
logEntryMap.insert("value", LogValueTool::convertVariantToString(logEntry.value()));
|
||||
break;
|
||||
case Logging::LoggingSourceSystem:
|
||||
@ -251,13 +249,6 @@ LogFilter LoggingHandler::unpackLogFilter(const QVariantMap &logFilterMap)
|
||||
filter.addThingId(ThingId(thingId.toString()));
|
||||
}
|
||||
}
|
||||
// DEPRECATED
|
||||
if (logFilterMap.contains("deviceIds")) {
|
||||
QVariantList deviceIds = logFilterMap.value("deviceIds").toList();
|
||||
foreach (const QVariant &deviceId, deviceIds) {
|
||||
filter.addThingId(ThingId(deviceId.toString()));
|
||||
}
|
||||
}
|
||||
if (logFilterMap.contains("values")) {
|
||||
QVariantList values = logFilterMap.value("values").toList();
|
||||
foreach (const QVariant &value, values) {
|
||||
|
||||
@ -166,8 +166,7 @@ RulesHandler::RulesHandler(QObject *parent) :
|
||||
|
||||
params.clear(); returns.clear();
|
||||
description = "Find a list of rules containing any of the given parameters.";
|
||||
params.insert("o:thingId", enumValueName(Uuid)); // TODO: remove "o:" from thingId once we drop deviceId support
|
||||
params.insert("d:o:deviceId", enumValueName(Uuid));
|
||||
params.insert("thingId", enumValueName(Uuid));
|
||||
returns.insert("ruleIds", QVariantList() << enumValueName(Uuid));
|
||||
registerMethod("FindRules", description, params, returns);
|
||||
|
||||
@ -301,10 +300,7 @@ JsonReply* RulesHandler::RemoveRule(const QVariantMap ¶ms)
|
||||
|
||||
JsonReply *RulesHandler::FindRules(const QVariantMap ¶ms)
|
||||
{
|
||||
ThingId thingId = ThingId(params.value("deviceId").toString()); // DEPRECATED
|
||||
if (params.contains("thingId")) {
|
||||
thingId = ThingId(params.value("thingId").toString());
|
||||
}
|
||||
ThingId thingId = ThingId(params.value("thingId").toString());
|
||||
QList<RuleId> rules = NymeaCore::instance()->ruleEngine()->findRules(thingId);
|
||||
|
||||
QVariantList rulesList;
|
||||
|
||||
@ -1,97 +0,0 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2020, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
* This project including source code and documentation is protected by
|
||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
||||
* reproduction, publication, editing and translation, are reserved. The use of
|
||||
* this project is subject to the terms of a license agreement to be concluded
|
||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
||||
* under https://nymea.io/license
|
||||
*
|
||||
* GNU General Public License Usage
|
||||
* Alternatively, this project may be redistributed and/or modified under the
|
||||
* terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, GNU version 3. This project 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 General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For any further details and any questions please contact us under
|
||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
||||
* https://nymea.io/license/faq
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*!
|
||||
\class nymeaserver::StateHandler
|
||||
\brief This subclass of \l{JsonHandler} processes the JSON requests for the \tt States namespace of the JSON-RPC API.
|
||||
|
||||
\ingroup json
|
||||
\inmodule core
|
||||
|
||||
This \l{JsonHandler} will be created in the \l{JsonRPCServer} and used to handle JSON-RPC requests
|
||||
for the \tt {States} namespace of the API.
|
||||
|
||||
\sa State, JsonHandler, JsonRPCServer
|
||||
*/
|
||||
|
||||
#include "statehandler.h"
|
||||
#include "nymeacore.h"
|
||||
#include "loggingcategories.h"
|
||||
|
||||
#include "devicehandler.h"
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
/*! Constructs a new \l{StateHandler} with the given \a parent. */
|
||||
StateHandler::StateHandler(QObject *parent) :
|
||||
JsonHandler(parent)
|
||||
{
|
||||
registerEnum<Types::Unit>();
|
||||
registerEnum<Types::IOType>();
|
||||
registerObject<State>();
|
||||
registerObject<StateType>();
|
||||
|
||||
// Methods
|
||||
QString description; QVariantMap params; QVariantMap returns;
|
||||
description = "Get the StateType for the given stateTypeId.";
|
||||
params.insert("stateTypeId", enumValueName(Uuid));
|
||||
returns.insert("deviceError", enumRef<Device::DeviceError>());
|
||||
returns.insert("o:stateType", objectRef<StateType>());
|
||||
registerMethod("GetStateType", description, params, returns, "Please use the Integrations namespace instead.");
|
||||
}
|
||||
|
||||
/*! Returns the name of the \l{StateHandler}. In this case \b States.*/
|
||||
QString StateHandler::name() const
|
||||
{
|
||||
return "States";
|
||||
}
|
||||
|
||||
JsonReply* StateHandler::GetStateType(const QVariantMap ¶ms, const JsonContext &context) const
|
||||
{
|
||||
qCDebug(dcJsonRpc) << "asked for state type" << params;
|
||||
StateTypeId stateTypeId(params.value("stateTypeId").toString());
|
||||
foreach (const ThingClass &deviceClass, NymeaCore::instance()->thingManager()->supportedThings()) {
|
||||
foreach (const StateType &stateType, deviceClass.stateTypes()) {
|
||||
if (stateType.id() == stateTypeId) {
|
||||
QVariantMap data;
|
||||
data.insert("deviceError", enumValueName<Thing::ThingError>(Thing::ThingErrorNoError).replace("ThingError", "DeviceError"));
|
||||
StateType translatedStateType = stateType;
|
||||
translatedStateType.setDisplayName(NymeaCore::instance()->thingManager()->translate(deviceClass.pluginId(), stateType.displayName(), context.locale()));
|
||||
data.insert("stateType", pack(translatedStateType));
|
||||
return createReply(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
QVariantMap data;
|
||||
data.insert("deviceError", enumValueName<Thing::ThingError>(Thing::ThingErrorStateTypeNotFound).replace("ThingError", "DeviceError"));
|
||||
return createReply(data);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,51 +0,0 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2020, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
* This project including source code and documentation is protected by
|
||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
||||
* reproduction, publication, editing and translation, are reserved. The use of
|
||||
* this project is subject to the terms of a license agreement to be concluded
|
||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
||||
* under https://nymea.io/license
|
||||
*
|
||||
* GNU General Public License Usage
|
||||
* Alternatively, this project may be redistributed and/or modified under the
|
||||
* terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, GNU version 3. This project 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 General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For any further details and any questions please contact us under
|
||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
||||
* https://nymea.io/license/faq
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#ifndef STATEHANDLER_H
|
||||
#define STATEHANDLER_H
|
||||
|
||||
#include "jsonrpc/jsonhandler.h"
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
class StateHandler : public JsonHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit StateHandler(QObject *parent = nullptr);
|
||||
QString name() const override;
|
||||
|
||||
Q_INVOKABLE JsonReply *GetStateType(const QVariantMap ¶ms, const JsonContext &context) const;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // EVENTHANDLER_H
|
||||
@ -49,7 +49,6 @@ TagsHandler::TagsHandler(QObject *parent) : JsonHandler(parent)
|
||||
"Tags can be filtered by a thingID, a ruleId, an appId, a tagId or a combination of any (however, "
|
||||
"combining thingId and ruleId will return an empty result set).";
|
||||
params.insert("o:thingId", enumValueName(Uuid));
|
||||
params.insert("d:o:deviceId", enumValueName(Uuid));
|
||||
params.insert("o:ruleId", enumValueName(Uuid));
|
||||
params.insert("o:appId", enumValueName(String));
|
||||
params.insert("o:tagId", enumValueName(String));
|
||||
@ -108,10 +107,6 @@ JsonReply *TagsHandler::GetTags(const QVariantMap ¶ms) const
|
||||
if (params.contains("thingId") && params.value("thingId").toUuid() != tag.thingId()) {
|
||||
continue;
|
||||
}
|
||||
if (params.contains("deviceId") && params.value("deviceId").toUuid() != tag.thingId()) {
|
||||
// nymea < 0.19
|
||||
continue;
|
||||
}
|
||||
if (params.contains("ruleId") && params.value("ruleId").toUuid() != tag.ruleId()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -103,11 +103,7 @@ HEADERS += nymeacore.h \
|
||||
jsonrpc/jsonrpcserverimplementation.h \
|
||||
jsonrpc/jsonvalidator.h \
|
||||
jsonrpc/integrationshandler.h \
|
||||
jsonrpc/devicehandler.h \
|
||||
jsonrpc/ruleshandler.h \
|
||||
jsonrpc/actionhandler.h \
|
||||
jsonrpc/eventhandler.h \
|
||||
jsonrpc/statehandler.h \
|
||||
jsonrpc/logginghandler.h \
|
||||
jsonrpc/configurationhandler.h \
|
||||
jsonrpc/networkmanagerhandler.h \
|
||||
@ -197,11 +193,7 @@ SOURCES += nymeacore.cpp \
|
||||
jsonrpc/jsonrpcserverimplementation.cpp \
|
||||
jsonrpc/jsonvalidator.cpp \
|
||||
jsonrpc/integrationshandler.cpp \
|
||||
jsonrpc/devicehandler.cpp \
|
||||
jsonrpc/ruleshandler.cpp \
|
||||
jsonrpc/actionhandler.cpp \
|
||||
jsonrpc/eventhandler.cpp \
|
||||
jsonrpc/statehandler.cpp \
|
||||
jsonrpc/logginghandler.cpp \
|
||||
jsonrpc/configurationhandler.cpp \
|
||||
jsonrpc/networkmanagerhandler.cpp \
|
||||
|
||||
@ -48,7 +48,6 @@ class LogEntry
|
||||
Q_PROPERTY(Logging::LoggingSource source READ source)
|
||||
Q_PROPERTY(QUuid typeId READ typeId USER true)
|
||||
Q_PROPERTY(QUuid thingId READ thingId USER true)
|
||||
Q_PROPERTY(QUuid deviceId READ thingId USER true REVISION 1)
|
||||
Q_PROPERTY(QVariant value READ value USER true)
|
||||
Q_PROPERTY(bool active READ active USER true)
|
||||
Q_PROPERTY(Logging::LoggingEventType eventType READ eventType USER true)
|
||||
|
||||
@ -40,7 +40,6 @@ class LIBNYMEA_EXPORT RuleAction
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(QUuid thingId READ thingId WRITE setThingId USER true)
|
||||
Q_PROPERTY(QUuid deviceId READ thingId WRITE setThingId USER true REVISION 1)
|
||||
Q_PROPERTY(QUuid actionTypeId READ actionTypeId WRITE setActionTypeId USER true)
|
||||
Q_PROPERTY(QString interface READ interface WRITE setInterface USER true)
|
||||
Q_PROPERTY(QString interfaceAction READ interfaceAction WRITE setInterfaceAction USER true)
|
||||
|
||||
@ -48,7 +48,6 @@ class LIBNYMEA_EXPORT RuleActionParam
|
||||
Q_PROPERTY(QUuid eventTypeId READ eventTypeId WRITE setEventTypeId USER true)
|
||||
Q_PROPERTY(QUuid eventParamTypeId READ eventParamTypeId WRITE setEventParamTypeId USER true)
|
||||
Q_PROPERTY(QUuid stateThingId READ stateThingId WRITE setStateThingId USER true)
|
||||
Q_PROPERTY(QUuid stateDeviceId READ stateThingId WRITE setStateThingId USER true REVISION 1)
|
||||
Q_PROPERTY(QUuid stateTypeId READ stateTypeId WRITE setStateTypeId USER true)
|
||||
|
||||
public:
|
||||
|
||||
@ -57,12 +57,9 @@ QtMessageHandler ScriptEngine::s_upstreamMessageHandler;
|
||||
QLoggingCategory::CategoryFilter ScriptEngine::s_oldCategoryFilter = nullptr;
|
||||
QMutex ScriptEngine::s_loggerMutex;
|
||||
|
||||
ScriptEngine::ScriptEngine(ThingManager *deviceManager, QObject *parent) : QObject(parent),
|
||||
m_deviceManager(deviceManager)
|
||||
ScriptEngine::ScriptEngine(ThingManager *thingManager, QObject *parent) : QObject(parent),
|
||||
m_thingManager(thingManager)
|
||||
{
|
||||
qmlRegisterType<ScriptEvent>("nymea", 1, 0, "DeviceEvent");
|
||||
qmlRegisterType<ScriptAction>("nymea", 1, 0, "DeviceAction");
|
||||
qmlRegisterType<ScriptState>("nymea", 1, 0, "DeviceState");
|
||||
qmlRegisterType<ScriptEvent>("nymea", 1, 0, "ThingEvent");
|
||||
qmlRegisterType<ScriptAction>("nymea", 1, 0, "ThingAction");
|
||||
qmlRegisterType<ScriptState>("nymea", 1, 0, "ThingState");
|
||||
@ -71,7 +68,7 @@ ScriptEngine::ScriptEngine(ThingManager *deviceManager, QObject *parent) : QObje
|
||||
qmlRegisterType<ScriptAlarm>("nymea", 1, 0, "Alarm");
|
||||
|
||||
m_engine = new QQmlEngine(this);
|
||||
m_engine->setProperty("thingManager", reinterpret_cast<quint64>(m_deviceManager));
|
||||
m_engine->setProperty("thingManager", reinterpret_cast<quint64>(m_thingManager));
|
||||
|
||||
// Don't automatically print script warnings (that is, runtime errors, *not* console.warn() messages)
|
||||
// to stdout as they'd end up on the "default" logging category.
|
||||
|
||||
@ -75,7 +75,7 @@ public:
|
||||
QByteArray content;
|
||||
};
|
||||
|
||||
explicit ScriptEngine(ThingManager *deviceManager, QObject *parent = nullptr);
|
||||
explicit ScriptEngine(ThingManager *thingManager, QObject *parent = nullptr);
|
||||
~ScriptEngine();
|
||||
|
||||
Scripts scripts();
|
||||
@ -102,7 +102,7 @@ private:
|
||||
|
||||
void onScriptMessage(QtMsgType type, const QMessageLogContext &context, const QString &message);
|
||||
private:
|
||||
ThingManager *m_deviceManager = nullptr;
|
||||
ThingManager *m_thingManager = nullptr;
|
||||
QQmlEngine *m_engine = nullptr;
|
||||
|
||||
QHash<QUuid, Script*> m_scripts;
|
||||
|
||||
@ -44,7 +44,6 @@ class Tag
|
||||
Q_PROPERTY(QString appId READ appId WRITE setAppId)
|
||||
Q_PROPERTY(QString tagId READ tagId WRITE setTagId)
|
||||
Q_PROPERTY(QUuid thingId READ thingId WRITE setThingId USER true)
|
||||
Q_PROPERTY(QUuid deviceId READ thingId WRITE setThingId USER true REVISION 1)
|
||||
Q_PROPERTY(QUuid ruleId READ ruleId WRITE setRuleId USER true)
|
||||
Q_PROPERTY(QString value READ value WRITE setValue USER true)
|
||||
public:
|
||||
|
||||
@ -45,7 +45,6 @@ class LIBNYMEA_EXPORT ThingDescriptor
|
||||
Q_PROPERTY(QUuid thingId READ thingId USER true)
|
||||
Q_PROPERTY(QString title READ title)
|
||||
Q_PROPERTY(QString description READ description)
|
||||
Q_PROPERTY(ParamList deviceParams READ params REVISION 1) // Had been forgotten in the device->thing transition.
|
||||
Q_PROPERTY(ParamList params READ params) // added in 0.27
|
||||
|
||||
public:
|
||||
|
||||
@ -42,7 +42,6 @@ class LIBNYMEA_EXPORT Action
|
||||
Q_GADGET
|
||||
Q_PROPERTY(QUuid actionTypeId READ actionTypeId WRITE setActionTypeId)
|
||||
Q_PROPERTY(QUuid thingId READ thingId WRITE setThingId)
|
||||
Q_PROPERTY(QUuid deviceId READ thingId WRITE setThingId REVISION 1)
|
||||
Q_PROPERTY(ParamList params READ params WRITE setParams USER true)
|
||||
|
||||
public:
|
||||
|
||||
@ -44,7 +44,6 @@ class LIBNYMEA_EXPORT Event
|
||||
Q_GADGET
|
||||
Q_PROPERTY(QUuid eventTypeId READ eventTypeId)
|
||||
Q_PROPERTY(QUuid thingId READ thingId)
|
||||
Q_PROPERTY(QUuid deviceId READ thingId REVISION 1)
|
||||
Q_PROPERTY(ParamList params READ params)
|
||||
public:
|
||||
Event();
|
||||
|
||||
@ -44,7 +44,6 @@ class LIBNYMEA_EXPORT EventDescriptor
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(QUuid thingId READ thingId WRITE setThingId USER true)
|
||||
Q_PROPERTY(QUuid deviceId READ thingId WRITE setThingId USER true REVISION 1)
|
||||
Q_PROPERTY(QUuid eventTypeId READ eventTypeId WRITE setEventTypeId USER true)
|
||||
Q_PROPERTY(QString interface READ interface WRITE setInterface USER true)
|
||||
Q_PROPERTY(QString interfaceEvent READ interfaceEvent WRITE setInterfaceEvent USER true)
|
||||
|
||||
@ -46,7 +46,6 @@ class LIBNYMEA_EXPORT StateDescriptor
|
||||
Q_GADGET
|
||||
Q_PROPERTY(QUuid stateTypeId READ stateTypeId WRITE setStateTypeId USER true)
|
||||
Q_PROPERTY(QUuid thingId READ thingId WRITE setThingId USER true)
|
||||
Q_PROPERTY(QUuid deviceId READ thingId WRITE setThingId USER true REVISION 1)
|
||||
Q_PROPERTY(QString interface READ interface WRITE setInterface USER true)
|
||||
Q_PROPERTY(QString interfaceState READ interfaceState WRITE setInterfaceState USER true)
|
||||
Q_PROPERTY(QVariant value READ stateValue WRITE setStateValue USER true)
|
||||
|
||||
@ -4,8 +4,8 @@ include(nymea.pri)
|
||||
NYMEA_VERSION_STRING=$$system('dpkg-parsechangelog | sed -n -e "s/^Version: //p"')
|
||||
|
||||
# define protocol versions
|
||||
JSON_PROTOCOL_VERSION_MAJOR=5
|
||||
JSON_PROTOCOL_VERSION_MINOR=8
|
||||
JSON_PROTOCOL_VERSION_MAJOR=6
|
||||
JSON_PROTOCOL_VERSION_MINOR=0
|
||||
JSON_PROTOCOL_VERSION="$${JSON_PROTOCOL_VERSION_MAJOR}.$${JSON_PROTOCOL_VERSION_MINOR}"
|
||||
LIBNYMEA_API_VERSION_MAJOR=7
|
||||
LIBNYMEA_API_VERSION_MINOR=3
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
TARGET = testactions
|
||||
|
||||
include(../../../nymea.pri)
|
||||
include(../autotests.pri)
|
||||
|
||||
SOURCES += testactions.cpp
|
||||
@ -1,153 +0,0 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2020, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
* This project including source code and documentation is protected by
|
||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
||||
* reproduction, publication, editing and translation, are reserved. The use of
|
||||
* this project is subject to the terms of a license agreement to be concluded
|
||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
||||
* under https://nymea.io/license
|
||||
*
|
||||
* GNU General Public License Usage
|
||||
* Alternatively, this project may be redistributed and/or modified under the
|
||||
* terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, GNU version 3. This project 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 General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For any further details and any questions please contact us under
|
||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
||||
* https://nymea.io/license/faq
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#include "nymeatestbase.h"
|
||||
#include "integrations/thing.h"
|
||||
#include "jsonrpc/devicehandler.h"
|
||||
|
||||
using namespace nymeaserver;
|
||||
|
||||
class TestActions: public NymeaTestBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void executeAction_data();
|
||||
void executeAction();
|
||||
|
||||
void getActionType_data();
|
||||
void getActionType();
|
||||
|
||||
};
|
||||
|
||||
void TestActions::executeAction_data()
|
||||
{
|
||||
QTest::addColumn<ThingId>("deviceId");
|
||||
QTest::addColumn<ActionTypeId>("actionTypeId");
|
||||
QTest::addColumn<QVariantList>("actionParams");
|
||||
QTest::addColumn<Device::DeviceError>("error");
|
||||
|
||||
QVariantList params;
|
||||
QVariantMap param1;
|
||||
param1.insert("paramTypeId", mockWithParamsActionParam1ParamTypeId);
|
||||
param1.insert("value", 5);
|
||||
params.append(param1);
|
||||
QVariantMap param2;
|
||||
param2.insert("paramTypeId", mockWithParamsActionParam2ParamTypeId);
|
||||
param2.insert("value", true);
|
||||
params.append(param2);
|
||||
|
||||
QTest::newRow("valid action") << m_mockThingId << mockWithParamsActionTypeId << params << Device::DeviceErrorNoError;
|
||||
QTest::newRow("invalid deviceId") << ThingId::createThingId() << mockWithParamsActionTypeId << params << Device::DeviceErrorDeviceNotFound;
|
||||
QTest::newRow("invalid actionTypeId") << m_mockThingId << ActionTypeId::createActionTypeId() << params << Device::DeviceErrorActionTypeNotFound;
|
||||
QTest::newRow("missing params") << m_mockThingId << mockWithParamsActionTypeId << QVariantList() << Device::DeviceErrorMissingParameter;
|
||||
QTest::newRow("async action") << m_mockThingId << mockAsyncActionTypeId << QVariantList() << Device::DeviceErrorNoError;
|
||||
QTest::newRow("broken action") << m_mockThingId << mockFailingActionTypeId << QVariantList() << Device::DeviceErrorSetupFailed;
|
||||
QTest::newRow("async broken action") << m_mockThingId << mockAsyncFailingActionTypeId << QVariantList() << Device::DeviceErrorSetupFailed;
|
||||
}
|
||||
|
||||
void TestActions::executeAction()
|
||||
{
|
||||
QFETCH(ThingId, deviceId);
|
||||
QFETCH(ActionTypeId, actionTypeId);
|
||||
QFETCH(QVariantList, actionParams);
|
||||
QFETCH(Device::DeviceError, error);
|
||||
|
||||
QVariantMap params;
|
||||
params.insert("actionTypeId", actionTypeId);
|
||||
params.insert("deviceId", deviceId);
|
||||
params.insert("params", actionParams);
|
||||
QVariant response = injectAndWait("Actions.ExecuteAction", params);
|
||||
verifyError(response, "deviceError", enumValueName(error));
|
||||
|
||||
// Fetch action execution history from mock device
|
||||
QNetworkAccessManager nam;
|
||||
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
|
||||
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/actionhistory").arg(m_mockThing1Port)));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
reply->deleteLater();
|
||||
QByteArray data = reply->readAll();
|
||||
|
||||
if (error == Device::DeviceErrorNoError) {
|
||||
QVERIFY2(actionTypeId == ActionTypeId(data), QString("ActionTypeId mismatch. Got %1, Expected: %2")
|
||||
.arg(ActionTypeId(data).toString()).arg(actionTypeId.toString()).toLatin1().data());
|
||||
} else {
|
||||
QVERIFY2(data.length() == 0, QString("Data is %1, should be empty.").arg(QString(data)).toLatin1().data());
|
||||
}
|
||||
|
||||
// cleanup for the next run
|
||||
spy.clear();
|
||||
request.setUrl(QUrl(QString("http://localhost:%1/clearactionhistory").arg(m_mockThing1Port)));
|
||||
reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
reply->deleteLater();
|
||||
|
||||
spy.clear();
|
||||
request.setUrl(QUrl(QString("http://localhost:%1/actionhistory").arg(m_mockThing1Port)));
|
||||
reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
reply->deleteLater();
|
||||
data = reply->readAll();
|
||||
qDebug() << "cleared data:" << data;
|
||||
|
||||
}
|
||||
|
||||
void TestActions::getActionType_data()
|
||||
{
|
||||
QTest::addColumn<ActionTypeId>("actionTypeId");
|
||||
QTest::addColumn<Device::DeviceError>("error");
|
||||
|
||||
QTest::newRow("valid actiontypeid") << mockWithParamsActionTypeId << Device::DeviceErrorNoError;
|
||||
QTest::newRow("invalid actiontypeid") << ActionTypeId::createActionTypeId() << Device::DeviceErrorActionTypeNotFound;
|
||||
}
|
||||
|
||||
void TestActions::getActionType()
|
||||
{
|
||||
QFETCH(ActionTypeId, actionTypeId);
|
||||
QFETCH(Device::DeviceError, error);
|
||||
|
||||
QVariantMap params;
|
||||
params.insert("actionTypeId", actionTypeId.toString());
|
||||
QVariant response = injectAndWait("Actions.GetActionType", params);
|
||||
|
||||
verifyError(response, "deviceError", enumValueName(error));
|
||||
|
||||
if (error == Device::DeviceErrorNoError) {
|
||||
QVERIFY2(ActionTypeId(response.toMap().value("params").toMap().value("actionType").toMap().value("id").toString()) == actionTypeId, "Didn't get a reply for the same actionTypeId as requested.");
|
||||
}
|
||||
}
|
||||
|
||||
#include "testactions.moc"
|
||||
QTEST_MAIN(TestActions)
|
||||
@ -1,4 +1,4 @@
|
||||
5.8
|
||||
6.0
|
||||
{
|
||||
"enums": {
|
||||
"BasicType": [
|
||||
@ -47,41 +47,6 @@
|
||||
"CreateMethodAuto",
|
||||
"CreateMethodDiscovery"
|
||||
],
|
||||
"DeviceError": [
|
||||
"DeviceErrorNoError",
|
||||
"DeviceErrorPluginNotFound",
|
||||
"DeviceErrorVendorNotFound",
|
||||
"DeviceErrorDeviceNotFound",
|
||||
"DeviceErrorDeviceClassNotFound",
|
||||
"DeviceErrorActionTypeNotFound",
|
||||
"DeviceErrorStateTypeNotFound",
|
||||
"DeviceErrorEventTypeNotFound",
|
||||
"DeviceErrorDeviceDescriptorNotFound",
|
||||
"DeviceErrorMissingParameter",
|
||||
"DeviceErrorInvalidParameter",
|
||||
"DeviceErrorSetupFailed",
|
||||
"DeviceErrorDuplicateUuid",
|
||||
"DeviceErrorCreationMethodNotSupported",
|
||||
"DeviceErrorSetupMethodNotSupported",
|
||||
"DeviceErrorHardwareNotAvailable",
|
||||
"DeviceErrorHardwareFailure",
|
||||
"DeviceErrorAuthenticationFailure",
|
||||
"DeviceErrorDeviceInUse",
|
||||
"DeviceErrorDeviceInRule",
|
||||
"DeviceErrorDeviceIsChild",
|
||||
"DeviceErrorPairingTransactionIdNotFound",
|
||||
"DeviceErrorParameterNotWritable",
|
||||
"DeviceErrorItemNotFound",
|
||||
"DeviceErrorItemNotExecutable",
|
||||
"DeviceErrorUnsupportedFeature",
|
||||
"DeviceErrorTimeout"
|
||||
],
|
||||
"DeviceSetupStatus": [
|
||||
"DeviceSetupStatusNone",
|
||||
"DeviceSetupStatusInProgress",
|
||||
"DeviceSetupStatusComplete",
|
||||
"DeviceSetupStatusFailed"
|
||||
],
|
||||
"IOType": [
|
||||
"IOTypeNone",
|
||||
"IOTypeDigitalInput",
|
||||
@ -441,54 +406,6 @@
|
||||
]
|
||||
},
|
||||
"methods": {
|
||||
"Actions.ExecuteAction": {
|
||||
"deprecated": "Please use Integrations.ExecuteAction instead.",
|
||||
"description": "Execute a single action.",
|
||||
"params": {
|
||||
"actionTypeId": "Uuid",
|
||||
"deviceId": "Uuid",
|
||||
"o:params": "$ref:ParamList"
|
||||
},
|
||||
"returns": {
|
||||
"deviceError": "$ref:DeviceError",
|
||||
"o:displayMessage": "String"
|
||||
}
|
||||
},
|
||||
"Actions.ExecuteBrowserItem": {
|
||||
"deprecated": "Please use Integrations.ExecuteBrowserItem instead.",
|
||||
"description": "Execute the item identified by itemId on the given device.",
|
||||
"params": {
|
||||
"deviceId": "Uuid",
|
||||
"itemId": "String"
|
||||
},
|
||||
"returns": {
|
||||
"deviceError": "$ref:DeviceError"
|
||||
}
|
||||
},
|
||||
"Actions.ExecuteBrowserItemAction": {
|
||||
"deprecated": "Please use Integrations.ExecuteBrowserItem instead.",
|
||||
"description": "Execute the action for the browser item identified by actionTypeId and the itemId on the given device.",
|
||||
"params": {
|
||||
"actionTypeId": "Uuid",
|
||||
"deviceId": "Uuid",
|
||||
"itemId": "String",
|
||||
"o:params": "$ref:ParamList"
|
||||
},
|
||||
"returns": {
|
||||
"deviceError": "$ref:DeviceError"
|
||||
}
|
||||
},
|
||||
"Actions.GetActionType": {
|
||||
"deprecated": "Please use the Integrations namespace instead.",
|
||||
"description": "Get the ActionType for the given ActionTypeId.",
|
||||
"params": {
|
||||
"actionTypeId": "Uuid"
|
||||
},
|
||||
"returns": {
|
||||
"deviceError": "$ref:DeviceError",
|
||||
"o:actionType": "$ref:ActionType"
|
||||
}
|
||||
},
|
||||
"AppData.Load": {
|
||||
"description": "Retrieve an app data storage value that has previously been set with Store(). If no value had been set for this appId/key combination before, an empty value will be returned.",
|
||||
"params": {
|
||||
@ -717,289 +634,6 @@
|
||||
"configurationError": "$ref:ConfigurationError"
|
||||
}
|
||||
},
|
||||
"Devices.AddConfiguredDevice": {
|
||||
"description": "Add a configured device with a setupMethod of SetupMethodJustAdd. For devices with a setupMethod different than SetupMethodJustAdd, use PairDevice. Devices with CreateMethodJustAdd require all parameters to be supplied here. Devices with CreateMethodDiscovery require the use of a deviceDescriptorId. For discovered devices params are not required and will be taken from the DeviceDescriptor, however, they may be overridden by supplying deviceParams.",
|
||||
"params": {
|
||||
"deviceClassId": "Uuid",
|
||||
"name": "String",
|
||||
"o:deviceDescriptorId": "Uuid",
|
||||
"o:deviceParams": "$ref:ParamList"
|
||||
},
|
||||
"returns": {
|
||||
"deviceError": "$ref:DeviceError",
|
||||
"o:deviceId": "Uuid",
|
||||
"o:displayMessage": "String"
|
||||
}
|
||||
},
|
||||
"Devices.BrowseDevice": {
|
||||
"description": "Browse a device. If a DeviceClass indicates a device is browsable, this method will return the BrowserItems. If no parameter besides the deviceId is used, the root node of this device will be returned. Any returned item which is browsable can be passed as node. Results will be children of the given node.\nIn case of an error during browsing, the error will be indicated and the displayMessage may contain additional information for the user. The displayMessage will be translated. A client UI showing this message to the user should be prepared for empty, but also longer strings.",
|
||||
"params": {
|
||||
"deviceId": "Uuid",
|
||||
"o:itemId": "String"
|
||||
},
|
||||
"returns": {
|
||||
"deviceError": "$ref:DeviceError",
|
||||
"items": [
|
||||
"$ref:BrowserItem"
|
||||
],
|
||||
"o:displayMessage": "String"
|
||||
}
|
||||
},
|
||||
"Devices.ConfirmPairing": {
|
||||
"description": "Confirm an ongoing pairing. For SetupMethodUserAndPassword, provide the username in the \"username\" field and the password in the \"secret\" field. For SetupMethodEnterPin and provide the PIN in the \"secret\" field. In case of SetupMethodOAuth, the previously opened web view will eventually be redirected to http://128.0.0.1:8888 and the OAuth code as query parameters to this url. Provide the entire unmodified URL in the secret field.",
|
||||
"params": {
|
||||
"o:secret": "String",
|
||||
"o:username": "String",
|
||||
"pairingTransactionId": "Uuid"
|
||||
},
|
||||
"returns": {
|
||||
"deviceError": "$ref:DeviceError",
|
||||
"o:deviceId": "Uuid",
|
||||
"o:displayMessage": "String"
|
||||
}
|
||||
},
|
||||
"Devices.EditDevice": {
|
||||
"description": "Edit the name of a device. This method does not change the configuration of the device.",
|
||||
"params": {
|
||||
"deviceId": "Uuid",
|
||||
"name": "String"
|
||||
},
|
||||
"returns": {
|
||||
"deviceError": "$ref:DeviceError"
|
||||
}
|
||||
},
|
||||
"Devices.ExecuteAction": {
|
||||
"description": "Execute a single action.",
|
||||
"params": {
|
||||
"actionTypeId": "Uuid",
|
||||
"deviceId": "Uuid",
|
||||
"o:params": "$ref:ParamList"
|
||||
},
|
||||
"returns": {
|
||||
"deviceError": "$ref:DeviceError",
|
||||
"o:displayMessage": "String"
|
||||
}
|
||||
},
|
||||
"Devices.ExecuteBrowserItem": {
|
||||
"description": "Execute the item identified by itemId on the given device.\nIn case of an error during execution, the error will be indicated and the displayMessage may contain additional information for the user. The displayMessage will be translated. A client UI showing this message to the user should be prepared for empty, but also longer strings.",
|
||||
"params": {
|
||||
"deviceId": "Uuid",
|
||||
"itemId": "String"
|
||||
},
|
||||
"returns": {
|
||||
"deviceError": "$ref:DeviceError",
|
||||
"o:displayMessage": "String"
|
||||
}
|
||||
},
|
||||
"Devices.ExecuteBrowserItemAction": {
|
||||
"description": "Execute the action for the browser item identified by actionTypeId and the itemId on the given device.\nIn case of an error during execution, the error will be indicated and the displayMessage may contain additional information for the user. The displayMessage will be translated. A client UI showing this message to the user should be prepared for empty, but also longer strings.",
|
||||
"params": {
|
||||
"actionTypeId": "Uuid",
|
||||
"deviceId": "Uuid",
|
||||
"itemId": "String",
|
||||
"o:params": "$ref:ParamList"
|
||||
},
|
||||
"returns": {
|
||||
"deviceError": "$ref:DeviceError",
|
||||
"o:displayMessage": "String"
|
||||
}
|
||||
},
|
||||
"Devices.GetActionTypes": {
|
||||
"description": "Get action types for a specified deviceClassId.",
|
||||
"params": {
|
||||
"deviceClassId": "Uuid"
|
||||
},
|
||||
"returns": {
|
||||
"actionTypes": "$ref:ActionTypes"
|
||||
}
|
||||
},
|
||||
"Devices.GetBrowserItem": {
|
||||
"description": "Get a single item from the browser. This won't give any more info on an item than a regular browseDevice call, but it allows to fetch details of an item if only the ID is known.\nIn case of an error during browsing, the error will be indicated and the displayMessage may contain additional information for the user. The displayMessage will be translated. A client UI showing this message to the user should be prepared for empty, but also longer strings.",
|
||||
"params": {
|
||||
"deviceId": "Uuid",
|
||||
"o:itemId": "String"
|
||||
},
|
||||
"returns": {
|
||||
"deviceError": "$ref:DeviceError",
|
||||
"o:displayMessage": "String",
|
||||
"o:item": "$ref:BrowserItem"
|
||||
}
|
||||
},
|
||||
"Devices.GetConfiguredDevices": {
|
||||
"description": "Returns a list of configured devices, optionally filtered by deviceId.",
|
||||
"params": {
|
||||
"o:deviceId": "Uuid"
|
||||
},
|
||||
"returns": {
|
||||
"devices": "$ref:Devices"
|
||||
}
|
||||
},
|
||||
"Devices.GetDiscoveredDevices": {
|
||||
"description": "Performs a device discovery and returns the results. This function may take a while to return. Note that this method will include all the found devices, that is, including devices that already have been added. Those devices will have deviceId set to the device id of the already added device. Such results may be used to reconfigure existing devices and might be filtered in cases where only unknown devices are of interest.",
|
||||
"params": {
|
||||
"deviceClassId": "Uuid",
|
||||
"o:discoveryParams": "$ref:ParamList"
|
||||
},
|
||||
"returns": {
|
||||
"deviceError": "$ref:DeviceError",
|
||||
"o:deviceDescriptors": "$ref:DeviceDescriptors",
|
||||
"o:displayMessage": "String"
|
||||
}
|
||||
},
|
||||
"Devices.GetEventTypes": {
|
||||
"description": "Get event types for a specified deviceClassId.",
|
||||
"params": {
|
||||
"deviceClassId": "Uuid"
|
||||
},
|
||||
"returns": {
|
||||
"eventTypes": "$ref:EventTypes"
|
||||
}
|
||||
},
|
||||
"Devices.GetPluginConfiguration": {
|
||||
"description": "Get a plugin's params.",
|
||||
"params": {
|
||||
"pluginId": "Uuid"
|
||||
},
|
||||
"returns": {
|
||||
"deviceError": "$ref:DeviceError",
|
||||
"o:configuration": "$ref:ParamList"
|
||||
}
|
||||
},
|
||||
"Devices.GetPlugins": {
|
||||
"description": "Returns a list of loaded plugins.",
|
||||
"params": {
|
||||
},
|
||||
"returns": {
|
||||
"plugins": "$ref:DevicePlugins"
|
||||
}
|
||||
},
|
||||
"Devices.GetStateTypes": {
|
||||
"description": "Get state types for a specified deviceClassId.",
|
||||
"params": {
|
||||
"deviceClassId": "Uuid"
|
||||
},
|
||||
"returns": {
|
||||
"stateTypes": "$ref:StateTypes"
|
||||
}
|
||||
},
|
||||
"Devices.GetStateValue": {
|
||||
"description": "Get the value of the given device and the given stateType",
|
||||
"params": {
|
||||
"deviceId": "Uuid",
|
||||
"stateTypeId": "Uuid"
|
||||
},
|
||||
"returns": {
|
||||
"deviceError": "$ref:DeviceError",
|
||||
"o:value": "Variant"
|
||||
}
|
||||
},
|
||||
"Devices.GetStateValues": {
|
||||
"description": "Get all the state values of the given device.",
|
||||
"params": {
|
||||
"deviceId": "Uuid"
|
||||
},
|
||||
"returns": {
|
||||
"deviceError": "$ref:DeviceError",
|
||||
"o:values": "$ref:States"
|
||||
}
|
||||
},
|
||||
"Devices.GetSupportedDevices": {
|
||||
"description": "Returns a list of supported Device classes, optionally filtered by vendorId.",
|
||||
"params": {
|
||||
"o:vendorId": "Uuid"
|
||||
},
|
||||
"returns": {
|
||||
"deviceClasses": "$ref:DeviceClasses"
|
||||
}
|
||||
},
|
||||
"Devices.GetSupportedVendors": {
|
||||
"description": "Returns a list of supported Vendors.",
|
||||
"params": {
|
||||
},
|
||||
"returns": {
|
||||
"vendors": "$ref:Vendors"
|
||||
}
|
||||
},
|
||||
"Devices.PairDevice": {
|
||||
"description": "Pair a device. Use this to set up or reconfigure devices for DeviceClasses with a setupMethod different than SetupMethodJustAdd. Depending on the CreateMethod and whether a new devices is set up or an existing one is reconfigured, different parameters are required:\nCreateMethodJustAdd takes the deviceClassId and the parameters to be used with that device. If an existing device should be reconfigured, the deviceId of said device should be given additionally.\nCreateMethodDiscovery requires the use of a deviceDescriptorId, previously obtained with DiscoverDevices. Optionally, parameters can be overridden with the give deviceParams. DeviceDescriptors containing a deviceId will reconfigure that device, descriptors without deviceId will add a new one.\nIf success is true, the return values will contain a pairingTransactionId, a displayMessage and the setupMethod. Depending on the setupMethod, the application should present the use an appropriate login mask, that is, For SetupMethodDisplayPin the user should enter a pin that is displayed on the device, for SetupMethodEnterPin the application should present the given PIN so the user can enter it on the device. For SetupMethodPushButton, the displayMessage shall be presented to the user as informational hints to press a button on the device. For SetupMethodUserAndPassword a login mask for a user and password login should be presented to the user. In case of SetupMethodOAuth, an OAuth URL will be returned which shall be opened in a web view to allow the user logging in.\nOnce the login procedure has completed, the application shall proceed with ConfirmPairing, providing the results of the pairing procedure.",
|
||||
"params": {
|
||||
"o:deviceClassId": "Uuid",
|
||||
"o:deviceDescriptorId": "Uuid",
|
||||
"o:deviceId": "Uuid",
|
||||
"o:deviceParams": "$ref:ParamList",
|
||||
"o:name": "String"
|
||||
},
|
||||
"returns": {
|
||||
"deviceError": "$ref:DeviceError",
|
||||
"o:displayMessage": "String",
|
||||
"o:oAuthUrl": "String",
|
||||
"o:pairingTransactionId": "Uuid",
|
||||
"o:pin": "String",
|
||||
"o:setupMethod": "$ref:SetupMethod"
|
||||
}
|
||||
},
|
||||
"Devices.ReconfigureDevice": {
|
||||
"description": "Reconfigure a device. This comes down to removing and recreating a device with new parameters but keeping its device id the same (and with that keeping rules, tags etc). For devices with create method CreateMethodDiscovery, a discovery (GetDiscoveredDevices) shall be performed first and this method is to be called with a deviceDescriptorId of the re-discovered device instead of the deviceId directly. Device parameters will be taken from the discovery, but can be overridden individually here by providing them in the deviceParams parameter. Only writable parameters can be changed.",
|
||||
"params": {
|
||||
"o:deviceDescriptorId": "Uuid",
|
||||
"o:deviceId": "Uuid",
|
||||
"o:deviceParams": "$ref:ParamList"
|
||||
},
|
||||
"returns": {
|
||||
"deviceError": "$ref:DeviceError",
|
||||
"o:displayMessage": "String"
|
||||
}
|
||||
},
|
||||
"Devices.RemoveConfiguredDevice": {
|
||||
"description": "Remove a device from the system.",
|
||||
"params": {
|
||||
"deviceId": "Uuid",
|
||||
"o:removePolicy": "$ref:RemovePolicy",
|
||||
"o:removePolicyList": [
|
||||
{
|
||||
"policy": "$ref:RemovePolicy",
|
||||
"ruleId": "Uuid"
|
||||
}
|
||||
]
|
||||
},
|
||||
"returns": {
|
||||
"deviceError": "$ref:DeviceError",
|
||||
"o:ruleIds": [
|
||||
"Uuid"
|
||||
]
|
||||
}
|
||||
},
|
||||
"Devices.SetDeviceSettings": {
|
||||
"description": "Change the settings of a device.",
|
||||
"params": {
|
||||
"deviceId": "Uuid",
|
||||
"settings": "$ref:ParamList"
|
||||
},
|
||||
"returns": {
|
||||
"deviceError": "$ref:DeviceError"
|
||||
}
|
||||
},
|
||||
"Devices.SetPluginConfiguration": {
|
||||
"description": "Set a plugin's params.",
|
||||
"params": {
|
||||
"configuration": "$ref:ParamList",
|
||||
"pluginId": "Uuid"
|
||||
},
|
||||
"returns": {
|
||||
"deviceError": "$ref:DeviceError"
|
||||
}
|
||||
},
|
||||
"Events.GetEventType": {
|
||||
"deprecated": "Please use the Devices namespace instead.",
|
||||
"description": "Get the EventType for the given eventTypeId.",
|
||||
"params": {
|
||||
"eventTypeId": "Uuid"
|
||||
},
|
||||
"returns": {
|
||||
"deviceError": "$ref:DeviceError",
|
||||
"o:eventType": "$ref:EventType"
|
||||
}
|
||||
},
|
||||
"Integrations.AddThing": {
|
||||
"description": "Add a new thing to the system. Only things with a setupMethod of SetupMethodJustAdd can be added this way. For things with a setupMethod different than SetupMethodJustAdd, use PairThing. Things with CreateMethodJustAdd require all parameters to be supplied here. Things with CreateMethodDiscovery require the use of a thingDescriptorId. For discovered things, params are not required and will be taken from the ThingDescriptor, however, they may be overridden by supplying thingParams.",
|
||||
"params": {
|
||||
@ -1489,9 +1123,6 @@
|
||||
"Logging.GetLogEntries": {
|
||||
"description": "Get the LogEntries matching the given filter. The result set will contain entries matching all filter rules combined. If multiple options are given for a single filter type, the result set will contain entries matching any of those. The offset starts at the newest entry in the result set. By default all items are returned. Example: If the specified filter returns a total amount of 100 entries:\n- a offset value of 10 would include the oldest 90 entries\n- a offset value of 0 would return all 100 entries\n\nThe offset is particularly useful in combination with the maxCount property and can be used for pagination. E.g. A result set of 10000 entries can be fetched in batches of 1000 entries by fetching\n1) offset 0, maxCount 1000: Entries 0 to 9999\n2) offset 10000, maxCount 1000: Entries 10000 - 19999\n3) offset 20000, maxCount 1000: Entries 20000 - 29999\n...",
|
||||
"params": {
|
||||
"d:o:deviceIds": [
|
||||
"Uuid"
|
||||
],
|
||||
"o:eventTypes": [
|
||||
"$ref:LoggingEventType"
|
||||
],
|
||||
@ -1769,8 +1400,7 @@
|
||||
"Rules.FindRules": {
|
||||
"description": "Find a list of rules containing any of the given parameters.",
|
||||
"params": {
|
||||
"d:o:deviceId": "Uuid",
|
||||
"o:thingId": "Uuid"
|
||||
"thingId": "Uuid"
|
||||
},
|
||||
"returns": {
|
||||
"ruleIds": [
|
||||
@ -1858,17 +1488,6 @@
|
||||
"scriptError": "$ref:ScriptError"
|
||||
}
|
||||
},
|
||||
"States.GetStateType": {
|
||||
"deprecated": "Please use the Integrations namespace instead.",
|
||||
"description": "Get the StateType for the given stateTypeId.",
|
||||
"params": {
|
||||
"stateTypeId": "Uuid"
|
||||
},
|
||||
"returns": {
|
||||
"deviceError": "$ref:DeviceError",
|
||||
"o:stateType": "$ref:StateType"
|
||||
}
|
||||
},
|
||||
"System.CheckForUpdates": {
|
||||
"description": "Instruct the system to poll the server for updates. Normally the system should automatically do this in regular intervals, however, if the client wants to allow the user to manually check for new updates now, this can be called. Returns true if the operation has been started successfully and the update manager will become busy. In order to know whether there are updates available, clients should walk through the list of packages retrieved from GetPackages and check whether there are packages with the updateAvailable flag set to true.",
|
||||
"params": {
|
||||
@ -2029,7 +1648,6 @@
|
||||
"Tags.GetTags": {
|
||||
"description": "Get the Tags matching the given filter. Tags can be filtered by a thingID, a ruleId, an appId, a tagId or a combination of any (however, combining thingId and ruleId will return an empty result set).",
|
||||
"params": {
|
||||
"d:o:deviceId": "Uuid",
|
||||
"o:appId": "String",
|
||||
"o:ruleId": "Uuid",
|
||||
"o:tagId": "String",
|
||||
@ -2307,60 +1925,6 @@
|
||||
"id": "String"
|
||||
}
|
||||
},
|
||||
"Devices.DeviceAdded": {
|
||||
"description": "Emitted whenever a Device was added.",
|
||||
"params": {
|
||||
"device": "$ref:Device"
|
||||
}
|
||||
},
|
||||
"Devices.DeviceChanged": {
|
||||
"description": "Emitted whenever the params, name or setupStatus of a Device changes.",
|
||||
"params": {
|
||||
"device": "$ref:Device"
|
||||
}
|
||||
},
|
||||
"Devices.DeviceRemoved": {
|
||||
"description": "Emitted whenever a Device was removed.",
|
||||
"params": {
|
||||
"deviceId": "Uuid"
|
||||
}
|
||||
},
|
||||
"Devices.DeviceSettingChanged": {
|
||||
"description": "Emitted whenever the setting of a Device is changed.",
|
||||
"params": {
|
||||
"deviceId": "Uuid",
|
||||
"paramTypeId": "Uuid",
|
||||
"value": "Variant"
|
||||
}
|
||||
},
|
||||
"Devices.EventTriggered": {
|
||||
"description": "Emitted whenever an Event is triggered.",
|
||||
"params": {
|
||||
"event": "$ref:Event"
|
||||
}
|
||||
},
|
||||
"Devices.PluginConfigurationChanged": {
|
||||
"description": "Emitted whenever a plugin's configuration is changed.",
|
||||
"params": {
|
||||
"configuration": "$ref:ParamList",
|
||||
"pluginId": "Uuid"
|
||||
}
|
||||
},
|
||||
"Devices.StateChanged": {
|
||||
"description": "Emitted whenever a State of a device changes.",
|
||||
"params": {
|
||||
"deviceId": "Uuid",
|
||||
"stateTypeId": "Uuid",
|
||||
"value": "Variant"
|
||||
}
|
||||
},
|
||||
"Events.EventTriggered": {
|
||||
"deprecated": "Please use Devices.EventTriggered instead.",
|
||||
"description": "Emitted whenever an Event is triggered.",
|
||||
"params": {
|
||||
"event": "$ref:Event"
|
||||
}
|
||||
},
|
||||
"Integrations.EventTriggered": {
|
||||
"description": "Emitted whenever an Event is triggered.",
|
||||
"params": {
|
||||
@ -2723,7 +2287,6 @@
|
||||
"types": {
|
||||
"Action": {
|
||||
"actionTypeId": "Uuid",
|
||||
"d:deviceId": "Uuid",
|
||||
"o:params": "$ref:ParamList",
|
||||
"thingId": "Uuid"
|
||||
},
|
||||
@ -2764,79 +2327,12 @@
|
||||
"CalendarItems": [
|
||||
"$ref:CalendarItem"
|
||||
],
|
||||
"Device": {
|
||||
"d:r:setupComplete": "Bool",
|
||||
"o:name": "String",
|
||||
"o:settings": "$ref:ParamList",
|
||||
"r:deviceClassId": "Uuid",
|
||||
"r:id": "Uuid",
|
||||
"r:o:loggedEventTypeIds": [
|
||||
"Uuid"
|
||||
],
|
||||
"r:o:parentId": "Uuid",
|
||||
"r:o:setupDisplayMessage": "String",
|
||||
"r:params": "$ref:ParamList",
|
||||
"r:setupError": "$ref:ThingError",
|
||||
"r:setupStatus": "$ref:ThingSetupStatus",
|
||||
"r:states": "$ref:States",
|
||||
"r:thingClassId": "Uuid"
|
||||
},
|
||||
"DeviceClass": {
|
||||
"r:actionTypes": "$ref:ActionTypes",
|
||||
"r:browsable": "Bool",
|
||||
"r:browserItemActionTypes": "$ref:ActionTypes",
|
||||
"r:createMethods": "$ref:CreateMethods",
|
||||
"r:discoveryParamTypes": "$ref:ParamTypes",
|
||||
"r:displayName": "String",
|
||||
"r:eventTypes": "$ref:EventTypes",
|
||||
"r:id": "Uuid",
|
||||
"r:interfaces": "StringList",
|
||||
"r:name": "String",
|
||||
"r:paramTypes": "$ref:ParamTypes",
|
||||
"r:pluginId": "Uuid",
|
||||
"r:providedInterfaces": "StringList",
|
||||
"r:settingsTypes": "$ref:ParamTypes",
|
||||
"r:setupMethod": "$ref:SetupMethod",
|
||||
"r:stateTypes": "$ref:StateTypes",
|
||||
"r:vendorId": "Uuid"
|
||||
},
|
||||
"DeviceClasses": [
|
||||
"$ref:DeviceClass"
|
||||
],
|
||||
"DeviceDescriptor": {
|
||||
"d:r:deviceParams": "$ref:ParamList",
|
||||
"r:description": "String",
|
||||
"r:deviceParams": "$ref:ParamList",
|
||||
"r:id": "Uuid",
|
||||
"r:o:deviceId": "Uuid",
|
||||
"r:o:thingId": "Uuid",
|
||||
"r:params": "$ref:ParamList",
|
||||
"r:thingClassId": "Uuid",
|
||||
"r:title": "String"
|
||||
},
|
||||
"DeviceDescriptors": [
|
||||
"$ref:DeviceDescriptor"
|
||||
],
|
||||
"DevicePlugin": {
|
||||
"r:displayName": "String",
|
||||
"r:id": "Uuid",
|
||||
"r:name": "String",
|
||||
"r:paramTypes": "$ref:ParamTypes"
|
||||
},
|
||||
"DevicePlugins": [
|
||||
"$ref:DevicePlugin"
|
||||
],
|
||||
"Devices": [
|
||||
"$ref:Device"
|
||||
],
|
||||
"Event": {
|
||||
"d:r:deviceId": "Uuid",
|
||||
"r:eventTypeId": "Uuid",
|
||||
"r:params": "$ref:ParamList",
|
||||
"r:thingId": "Uuid"
|
||||
},
|
||||
"EventDescriptor": {
|
||||
"d:o:deviceId": "Uuid",
|
||||
"o:eventTypeId": "Uuid",
|
||||
"o:interface": "String",
|
||||
"o:interfaceEvent": "String",
|
||||
@ -2884,7 +2380,6 @@
|
||||
"$ref:LogEntry"
|
||||
],
|
||||
"LogEntry": {
|
||||
"d:r:o:deviceId": "Uuid",
|
||||
"r:loggingLevel": "$ref:LoggingLevel",
|
||||
"r:o:active": "Bool",
|
||||
"r:o:errorCode": "String",
|
||||
@ -2992,7 +2487,6 @@
|
||||
"r:id": "Uuid"
|
||||
},
|
||||
"RuleAction": {
|
||||
"d:o:deviceId": "Uuid",
|
||||
"o:actionTypeId": "Uuid",
|
||||
"o:browserItemId": "String",
|
||||
"o:interface": "String",
|
||||
@ -3001,7 +2495,6 @@
|
||||
"o:thingId": "Uuid"
|
||||
},
|
||||
"RuleActionParam": {
|
||||
"d:o:stateDeviceId": "Uuid",
|
||||
"o:eventParamTypeId": "Uuid",
|
||||
"o:eventTypeId": "Uuid",
|
||||
"o:paramName": "String",
|
||||
@ -3057,7 +2550,6 @@
|
||||
"r:value": "Variant"
|
||||
},
|
||||
"StateDescriptor": {
|
||||
"d:o:deviceId": "Uuid",
|
||||
"o:interface": "String",
|
||||
"o:interfaceState": "String",
|
||||
"o:stateTypeId": "Uuid",
|
||||
@ -3098,7 +2590,6 @@
|
||||
],
|
||||
"Tag": {
|
||||
"appId": "String",
|
||||
"d:o:deviceId": "Uuid",
|
||||
"o:ruleId": "Uuid",
|
||||
"o:thingId": "Uuid",
|
||||
"o:value": "String",
|
||||
@ -3146,7 +2637,6 @@
|
||||
"$ref:ThingClass"
|
||||
],
|
||||
"ThingDescriptor": {
|
||||
"d:r:deviceParams": "$ref:ParamList",
|
||||
"r:description": "String",
|
||||
"r:id": "Uuid",
|
||||
"r:o:thingId": "Uuid",
|
||||
|
||||
@ -1,10 +1,7 @@
|
||||
TEMPLATE = subdirs
|
||||
|
||||
SUBDIRS = \
|
||||
actions \
|
||||
configurations \
|
||||
devices \
|
||||
events \
|
||||
integrations \
|
||||
ioconnections \
|
||||
jsonrpc \
|
||||
@ -16,7 +13,6 @@ SUBDIRS = \
|
||||
pythonplugins \
|
||||
rules \
|
||||
scripts \
|
||||
states \
|
||||
tags \
|
||||
timemanager \
|
||||
userloading \
|
||||
|
||||
@ -1,5 +0,0 @@
|
||||
include(../../../nymea.pri)
|
||||
include(../autotests.pri)
|
||||
|
||||
TARGET = testdevices
|
||||
SOURCES += testdevices.cpp
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,5 +0,0 @@
|
||||
include(../../../nymea.pri)
|
||||
include(../autotests.pri)
|
||||
|
||||
TARGET = testevents
|
||||
SOURCES += testevents.cpp
|
||||
@ -1,181 +0,0 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2020, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
* This project including source code and documentation is protected by
|
||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
||||
* reproduction, publication, editing and translation, are reserved. The use of
|
||||
* this project is subject to the terms of a license agreement to be concluded
|
||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
||||
* under https://nymea.io/license
|
||||
*
|
||||
* GNU General Public License Usage
|
||||
* Alternatively, this project may be redistributed and/or modified under the
|
||||
* terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, GNU version 3. This project 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 General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For any further details and any questions please contact us under
|
||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
||||
* https://nymea.io/license/faq
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#include "nymeatestbase.h"
|
||||
#include "nymeacore.h"
|
||||
|
||||
#include "jsonrpc/devicehandler.h"
|
||||
#include "servers/mocktcpserver.h"
|
||||
|
||||
using namespace nymeaserver;
|
||||
|
||||
class TestEvents: public NymeaTestBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void triggerEvent();
|
||||
void triggerStateChangeEvent();
|
||||
|
||||
void params();
|
||||
|
||||
void getEventType_data();
|
||||
void getEventType();
|
||||
};
|
||||
|
||||
void TestEvents::triggerEvent()
|
||||
{
|
||||
enableNotifications({"Events"});
|
||||
|
||||
QList<Thing*> devices = NymeaCore::instance()->thingManager()->findConfiguredThings(mockThingClassId);
|
||||
QVERIFY2(devices.count() > 0, "There needs to be at least one configured Mock Device for this test");
|
||||
Thing *device = devices.first();
|
||||
|
||||
QSignalSpy spy(NymeaCore::instance(), SIGNAL(eventTriggered(const Event&)));
|
||||
QSignalSpy notificationSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray)));
|
||||
|
||||
// Setup connection to mock client
|
||||
QNetworkAccessManager nam;
|
||||
|
||||
// trigger event in mock device
|
||||
int port = device->paramValue(mockThingHttpportParamTypeId).toInt();
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(port).arg(mockEvent1EventTypeId.toString())));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
||||
|
||||
// Lets wait for the notification
|
||||
spy.wait();
|
||||
QVERIFY(spy.count() > 0);
|
||||
for (int i = 0; i < spy.count(); i++ ){
|
||||
Event event = spy.at(i).at(0).value<Event>();
|
||||
if (event.thingId() == device->id()) {
|
||||
// Make sure the event contains all the stuff we expect
|
||||
QCOMPARE(event.eventTypeId(), mockEvent1EventTypeId);
|
||||
}
|
||||
}
|
||||
|
||||
// Check for the notification on JSON API
|
||||
QVariantList notifications;
|
||||
notifications = checkNotifications(notificationSpy, "Events.EventTriggered");
|
||||
QVERIFY2(notifications.count() == 1, "Should get Events.EventTriggered notification");
|
||||
QVERIFY2(notifications.first().toMap().contains("deprecationWarning"), "Deprecation warning not included in notification");
|
||||
|
||||
QVariantMap notificationContent = notifications.first().toMap().value("params").toMap();
|
||||
QCOMPARE(notificationContent.value("event").toMap().value("deviceId").toUuid().toString(), device->id().toString());
|
||||
QCOMPARE(notificationContent.value("event").toMap().value("eventTypeId").toUuid().toString(), mockEvent1EventTypeId.toString());
|
||||
}
|
||||
|
||||
void TestEvents::triggerStateChangeEvent()
|
||||
{
|
||||
enableNotifications({"Events"});
|
||||
|
||||
QList<Thing*> devices = NymeaCore::instance()->thingManager()->findConfiguredThings(mockThingClassId);
|
||||
QVERIFY2(devices.count() > 0, "There needs to be at least one configured Mock Device for this test");
|
||||
Thing *device = devices.first();
|
||||
|
||||
QSignalSpy spy(NymeaCore::instance(), SIGNAL(eventTriggered(const Event&)));
|
||||
QSignalSpy notificationSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray)));
|
||||
|
||||
// Setup connection to mock client
|
||||
QNetworkAccessManager nam;
|
||||
|
||||
// trigger state changed event in mock device
|
||||
int port = device->paramValue(mockThingHttpportParamTypeId).toInt();
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(port).arg(mockIntStateTypeId.toString()).arg(11)));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
||||
|
||||
// Lets wait for the notification
|
||||
spy.wait();
|
||||
QVERIFY(spy.count() > 0);
|
||||
for (int i = 0; i < spy.count(); i++ ){
|
||||
Event event = spy.at(i).at(0).value<Event>();
|
||||
if (event.thingId() == device->id()) {
|
||||
// Make sure the event contains all the stuff we expect
|
||||
QCOMPARE(event.eventTypeId().toString(), mockIntStateTypeId.toString());
|
||||
QCOMPARE(event.param(ParamTypeId(mockIntStateTypeId.toString())).value().toInt(), 11);
|
||||
}
|
||||
}
|
||||
|
||||
// Check for the notification on JSON API
|
||||
QVariantList notifications;
|
||||
notifications = checkNotifications(notificationSpy, "Events.EventTriggered");
|
||||
QVERIFY2(notifications.count() == 1, "Should get Devices.EventTriggered notification");
|
||||
QVERIFY2(notifications.first().toMap().contains("deprecationWarning"), "Deprecation warning not included in notification!");
|
||||
|
||||
QVariantMap notificationContent = notifications.first().toMap().value("params").toMap();
|
||||
|
||||
QCOMPARE(notificationContent.value("event").toMap().value("deviceId").toUuid().toString(), device->id().toString());
|
||||
QCOMPARE(notificationContent.value("event").toMap().value("eventTypeId").toUuid().toString(), mockIntEventTypeId.toString());
|
||||
}
|
||||
|
||||
void TestEvents::params()
|
||||
{
|
||||
Event event;
|
||||
ParamList params;
|
||||
ParamTypeId id = ParamTypeId::createParamTypeId();
|
||||
Param p(id, "foo bar");
|
||||
params.append(p);
|
||||
event.setParams(params);
|
||||
|
||||
QVERIFY(event.param(id).value().toString() == "foo bar");
|
||||
QVERIFY(!event.param(ParamTypeId::createParamTypeId()).value().isValid());
|
||||
}
|
||||
|
||||
void TestEvents::getEventType_data()
|
||||
{
|
||||
QTest::addColumn<EventTypeId>("eventTypeId");
|
||||
QTest::addColumn<Device::DeviceError>("error");
|
||||
|
||||
QTest::newRow("valid eventypeid") << mockEvent1EventTypeId << Device::DeviceErrorNoError;
|
||||
QTest::newRow("invalid eventypeid") << EventTypeId::createEventTypeId() << Device::DeviceErrorEventTypeNotFound;
|
||||
}
|
||||
|
||||
void TestEvents::getEventType()
|
||||
{
|
||||
QFETCH(EventTypeId, eventTypeId);
|
||||
QFETCH(Device::DeviceError, error);
|
||||
|
||||
QVariantMap params;
|
||||
params.insert("eventTypeId", eventTypeId.toString());
|
||||
QVariant response = injectAndWait("Events.GetEventType", params);
|
||||
|
||||
verifyError(response, "deviceError", enumValueName(error));
|
||||
|
||||
qCDebug(dcTests()) << "*content" << response;
|
||||
QVERIFY2(response.toMap().contains("deprecationWarning"), "Deprecation warning not shown in reply");
|
||||
|
||||
if (error == Device::DeviceErrorNoError) {
|
||||
QVERIFY2(EventTypeId(response.toMap().value("params").toMap().value("eventType").toMap().value("id").toString()) == eventTypeId, "Didn't get a reply for the same actionTypeId as requested.");
|
||||
}
|
||||
}
|
||||
|
||||
#include "testevents.moc"
|
||||
QTEST_MAIN(TestEvents)
|
||||
@ -84,6 +84,8 @@ private slots:
|
||||
|
||||
void storedThings();
|
||||
|
||||
void stateCache();
|
||||
|
||||
void discoverThings_data();
|
||||
void discoverThings();
|
||||
|
||||
@ -650,6 +652,74 @@ void TestIntegrations::storedThings()
|
||||
verifyThingError(response);
|
||||
}
|
||||
|
||||
void TestIntegrations::stateCache()
|
||||
{
|
||||
ThingClass mockThingClass = NymeaCore::instance()->thingManager()->findThingClass(mockThingClassId);
|
||||
|
||||
QVERIFY2(mockThingClass.getStateType(mockIntStateTypeId).cached(), "Mock int state is not cached (required to be true for this test)");
|
||||
QVERIFY2(!mockThingClass.getStateType(mockBoolStateTypeId).cached(), "Mock bool state is cached (required to be false for this test)");
|
||||
|
||||
Thing* thing = NymeaCore::instance()->thingManager()->findConfiguredThings(mockThingClassId).first();
|
||||
int port = thing->paramValue(mockThingHttpportParamTypeId).toInt();
|
||||
QNetworkAccessManager nam;
|
||||
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
|
||||
|
||||
|
||||
// First set the state values to something that is *not* the default
|
||||
int oldIntValue = mockThingClass.getStateType(mockIntStateTypeId).defaultValue().toInt();
|
||||
int newIntValue = oldIntValue + 1;
|
||||
bool oldBoolValue = mockThingClass.getStateType(mockBoolStateTypeId).defaultValue().toBool();
|
||||
bool newBoolValue = !oldBoolValue;
|
||||
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(port).arg(mockIntStateTypeId.toString()).arg(newIntValue)));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
||||
spy.wait();
|
||||
|
||||
spy.clear();
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(port).arg(mockBoolStateTypeId.toString()).arg(newBoolValue)));
|
||||
reply = nam.get(request);
|
||||
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
||||
spy.wait();
|
||||
|
||||
// For completeness, verify through JSONRPC that they were actually yet.
|
||||
QVariantMap params;
|
||||
params.insert("thingId", thing->id());
|
||||
|
||||
params["stateTypeId"] = mockIntStateTypeId;
|
||||
QVariant response = injectAndWait("Integrations.GetStateValue", params);
|
||||
QCOMPARE(response.toMap().value("params").toMap().value("value").toInt(), newIntValue);
|
||||
|
||||
params["stateTypeId"] = mockBoolStateTypeId;
|
||||
response = injectAndWait("Integrations.GetStateValue", params);
|
||||
QCOMPARE(response.toMap().value("params").toMap().value("value").toBool(), newBoolValue);
|
||||
|
||||
// Restart the server
|
||||
restartServer();
|
||||
|
||||
// And check if the cached int state has successfully been restored
|
||||
params["stateTypeId"] = mockIntStateTypeId;
|
||||
response = injectAndWait("Integrations.GetStateValue", params);
|
||||
QCOMPARE(response.toMap().value("params").toMap().value("value").toInt(), newIntValue);
|
||||
|
||||
// and that the non-cached bool state is back to its default
|
||||
params["stateTypeId"] = mockBoolStateTypeId;
|
||||
response = injectAndWait("Integrations.GetStateValue", params);
|
||||
QCOMPARE(response.toMap().value("params").toMap().value("value").toBool(), mockThingClass.getStateType(mockBoolStateTypeId).defaultValue().toBool());
|
||||
|
||||
// Reset back to default values
|
||||
spy.clear();
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(port).arg(mockBoolStateTypeId.toString()).arg(oldIntValue)));
|
||||
reply = nam.get(request);
|
||||
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
||||
spy.wait();
|
||||
spy.clear();
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(port).arg(mockBoolStateTypeId.toString()).arg(oldBoolValue)));
|
||||
reply = nam.get(request);
|
||||
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
||||
spy.wait();
|
||||
}
|
||||
|
||||
void TestIntegrations::discoverThings_data()
|
||||
{
|
||||
QTest::addColumn<ThingClassId>("thingClassId");
|
||||
@ -1011,6 +1081,7 @@ void TestIntegrations::getStateValue_data()
|
||||
|
||||
void TestIntegrations::getStateValue()
|
||||
{
|
||||
NymeaCore::instance()->thingManager()->findConfiguredThing(m_mockThingId)->setStateValue(mockIntStateTypeId, 10);
|
||||
QFETCH(ThingId, thingId);
|
||||
QFETCH(StateTypeId, stateTypeId);
|
||||
QFETCH(Thing::ThingError, statusCode);
|
||||
@ -2085,7 +2156,7 @@ void TestIntegrations::triggerStateChangeEvent()
|
||||
|
||||
// trigger state changed event in mock device
|
||||
int port = thing->paramValue(mockThingHttpportParamTypeId).toInt();
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(port).arg(mockIntStateTypeId.toString()).arg(11)));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(port).arg(mockIntStateTypeId.toString()).arg(37)));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
||||
|
||||
@ -2097,7 +2168,7 @@ void TestIntegrations::triggerStateChangeEvent()
|
||||
if (event.thingId() == thing->id()) {
|
||||
// Make sure the event contains all the stuff we expect
|
||||
QCOMPARE(event.eventTypeId().toString(), mockIntStateTypeId.toString());
|
||||
QCOMPARE(event.param(ParamTypeId(mockIntStateTypeId.toString())).value().toInt(), 11);
|
||||
QCOMPARE(event.param(ParamTypeId(mockIntStateTypeId.toString())).value().toInt(), 37);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2107,7 +2178,7 @@ void TestIntegrations::triggerStateChangeEvent()
|
||||
QVERIFY2(notifications.count() == 1, "Should get Integrations.EventTriggered notification");
|
||||
QVariantMap notificationContent = notifications.first().toMap().value("params").toMap();
|
||||
|
||||
QCOMPARE(notificationContent.value("event").toMap().value("deviceId").toUuid().toString(), thing->id().toString());
|
||||
QCOMPARE(notificationContent.value("event").toMap().value("thingId").toUuid().toString(), thing->id().toString());
|
||||
QCOMPARE(notificationContent.value("event").toMap().value("eventTypeId").toUuid().toString(), mockIntEventTypeId.toString());
|
||||
|
||||
}
|
||||
|
||||
@ -150,8 +150,7 @@ QStringList TestJSONRPC::extractRefs(const QVariant &variant)
|
||||
void TestJSONRPC::initTestCase()
|
||||
{
|
||||
NymeaDBusService::setBusType(QDBusConnection::SessionBus);
|
||||
NymeaTestBase::initTestCase();
|
||||
QLoggingCategory::setFilterRules("*.debug=false\n"
|
||||
NymeaTestBase::initTestCase("*.debug=false\n"
|
||||
// "JsonRpcTraffic.debug=true\n"
|
||||
"JsonRpc.debug=true\n"
|
||||
"Translations.debug=true\n"
|
||||
@ -674,7 +673,7 @@ void TestJSONRPC::enableDisableNotifications_legacy()
|
||||
|
||||
QStringList expectedNamespaces;
|
||||
if (enabled == "true") {
|
||||
expectedNamespaces << "Actions" << "NetworkManager" << "Devices" << "Integrations" << "System" << "Rules" << "States" << "Logging" << "Tags" << "AppData" << "JSONRPC" << "Configuration" << "Events" << "Scripts" << "Users" << "Zigbee" << "ModbusRtu";
|
||||
expectedNamespaces << "NetworkManager" << "Integrations" << "System" << "Rules"<< "Logging" << "Tags" << "AppData" << "JSONRPC" << "Configuration" << "Scripts" << "Users" << "Zigbee" << "ModbusRtu";
|
||||
}
|
||||
std::sort(expectedNamespaces.begin(), expectedNamespaces.end());
|
||||
|
||||
@ -700,7 +699,6 @@ void TestJSONRPC::ruleAddedRemovedNotifications()
|
||||
QVariantMap stateDescriptor;
|
||||
stateDescriptor.insert("stateTypeId", mockIntStateTypeId);
|
||||
stateDescriptor.insert("thingId", m_mockThingId);
|
||||
stateDescriptor.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
stateDescriptor.insert("operator", enumValueName(Types::ValueOperatorLess));
|
||||
stateDescriptor.insert("value", "20");
|
||||
// This is a bit odd: QUuid.toString() wraps the uuids in {}, however, the implicit cast doesn't
|
||||
@ -715,7 +713,6 @@ void TestJSONRPC::ruleAddedRemovedNotifications()
|
||||
QVariantMap actionNoParams;
|
||||
actionNoParams.insert("actionTypeId", mockWithoutParamsActionTypeId);
|
||||
actionNoParams.insert("thingId", m_mockThingId);
|
||||
actionNoParams.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
// This is a bit odd: QUuid.toString() wraps the uuids in {}, however, the implicit cast doesn't
|
||||
// .toString(QUuid::WithoutBraces) has only been added in 5.11 so we can't use that either...
|
||||
// Only hack I can come up with right now is to convert it to a Json and back to use the implicit cast
|
||||
@ -725,7 +722,6 @@ void TestJSONRPC::ruleAddedRemovedNotifications()
|
||||
QVariantMap eventDescriptor;
|
||||
eventDescriptor.insert("eventTypeId", mockEvent1EventTypeId);
|
||||
eventDescriptor.insert("thingId", m_mockThingId);
|
||||
eventDescriptor.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
// This is a bit odd: QUuid.toString() wraps the uuids in {}, however, the implicit cast doesn't
|
||||
// .toString(QUuid::WithoutBraces) has only been added in 5.11 so we can't use that either...
|
||||
// Only hack I can come up with right now is to convert it to a Json and back to use the implicit cast
|
||||
@ -789,7 +785,6 @@ void TestJSONRPC::ruleActiveChangedNotifications()
|
||||
QVariantMap stateDescriptor;
|
||||
stateDescriptor.insert("stateTypeId", mockIntStateTypeId);
|
||||
stateDescriptor.insert("thingId", m_mockThingId);
|
||||
stateDescriptor.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
stateDescriptor.insert("operator", enumValueName(Types::ValueOperatorEquals));
|
||||
stateDescriptor.insert("value", "20");
|
||||
// This is a bit odd: QUuid.toString() wraps the uuids in {}, however, the implicit cast doesn't
|
||||
@ -804,7 +799,6 @@ void TestJSONRPC::ruleActiveChangedNotifications()
|
||||
QVariantMap actionNoParams;
|
||||
actionNoParams.insert("actionTypeId", mockWithoutParamsActionTypeId);
|
||||
actionNoParams.insert("thingId", m_mockThingId);
|
||||
actionNoParams.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
// This is a bit odd: QUuid.toString() wraps the uuids in {}, however, the implicit cast doesn't
|
||||
// .toString(QUuid::WithoutBraces) has only been added in 5.11 so we can't use that either...
|
||||
// Only hack I can come up with right now is to convert it to a Json and back to use the implicit cast
|
||||
@ -855,21 +849,18 @@ void TestJSONRPC::ruleActiveChangedNotifications()
|
||||
spy.clear(); clientSpy.clear();
|
||||
|
||||
// set the rule inactive
|
||||
qDebug() << "setting mock int state to 42";
|
||||
qCDebug(dcTests) << "setting mock int state to 42";
|
||||
QNetworkRequest request2(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(mockIntStateTypeId.toString()).arg(42)));
|
||||
QNetworkReply *reply2 = nam.get(request2);
|
||||
connect(reply2, SIGNAL(finished()), reply2, SLOT(deleteLater()));
|
||||
|
||||
// Waiting for notifications:
|
||||
// Devices.StateChanged for the change we did
|
||||
// Devices.EventTriggered
|
||||
// Events.EventTriggered <-- deprecated
|
||||
// Integrations.StateChanged for the change we did
|
||||
// Integrations.EventTriggered
|
||||
// Rules.RuleActiveChanged
|
||||
// Logging.LogEntryAdded
|
||||
// Devices.StateChanged for the change done by the rule
|
||||
// Devices.EventTriggered
|
||||
// Events.EventTriggered <-- deprecated
|
||||
while (clientSpy.count() < 8) {
|
||||
// Logging.LogEntryAdded // One for the state change we did
|
||||
// Logging.LogEntryAdded // One for the rule state change
|
||||
while (clientSpy.count() < 5) {
|
||||
clientSpy.wait();
|
||||
}
|
||||
|
||||
@ -894,7 +885,7 @@ void TestJSONRPC::ruleActiveChangedNotifications()
|
||||
|
||||
void TestJSONRPC::stateChangeEmitsNotifications()
|
||||
{
|
||||
enableNotifications({"Devices", "States", "Logging", "Events"});
|
||||
enableNotifications({"Integrations", "Logging"});
|
||||
bool found = false;
|
||||
|
||||
// Setup connection to mock client
|
||||
@ -911,9 +902,9 @@ void TestJSONRPC::stateChangeEmitsNotifications()
|
||||
if (replySpy.count() == 0) replySpy.wait();
|
||||
|
||||
// Make sure the notification contains all the stuff we expect
|
||||
QVariantList stateChangedVariants = checkNotifications(clientSpy, "Devices.StateChanged");
|
||||
QVERIFY2(!stateChangedVariants.isEmpty(), "Did not get Devices.StateChanged notification.");
|
||||
qDebug() << "got" << stateChangedVariants.count() << "Devices.StateChanged notifications";
|
||||
QVariantList stateChangedVariants = checkNotifications(clientSpy, "Integrations.StateChanged");
|
||||
QVERIFY2(!stateChangedVariants.isEmpty(), "Did not get Integrations.StateChanged notification.");
|
||||
qDebug() << "got" << stateChangedVariants.count() << "Integrations.StateChanged notifications";
|
||||
foreach (const QVariant &stateChangedVariant, stateChangedVariants) {
|
||||
if (stateChangedVariant.toMap().value("params").toMap().value("stateTypeId").toUuid() == stateTypeId) {
|
||||
found = true;
|
||||
@ -933,8 +924,8 @@ void TestJSONRPC::stateChangeEmitsNotifications()
|
||||
}
|
||||
|
||||
// Make sure the notification contains all the stuff we expect
|
||||
QVariantList eventTriggeredVariants = checkNotifications(clientSpy, "Events.EventTriggered");
|
||||
QVERIFY2(!eventTriggeredVariants.isEmpty(), "Did not get Events.EventTriggered notification.");
|
||||
QVariantList eventTriggeredVariants = checkNotifications(clientSpy, "Integrations.EventTriggered");
|
||||
QVERIFY2(!eventTriggeredVariants.isEmpty(), "Did not get Integrations.EventTriggered notification.");
|
||||
found = false;
|
||||
foreach (const QVariant &eventTriggeredVariant, eventTriggeredVariants) {
|
||||
if (eventTriggeredVariant.toMap().value("params").toMap().value("event").toMap().value("eventTypeId").toUuid() == stateTypeId) {
|
||||
@ -944,7 +935,7 @@ void TestJSONRPC::stateChangeEmitsNotifications()
|
||||
}
|
||||
}
|
||||
|
||||
QVERIFY2(found, "Could not find the corresponding Events.EventTriggered notification");
|
||||
QVERIFY2(found, "Could not find the corresponding Integrations.EventTriggered notification");
|
||||
|
||||
// Now turn off notifications
|
||||
QCOMPARE(disableNotifications(), true);
|
||||
|
||||
@ -300,7 +300,7 @@ void TestLogging::eventLogs()
|
||||
|
||||
// Now snoop in for the events
|
||||
clearLoggingDatabase();
|
||||
enableNotifications({"Events", "Logging"});
|
||||
enableNotifications({"Integrations", "Logging"});
|
||||
QSignalSpy clientSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray)));
|
||||
|
||||
// trigger state change in mock device
|
||||
|
||||
@ -422,7 +422,6 @@ void TestRules::addRemoveRules_data()
|
||||
QVariantMap validActionNoParams;
|
||||
validActionNoParams.insert("actionTypeId", mockWithoutParamsActionTypeId);
|
||||
validActionNoParams.insert("thingId", m_mockThingId);
|
||||
validActionNoParams.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
|
||||
QVariantMap invalidAction;
|
||||
invalidAction.insert("actionTypeId", ActionTypeId("f32c7efb-38b6-4576-a496-c75bbb23132f"));
|
||||
@ -432,7 +431,6 @@ void TestRules::addRemoveRules_data()
|
||||
QVariantMap validExitActionNoParams;
|
||||
validExitActionNoParams.insert("actionTypeId", mockWithoutParamsActionTypeId);
|
||||
validExitActionNoParams.insert("thingId", m_mockThingId);
|
||||
validExitActionNoParams.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
|
||||
QVariantMap invalidExitAction;
|
||||
invalidExitAction.insert("actionTypeId", ActionTypeId("f32c7efb-38b6-4576-a496-c75bbb23132f"));
|
||||
@ -458,12 +456,10 @@ void TestRules::addRemoveRules_data()
|
||||
QVariantMap validEventDescriptor1;
|
||||
validEventDescriptor1.insert("eventTypeId", mockEvent1EventTypeId);
|
||||
validEventDescriptor1.insert("thingId", m_mockThingId);
|
||||
validEventDescriptor1.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
|
||||
QVariantMap validEventDescriptor2;
|
||||
validEventDescriptor2.insert("eventTypeId", mockEvent2EventTypeId);
|
||||
validEventDescriptor2.insert("thingId", m_mockThingId);
|
||||
validEventDescriptor2.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
|
||||
QVariantList params;
|
||||
QVariantMap param1;
|
||||
@ -476,7 +472,6 @@ void TestRules::addRemoveRules_data()
|
||||
QVariantMap validEventDescriptor3;
|
||||
validEventDescriptor3.insert("eventTypeId", mockEvent2EventTypeId);
|
||||
validEventDescriptor3.insert("thingId", m_mockThingId);
|
||||
validEventDescriptor3.insert("deviceId", m_mockThingId); // DREPECATED
|
||||
|
||||
// EventDescriptorList
|
||||
QVariantList eventDescriptorList;
|
||||
@ -491,7 +486,6 @@ void TestRules::addRemoveRules_data()
|
||||
QVariantMap validActionEventBased;
|
||||
validActionEventBased.insert("actionTypeId", mockWithParamsActionTypeId);
|
||||
validActionEventBased.insert("thingId", m_mockThingId);
|
||||
validActionEventBased.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
QVariantMap validActionEventBasedParam1;
|
||||
validActionEventBasedParam1.insert("paramTypeId", mockWithParamsActionParam1ParamTypeId);
|
||||
validActionEventBasedParam1.insert("eventTypeId", mockEvent2EventTypeId);
|
||||
@ -675,7 +669,6 @@ void TestRules::editRules_data()
|
||||
QVariantMap validActionNoParams;
|
||||
validActionNoParams.insert("actionTypeId", mockWithoutParamsActionTypeId);
|
||||
validActionNoParams.insert("thingId", m_mockThingId);
|
||||
validActionNoParams.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
|
||||
QVariantMap invalidAction;
|
||||
invalidAction.insert("actionTypeId", ActionTypeId());
|
||||
@ -685,7 +678,6 @@ void TestRules::editRules_data()
|
||||
QVariantMap validExitActionNoParams;
|
||||
validExitActionNoParams.insert("actionTypeId", mockWithoutParamsActionTypeId);
|
||||
validExitActionNoParams.insert("thingId", m_mockThingId);
|
||||
validExitActionNoParams.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
|
||||
QVariantMap invalidExitAction;
|
||||
invalidExitAction.insert("actionTypeId", ActionTypeId());
|
||||
@ -711,12 +703,10 @@ void TestRules::editRules_data()
|
||||
QVariantMap validEventDescriptor1;
|
||||
validEventDescriptor1.insert("eventTypeId", mockEvent1EventTypeId);
|
||||
validEventDescriptor1.insert("thingId", m_mockThingId);
|
||||
validEventDescriptor1.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
|
||||
QVariantMap validEventDescriptor2;
|
||||
validEventDescriptor2.insert("eventTypeId", mockEvent2EventTypeId);
|
||||
validEventDescriptor2.insert("thingId", m_mockThingId);
|
||||
validEventDescriptor2.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
QVariantList params;
|
||||
QVariantMap param1;
|
||||
param1.insert("paramTypeId", mockEvent2EventIntParamParamTypeId);
|
||||
@ -728,7 +718,6 @@ void TestRules::editRules_data()
|
||||
QVariantMap validEventDescriptor3;
|
||||
validEventDescriptor3.insert("eventTypeId", mockEvent2EventTypeId);
|
||||
validEventDescriptor3.insert("thingId", m_mockThingId);
|
||||
validEventDescriptor3.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
|
||||
// EventDescriptorList
|
||||
QVariantList eventDescriptorList;
|
||||
@ -743,7 +732,6 @@ void TestRules::editRules_data()
|
||||
QVariantMap validActionEventBased;
|
||||
validActionEventBased.insert("actionTypeId", mockWithParamsActionTypeId);
|
||||
validActionEventBased.insert("thingId", m_mockThingId);
|
||||
validActionEventBased.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
QVariantMap validActionEventBasedParam1;
|
||||
validActionEventBasedParam1.insert("paramTypeId", mockWithParamsActionParam1ParamTypeId);
|
||||
validActionEventBasedParam1.insert("eventTypeId", mockEvent2EventTypeId);
|
||||
@ -828,11 +816,9 @@ void TestRules::editRules()
|
||||
QVariantMap eventDescriptor1;
|
||||
eventDescriptor1.insert("eventTypeId", mockEvent1EventTypeId);
|
||||
eventDescriptor1.insert("thingId", m_mockThingId);
|
||||
eventDescriptor1.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
QVariantMap eventDescriptor2;
|
||||
eventDescriptor2.insert("eventTypeId", mockEvent2EventTypeId);
|
||||
eventDescriptor2.insert("thingId", m_mockThingId);
|
||||
eventDescriptor2.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
QVariantMap eventParam1;
|
||||
eventParam1.insert("paramTypeId", mockEvent2EventIntParamParamTypeId);
|
||||
eventParam1.insert("value", 3);
|
||||
@ -889,7 +875,6 @@ void TestRules::editRules()
|
||||
QVariantMap validActionEventBased;
|
||||
validActionEventBased.insert("actionTypeId", mockWithParamsActionTypeId);
|
||||
validActionEventBased.insert("thingId", m_mockThingId);
|
||||
validActionEventBased.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
QVariantMap validActionEventBasedParam1;
|
||||
validActionEventBasedParam1.insert("paramTypeId", mockWithParamsActionParam1ParamTypeId);
|
||||
validActionEventBasedParam1.insert("eventTypeId", mockEvent2EventTypeId);
|
||||
@ -903,7 +888,6 @@ void TestRules::editRules()
|
||||
QVariantMap validEventDescriptor3;
|
||||
validEventDescriptor3.insert("eventTypeId", mockEvent2EventTypeId);
|
||||
validEventDescriptor3.insert("thingId", m_mockThingId);
|
||||
validEventDescriptor3.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
validEventDescriptor3.insert("paramDescriptors", QVariantList());
|
||||
validEventDescriptors3.append(validEventDescriptor3);
|
||||
|
||||
@ -978,7 +962,7 @@ void TestRules::editRules()
|
||||
foreach (const QVariant &eventDescriptorVariant, eventDescriptorList) {
|
||||
bool found = false;
|
||||
foreach (const QVariant &replyEventDescriptorVariant, eventDescriptors) {
|
||||
if (eventDescriptorVariant.toMap().value("deviceId") == replyEventDescriptorVariant.toMap().value("deviceId") &&
|
||||
if (eventDescriptorVariant.toMap().value("thingId") == replyEventDescriptorVariant.toMap().value("thingId") &&
|
||||
eventDescriptorVariant.toMap().value("eventTypeId") == replyEventDescriptorVariant.toMap().value("eventTypeId")) {
|
||||
found = true;
|
||||
QVERIFY2(eventDescriptorVariant == replyEventDescriptorVariant, "Event descriptor doesn't match");
|
||||
@ -1135,12 +1119,10 @@ void TestRules::loadStoreConfig()
|
||||
QVariantMap eventDescriptor1;
|
||||
eventDescriptor1.insert("eventTypeId", mockEvent1EventTypeId);
|
||||
eventDescriptor1.insert("thingId", m_mockThingId);
|
||||
eventDescriptor1.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
|
||||
QVariantMap eventDescriptor2;
|
||||
eventDescriptor2.insert("eventTypeId", mockEvent2EventTypeId);
|
||||
eventDescriptor2.insert("thingId", m_mockThingId);
|
||||
eventDescriptor2.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
QVariantList eventParamDescriptors;
|
||||
QVariantMap eventParam1;
|
||||
eventParam1.insert("paramTypeId", mockEvent2EventIntParamParamTypeId);
|
||||
@ -1158,7 +1140,6 @@ void TestRules::loadStoreConfig()
|
||||
|
||||
QVariantMap stateDescriptor2;
|
||||
stateDescriptor2.insert("thingId", m_mockThingId);
|
||||
stateDescriptor2.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
stateDescriptor2.insert("operator", enumValueName(Types::ValueOperatorEquals));
|
||||
stateDescriptor2.insert("stateTypeId", mockIntStateTypeId);
|
||||
stateDescriptor2.insert("value", 1);
|
||||
@ -1168,7 +1149,6 @@ void TestRules::loadStoreConfig()
|
||||
|
||||
QVariantMap stateDescriptor3;
|
||||
stateDescriptor3.insert("thingId", m_mockThingId);
|
||||
stateDescriptor3.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
stateDescriptor3.insert("operator", enumValueName(Types::ValueOperatorEquals));
|
||||
stateDescriptor3.insert("stateTypeId", mockBoolStateTypeId);
|
||||
stateDescriptor3.insert("value", true);
|
||||
@ -1196,13 +1176,11 @@ void TestRules::loadStoreConfig()
|
||||
QVariantMap action1;
|
||||
action1.insert("actionTypeId", mockWithoutParamsActionTypeId);
|
||||
action1.insert("thingId", m_mockThingId);
|
||||
action1.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
action1.insert("ruleActionParams", QVariantList());
|
||||
|
||||
QVariantMap action2;
|
||||
action2.insert("actionTypeId", mockWithParamsActionTypeId);
|
||||
action2.insert("thingId", m_mockThingId);
|
||||
action2.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
QVariantList action2Params;
|
||||
QVariantMap action2Param1;
|
||||
action2Param1.insert("paramTypeId", mockWithParamsActionParam1ParamTypeId);
|
||||
@ -1218,7 +1196,6 @@ void TestRules::loadStoreConfig()
|
||||
QVariantMap validActionEventBased;
|
||||
validActionEventBased.insert("actionTypeId", mockWithParamsActionTypeId);
|
||||
validActionEventBased.insert("thingId", m_mockThingId);
|
||||
validActionEventBased.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
QVariantMap validActionEventBasedParam1;
|
||||
validActionEventBasedParam1.insert("paramTypeId", mockWithParamsActionParam1ParamTypeId);
|
||||
validActionEventBasedParam1.insert("eventTypeId", mockEvent2EventTypeId);
|
||||
@ -1232,7 +1209,6 @@ void TestRules::loadStoreConfig()
|
||||
QVariantMap validEventDescriptor3;
|
||||
validEventDescriptor3.insert("eventTypeId", mockEvent2EventTypeId);
|
||||
validEventDescriptor3.insert("thingId", m_mockThingId);
|
||||
validEventDescriptor3.insert("deviceId", m_mockThingId); // DEPRECATED
|
||||
validEventDescriptors3.append(validEventDescriptor3);
|
||||
|
||||
// Interface based event descriptor
|
||||
@ -1446,7 +1422,7 @@ void TestRules::loadStoreConfig()
|
||||
QVERIFY2(stateDescriptor.value("interface") == "battery", "Interface of stateDescriptor does not match");
|
||||
QVERIFY2(stateDescriptor.value("interfaceState") == "batteryCritical", "InterfaceState of stateDescriptor doesn't match");
|
||||
} else {
|
||||
QVERIFY2(false, "StateDescriptor must have either deviceId/stateTypeId or interface/interfaceState.");
|
||||
QVERIFY2(false, "StateDescriptor must have either thingId/stateTypeId or interface/interfaceState.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -99,11 +99,11 @@ void TestScripts::testScriptEventById()
|
||||
QString script = QString("import QtQuick 2.0\n"
|
||||
"import nymea 1.0\n"
|
||||
"Item {\n"
|
||||
" DeviceEvent {\n"
|
||||
" deviceId: \"%1\"\n"
|
||||
" ThingEvent {\n"
|
||||
" thingId: \"%1\"\n"
|
||||
" eventTypeId: \"%2\"\n"
|
||||
" onTriggered: {\n"
|
||||
" TestHelper.logEvent(deviceId, eventTypeId, params);\n"
|
||||
" TestHelper.logEvent(thingId, eventTypeId, params);\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n").arg(m_mockThingId.toString()).arg(mockPowerEventTypeId.toString());
|
||||
@ -135,11 +135,11 @@ void TestScripts::testScriptEventByName()
|
||||
QString script = QString("import QtQuick 2.0\n"
|
||||
"import nymea 1.0\n"
|
||||
"Item {\n"
|
||||
" DeviceEvent {\n"
|
||||
" deviceId: \"%1\"\n"
|
||||
" ThingEvent {\n"
|
||||
" thingId: \"%1\"\n"
|
||||
" eventName: \"%2\"\n"
|
||||
" onTriggered: {\n"
|
||||
" TestHelper.logEvent(deviceId, eventName, params);\n"
|
||||
" TestHelper.logEvent(thingId, eventName, params);\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n").arg(m_mockThingId.toString()).arg("power");
|
||||
@ -171,11 +171,11 @@ void TestScripts::testReadScriptStateById()
|
||||
QString script = QString("import QtQuick 2.0\n"
|
||||
"import nymea 1.0\n"
|
||||
"Item {\n"
|
||||
" DeviceState {\n"
|
||||
" deviceId: \"%1\"\n"
|
||||
" ThingState {\n"
|
||||
" thingId: \"%1\"\n"
|
||||
" stateTypeId: \"%2\"\n"
|
||||
" onValueChanged: {\n"
|
||||
" TestHelper.logStateChange(deviceId, stateTypeId, value);\n"
|
||||
" TestHelper.logStateChange(thingId, stateTypeId, value);\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n").arg(m_mockThingId.toString()).arg(mockPowerStateTypeId.toString());
|
||||
@ -204,11 +204,11 @@ void TestScripts::testReadScriptStateByNyme()
|
||||
QString script = QString("import QtQuick 2.0\n"
|
||||
"import nymea 1.0\n"
|
||||
"Item {\n"
|
||||
" DeviceState {\n"
|
||||
" deviceId: \"%1\"\n"
|
||||
" ThingState {\n"
|
||||
" thingId: \"%1\"\n"
|
||||
" stateName: \"%2\"\n"
|
||||
" onValueChanged: {\n"
|
||||
" TestHelper.logStateChange(deviceId, stateName, value);\n"
|
||||
" TestHelper.logStateChange(thingId, stateName, value);\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n").arg(m_mockThingId.toString()).arg("power");
|
||||
@ -237,15 +237,15 @@ void TestScripts::testWriteScriptStateById()
|
||||
QString script = QString("import QtQuick 2.0\n"
|
||||
"import nymea 1.0\n"
|
||||
"Item {\n"
|
||||
" DeviceState {\n"
|
||||
" id: deviceState\n"
|
||||
" deviceId: \"%1\"\n"
|
||||
" ThingState {\n"
|
||||
" id: thingState\n"
|
||||
" thingId: \"%1\"\n"
|
||||
" stateTypeId: \"%2\"\n"
|
||||
" }\n"
|
||||
" Connections {\n"
|
||||
" target: TestHelper\n"
|
||||
" onSetState: {\n"
|
||||
" deviceState.value = value\n"
|
||||
" thingState.value = value\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n").arg(m_mockThingId.toString()).arg(mockPowerStateTypeId.toString());
|
||||
@ -271,15 +271,15 @@ void TestScripts::testWriteScriptStateByName()
|
||||
QString script = QString("import QtQuick 2.0\n"
|
||||
"import nymea 1.0\n"
|
||||
"Item {\n"
|
||||
" DeviceState {\n"
|
||||
" id: deviceState\n"
|
||||
" deviceId: \"%1\"\n"
|
||||
" ThingState {\n"
|
||||
" id: thingState\n"
|
||||
" thingId: \"%1\"\n"
|
||||
" stateName: \"%2\"\n"
|
||||
" }\n"
|
||||
" Connections {\n"
|
||||
" target: TestHelper\n"
|
||||
" onSetState: {\n"
|
||||
" deviceState.value = value\n"
|
||||
" thingState.value = value\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n").arg(m_mockThingId.toString()).arg("power");
|
||||
@ -305,15 +305,15 @@ void TestScripts::testScriptActionById()
|
||||
QString script = QString("import QtQuick 2.0\n"
|
||||
"import nymea 1.0\n"
|
||||
"Item {\n"
|
||||
" DeviceAction {\n"
|
||||
" id: deviceAction\n"
|
||||
" deviceId: \"%1\"\n"
|
||||
" ThingAction {\n"
|
||||
" id: thingAction\n"
|
||||
" thingId: \"%1\"\n"
|
||||
" actionTypeId: \"%2\"\n"
|
||||
" }\n"
|
||||
" Connections {\n"
|
||||
" target: TestHelper\n"
|
||||
" onExecuteAction: {\n"
|
||||
" deviceAction.execute(params)\n"
|
||||
" thingAction.execute(params)\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n").arg(m_mockThingId.toString()).arg(mockPowerActionTypeId.toString());
|
||||
@ -341,15 +341,15 @@ void TestScripts::testScriptActionByName()
|
||||
QString script = QString("import QtQuick 2.0\n"
|
||||
"import nymea 1.0\n"
|
||||
"Item {\n"
|
||||
" DeviceAction {\n"
|
||||
" id: deviceAction\n"
|
||||
" deviceId: \"%1\"\n"
|
||||
" ThingAction {\n"
|
||||
" id: thingAction\n"
|
||||
" thingId: \"%1\"\n"
|
||||
" actionName: \"%2\"\n"
|
||||
" }\n"
|
||||
" Connections {\n"
|
||||
" target: TestHelper\n"
|
||||
" onExecuteAction: {\n"
|
||||
" deviceAction.execute(params)\n"
|
||||
" thingAction.execute(params)\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n").arg(m_mockThingId.toString()).arg("power");
|
||||
|
||||
@ -1,5 +0,0 @@
|
||||
include(../../../nymea.pri)
|
||||
include(../autotests.pri)
|
||||
|
||||
TARGET = states
|
||||
SOURCES += teststates.cpp
|
||||
@ -1,144 +0,0 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2020, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
* This project including source code and documentation is protected by
|
||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
||||
* reproduction, publication, editing and translation, are reserved. The use of
|
||||
* this project is subject to the terms of a license agreement to be concluded
|
||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
||||
* under https://nymea.io/license
|
||||
*
|
||||
* GNU General Public License Usage
|
||||
* Alternatively, this project may be redistributed and/or modified under the
|
||||
* terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, GNU version 3. This project 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 General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For any further details and any questions please contact us under
|
||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
||||
* https://nymea.io/license/faq
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#include "nymeatestbase.h"
|
||||
#include "nymeacore.h"
|
||||
#include "jsonrpc/devicehandler.h"
|
||||
|
||||
using namespace nymeaserver;
|
||||
|
||||
class TestStates: public NymeaTestBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void getStateTypes();
|
||||
|
||||
void getStateValue_data();
|
||||
void getStateValue();
|
||||
|
||||
void save_load_states();
|
||||
};
|
||||
|
||||
void TestStates::getStateTypes()
|
||||
{
|
||||
QVariantMap params;
|
||||
params.insert("deviceClassId", mockThingClassId);
|
||||
QVariant response = injectAndWait("Devices.GetStateTypes", params);
|
||||
QVERIFY(!response.isNull());
|
||||
//verifyDeviceError(response);
|
||||
}
|
||||
|
||||
void TestStates::getStateValue_data()
|
||||
{
|
||||
QList<Thing*> devices = NymeaCore::instance()->thingManager()->findConfiguredThings(mockThingClassId);
|
||||
QVERIFY2(devices.count() > 0, "There needs to be at least one configured Mock Device for this test");
|
||||
Thing *device = devices.first();
|
||||
|
||||
QTest::addColumn<ThingId>("deviceId");
|
||||
QTest::addColumn<StateTypeId>("stateTypeId");
|
||||
QTest::addColumn<Device::DeviceError>("error");
|
||||
|
||||
QTest::newRow("existing state") << device->id() << mockIntStateTypeId << Device::DeviceErrorNoError;
|
||||
QTest::newRow("invalid device") << ThingId::createThingId() << mockIntStateTypeId << Device::DeviceErrorDeviceNotFound;
|
||||
QTest::newRow("invalid statetype") << device->id() << StateTypeId::createStateTypeId() << Device::DeviceErrorStateTypeNotFound;
|
||||
}
|
||||
|
||||
void TestStates::getStateValue()
|
||||
{
|
||||
QFETCH(ThingId, deviceId);
|
||||
QFETCH(StateTypeId, stateTypeId);
|
||||
QFETCH(Device::DeviceError, error);
|
||||
|
||||
QVariantMap params;
|
||||
params.insert("deviceId", deviceId.toString());
|
||||
params.insert("stateTypeId", stateTypeId.toString());
|
||||
|
||||
QVariant response = injectAndWait("Devices.GetStateValue", params);
|
||||
|
||||
verifyError(response, "deviceError", enumValueName(error));
|
||||
}
|
||||
|
||||
void TestStates::save_load_states()
|
||||
{
|
||||
ThingClass mockDeviceClass = NymeaCore::instance()->thingManager()->findThingClass(mockThingClassId);
|
||||
|
||||
QVERIFY2(mockDeviceClass.getStateType(mockIntStateTypeId).cached(), "Mock int state is not cached (required to be true for this test)");
|
||||
QVERIFY2(!mockDeviceClass.getStateType(mockBoolStateTypeId).cached(), "Mock bool state is cached (required to be false for this test)");
|
||||
|
||||
Thing* device = NymeaCore::instance()->thingManager()->findConfiguredThings(mockThingClassId).first();
|
||||
int port = device->paramValue(mockThingHttpportParamTypeId).toInt();
|
||||
QNetworkAccessManager nam;
|
||||
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
|
||||
|
||||
|
||||
// First set the state values to something that is *not* the default
|
||||
int newIntValue = mockDeviceClass.getStateType(mockIntStateTypeId).defaultValue().toInt() + 1;
|
||||
bool newBoolValue = !mockDeviceClass.getStateType(mockBoolStateTypeId).defaultValue().toBool();
|
||||
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(port).arg(mockIntStateTypeId.toString()).arg(newIntValue)));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
||||
spy.wait();
|
||||
|
||||
spy.clear();
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(port).arg(mockBoolStateTypeId.toString()).arg(newBoolValue)));
|
||||
reply = nam.get(request);
|
||||
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
||||
spy.wait();
|
||||
|
||||
// For completeness, verify through JSONRPC that they were actually yet.
|
||||
QVariantMap params;
|
||||
params.insert("deviceId", device->id());
|
||||
|
||||
params["stateTypeId"] = mockIntStateTypeId;
|
||||
QVariant response = injectAndWait("Devices.GetStateValue", params);
|
||||
QCOMPARE(response.toMap().value("params").toMap().value("value").toInt(), newIntValue);
|
||||
|
||||
params["stateTypeId"] = mockBoolStateTypeId;
|
||||
response = injectAndWait("Devices.GetStateValue", params);
|
||||
QCOMPARE(response.toMap().value("params").toMap().value("value").toBool(), newBoolValue);
|
||||
|
||||
// Restart the server
|
||||
restartServer();
|
||||
|
||||
// And check if the cached int state has successfully been restored
|
||||
params["stateTypeId"] = mockIntStateTypeId;
|
||||
response = injectAndWait("Devices.GetStateValue", params);
|
||||
QCOMPARE(response.toMap().value("params").toMap().value("value").toInt(), newIntValue);
|
||||
|
||||
// and that the non-cached bool state is back to its default
|
||||
params["stateTypeId"] = mockBoolStateTypeId;
|
||||
response = injectAndWait("Devices.GetStateValue", params);
|
||||
QCOMPARE(response.toMap().value("params").toMap().value("value").toBool(), mockDeviceClass.getStateType(mockBoolStateTypeId).defaultValue().toBool());
|
||||
}
|
||||
|
||||
#include "teststates.moc"
|
||||
QTEST_MAIN(TestStates)
|
||||
@ -83,7 +83,6 @@ QVariantMap TestTags::createRuleTag(const QString &ruleId, const QString &appId,
|
||||
bool TestTags::compareThingTag(const QVariantMap &tag, const QUuid &thingId, const QString &appId, const QString &tagId, const QString &value)
|
||||
{
|
||||
return tag.value("thingId").toUuid() == thingId &&
|
||||
tag.value("deviceId").toUuid() == thingId && // backwards compatibility to < 0.19 adds deviceId along with thingId
|
||||
tag.value("appId").toString() == appId &&
|
||||
tag.value("tagId").toString() == tagId &&
|
||||
tag.value("value").toString() == value;
|
||||
|
||||
@ -141,14 +141,13 @@ private:
|
||||
|
||||
void TestTimeManager::initTestCase()
|
||||
{
|
||||
NymeaTestBase::initTestCase();
|
||||
QLoggingCategory::setFilterRules("*.debug=false\n"
|
||||
"Tests.debug=true\n"
|
||||
"RuleEngine.debug=true\n"
|
||||
// "RuleEngineDebug.debug=true\n"
|
||||
"Mock.debug=true\n"
|
||||
"JsonRpc.debug=true\n"
|
||||
"TimeManager.debug=true");
|
||||
NymeaTestBase::initTestCase("*.debug=false\n"
|
||||
"Tests.debug=true\n"
|
||||
"RuleEngine.debug=true\n"
|
||||
// "RuleEngineDebug.debug=true\n"
|
||||
"Mock.debug=true\n"
|
||||
"JsonRpc.debug=true\n"
|
||||
"TimeManager.debug=true");
|
||||
}
|
||||
|
||||
void TestTimeManager::loadSaveTimeDescriptor_data()
|
||||
@ -2028,7 +2027,7 @@ void TestTimeManager::initTimeManager()
|
||||
{
|
||||
cleanupMockHistory();
|
||||
removeAllRules();
|
||||
enableNotifications({"Rules", "Integrations", "Events"});
|
||||
enableNotifications({"Rules", "Integrations"});
|
||||
NymeaCore::instance()->timeManager()->stopTimer();
|
||||
qDebug() << NymeaCore::instance()->timeManager()->currentDateTime().toString();
|
||||
}
|
||||
@ -2183,14 +2182,14 @@ void TestTimeManager::triggerMockEvent1()
|
||||
if (eventSpy.isEmpty()) {
|
||||
eventSpy.wait();
|
||||
}
|
||||
QVariantList eventTriggerVariants = checkNotifications(eventSpy, "Events.EventTriggered");
|
||||
QVariantList eventTriggerVariants = checkNotifications(eventSpy, "Integrations.EventTriggered");
|
||||
QVERIFY2(eventTriggerVariants.count() == 1, "Did not get Events.EventTriggered notification.");
|
||||
QVERIFY2(eventTriggerVariants.first().toMap().value("params").toMap().contains("event"), "Notification Events.EventTriggered does not contain event.");
|
||||
QVariantMap eventMap = eventTriggerVariants.first().toMap().value("params").toMap().value("event").toMap();
|
||||
|
||||
QVERIFY2(eventMap.contains("thingId"), "Events.EventTriggered notification does not contain thingId");
|
||||
QVERIFY2(ThingId(eventMap.value("thingId").toString()) == m_mockThingId, "Events.EventTriggered notification does not contain the correct thingId");
|
||||
QVERIFY2(eventMap.contains("eventTypeId"), "Events.EventTriggered notification does not contain eventTypeId");
|
||||
QVERIFY2(eventMap.contains("thingId"), "Integrations.EventTriggered notification does not contain thingId");
|
||||
QVERIFY2(ThingId(eventMap.value("thingId").toString()) == m_mockThingId, "Integrations.EventTriggered notification does not contain the correct thingId");
|
||||
QVERIFY2(eventMap.contains("eventTypeId"), "Integrations.EventTriggered notification does not contain eventTypeId");
|
||||
QVERIFY2(EventTypeId(eventMap.value("eventTypeId").toString()) == mockEvent1EventTypeId, "Events.EventTriggered notification does not contain the correct eventTypeId");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user