More work
This commit is contained in:
parent
3e425fc55b
commit
2fbbaeda97
@ -110,7 +110,7 @@ JsonReply* ActionHandler::ExecuteAction(const QVariantMap ¶ms, const JsonCon
|
||||
ThingActionInfo *info = NymeaCore::instance()->executeAction(action);
|
||||
connect(info, &ThingActionInfo::finished, jsonReply, [info, jsonReply, locale](){
|
||||
QVariantMap data;
|
||||
data.insert("deviceError", enumValueName(info->status()).replace("ThingError", "DeviceError"));
|
||||
data.insert("deviceError", enumValueName(info->status()).replace("Thing", "Device"));
|
||||
if (!info->displayMessage().isEmpty()) {
|
||||
data.insert("displayMessage", info->translatedDisplayMessage(locale));
|
||||
}
|
||||
|
||||
@ -75,6 +75,7 @@ DeviceHandler::DeviceHandler(QObject *parent) :
|
||||
registerObject<ActionType, ActionTypes>();
|
||||
registerObject<DeviceClass, DeviceClasses>();
|
||||
registerObject<DeviceDescriptor, DeviceDescriptors>();
|
||||
registerObject<ThingDescriptor, ThingDescriptors>();
|
||||
registerObject<Event>();
|
||||
registerObject<Action>();
|
||||
registerObject<State, States>();
|
||||
@ -426,12 +427,16 @@ JsonReply *DeviceHandler::GetDiscoveredDevices(const QVariantMap ¶ms, const
|
||||
ThingDiscoveryInfo *info = NymeaCore::instance()->thingManager()->discoverThings(thingClassId, discoveryParams);
|
||||
connect(info, &ThingDiscoveryInfo::finished, reply, [this, reply, info, locale](){
|
||||
QVariantMap returns;
|
||||
returns.insert("deviceError", enumValueName<Device::ThingError>(info->status()).replace("ThingError", "DeviceError"));
|
||||
returns.insert("deviceError", enumValueName<Device::ThingError>(info->status()).replace("Thing", "Device"));
|
||||
|
||||
if (info->status() == Device::ThingErrorNoError) {
|
||||
QVariantList deviceDescriptorList;
|
||||
foreach (const ThingDescriptor &deviceDescriptor, info->thingDescriptors()) {
|
||||
deviceDescriptorList.append(pack(deviceDescriptor));
|
||||
foreach (const ThingDescriptor &thingDescriptor, info->thingDescriptors()) {
|
||||
QVariantMap packedDescriptor = pack(thingDescriptor).toMap();
|
||||
if (packedDescriptor.contains("thingId")) {
|
||||
packedDescriptor.insert("deviceId", packedDescriptor.value("thingId"));
|
||||
}
|
||||
deviceDescriptorList.append(packedDescriptor);
|
||||
}
|
||||
returns.insert("deviceDescriptors", deviceDescriptorList);
|
||||
}
|
||||
@ -468,7 +473,7 @@ JsonReply *DeviceHandler::GetPluginConfiguration(const QVariantMap ¶ms) cons
|
||||
|
||||
IntegrationPlugin *plugin = NymeaCore::instance()->thingManager()->plugins().findById(PluginId(params.value("pluginId").toString()));
|
||||
if (!plugin) {
|
||||
returns.insert("deviceError", enumValueName<Device::ThingError>(Device::ThingErrorPluginNotFound).replace("ThingError", "DeviceError"));
|
||||
returns.insert("deviceError", enumValueName<Device::ThingError>(Device::ThingErrorPluginNotFound).replace("Thing", "Device"));
|
||||
return createReply(returns);
|
||||
}
|
||||
|
||||
@ -477,7 +482,7 @@ JsonReply *DeviceHandler::GetPluginConfiguration(const QVariantMap ¶ms) cons
|
||||
paramVariantList.append(pack(param));
|
||||
}
|
||||
returns.insert("configuration", paramVariantList);
|
||||
returns.insert("deviceError", enumValueName<Device::ThingError>(Device::ThingErrorNoError).replace("ThingError", "DeviceError"));
|
||||
returns.insert("deviceError", enumValueName<Device::ThingError>(Device::ThingErrorNoError).replace("Thing", "Device"));
|
||||
return createReply(returns);
|
||||
}
|
||||
|
||||
@ -487,7 +492,7 @@ JsonReply* DeviceHandler::SetPluginConfiguration(const QVariantMap ¶ms)
|
||||
PluginId pluginId = PluginId(params.value("pluginId").toString());
|
||||
ParamList pluginParams = unpack<ParamList>(params.value("configuration"));
|
||||
Device::ThingError result = NymeaCore::instance()->thingManager()->setPluginConfig(pluginId, pluginParams);
|
||||
returns.insert("deviceError",enumValueName<Device::ThingError>(result).replace("ThingError", "DeviceError"));
|
||||
returns.insert("deviceError",enumValueName<Device::ThingError>(result).replace("Thing", "Device"));
|
||||
return createReply(returns);
|
||||
}
|
||||
|
||||
@ -509,7 +514,7 @@ JsonReply* DeviceHandler::AddConfiguredDevice(const QVariantMap ¶ms, const J
|
||||
}
|
||||
connect(info, &ThingSetupInfo::finished, jsonReply, [info, jsonReply, locale](){
|
||||
QVariantMap returns;
|
||||
returns.insert("deviceError", enumValueName<Device::ThingError>(info->status()).replace("ThingError", "DeviceError"));
|
||||
returns.insert("deviceError", enumValueName<Device::ThingError>(info->status()).replace("Thing", "Device"));
|
||||
|
||||
if (!info->displayMessage().isEmpty()) {
|
||||
returns.insert("displayMessage", info->translatedDisplayMessage(locale));
|
||||
@ -547,7 +552,7 @@ JsonReply *DeviceHandler::PairDevice(const QVariantMap ¶ms, const JsonContex
|
||||
|
||||
connect(info, &ThingPairingInfo::finished, jsonReply, [jsonReply, info, locale](){
|
||||
QVariantMap returns;
|
||||
returns.insert("deviceError", enumValueName<Device::ThingError>(info->status()).replace("ThingError", "DeviceError"));
|
||||
returns.insert("deviceError", enumValueName<Device::ThingError>(info->status()).replace("Thing", "Device"));
|
||||
returns.insert("pairingTransactionId", info->transactionId().toString());
|
||||
|
||||
if (info->status() == Device::ThingErrorNoError) {
|
||||
@ -583,7 +588,7 @@ JsonReply *DeviceHandler::ConfirmPairing(const QVariantMap ¶ms, const JsonCo
|
||||
connect(info, &ThingPairingInfo::finished, jsonReply, [info, jsonReply, locale](){
|
||||
|
||||
QVariantMap returns;
|
||||
returns.insert("deviceError", enumValueName<Device::ThingError>(info->status()).replace("ThingError", "DeviceError"));
|
||||
returns.insert("deviceError", enumValueName<Device::ThingError>(info->status()).replace("Thing", "Device"));
|
||||
if (!info->displayMessage().isEmpty()) {
|
||||
returns.insert("displayMessage", info->translatedDisplayMessage(locale));
|
||||
}
|
||||
@ -683,7 +688,7 @@ JsonReply* DeviceHandler::RemoveConfiguredDevice(const QVariantMap ¶ms)
|
||||
if (params.contains("removePolicy")) {
|
||||
RuleEngine::RemovePolicy removePolicy = params.value("removePolicy").toString() == "RemovePolicyCascade" ? RuleEngine::RemovePolicyCascade : RuleEngine::RemovePolicyUpdate;
|
||||
Device::ThingError status = NymeaCore::instance()->removeConfiguredThing(thingId, removePolicy);
|
||||
returns.insert("deviceError", enumValueName<Device::ThingError>(status));
|
||||
returns.insert("deviceError", enumValueName<Device::ThingError>(status).replace("Thing", "Device"));
|
||||
return createReply(returns);
|
||||
}
|
||||
|
||||
@ -833,7 +838,7 @@ JsonReply *DeviceHandler::ExecuteAction(const QVariantMap ¶ms, const JsonCon
|
||||
ThingActionInfo *info = NymeaCore::instance()->executeAction(action);
|
||||
connect(info, &ThingActionInfo::finished, jsonReply, [info, jsonReply, locale](){
|
||||
QVariantMap data;
|
||||
data.insert("deviceError", enumValueName(info->status()).replace("ThingError", "DeviceError"));
|
||||
data.insert("deviceError", enumValueName(info->status()).replace("Thing", "Device"));
|
||||
if (!info->displayMessage().isEmpty()) {
|
||||
data.insert("displayMessage", info->translatedDisplayMessage(locale));
|
||||
}
|
||||
@ -855,7 +860,7 @@ JsonReply *DeviceHandler::ExecuteBrowserItem(const QVariantMap ¶ms)
|
||||
BrowserActionInfo *info = NymeaCore::instance()->executeBrowserItem(action);
|
||||
connect(info, &BrowserActionInfo::finished, jsonReply, [info, jsonReply](){
|
||||
QVariantMap data;
|
||||
data.insert("deviceError", enumValueName<Device::ThingError>(info->status()).replace("ThingError", "DeviceError"));
|
||||
data.insert("deviceError", enumValueName<Device::ThingError>(info->status()).replace("Thing", "Device"));
|
||||
jsonReply->setData(data);
|
||||
jsonReply->finished();
|
||||
});
|
||||
@ -876,7 +881,7 @@ JsonReply *DeviceHandler::ExecuteBrowserItemAction(const QVariantMap ¶ms)
|
||||
BrowserItemActionInfo *info = NymeaCore::instance()->executeBrowserItemAction(browserItemAction);
|
||||
connect(info, &BrowserItemActionInfo::finished, jsonReply, [info, jsonReply](){
|
||||
QVariantMap data;
|
||||
data.insert("deviceError", enumValueName<Device::ThingError>(info->status()));
|
||||
data.insert("deviceError", enumValueName<Device::ThingError>(info->status()).replace("Thing", "Device"));
|
||||
jsonReply->setData(data);
|
||||
jsonReply->finished();
|
||||
});
|
||||
@ -938,15 +943,19 @@ void DeviceHandler::deviceAddedNotification(Thing *thing)
|
||||
{
|
||||
QVariantMap params;
|
||||
QVariantMap deviceMap = pack(thing).toMap();
|
||||
// Patch in deviceClassId
|
||||
deviceMap.insert("deviceClassId", deviceMap.value("thingClassId"));
|
||||
params.insert("device", deviceMap);
|
||||
emit DeviceAdded(params);
|
||||
}
|
||||
|
||||
void DeviceHandler::deviceChangedNotification(Thing *device)
|
||||
void DeviceHandler::deviceChangedNotification(Thing *thing)
|
||||
{
|
||||
QVariantMap params;
|
||||
params.insert("device", pack(device));
|
||||
QVariantMap deviceMap = pack(thing).toMap();
|
||||
// Patch in deviceClassId
|
||||
deviceMap.insert("deviceClassId", deviceMap.value("thingClassId"));
|
||||
params.insert("device", deviceMap);
|
||||
emit DeviceChanged(params);
|
||||
}
|
||||
|
||||
|
||||
@ -190,7 +190,7 @@ private slots:
|
||||
|
||||
void deviceAddedNotification(Thing *thing);
|
||||
|
||||
void deviceChangedNotification(Thing *device);
|
||||
void deviceChangedNotification(Thing *thing);
|
||||
|
||||
void deviceSettingChangedNotification(const ThingId &thingId, const ParamTypeId ¶mTypeId, const QVariant &value);
|
||||
|
||||
|
||||
@ -48,10 +48,9 @@
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
/*! Constructs a new \l DeviceHandler with the given \a parent. */
|
||||
IntegrationsHandler::IntegrationsHandler(ThingManager *deviceManager, QObject *parent) :
|
||||
IntegrationsHandler::IntegrationsHandler(ThingManager *thingManager, QObject *parent) :
|
||||
JsonHandler(parent),
|
||||
m_deviceManager(deviceManager)
|
||||
m_thingManager(thingManager)
|
||||
{
|
||||
// Enums
|
||||
registerEnum<Thing::ThingError>();
|
||||
@ -79,8 +78,8 @@ IntegrationsHandler::IntegrationsHandler(ThingManager *deviceManager, QObject *p
|
||||
registerObject<State, States>();
|
||||
registerUncreatableObject<Thing, Things>();
|
||||
|
||||
// Regsitering browseritem manually for now. Not sure how to deal with the
|
||||
// polymorphism in int (e.g MediaBrowserItem)
|
||||
// Registering browseritem manually for now. Not sure how to deal with the
|
||||
// polymorphism in it (e.g MediaBrowserItem)
|
||||
QVariantMap browserItem;
|
||||
browserItem.insert("id", enumValueName(String));
|
||||
browserItem.insert("displayName", enumValueName(String));
|
||||
@ -99,13 +98,14 @@ IntegrationsHandler::IntegrationsHandler(ThingManager *deviceManager, QObject *p
|
||||
QString description; QVariantMap returns; QVariantMap params;
|
||||
description = "Returns a list of supported Vendors.";
|
||||
returns.insert("vendors", objectRef<Vendors>());
|
||||
registerMethod("GetSupportedVendors", description, params, returns);
|
||||
registerMethod("GetVendors", description, params, returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
description = "Returns a list of supported Device classes, optionally filtered by vendorId.";
|
||||
description = "Returns a list of supported thing classes, optionally filtered by vendorId.";
|
||||
params.insert("o:vendorId", enumValueName(Uuid));
|
||||
returns.insert("deviceClasses", objectRef<ThingClass>());
|
||||
registerMethod("GetSupportedDevices", description, params, returns);
|
||||
returns.insert("thingError", enumRef<Thing::ThingError>());
|
||||
returns.insert("o:thingClasses", objectRef<ThingClasses>());
|
||||
registerMethod("GetThingClasses", description, params, returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
description = "Returns a list of loaded plugins.";
|
||||
@ -115,7 +115,7 @@ IntegrationsHandler::IntegrationsHandler(ThingManager *deviceManager, QObject *p
|
||||
params.clear(); returns.clear();
|
||||
description = "Get a plugin's params.";
|
||||
params.insert("pluginId", enumValueName(Uuid));
|
||||
returns.insert("deviceError", enumRef<Thing::ThingError>());
|
||||
returns.insert("thingError", enumRef<Thing::ThingError>());
|
||||
returns.insert("o:configuration", objectRef<ParamList>());
|
||||
registerMethod("GetPluginConfiguration", description, params, returns);
|
||||
|
||||
@ -123,55 +123,56 @@ IntegrationsHandler::IntegrationsHandler(ThingManager *deviceManager, QObject *p
|
||||
description = "Set a plugin's params.";
|
||||
params.insert("pluginId", enumValueName(Uuid));
|
||||
params.insert("configuration", objectRef<ParamList>());
|
||||
returns.insert("deviceError", enumRef<Thing::ThingError>());
|
||||
returns.insert("thingError", enumRef<Thing::ThingError>());
|
||||
registerMethod("SetPluginConfiguration", description, params, returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
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.";
|
||||
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.insert("thingClassId", enumValueName(Uuid));
|
||||
params.insert("name", enumValueName(String));
|
||||
params.insert("o:deviceDescriptorId", enumValueName(Uuid));
|
||||
params.insert("o:deviceParams", objectRef<ParamList>());
|
||||
returns.insert("deviceError", enumRef<Thing::ThingError>());
|
||||
returns.insert("o:deviceId", enumValueName(Uuid));
|
||||
params.insert("o:thingDescriptorId", enumValueName(Uuid));
|
||||
params.insert("o:thingParams", objectRef<ParamList>());
|
||||
returns.insert("thingError", enumRef<Thing::ThingError>());
|
||||
returns.insert("o:thingId", enumValueName(Uuid));
|
||||
returns.insert("o:displayMessage", enumValueName(String));
|
||||
registerMethod("AddConfiguredDevice", description, params, returns);
|
||||
registerMethod("AddThing", description, params, returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
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:\n"
|
||||
"CreateMethodJustAdd takes the thingClassId and the parameters you want to have with that device.\n"
|
||||
"CreateMethodDiscovery requires the use of a deviceDescriptorId, previously obtained with DiscoverDevices. Optionally, "
|
||||
"parameters can be overridden with the give deviceParams.\n"
|
||||
"If an existing device should be reconfigured, the deviceId of said device should be given additionally.\n"
|
||||
"If 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.\n"
|
||||
"Once the login procedure has completed, the application shall proceed with ConfirmPairing, providing the results of the pairing "
|
||||
"procedure.";
|
||||
params.insert("o:ThingClassId", enumValueName(Uuid));
|
||||
description = "Pair a new thing. "
|
||||
"Use this to set up or reconfigure things for ThingClasses with a setupMethod different than SetupMethodJustAdd. "
|
||||
"Depending on the CreateMethod and whether a new thing is set up or an existing one is reconfigured, different parameters "
|
||||
"are required:\n"
|
||||
"CreateMethodJustAdd takes the thingClassId and the parameters you want to have with that thing.\n"
|
||||
"CreateMethodDiscovery requires the use of a thingDescriptorId, previously obtained with DiscoverThings. Optionally, "
|
||||
"parameters can be overridden with the give thingParams.\n"
|
||||
"If an existing thing should be reconfigured, the thingId of said thing should be given additionally.\n"
|
||||
"If 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 or online service, for SetupMethodEnterPin the "
|
||||
"application should present the given PIN so the user can enter it on the device or online service. 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.\n"
|
||||
"Once the login procedure has completed, the application shall proceed with ConfirmPairing, providing the results of the pairing "
|
||||
"procedure.";
|
||||
params.insert("o:thingClassId", enumValueName(Uuid));
|
||||
params.insert("o:name", enumValueName(String));
|
||||
params.insert("o:deviceDescriptorId", enumValueName(Uuid));
|
||||
params.insert("o:deviceParams", objectRef<ParamList>());
|
||||
params.insert("o:deviceId", enumValueName(Uuid));
|
||||
returns.insert("deviceError", enumRef<Thing::ThingError>());
|
||||
params.insert("o:thingDescriptorId", enumValueName(Uuid));
|
||||
params.insert("o:thingParams", objectRef<ParamList>());
|
||||
params.insert("o:thingId", enumValueName(Uuid));
|
||||
returns.insert("thingError", enumRef<Thing::ThingError>());
|
||||
returns.insert("o:setupMethod", enumRef<ThingClass::SetupMethod>());
|
||||
returns.insert("o:pairingTransactionId", enumValueName(Uuid));
|
||||
returns.insert("o:displayMessage", enumValueName(String));
|
||||
returns.insert("o:oAuthUrl", enumValueName(String));
|
||||
returns.insert("o:pin", enumValueName(String));
|
||||
registerMethod("PairDevice", description, params, returns);
|
||||
registerMethod("PairThing", description, params, returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
description = "Confirm an ongoing pairing. For SetupMethodUserAndPassword, provide the username in the \"username\" field "
|
||||
@ -181,64 +182,63 @@ IntegrationsHandler::IntegrationsHandler(ThingManager *deviceManager, QObject *p
|
||||
params.insert("pairingTransactionId", enumValueName(Uuid));
|
||||
params.insert("o:username", enumValueName(String));
|
||||
params.insert("o:secret", enumValueName(String));
|
||||
returns.insert("deviceError", enumRef<Thing::ThingError>());
|
||||
returns.insert("thingError", enumRef<Thing::ThingError>());
|
||||
returns.insert("o:displayMessage", enumValueName(String));
|
||||
returns.insert("o:deviceId", enumValueName(Uuid));
|
||||
returns.insert("o:thingId", enumValueName(Uuid));
|
||||
registerMethod("ConfirmPairing", description, params, returns);
|
||||
|
||||
// FIXME: Add thingError!!!
|
||||
params.clear(); returns.clear();
|
||||
description = "Returns a list of configured devices, optionally filtered by deviceId.";
|
||||
params.insert("o:deviceId", enumValueName(Uuid));
|
||||
returns.insert("devices", objectRef<Things>());
|
||||
registerMethod("GetConfiguredDevices", description, params, returns);
|
||||
description = "Returns a list of configured things, optionally filtered by thingId.";
|
||||
params.insert("o:thingId", enumValueName(Uuid));
|
||||
returns.insert("o:things", objectRef<Things>());
|
||||
returns.insert("thingError", enumRef<Thing::ThingError>());
|
||||
registerMethod("GetThings", description, params, returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
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 may "
|
||||
"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.";
|
||||
description = "Performs a thing discovery for things of the given thingClassId and returns the results. "
|
||||
"This function may take a while to return. Note that this method will include all the found "
|
||||
"things, that is, including things that may already have been added. Those things will have "
|
||||
"thingId set to the id of the already added thing. Such results may be used to reconfigure "
|
||||
"existing things and might be filtered in cases where only unknown things are of interest.";
|
||||
params.insert("thingClassId", enumValueName(Uuid));
|
||||
params.insert("o:discoveryParams", objectRef<ParamList>());
|
||||
returns.insert("deviceError", enumRef<Thing::ThingError>());
|
||||
returns.insert("thingError", enumRef<Thing::ThingError>());
|
||||
returns.insert("o:displayMessage", enumValueName(String));
|
||||
returns.insert("o:deviceDescriptors", objectRef<ThingDescriptors>());
|
||||
registerMethod("GetDiscoveredDevices", description, params, returns);
|
||||
returns.insert("o:thingDescriptors", objectRef<ThingDescriptors>());
|
||||
registerMethod("DiscoverThings", description, params, returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
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.insert("o:deviceId", enumValueName(Uuid));
|
||||
params.insert("o:deviceDescriptorId", enumValueName(Uuid));
|
||||
params.insert("o:deviceParams", objectRef<ParamList>());
|
||||
returns.insert("deviceError", enumRef<Thing::ThingError>());
|
||||
description = "Reconfigure a thing. This comes down to removing and recreating a thing with new parameters "
|
||||
"but keeping its thing id the same (and with that keeping rules, tags etc). For things with "
|
||||
"create method CreateMethodDiscovery, a discovery (DiscoverThings) shall be performed first "
|
||||
"and this method is to be called with a thingDescriptorId of the re-discovered thing instead of "
|
||||
"the thingId directly. Thing parameters will be taken from the discovery, but can be overridden "
|
||||
"individually here by providing them in the thingParams parameter. Only writable parameters can "
|
||||
"be changed.";
|
||||
params.insert("o:thingId", enumValueName(Uuid));
|
||||
params.insert("o:thingDescriptorId", enumValueName(Uuid));
|
||||
params.insert("o:thingParams", objectRef<ParamList>());
|
||||
returns.insert("thingError", enumRef<Thing::ThingError>());
|
||||
returns.insert("o:displayMessage", enumValueName(String));
|
||||
registerMethod("ReconfigureDevice", description, params, returns);
|
||||
registerMethod("ReconfigureThing", description, params, returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
description = "Edit the name of a device. This method does not change the "
|
||||
"configuration of the device.";
|
||||
params.insert("deviceId", enumValueName(Uuid));
|
||||
description = "Edit the name of a thing.";
|
||||
params.insert("thingId", enumValueName(Uuid));
|
||||
params.insert("name", enumValueName(String));
|
||||
returns.insert("deviceError", enumRef<Thing::ThingError>());
|
||||
registerMethod("EditDevice", description, params, returns);
|
||||
returns.insert("thingError", enumRef<Thing::ThingError>());
|
||||
registerMethod("EditThing", description, params, returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
description = "Change the settings of a device.";
|
||||
params.insert("deviceId", enumValueName(Uuid));
|
||||
description = "Change the settings of a thing.";
|
||||
params.insert("thingId", enumValueName(Uuid));
|
||||
params.insert("settings", objectRef<ParamList>());
|
||||
returns.insert("deviceError", enumRef<Thing::ThingError>());
|
||||
registerMethod("SetDeviceSettings", description, params, returns);
|
||||
returns.insert("thingError", enumRef<Thing::ThingError>());
|
||||
registerMethod("SetThingSettings", description, params, returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
description = "Remove a device from the system.";
|
||||
params.insert("deviceId", enumValueName(Uuid));
|
||||
description = "Remove a thing from the system.";
|
||||
params.insert("thingId", enumValueName(Uuid));
|
||||
params.insert("o:removePolicy", enumRef<RuleEngine::RemovePolicy>());
|
||||
QVariantMap policy;
|
||||
policy.insert("ruleId", enumValueName(Uuid));
|
||||
@ -246,9 +246,9 @@ IntegrationsHandler::IntegrationsHandler(ThingManager *deviceManager, QObject *p
|
||||
QVariantList removePolicyList;
|
||||
removePolicyList.append(policy);
|
||||
params.insert("o:removePolicyList", removePolicyList);
|
||||
returns.insert("deviceError", enumRef<Thing::ThingError>());
|
||||
returns.insert("thingError", enumRef<Thing::ThingError>());
|
||||
returns.insert("o:ruleIds", QVariantList() << enumValueName(Uuid));
|
||||
registerMethod("RemoveConfiguredDevice", description, params, returns);
|
||||
registerMethod("RemoveThing", description, params, returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
description = "Get event types for a specified thingClassId.";
|
||||
@ -269,90 +269,95 @@ IntegrationsHandler::IntegrationsHandler(ThingManager *deviceManager, QObject *p
|
||||
registerMethod("GetStateTypes", description, params, returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
description = "Get the value of the given device and the given stateType";
|
||||
params.insert("deviceId", enumValueName(Uuid));
|
||||
description = "Get the value of the given thing and the given stateType";
|
||||
params.insert("thingId", enumValueName(Uuid));
|
||||
params.insert("stateTypeId", enumValueName(Uuid));
|
||||
returns.insert("deviceError", enumRef<Thing::ThingError>());
|
||||
returns.insert("thingError", enumRef<Thing::ThingError>());
|
||||
returns.insert("o:value", enumValueName(Variant));
|
||||
registerMethod("GetStateValue", description, params, returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
description = "Get all the state values of the given device.";
|
||||
params.insert("deviceId", enumValueName(Uuid));
|
||||
returns.insert("deviceError", enumRef<Thing::ThingError>());
|
||||
description = "Get all the state values of the given thing.";
|
||||
params.insert("thingId", enumValueName(Uuid));
|
||||
returns.insert("thingError", enumRef<Thing::ThingError>());
|
||||
returns.insert("o:values", objectRef<States>());
|
||||
registerMethod("GetStateValues", description, params, returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
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.";
|
||||
params.insert("deviceId", enumValueName(Uuid));
|
||||
description = "Browse a thing. "
|
||||
"If a ThingClass indicates a thing is browsable, this method will return the BrowserItems. If no "
|
||||
"parameter besides the thingId is used, the root node of this thingwill be returned. Any "
|
||||
"returned item which is browsable can be passed as node. Results will be children of the given node.";
|
||||
params.insert("thingId", enumValueName(Uuid));
|
||||
params.insert("o:itemId", enumValueName(String));
|
||||
returns.insert("deviceError", enumRef<Thing::ThingError>());
|
||||
returns.insert("thingError", enumRef<Thing::ThingError>());
|
||||
returns.insert("items", QVariantList() << objectRef("BrowserItem"));
|
||||
registerMethod("BrowseDevice", description, params, returns);
|
||||
registerMethod("BrowseThing", description, params, returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
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.";
|
||||
params.insert("deviceId", enumValueName(Uuid));
|
||||
description = "Get a single item from the browser. "
|
||||
"This won't give any more info on an item than a regular BrowseThing call, but it allows to fetch "
|
||||
"details of an item if only the ID is known.";
|
||||
params.insert("thingId", enumValueName(Uuid));
|
||||
params.insert("o:itemId", enumValueName(String));
|
||||
returns.insert("deviceError", enumRef<Thing::ThingError>());
|
||||
returns.insert("thingError", enumRef<Thing::ThingError>());
|
||||
returns.insert("o:item", objectRef("BrowserItem"));
|
||||
registerMethod("GetBrowserItem", description, params, returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
description = "Execute a single action.";
|
||||
params.insert("actionTypeId", enumValueName(Uuid));
|
||||
params.insert("deviceId", enumValueName(Uuid));
|
||||
params.insert("thingId", enumValueName(Uuid));
|
||||
params.insert("o:params", objectRef<ParamList>());
|
||||
returns.insert("deviceError", enumRef<Thing::ThingError>());
|
||||
returns.insert("thingError", enumRef<Thing::ThingError>());
|
||||
returns.insert("o:displayMessage", enumValueName(String));
|
||||
registerMethod("ExecuteAction", description, params, returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
description = "Execute the item identified by itemId on the given device.";
|
||||
params.insert("deviceId", enumValueName(Uuid));
|
||||
description = "Execute the item identified by itemId on the given thing.";
|
||||
params.insert("thingId", enumValueName(Uuid));
|
||||
params.insert("itemId", enumValueName(String));
|
||||
returns.insert("deviceError", enumRef<Thing::ThingError>());
|
||||
returns.insert("thingError", enumRef<Thing::ThingError>());
|
||||
registerMethod("ExecuteBrowserItem", description, params, returns);
|
||||
|
||||
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));
|
||||
description = "Execute the action for the browser item identified by actionTypeId and the itemId on the given thing.";
|
||||
params.insert("thingId", enumValueName(Uuid));
|
||||
params.insert("itemId", enumValueName(String));
|
||||
params.insert("actionTypeId", enumValueName(Uuid));
|
||||
params.insert("o:params", objectRef<ParamList>());
|
||||
returns.insert("deviceError", enumRef<Thing::ThingError>());
|
||||
returns.insert("thingError", enumRef<Thing::ThingError>());
|
||||
registerMethod("ExecuteBrowserItemAction", description, params, returns);
|
||||
|
||||
// Notifications
|
||||
params.clear(); returns.clear();
|
||||
description = "Emitted whenever a State of a device changes.";
|
||||
params.insert("deviceId", enumValueName(Uuid));
|
||||
description = "Emitted whenever a state of a thing changes.";
|
||||
params.insert("thingId", enumValueName(Uuid));
|
||||
params.insert("stateTypeId", enumValueName(Uuid));
|
||||
params.insert("value", enumValueName(Variant));
|
||||
registerNotification("StateChanged", description, params);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
description = "Emitted whenever a Device was removed.";
|
||||
params.insert("deviceId", enumValueName(Uuid));
|
||||
registerNotification("DeviceRemoved", description, params);
|
||||
description = "Emitted whenever a thing was removed.";
|
||||
params.insert("thingId", enumValueName(Uuid));
|
||||
registerNotification("ThingRemoved", description, params);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
description = "Emitted whenever a Device was added.";
|
||||
params.insert("device", objectRef<Thing>());
|
||||
registerNotification("DeviceAdded", description, params);
|
||||
description = "Emitted whenever a thing was added.";
|
||||
params.insert("thing", objectRef<Thing>());
|
||||
registerNotification("ThingAdded", description, params);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
description = "Emitted whenever the params or name of a Device are changed (by EditDevice or ReconfigureDevice).";
|
||||
params.insert("device", objectRef<Thing>());
|
||||
registerNotification("DeviceChanged", description, params);
|
||||
description = "Emitted whenever the params or name of a thing are changed (by EditThing or ReconfigureThing).";
|
||||
params.insert("thing", objectRef<Thing>());
|
||||
registerNotification("ThingChanged", description, params);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
description = "Emitted whenever the setting of a Device is changed.";
|
||||
params.insert("deviceId", enumValueName(Uuid));
|
||||
description = "Emitted whenever the setting of a thing is changed.";
|
||||
params.insert("thingId", enumValueName(Uuid));
|
||||
params.insert("paramTypeId", enumValueName(Uuid));
|
||||
params.insert("value", enumValueName(Variant));
|
||||
registerNotification("DeviceSettingChanged", description, params);
|
||||
registerNotification("ThingSettingChanged", description, params);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
description = "Emitted whenever a plugin's configuration is changed.";
|
||||
@ -373,24 +378,22 @@ IntegrationsHandler::IntegrationsHandler(ThingManager *deviceManager, QObject *p
|
||||
connect(NymeaCore::instance(), &NymeaCore::pluginConfigChanged, this, &IntegrationsHandler::pluginConfigChanged);
|
||||
connect(NymeaCore::instance(), &NymeaCore::thingStateChanged, this, &IntegrationsHandler::thingStateChanged);
|
||||
connect(NymeaCore::instance(), &NymeaCore::thingRemoved, this, &IntegrationsHandler::thingRemovedNotification);
|
||||
connect(NymeaCore::instance(), &NymeaCore::thingAdded, this, &IntegrationsHandler::deviceAddedNotification);
|
||||
connect(NymeaCore::instance(), &NymeaCore::thingChanged, this, &IntegrationsHandler::deviceChangedNotification);
|
||||
connect(NymeaCore::instance(), &NymeaCore::thingSettingChanged, this, &IntegrationsHandler::deviceSettingChangedNotification);
|
||||
connect(NymeaCore::instance(), &NymeaCore::thingAdded, this, &IntegrationsHandler::thingAddedNotification);
|
||||
connect(NymeaCore::instance(), &NymeaCore::thingChanged, this, &IntegrationsHandler::thingChangedNotification);
|
||||
connect(NymeaCore::instance(), &NymeaCore::thingSettingChanged, this, &IntegrationsHandler::thingSettingChangedNotification);
|
||||
}
|
||||
|
||||
/*! Returns the name of the \l{IntegrationsHandler}. In this case \b Devices.*/
|
||||
QString IntegrationsHandler::name() const
|
||||
{
|
||||
return "Integrations";
|
||||
}
|
||||
|
||||
JsonReply* IntegrationsHandler::GetSupportedVendors(const QVariantMap ¶ms) const
|
||||
JsonReply* IntegrationsHandler::GetVendors(const QVariantMap ¶ms, const JsonContext &context) const
|
||||
{
|
||||
QLocale locale = params.value("locale").toLocale();
|
||||
|
||||
Q_UNUSED(params)
|
||||
QVariantList vendors;
|
||||
foreach (const Vendor &vendor, NymeaCore::instance()->thingManager()->supportedVendors()) {
|
||||
Vendor translatedVendor = NymeaCore::instance()->thingManager()->translateVendor(vendor, locale);
|
||||
Vendor translatedVendor = NymeaCore::instance()->thingManager()->translateVendor(vendor, context.locale());
|
||||
vendors.append(pack(translatedVendor));
|
||||
}
|
||||
|
||||
@ -399,42 +402,54 @@ JsonReply* IntegrationsHandler::GetSupportedVendors(const QVariantMap ¶ms) c
|
||||
return createReply(returns);
|
||||
}
|
||||
|
||||
JsonReply* IntegrationsHandler::GetSupportedDevices(const QVariantMap ¶ms) const
|
||||
JsonReply* IntegrationsHandler::GetThingClasses(const QVariantMap ¶ms, const JsonContext &context) const
|
||||
{
|
||||
QLocale locale = params.value("locale").toLocale();
|
||||
VendorId vendorId = VendorId(params.value("vendorId").toString());
|
||||
QVariantMap returns;
|
||||
QVariantList deviceClasses;
|
||||
foreach (const ThingClass &deviceClass, NymeaCore::instance()->thingManager()->supportedThings(vendorId)) {
|
||||
ThingClass translatedDeviceClass = NymeaCore::instance()->thingManager()->translateThingClass(deviceClass, locale);
|
||||
deviceClasses.append(pack(translatedDeviceClass));
|
||||
QVariantList thingClasses;
|
||||
|
||||
if (params.contains("vendorId")) {
|
||||
VendorId vendorId = VendorId(params.value("vendorId").toString());
|
||||
if (m_thingManager->supportedVendors().findById(vendorId).id().isNull()) {
|
||||
qCWarning(dcThingManager()) << "No such vendor:" << vendorId;
|
||||
return createReply(statusToReply(Thing::ThingErrorVendorNotFound));
|
||||
}
|
||||
foreach (const ThingClass &thingClass, NymeaCore::instance()->thingManager()->supportedThings(vendorId)) {
|
||||
ThingClass translatedThingClass = NymeaCore::instance()->thingManager()->translateThingClass(thingClass, context.locale());
|
||||
thingClasses.append(pack(translatedThingClass));
|
||||
}
|
||||
} else {
|
||||
foreach (const ThingClass &thingClass, NymeaCore::instance()->thingManager()->supportedThings()) {
|
||||
ThingClass translatedThingClass = NymeaCore::instance()->thingManager()->translateThingClass(thingClass, context.locale());
|
||||
thingClasses.append(pack(translatedThingClass));
|
||||
}
|
||||
}
|
||||
|
||||
returns.insert("deviceClasses", deviceClasses);
|
||||
returns.insert("thingError", enumValueName(Thing::ThingErrorNoError));
|
||||
returns.insert("thingClasses", thingClasses);
|
||||
return createReply(returns);
|
||||
}
|
||||
|
||||
JsonReply *IntegrationsHandler::GetDiscoveredDevices(const QVariantMap ¶ms) const
|
||||
JsonReply *IntegrationsHandler::DiscoverThings(const QVariantMap ¶ms, const JsonContext &context) const
|
||||
{
|
||||
QLocale locale = params.value("locale").toLocale();
|
||||
QLocale locale = context.locale();
|
||||
|
||||
QVariantMap returns;
|
||||
|
||||
ThingClassId thingClassId = ThingClassId(params.value("thingClassId").toString());
|
||||
ParamList discoveryParams = unpack<ParamList>(params.value("discoveryParams"));
|
||||
|
||||
JsonReply *reply = createAsyncReply("GetDiscoveredDevices");
|
||||
JsonReply *reply = createAsyncReply("DiscoverThings");
|
||||
ThingDiscoveryInfo *info = NymeaCore::instance()->thingManager()->discoverThings(thingClassId, discoveryParams);
|
||||
connect(info, &ThingDiscoveryInfo::finished, reply, [this, reply, info, locale](){
|
||||
QVariantMap returns;
|
||||
returns.insert("deviceError", enumValueName<Thing::ThingError>(info->status()));
|
||||
returns.insert("thingError", enumValueName<Thing::ThingError>(info->status()));
|
||||
|
||||
if (info->status() == Thing::ThingErrorNoError) {
|
||||
QVariantList deviceDescriptorList;
|
||||
foreach (const ThingDescriptor &deviceDescriptor, info->thingDescriptors()) {
|
||||
deviceDescriptorList.append(pack(deviceDescriptor));
|
||||
QVariantList thingDescriptorList;
|
||||
foreach (const ThingDescriptor &thingDescriptor, info->thingDescriptors()) {
|
||||
thingDescriptorList.append(pack(thingDescriptor));
|
||||
}
|
||||
returns.insert("deviceDescriptors", deviceDescriptorList);
|
||||
returns.insert("thingDescriptors", thingDescriptorList);
|
||||
}
|
||||
|
||||
if (!info->displayMessage().isEmpty()) {
|
||||
@ -448,14 +463,13 @@ JsonReply *IntegrationsHandler::GetDiscoveredDevices(const QVariantMap ¶ms)
|
||||
return reply;
|
||||
}
|
||||
|
||||
JsonReply* IntegrationsHandler::GetPlugins(const QVariantMap ¶ms) const
|
||||
JsonReply* IntegrationsHandler::GetPlugins(const QVariantMap ¶ms, const JsonContext &context) const
|
||||
{
|
||||
QLocale locale = params.value("locale").toLocale();
|
||||
|
||||
Q_UNUSED(params)
|
||||
QVariantList plugins;
|
||||
foreach (IntegrationPlugin* plugin, NymeaCore::instance()->thingManager()->plugins()) {
|
||||
QVariantMap packedPlugin = pack(*plugin).toMap();
|
||||
packedPlugin["displayName"] = NymeaCore::instance()->thingManager()->translate(plugin->pluginId(), plugin->pluginDisplayName(), locale);
|
||||
packedPlugin["displayName"] = NymeaCore::instance()->thingManager()->translate(plugin->pluginId(), plugin->pluginDisplayName(), context.locale());
|
||||
plugins.append(packedPlugin);
|
||||
}
|
||||
|
||||
@ -470,7 +484,7 @@ JsonReply *IntegrationsHandler::GetPluginConfiguration(const QVariantMap ¶ms
|
||||
|
||||
IntegrationPlugin *plugin = NymeaCore::instance()->thingManager()->plugins().findById(PluginId(params.value("pluginId").toString()));
|
||||
if (!plugin) {
|
||||
returns.insert("deviceError", enumValueName<Thing::ThingError>(Thing::ThingErrorPluginNotFound));
|
||||
returns.insert("thingError", enumValueName<Thing::ThingError>(Thing::ThingErrorPluginNotFound));
|
||||
return createReply(returns);
|
||||
}
|
||||
|
||||
@ -479,7 +493,7 @@ JsonReply *IntegrationsHandler::GetPluginConfiguration(const QVariantMap ¶ms
|
||||
paramVariantList.append(pack(param));
|
||||
}
|
||||
returns.insert("configuration", paramVariantList);
|
||||
returns.insert("deviceError", enumValueName<Thing::ThingError>(Thing::ThingErrorNoError));
|
||||
returns.insert("thingError", enumValueName<Thing::ThingError>(Thing::ThingErrorNoError));
|
||||
return createReply(returns);
|
||||
}
|
||||
|
||||
@ -489,36 +503,36 @@ JsonReply* IntegrationsHandler::SetPluginConfiguration(const QVariantMap ¶ms
|
||||
PluginId pluginId = PluginId(params.value("pluginId").toString());
|
||||
ParamList pluginParams = unpack<ParamList>(params.value("configuration"));
|
||||
Thing::ThingError result = NymeaCore::instance()->thingManager()->setPluginConfig(pluginId, pluginParams);
|
||||
returns.insert("deviceError",enumValueName<Thing::ThingError>(result));
|
||||
returns.insert("thingError",enumValueName<Thing::ThingError>(result));
|
||||
return createReply(returns);
|
||||
}
|
||||
|
||||
JsonReply* IntegrationsHandler::AddConfiguredDevice(const QVariantMap ¶ms)
|
||||
JsonReply* IntegrationsHandler::AddThing(const QVariantMap ¶ms, const JsonContext &context)
|
||||
{
|
||||
ThingClassId ThingClassId(params.value("thingClassId").toString());
|
||||
QString deviceName = params.value("name").toString();
|
||||
ParamList deviceParams = unpack<ParamList>(params.value("deviceParams"));
|
||||
ThingDescriptorId deviceDescriptorId(params.value("deviceDescriptorId").toString());
|
||||
QLocale locale = params.value("locale").toLocale();
|
||||
QString thingName = params.value("name").toString();
|
||||
ParamList thingParams = unpack<ParamList>(params.value("thingParams"));
|
||||
ThingDescriptorId thingDescriptorId(params.value("thingDescriptorId").toString());
|
||||
QLocale locale = context.locale();
|
||||
|
||||
JsonReply *jsonReply = createAsyncReply("AddConfiguredDevice");
|
||||
JsonReply *jsonReply = createAsyncReply("AddThing");
|
||||
|
||||
ThingSetupInfo *info;
|
||||
if (deviceDescriptorId.isNull()) {
|
||||
info = NymeaCore::instance()->thingManager()->addConfiguredThing(ThingClassId, deviceParams, deviceName);
|
||||
if (thingDescriptorId.isNull()) {
|
||||
info = NymeaCore::instance()->thingManager()->addConfiguredThing(ThingClassId, thingParams, thingName);
|
||||
} else {
|
||||
info = NymeaCore::instance()->thingManager()->addConfiguredThing(deviceDescriptorId, deviceParams, deviceName);
|
||||
info = NymeaCore::instance()->thingManager()->addConfiguredThing(thingDescriptorId, thingParams, thingName);
|
||||
}
|
||||
connect(info, &ThingSetupInfo::finished, jsonReply, [info, jsonReply, locale](){
|
||||
QVariantMap returns;
|
||||
returns.insert("deviceError", enumValueName<Thing::ThingError>(info->status()));
|
||||
returns.insert("thingError", enumValueName<Thing::ThingError>(info->status()));
|
||||
|
||||
if (!info->displayMessage().isEmpty()) {
|
||||
returns.insert("displayMessage", info->translatedDisplayMessage(locale));
|
||||
}
|
||||
|
||||
if(info->status() == Thing::ThingErrorNoError) {
|
||||
returns.insert("deviceId", info->thing()->id());
|
||||
returns.insert("thingId", info->thing()->id());
|
||||
}
|
||||
jsonReply->setData(returns);
|
||||
jsonReply->finished();
|
||||
@ -527,29 +541,29 @@ JsonReply* IntegrationsHandler::AddConfiguredDevice(const QVariantMap ¶ms)
|
||||
return jsonReply;
|
||||
}
|
||||
|
||||
JsonReply *IntegrationsHandler::PairDevice(const QVariantMap ¶ms)
|
||||
JsonReply *IntegrationsHandler::PairThing(const QVariantMap ¶ms, const JsonContext &context)
|
||||
{
|
||||
QString deviceName = params.value("name").toString();
|
||||
ParamList deviceParams = unpack<ParamList>(params.value("deviceParams"));
|
||||
QLocale locale = params.value("locale").toLocale();
|
||||
QString thingName = params.value("name").toString();
|
||||
ParamList thingParams = unpack<ParamList>(params.value("thingParams"));
|
||||
QLocale locale = context.locale();
|
||||
|
||||
ThingPairingInfo *info;
|
||||
if (params.contains("deviceDescriptorId")) {
|
||||
ThingDescriptorId deviceDescriptorId = ThingDescriptorId(params.value("deviceDescriptorId").toString());
|
||||
info = NymeaCore::instance()->thingManager()->pairThing(deviceDescriptorId, deviceParams, deviceName);
|
||||
} else if (params.contains("deviceId")) {
|
||||
ThingId deviceId = ThingId(params.value("deviceId").toString());
|
||||
info = NymeaCore::instance()->thingManager()->pairThing(deviceId, deviceParams, deviceName);
|
||||
if (params.contains("thingDescriptorId")) {
|
||||
ThingDescriptorId thingDescriptorId = ThingDescriptorId(params.value("thingDescriptorId").toString());
|
||||
info = NymeaCore::instance()->thingManager()->pairThing(thingDescriptorId, thingParams, thingName);
|
||||
} else if (params.contains("thingId")) {
|
||||
ThingId thingId = ThingId(params.value("thingId").toString());
|
||||
info = NymeaCore::instance()->thingManager()->pairThing(thingId, thingParams, thingName);
|
||||
} else {
|
||||
ThingClassId thingClassId(params.value("thingClassId").toString());
|
||||
info = NymeaCore::instance()->thingManager()->pairThing(thingClassId, deviceParams, deviceName);
|
||||
info = NymeaCore::instance()->thingManager()->pairThing(thingClassId, thingParams, thingName);
|
||||
}
|
||||
|
||||
JsonReply *jsonReply = createAsyncReply("PairDevice");
|
||||
JsonReply *jsonReply = createAsyncReply("PairThing");
|
||||
|
||||
connect(info, &ThingPairingInfo::finished, jsonReply, [jsonReply, info, locale](){
|
||||
QVariantMap returns;
|
||||
returns.insert("deviceError", enumValueName<Thing::ThingError>(info->status()));
|
||||
returns.insert("thingError", enumValueName<Thing::ThingError>(info->status()));
|
||||
returns.insert("pairingTransactionId", info->transactionId().toString());
|
||||
|
||||
if (info->status() == Thing::ThingErrorNoError) {
|
||||
@ -585,12 +599,12 @@ JsonReply *IntegrationsHandler::ConfirmPairing(const QVariantMap ¶ms)
|
||||
connect(info, &ThingPairingInfo::finished, jsonReply, [info, jsonReply, locale](){
|
||||
|
||||
QVariantMap returns;
|
||||
returns.insert("deviceError", enumValueName<Thing::ThingError>(info->status()));
|
||||
returns.insert("thingError", enumValueName<Thing::ThingError>(info->status()));
|
||||
if (!info->displayMessage().isEmpty()) {
|
||||
returns.insert("displayMessage", info->translatedDisplayMessage(locale));
|
||||
}
|
||||
if (info->status() == Thing::ThingErrorNoError) {
|
||||
returns.insert("deviceId", info->thingId().toString());
|
||||
returns.insert("thingId", info->thingId().toString());
|
||||
}
|
||||
jsonReply->setData(returns);
|
||||
jsonReply->finished();
|
||||
@ -599,52 +613,63 @@ JsonReply *IntegrationsHandler::ConfirmPairing(const QVariantMap ¶ms)
|
||||
return jsonReply;
|
||||
}
|
||||
|
||||
JsonReply* IntegrationsHandler::GetConfiguredDevices(const QVariantMap ¶ms) const
|
||||
JsonReply* IntegrationsHandler::GetThings(const QVariantMap ¶ms, const JsonContext &context) const
|
||||
{
|
||||
QVariantMap returns;
|
||||
QVariantList configuredDeviceList;
|
||||
if (params.contains("deviceId")) {
|
||||
Thing *device = NymeaCore::instance()->thingManager()->findConfiguredThing(ThingId(params.value("deviceId").toString()));
|
||||
if (!device) {
|
||||
returns.insert("deviceError", enumValueName<Thing::ThingError>(Thing::ThingErrorThingNotFound));
|
||||
QVariantList things;
|
||||
if (params.contains("thingId")) {
|
||||
Thing *thing = NymeaCore::instance()->thingManager()->findConfiguredThing(ThingId(params.value("thingId").toString()));
|
||||
if (!thing) {
|
||||
returns.insert("thingError", enumValueName<Thing::ThingError>(Thing::ThingErrorThingNotFound));
|
||||
return createReply(returns);
|
||||
} else {
|
||||
configuredDeviceList.append(pack(device));
|
||||
QVariantMap packedThing = pack(thing).toMap();
|
||||
QString translatedSetupStatus = NymeaCore::instance()->thingManager()->translate(thing->pluginId(), thing->setupDisplayMessage(), context.locale());
|
||||
if (!translatedSetupStatus.isEmpty()) {
|
||||
packedThing["setupDisplayMessage"] = translatedSetupStatus;
|
||||
}
|
||||
things.append(packedThing);
|
||||
}
|
||||
} else {
|
||||
foreach (Thing *device, NymeaCore::instance()->thingManager()->configuredThings()) {
|
||||
configuredDeviceList.append(pack(device));
|
||||
foreach (Thing *thing, NymeaCore::instance()->thingManager()->configuredThings()) {
|
||||
QVariantMap packedThing = pack(thing).toMap();
|
||||
QString translatedSetupStatus = NymeaCore::instance()->thingManager()->translate(thing->pluginId(), thing->setupDisplayMessage(), context.locale());
|
||||
if (!translatedSetupStatus.isEmpty()) {
|
||||
packedThing["setupDisplayMessage"] = translatedSetupStatus;
|
||||
}
|
||||
things.append(packedThing);
|
||||
}
|
||||
}
|
||||
returns.insert("devices", configuredDeviceList);
|
||||
returns.insert("thingError", enumValueName<Thing::ThingError>(Thing::ThingErrorNoError));
|
||||
returns.insert("things", things);
|
||||
return createReply(returns);
|
||||
}
|
||||
|
||||
JsonReply *IntegrationsHandler::ReconfigureDevice(const QVariantMap ¶ms)
|
||||
JsonReply *IntegrationsHandler::ReconfigureThing(const QVariantMap ¶ms, const JsonContext &context)
|
||||
{
|
||||
ThingId thingId = ThingId(params.value("deviceId").toString());
|
||||
ParamList deviceParams = unpack<ParamList>(params.value("deviceParams"));
|
||||
ThingDescriptorId deviceDescriptorId(params.value("deviceDescriptorId").toString());
|
||||
QLocale locale = params.value("locale").toLocale();
|
||||
ThingId thingId = ThingId(params.value("thingId").toString());
|
||||
ParamList thingParams = unpack<ParamList>(params.value("thingParams"));
|
||||
ThingDescriptorId thingDescriptorId(params.value("thingDescriptorId").toString());
|
||||
QLocale locale = context.locale();
|
||||
|
||||
JsonReply *jsonReply = createAsyncReply("ReconfigureDevice");
|
||||
JsonReply *jsonReply = createAsyncReply("ReconfigureThing");
|
||||
|
||||
ThingSetupInfo *info;
|
||||
if (!deviceDescriptorId.isNull()) {
|
||||
info = NymeaCore::instance()->thingManager()->reconfigureThing(deviceDescriptorId, deviceParams);
|
||||
if (!thingDescriptorId.isNull()) {
|
||||
info = NymeaCore::instance()->thingManager()->reconfigureThing(thingDescriptorId, thingParams);
|
||||
} else if (!thingId.isNull()){
|
||||
info = NymeaCore::instance()->thingManager()->reconfigureThing(thingId, deviceParams);
|
||||
info = NymeaCore::instance()->thingManager()->reconfigureThing(thingId, thingParams);
|
||||
} else {
|
||||
qCWarning(dcJsonRpc()) << "Either deviceId or deviceDescriptorId are required";
|
||||
qCWarning(dcJsonRpc()) << "Either thingId or thingDescriptorId are required";
|
||||
QVariantMap ret;
|
||||
ret.insert("deviceError", enumValueName(Thing::ThingErrorMissingParameter));
|
||||
ret.insert("thingError", enumValueName(Thing::ThingErrorMissingParameter));
|
||||
return createReply(ret);
|
||||
}
|
||||
|
||||
connect(info, &ThingSetupInfo::finished, jsonReply, [info, jsonReply, locale](){
|
||||
|
||||
QVariantMap returns;
|
||||
returns.insert("deviceError", enumValueName<Thing::ThingError>(info->status()));
|
||||
returns.insert("thingError", enumValueName<Thing::ThingError>(info->status()));
|
||||
returns.insert("displayMessage", info->translatedDisplayMessage(locale));
|
||||
jsonReply->setData(returns);
|
||||
jsonReply->finished();
|
||||
@ -654,28 +679,28 @@ JsonReply *IntegrationsHandler::ReconfigureDevice(const QVariantMap ¶ms)
|
||||
return jsonReply;
|
||||
}
|
||||
|
||||
JsonReply *IntegrationsHandler::EditDevice(const QVariantMap ¶ms)
|
||||
JsonReply *IntegrationsHandler::EditThing(const QVariantMap ¶ms)
|
||||
{
|
||||
ThingId thingId = ThingId(params.value("deviceId").toString());
|
||||
ThingId thingId = ThingId(params.value("thingId").toString());
|
||||
QString name = params.value("name").toString();
|
||||
|
||||
qCDebug(dcJsonRpc()) << "Edit device" << thingId << name;
|
||||
qCDebug(dcJsonRpc()) << "Edit thing" << thingId << name;
|
||||
|
||||
Thing::ThingError status = NymeaCore::instance()->thingManager()->editThing(thingId, name);
|
||||
|
||||
return createReply(statusToReply(status));
|
||||
}
|
||||
|
||||
JsonReply* IntegrationsHandler::RemoveConfiguredDevice(const QVariantMap ¶ms)
|
||||
JsonReply* IntegrationsHandler::RemoveThing(const QVariantMap ¶ms)
|
||||
{
|
||||
QVariantMap returns;
|
||||
ThingId thingId = ThingId(params.value("deviceId").toString());
|
||||
ThingId thingId = ThingId(params.value("thingId").toString());
|
||||
|
||||
// global removePolicy has priority
|
||||
if (params.contains("removePolicy")) {
|
||||
RuleEngine::RemovePolicy removePolicy = params.value("removePolicy").toString() == "RemovePolicyCascade" ? RuleEngine::RemovePolicyCascade : RuleEngine::RemovePolicyUpdate;
|
||||
Thing::ThingError status = NymeaCore::instance()->removeConfiguredThing(thingId, removePolicy);
|
||||
returns.insert("deviceError", enumValueName<Thing::ThingError>(status));
|
||||
returns.insert("thingError", enumValueName<Thing::ThingError>(status));
|
||||
return createReply(returns);
|
||||
}
|
||||
|
||||
@ -687,7 +712,7 @@ JsonReply* IntegrationsHandler::RemoveConfiguredDevice(const QVariantMap ¶ms
|
||||
}
|
||||
|
||||
QPair<Thing::ThingError, QList<RuleId> > status = NymeaCore::instance()->removeConfiguredThing(thingId, removePolicyList);
|
||||
returns.insert("deviceError", enumValueName<Thing::ThingError>(status.first));
|
||||
returns.insert("thingError", enumValueName<Thing::ThingError>(status.first));
|
||||
|
||||
if (!status.second.isEmpty()) {
|
||||
QVariantList ruleIdList;
|
||||
@ -700,53 +725,47 @@ JsonReply* IntegrationsHandler::RemoveConfiguredDevice(const QVariantMap ¶ms
|
||||
return createReply(returns);
|
||||
}
|
||||
|
||||
JsonReply *IntegrationsHandler::SetDeviceSettings(const QVariantMap ¶ms)
|
||||
JsonReply *IntegrationsHandler::SetThingSettings(const QVariantMap ¶ms)
|
||||
{
|
||||
ThingId thingId = ThingId(params.value("deviceId").toString());
|
||||
ThingId thingId = ThingId(params.value("thingId").toString());
|
||||
ParamList settings = unpack<ParamList>(params.value("settings"));
|
||||
Thing::ThingError status = NymeaCore::instance()->thingManager()->setThingSettings(thingId, settings);
|
||||
return createReply(statusToReply(status));
|
||||
}
|
||||
|
||||
JsonReply* IntegrationsHandler::GetEventTypes(const QVariantMap ¶ms) const
|
||||
JsonReply* IntegrationsHandler::GetEventTypes(const QVariantMap ¶ms, const JsonContext &context) const
|
||||
{
|
||||
QLocale locale = params.value("locale").toLocale();
|
||||
|
||||
ThingClass deviceClass = NymeaCore::instance()->thingManager()->findThingClass(ThingClassId(params.value("thingClassId").toString()));
|
||||
ThingClass translatedDeviceClass = NymeaCore::instance()->thingManager()->translateThingClass(deviceClass, locale);
|
||||
ThingClass thingClass = NymeaCore::instance()->thingManager()->findThingClass(ThingClassId(params.value("thingClassId").toString()));
|
||||
ThingClass translatedThingClass = NymeaCore::instance()->thingManager()->translateThingClass(thingClass, context.locale());
|
||||
|
||||
QVariantMap returns;
|
||||
returns.insert("eventTypes", pack(translatedDeviceClass.eventTypes()));
|
||||
returns.insert("eventTypes", pack(translatedThingClass.eventTypes()));
|
||||
return createReply(returns);
|
||||
}
|
||||
|
||||
JsonReply* IntegrationsHandler::GetActionTypes(const QVariantMap ¶ms) const
|
||||
JsonReply* IntegrationsHandler::GetActionTypes(const QVariantMap ¶ms, const JsonContext &context) const
|
||||
{
|
||||
QLocale locale = params.value("locale").toLocale();
|
||||
|
||||
ThingClass deviceClass = NymeaCore::instance()->thingManager()->findThingClass(ThingClassId(params.value("thingClassId").toString()));
|
||||
ThingClass translatedDeviceClass = NymeaCore::instance()->thingManager()->translateThingClass(deviceClass, locale);
|
||||
ThingClass thingClass = NymeaCore::instance()->thingManager()->findThingClass(ThingClassId(params.value("thingClassId").toString()));
|
||||
ThingClass translatedThingClass = NymeaCore::instance()->thingManager()->translateThingClass(thingClass, context.locale());
|
||||
|
||||
QVariantMap returns;
|
||||
returns.insert("actionTypes", pack(translatedDeviceClass.actionTypes()));
|
||||
returns.insert("actionTypes", pack(translatedThingClass.actionTypes()));
|
||||
return createReply(returns);
|
||||
}
|
||||
|
||||
JsonReply* IntegrationsHandler::GetStateTypes(const QVariantMap ¶ms) const
|
||||
JsonReply* IntegrationsHandler::GetStateTypes(const QVariantMap ¶ms, const JsonContext &context) const
|
||||
{
|
||||
QLocale locale = params.value("locale").toLocale();
|
||||
|
||||
ThingClass deviceClass = NymeaCore::instance()->thingManager()->findThingClass(ThingClassId(params.value("thingClassId").toString()));
|
||||
ThingClass translatedDeviceClass = NymeaCore::instance()->thingManager()->translateThingClass(deviceClass, locale);
|
||||
ThingClass thingClass = NymeaCore::instance()->thingManager()->findThingClass(ThingClassId(params.value("thingClassId").toString()));
|
||||
ThingClass translatedThingClass = NymeaCore::instance()->thingManager()->translateThingClass(thingClass, context.locale());
|
||||
|
||||
QVariantMap returns;
|
||||
returns.insert("stateTypes", pack(translatedDeviceClass.stateTypes()));
|
||||
returns.insert("stateTypes", pack(translatedThingClass.stateTypes()));
|
||||
return createReply(returns);
|
||||
}
|
||||
|
||||
JsonReply* IntegrationsHandler::GetStateValue(const QVariantMap ¶ms) const
|
||||
{
|
||||
Thing *thing = NymeaCore::instance()->thingManager()->findConfiguredThing(ThingId(params.value("deviceId").toString()));
|
||||
Thing *thing = NymeaCore::instance()->thingManager()->findConfiguredThing(ThingId(params.value("thingId").toString()));
|
||||
if (!thing) {
|
||||
return createReply(statusToReply(Thing::ThingErrorThingNotFound));
|
||||
}
|
||||
@ -762,7 +781,7 @@ JsonReply* IntegrationsHandler::GetStateValue(const QVariantMap ¶ms) const
|
||||
|
||||
JsonReply *IntegrationsHandler::GetStateValues(const QVariantMap ¶ms) const
|
||||
{
|
||||
Thing *thing = NymeaCore::instance()->thingManager()->findConfiguredThing(ThingId(params.value("deviceId").toString()));
|
||||
Thing *thing = NymeaCore::instance()->thingManager()->findConfiguredThing(ThingId(params.value("thingId").toString()));
|
||||
if (!thing) {
|
||||
return createReply(statusToReply(Thing::ThingErrorThingNotFound));
|
||||
}
|
||||
@ -772,14 +791,14 @@ JsonReply *IntegrationsHandler::GetStateValues(const QVariantMap ¶ms) const
|
||||
return createReply(returns);
|
||||
}
|
||||
|
||||
JsonReply *IntegrationsHandler::BrowseDevice(const QVariantMap ¶ms) const
|
||||
JsonReply *IntegrationsHandler::BrowseThing(const QVariantMap ¶ms, const JsonContext &context) const
|
||||
{
|
||||
ThingId thingId = ThingId(params.value("deviceId").toString());
|
||||
ThingId thingId = ThingId(params.value("thingId").toString());
|
||||
QString itemId = params.value("itemId").toString();
|
||||
|
||||
JsonReply *jsonReply = createAsyncReply("BrowseDevice");
|
||||
JsonReply *jsonReply = createAsyncReply("BrowseThing");
|
||||
|
||||
BrowseResult *result = NymeaCore::instance()->thingManager()->browseThing(thingId, itemId, params.value("locale").toLocale());
|
||||
BrowseResult *result = NymeaCore::instance()->thingManager()->browseThing(thingId, itemId, context.locale());
|
||||
connect(result, &BrowseResult::finished, jsonReply, [this, jsonReply, result](){
|
||||
|
||||
QVariantMap returns = statusToReply(result->status());
|
||||
@ -795,15 +814,15 @@ JsonReply *IntegrationsHandler::BrowseDevice(const QVariantMap ¶ms) const
|
||||
return jsonReply;
|
||||
}
|
||||
|
||||
JsonReply *IntegrationsHandler::GetBrowserItem(const QVariantMap ¶ms) const
|
||||
JsonReply *IntegrationsHandler::GetBrowserItem(const QVariantMap ¶ms, const JsonContext &context) const
|
||||
{
|
||||
QVariantMap returns;
|
||||
ThingId thingId = ThingId(params.value("deviceId").toString());
|
||||
ThingId thingId = ThingId(params.value("thingId").toString());
|
||||
QString itemId = params.value("itemId").toString();
|
||||
|
||||
JsonReply *jsonReply = createAsyncReply("GetBrowserItem");
|
||||
|
||||
BrowserItemResult *result = NymeaCore::instance()->thingManager()->browserItemDetails(thingId, itemId, params.value("locale").toLocale());
|
||||
BrowserItemResult *result = NymeaCore::instance()->thingManager()->browserItemDetails(thingId, itemId, context.locale());
|
||||
connect(result, &BrowserItemResult::finished, jsonReply, [this, jsonReply, result](){
|
||||
QVariantMap params = statusToReply(result->status());
|
||||
if (result->status() == Thing::ThingErrorNoError) {
|
||||
@ -816,12 +835,12 @@ JsonReply *IntegrationsHandler::GetBrowserItem(const QVariantMap ¶ms) const
|
||||
return jsonReply;
|
||||
}
|
||||
|
||||
JsonReply *IntegrationsHandler::ExecuteAction(const QVariantMap ¶ms)
|
||||
JsonReply *IntegrationsHandler::ExecuteAction(const QVariantMap ¶ms, const JsonContext &context)
|
||||
{
|
||||
ThingId thingId(params.value("deviceId").toString());
|
||||
ThingId thingId(params.value("thingId").toString());
|
||||
ActionTypeId actionTypeId(params.value("actionTypeId").toString());
|
||||
ParamList actionParams = unpack<ParamList>(params.value("params"));
|
||||
QLocale locale = params.value("locale").toLocale();
|
||||
QLocale locale = context.locale();
|
||||
|
||||
Action action(actionTypeId, thingId);
|
||||
action.setParams(actionParams);
|
||||
@ -831,7 +850,7 @@ JsonReply *IntegrationsHandler::ExecuteAction(const QVariantMap ¶ms)
|
||||
ThingActionInfo *info = NymeaCore::instance()->executeAction(action);
|
||||
connect(info, &ThingActionInfo::finished, jsonReply, [info, jsonReply, locale](){
|
||||
QVariantMap data;
|
||||
data.insert("deviceError", enumValueName(info->status()));
|
||||
data.insert("thingError", enumValueName(info->status()));
|
||||
if (!info->displayMessage().isEmpty()) {
|
||||
data.insert("displayMessage", info->translatedDisplayMessage(locale));
|
||||
}
|
||||
@ -844,7 +863,7 @@ JsonReply *IntegrationsHandler::ExecuteAction(const QVariantMap ¶ms)
|
||||
|
||||
JsonReply *IntegrationsHandler::ExecuteBrowserItem(const QVariantMap ¶ms)
|
||||
{
|
||||
ThingId thingId = ThingId(params.value("deviceId").toString());
|
||||
ThingId thingId = ThingId(params.value("thingId").toString());
|
||||
QString itemId = params.value("itemId").toString();
|
||||
BrowserAction action(thingId, itemId);
|
||||
|
||||
@ -853,7 +872,7 @@ JsonReply *IntegrationsHandler::ExecuteBrowserItem(const QVariantMap ¶ms)
|
||||
BrowserActionInfo *info = NymeaCore::instance()->executeBrowserItem(action);
|
||||
connect(info, &BrowserActionInfo::finished, jsonReply, [info, jsonReply](){
|
||||
QVariantMap data;
|
||||
data.insert("deviceError", enumValueName<Thing::ThingError>(info->status()));
|
||||
data.insert("thingError", enumValueName<Thing::ThingError>(info->status()));
|
||||
jsonReply->setData(data);
|
||||
jsonReply->finished();
|
||||
});
|
||||
@ -863,7 +882,7 @@ JsonReply *IntegrationsHandler::ExecuteBrowserItem(const QVariantMap ¶ms)
|
||||
|
||||
JsonReply *IntegrationsHandler::ExecuteBrowserItemAction(const QVariantMap ¶ms)
|
||||
{
|
||||
ThingId thingId = ThingId(params.value("deviceId").toString());
|
||||
ThingId thingId = ThingId(params.value("thingId").toString());
|
||||
QString itemId = params.value("itemId").toString();
|
||||
ActionTypeId actionTypeId = ActionTypeId(params.value("actionTypeId").toString());
|
||||
ParamList paramList = unpack<ParamList>(params.value("params"));
|
||||
@ -874,7 +893,7 @@ JsonReply *IntegrationsHandler::ExecuteBrowserItemAction(const QVariantMap ¶
|
||||
BrowserItemActionInfo *info = NymeaCore::instance()->executeBrowserItemAction(browserItemAction);
|
||||
connect(info, &BrowserItemActionInfo::finished, jsonReply, [info, jsonReply](){
|
||||
QVariantMap data;
|
||||
data.insert("deviceError", enumValueName<Thing::ThingError>(info->status()));
|
||||
data.insert("thingError", enumValueName<Thing::ThingError>(info->status()));
|
||||
jsonReply->setData(data);
|
||||
jsonReply->finished();
|
||||
});
|
||||
@ -929,36 +948,36 @@ void IntegrationsHandler::thingRemovedNotification(const ThingId &thingId)
|
||||
{
|
||||
QVariantMap params;
|
||||
params.insert("thingId", thingId);
|
||||
emit DeviceRemoved(params);
|
||||
emit ThingRemoved(params);
|
||||
}
|
||||
|
||||
void IntegrationsHandler::deviceAddedNotification(Thing *device)
|
||||
void IntegrationsHandler::thingAddedNotification(Thing *thing)
|
||||
{
|
||||
QVariantMap params;
|
||||
params.insert("device", pack(device));
|
||||
emit DeviceAdded(params);
|
||||
params.insert("thing", pack(thing));
|
||||
emit ThingAdded(params);
|
||||
}
|
||||
|
||||
void IntegrationsHandler::deviceChangedNotification(Thing *device)
|
||||
void IntegrationsHandler::thingChangedNotification(Thing *thing)
|
||||
{
|
||||
QVariantMap params;
|
||||
params.insert("device", pack(device));
|
||||
emit DeviceChanged(params);
|
||||
params.insert("thing", pack(thing));
|
||||
emit ThingChanged(params);
|
||||
}
|
||||
|
||||
void IntegrationsHandler::deviceSettingChangedNotification(const ThingId &thingId, const ParamTypeId ¶mTypeId, const QVariant &value)
|
||||
void IntegrationsHandler::thingSettingChangedNotification(const ThingId &thingId, const ParamTypeId ¶mTypeId, const QVariant &value)
|
||||
{
|
||||
QVariantMap params;
|
||||
params.insert("deviceId", thingId);
|
||||
params.insert("thingId", thingId);
|
||||
params.insert("paramTypeId", paramTypeId.toString());
|
||||
params.insert("value", value);
|
||||
emit DeviceSettingChanged(params);
|
||||
emit ThingSettingChanged(params);
|
||||
}
|
||||
|
||||
QVariantMap IntegrationsHandler::statusToReply(Thing::ThingError status) const
|
||||
{
|
||||
QVariantMap returns;
|
||||
returns.insert("deviceError", enumValueName<Thing::ThingError>(status));
|
||||
returns.insert("thingError", enumValueName<Thing::ThingError>(status));
|
||||
return returns;
|
||||
}
|
||||
|
||||
|
||||
@ -40,36 +40,35 @@ class IntegrationsHandler : public JsonHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit IntegrationsHandler(ThingManager *deviceManager, QObject *parent = nullptr);
|
||||
explicit IntegrationsHandler(ThingManager *thingManager, QObject *parent = nullptr);
|
||||
|
||||
QString name() const override;
|
||||
|
||||
Q_INVOKABLE JsonReply *GetSupportedVendors(const QVariantMap ¶ms) const;
|
||||
Q_INVOKABLE JsonReply *GetSupportedDevices(const QVariantMap ¶ms) const;
|
||||
Q_INVOKABLE JsonReply *GetDiscoveredDevices(const QVariantMap ¶ms) const;
|
||||
Q_INVOKABLE JsonReply *GetPlugins(const QVariantMap ¶ms) const;
|
||||
Q_INVOKABLE JsonReply *GetVendors(const QVariantMap ¶ms, const JsonContext &context) const;
|
||||
Q_INVOKABLE JsonReply *GetThingClasses(const QVariantMap ¶ms, const JsonContext &context) const;
|
||||
Q_INVOKABLE JsonReply *DiscoverThings(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);
|
||||
Q_INVOKABLE JsonReply *PairDevice(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply *AddThing(const QVariantMap ¶ms, const JsonContext &context);
|
||||
Q_INVOKABLE JsonReply *PairThing(const QVariantMap ¶ms, const JsonContext &context);
|
||||
Q_INVOKABLE JsonReply *ConfirmPairing(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply *GetConfiguredDevices(const QVariantMap ¶ms) const;
|
||||
Q_INVOKABLE JsonReply *ReconfigureDevice(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply *EditDevice(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply *RemoveConfiguredDevice(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply *SetDeviceSettings(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply *GetThings(const QVariantMap ¶ms, const JsonContext &context) const;
|
||||
Q_INVOKABLE JsonReply *ReconfigureThing(const QVariantMap ¶ms, const JsonContext &context);
|
||||
Q_INVOKABLE JsonReply *EditThing(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply *RemoveThing(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply *SetThingSettings(const QVariantMap ¶ms);
|
||||
|
||||
Q_INVOKABLE JsonReply *GetEventTypes(const QVariantMap ¶ms) const;
|
||||
Q_INVOKABLE JsonReply *GetActionTypes(const QVariantMap ¶ms) const;
|
||||
Q_INVOKABLE JsonReply *GetStateTypes(const QVariantMap ¶ms) const;
|
||||
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;
|
||||
Q_INVOKABLE JsonReply *GetBrowserItem(const QVariantMap ¶ms) const;
|
||||
Q_INVOKABLE JsonReply *BrowseThing(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);
|
||||
Q_INVOKABLE JsonReply *ExecuteAction(const QVariantMap ¶ms, const JsonContext &context);
|
||||
Q_INVOKABLE JsonReply *ExecuteBrowserItem(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply *ExecuteBrowserItemAction(const QVariantMap ¶ms);
|
||||
|
||||
@ -78,10 +77,10 @@ public:
|
||||
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 ThingRemoved(const QVariantMap ¶ms);
|
||||
void ThingAdded(const QVariantMap ¶ms);
|
||||
void ThingChanged(const QVariantMap ¶ms);
|
||||
void ThingSettingChanged(const QVariantMap ¶ms);
|
||||
void EventTriggered(const QVariantMap ¶ms);
|
||||
|
||||
private slots:
|
||||
@ -91,14 +90,14 @@ private slots:
|
||||
|
||||
void thingRemovedNotification(const ThingId &thingId);
|
||||
|
||||
void deviceAddedNotification(Thing *device);
|
||||
void thingAddedNotification(Thing *thing);
|
||||
|
||||
void deviceChangedNotification(Thing *device);
|
||||
void thingChangedNotification(Thing *thing);
|
||||
|
||||
void deviceSettingChangedNotification(const ThingId &thingId, const ParamTypeId ¶mTypeId, const QVariant &value);
|
||||
void thingSettingChangedNotification(const ThingId &thingId, const ParamTypeId ¶mTypeId, const QVariant &value);
|
||||
|
||||
private:
|
||||
ThingManager *m_deviceManager = nullptr;
|
||||
ThingManager *m_thingManager = nullptr;
|
||||
QVariantMap statusToReply(Thing::ThingError status) const;
|
||||
};
|
||||
|
||||
|
||||
@ -17,7 +17,6 @@ RESOURCES += $$top_srcdir/icons.qrc \
|
||||
|
||||
HEADERS += nymeacore.h \
|
||||
integrations/plugininfocache.h \
|
||||
integrations/scriptintegrationplugin.h \
|
||||
integrations/thingmanagerimplementation.h \
|
||||
integrations/translator.h \
|
||||
experiences/experiencemanager.h \
|
||||
@ -104,7 +103,6 @@ HEADERS += nymeacore.h \
|
||||
|
||||
SOURCES += nymeacore.cpp \
|
||||
integrations/plugininfocache.cpp \
|
||||
integrations/scriptintegrationplugin.cpp \
|
||||
integrations/thingmanagerimplementation.cpp \
|
||||
integrations/translator.cpp \
|
||||
experiences/experiencemanager.cpp \
|
||||
@ -189,6 +187,8 @@ SOURCES += nymeacore.cpp \
|
||||
|
||||
versionAtLeast(QT_VERSION, 5.12.0) {
|
||||
HEADERS += \
|
||||
integrations/scriptintegrationplugin.h
|
||||
|
||||
SOURCES += \
|
||||
integrations/scriptintegrationplugin.cpp
|
||||
}
|
||||
|
||||
@ -194,9 +194,9 @@ void PluginMetadata::parse(const QJsonObject &jsonObject)
|
||||
|
||||
// Check mandatory fields
|
||||
if (!verificationResult.first.isEmpty()) {
|
||||
m_validationErrors.append("Device class has missing fields: \"" + verificationResult.first.join("\", \"") + "\"\n" + qUtf8Printable(QJsonDocument::fromVariant(thingClassObject.toVariantMap()).toJson(QJsonDocument::Indented)));
|
||||
m_validationErrors.append("Thing class has missing fields: \"" + verificationResult.first.join("\", \"") + "\"\n" + qUtf8Printable(QJsonDocument::fromVariant(thingClassObject.toVariantMap()).toJson(QJsonDocument::Indented)));
|
||||
hasError = true;
|
||||
// Stop parsing this deviceClass as we rely on mandatory fields being around.
|
||||
// Stop parsing this thingClass as we rely on mandatory fields being around.
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -210,11 +210,11 @@ void PluginMetadata::parse(const QJsonObject &jsonObject)
|
||||
}
|
||||
|
||||
if (thingClassId.isNull()) {
|
||||
m_validationErrors.append("Device class \"" + thingClassName + "\" has invalid UUID: " + thingClassObject.value("id").toString());
|
||||
m_validationErrors.append("Thing class \"" + thingClassName + "\" has invalid UUID: " + thingClassObject.value("id").toString());
|
||||
hasError = true;
|
||||
}
|
||||
if (!verifyDuplicateUuid(thingClassId)) {
|
||||
m_validationErrors.append("Device class \"" + thingClassName + "\" has duplicate UUID: " + thingClassName);
|
||||
m_validationErrors.append("Thing class \"" + thingClassName + "\" has duplicate UUID: " + thingClassName);
|
||||
hasError = true;
|
||||
}
|
||||
|
||||
@ -306,7 +306,7 @@ void PluginMetadata::parse(const QJsonObject &jsonObject)
|
||||
|
||||
// Check mandatory fields
|
||||
if (!verificationResult.first.isEmpty()) {
|
||||
m_validationErrors.append("Device class \"" + thingClass.name() + "\" has missing properties \"" + verificationResult.first.join("\", \"") + "\" in stateType definition\n" + qUtf8Printable(QJsonDocument::fromVariant(st.toVariantMap()).toJson(QJsonDocument::Indented)));
|
||||
m_validationErrors.append("Thing class \"" + thingClass.name() + "\" has missing properties \"" + verificationResult.first.join("\", \"") + "\" in stateType definition\n" + qUtf8Printable(QJsonDocument::fromVariant(st.toVariantMap()).toJson(QJsonDocument::Indented)));
|
||||
hasError = true;
|
||||
// Not processing further as mandatory fields are expected to be here
|
||||
continue;
|
||||
|
||||
@ -84,7 +84,7 @@ DevicePluginMock::~DevicePluginMock()
|
||||
void DevicePluginMock::discoverThings(ThingDiscoveryInfo *info)
|
||||
{
|
||||
if (info->thingClassId() == mockThingClassId) {
|
||||
qCDebug(dcMockDevice) << "starting mock discovery:" << info->params();
|
||||
qCDebug(dcMock()) << "starting mock discovery:" << info->params();
|
||||
m_discoveredDeviceCount = info->params().paramValue(mockDiscoveryResultCountParamTypeId).toInt();
|
||||
QTimer::singleShot(1000, info, [this, info](){
|
||||
generateDiscoveredDevices(info);
|
||||
@ -92,39 +92,39 @@ void DevicePluginMock::discoverThings(ThingDiscoveryInfo *info)
|
||||
return;
|
||||
}
|
||||
|
||||
if (info->thingClassId() == mockPushButtonThingClassId) {
|
||||
qCDebug(dcMockDevice) << "starting mock push button discovery:" << info->params();
|
||||
m_discoveredDeviceCount = info->params().paramValue(mockPushButtonDiscoveryResultCountParamTypeId).toInt();
|
||||
if (info->thingClassId() == pushButtonMockThingClassId) {
|
||||
qCDebug(dcMock()) << "starting mock push button discovery:" << info->params();
|
||||
m_discoveredDeviceCount = info->params().paramValue(pushButtonMockDiscoveryResultCountParamTypeId).toInt();
|
||||
QTimer::singleShot(1000, info, [this, info]() {
|
||||
generateDiscoveredPushButtonDevices(info);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (info->thingClassId() == mockDisplayPinThingClassId) {
|
||||
qCDebug(dcMockDevice) << "starting mock display pin discovery:" << info->params();
|
||||
m_discoveredDeviceCount = info->params().paramValue(mockDisplayPinDiscoveryResultCountParamTypeId).toInt();
|
||||
if (info->thingClassId() == displayPinMockThingClassId) {
|
||||
qCDebug(dcMock()) << "starting mock display pin discovery:" << info->params();
|
||||
m_discoveredDeviceCount = info->params().paramValue(displayPinMockDiscoveryResultCountParamTypeId).toInt();
|
||||
QTimer::singleShot(1000, info, [this, info]() {
|
||||
generateDiscoveredDisplayPinDevices(info);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (info->thingClassId() == mockParentThingClassId) {
|
||||
qCDebug(dcMockDevice()) << "Starting discovery for mock device parent";
|
||||
if (info->thingClassId() == parentMockThingClassId) {
|
||||
qCDebug(dcMock()) << "Starting discovery for mocked parent thing";
|
||||
QTimer::singleShot(1000, info, [info](){
|
||||
ThingDescriptor descriptor(mockParentThingClassId, "Mock Parent (Discovered)");
|
||||
ThingDescriptor descriptor(parentMockThingClassId, "Mocked Thing Parent (Discovered)");
|
||||
info->addThingDescriptor(descriptor);
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (info->thingClassId() == mockChildThingClassId) {
|
||||
if (info->thingClassId() == childMockThingClassId) {
|
||||
QTimer::singleShot(1000, info, [this, info](){
|
||||
if (!myThings().filterByThingClassId(mockParentThingClassId).isEmpty()) {
|
||||
Thing *parent = myThings().filterByThingClassId(mockParentThingClassId).first();
|
||||
ThingDescriptor descriptor(mockChildThingClassId, "Mock Child (Discovered)", QString(), parent->id());
|
||||
if (!myThings().filterByThingClassId(parentMockThingClassId).isEmpty()) {
|
||||
Thing *parent = myThings().filterByThingClassId(parentMockThingClassId).first();
|
||||
ThingDescriptor descriptor(childMockThingClassId, "Mocked Thing Child (Discovered)", QString(), parent->id());
|
||||
info->addThingDescriptor(descriptor);
|
||||
}
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
@ -132,10 +132,10 @@ void DevicePluginMock::discoverThings(ThingDiscoveryInfo *info)
|
||||
return;
|
||||
}
|
||||
|
||||
if (info->thingClassId() == mockUserAndPassThingClassId) {
|
||||
if (info->thingClassId() == userAndPassMockThingClassId) {
|
||||
QTimer::singleShot(1000, info, [this, info](){
|
||||
if (myThings().filterByThingClassId(mockUserAndPassThingClassId).isEmpty()) {
|
||||
ThingDescriptor descriptor(mockUserAndPassThingClassId, "Mock User & Password (Discovered)", QString());
|
||||
if (myThings().filterByThingClassId(userAndPassMockThingClassId).isEmpty()) {
|
||||
ThingDescriptor descriptor(userAndPassMockThingClassId, "Mocked Thing User & Password (Discovered)", QString());
|
||||
info->addThingDescriptor(descriptor);
|
||||
}
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
@ -143,27 +143,27 @@ void DevicePluginMock::discoverThings(ThingDiscoveryInfo *info)
|
||||
return;
|
||||
}
|
||||
|
||||
qCWarning(dcMockDevice()) << "Cannot discover for ThingClassId" << info->thingClassId();
|
||||
qCWarning(dcMock()) << "Cannot discover for ThingClassId" << info->thingClassId();
|
||||
info->finish(Thing::ThingErrorThingNotFound);
|
||||
}
|
||||
|
||||
void DevicePluginMock::setupThing(ThingSetupInfo *info)
|
||||
{
|
||||
if (info->thing()->thingClassId() == mockThingClassId || info->thing()->thingClassId() == mockDeviceAutoThingClassId) {
|
||||
if (info->thing()->thingClassId() == mockThingClassId || info->thing()->thingClassId() == autoMockThingClassId) {
|
||||
bool async = false;
|
||||
bool broken = false;
|
||||
if (info->thing()->thingClassId() == mockThingClassId) {
|
||||
async = info->thing()->paramValue(mockDeviceAsyncParamTypeId).toBool();
|
||||
broken = info->thing()->paramValue(mockDeviceBrokenParamTypeId).toBool();
|
||||
async = info->thing()->paramValue(mockThingAsyncParamTypeId).toBool();
|
||||
broken = info->thing()->paramValue(mockThingBrokenParamTypeId).toBool();
|
||||
} else {
|
||||
async = info->thing()->paramValue(mockDeviceAutoDeviceAsyncParamTypeId).toBool();
|
||||
broken = info->thing()->paramValue(mockDeviceAutoDeviceBrokenParamTypeId).toBool();
|
||||
async = info->thing()->paramValue(autoMockThingAsyncParamTypeId).toBool();
|
||||
broken = info->thing()->paramValue(autoMockThingBrokenParamTypeId).toBool();
|
||||
}
|
||||
qCDebug(dcMockDevice()) << "SetupDevice for" << info->thing()->name() << "Async:" << async << "Broken:" << broken;
|
||||
qCDebug(dcMock()) << "SetupThing for" << info->thing()->name() << "Async:" << async << "Broken:" << broken;
|
||||
|
||||
if (!async && broken) {
|
||||
qCWarning(dcMockDevice) << "This device is intentionally broken.";
|
||||
info->finish(Thing::ThingErrorSetupFailed, QT_TR_NOOP("This mock device is intentionally broken."));
|
||||
qCWarning(dcMock()) << "This thing is intentionally broken.";
|
||||
info->finish(Thing::ThingErrorSetupFailed, QT_TR_NOOP("This mocked thing is intentionally broken."));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -172,7 +172,7 @@ void DevicePluginMock::setupThing(ThingSetupInfo *info)
|
||||
m_daemons.insert(info->thing(), daemon);
|
||||
|
||||
if (!daemon->isListening()) {
|
||||
qCWarning(dcMockDevice) << "HTTP port opening failed:" << info->thing()->paramValue(mockDeviceHttpportParamTypeId).toInt();
|
||||
qCWarning(dcMock()) << "HTTP port opening failed:" << info->thing()->paramValue(mockThingHttpportParamTypeId).toInt();
|
||||
info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("Failed to open HTTP port. Port in use?"));
|
||||
return;
|
||||
}
|
||||
@ -188,83 +188,83 @@ void DevicePluginMock::setupThing(ThingSetupInfo *info)
|
||||
if (async) {
|
||||
Thing *device = info->thing();
|
||||
QTimer::singleShot(1000, device, [info](){
|
||||
qCDebug(dcMockDevice) << "Finishing device setup for mock device" << info->thing()->name();
|
||||
if (info->thing()->paramValue(mockDeviceBrokenParamTypeId).toBool()) {
|
||||
info->finish(Thing::ThingErrorSetupFailed, QT_TR_NOOP("This mock device is intentionally broken."));
|
||||
qCDebug(dcMock()) << "Finishing thing setup for mocked thing" << info->thing()->name();
|
||||
if (info->thing()->paramValue(mockThingBrokenParamTypeId).toBool()) {
|
||||
info->finish(Thing::ThingErrorSetupFailed, QT_TR_NOOP("This mocked thing is intentionally broken."));
|
||||
} else {
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
qCDebug(dcMockDevice()) << "Setup complete" << info->thing()->name();
|
||||
qCDebug(dcMock()) << "Setup complete" << info->thing()->name();
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
}
|
||||
|
||||
if (info->thing()->thingClassId() == mockPushButtonThingClassId) {
|
||||
qCDebug(dcMockDevice) << "Setup PushButton mock device" << info->thing()->params();
|
||||
if (info->thing()->thingClassId() == pushButtonMockThingClassId) {
|
||||
qCDebug(dcMock()) << "Setup PushButton mock thing" << info->thing()->params();
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
}
|
||||
|
||||
if (info->thing()->thingClassId() == mockDisplayPinThingClassId) {
|
||||
qCDebug(dcMockDevice) << "Setup DisplayPin mock device" << info->thing()->params();
|
||||
if (info->thing()->thingClassId() == displayPinMockThingClassId) {
|
||||
qCDebug(dcMock()) << "Setup DisplayPin mock thing" << info->thing()->params();
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
}
|
||||
|
||||
if (info->thing()->thingClassId() == mockParentThingClassId) {
|
||||
qCDebug(dcMockDevice) << "Setup Parent mock device" << info->thing()->params();
|
||||
if (info->thing()->thingClassId() == parentMockThingClassId) {
|
||||
qCDebug(dcMock()) << "Setup Parent mock thing" << info->thing()->params();
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
}
|
||||
|
||||
if (info->thing()->thingClassId() == mockChildThingClassId) {
|
||||
qCDebug(dcMockDevice) << "Setup Child mock device" << info->thing()->params();
|
||||
if (info->thing()->thingClassId() == childMockThingClassId) {
|
||||
qCDebug(dcMock()) << "Setup Child mock thing" << info->thing()->params();
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
}
|
||||
|
||||
if (info->thing()->thingClassId() == mockInputTypeThingClassId) {
|
||||
qCDebug(dcMockDevice) << "Setup InputType mock device" << info->thing()->params();
|
||||
if (info->thing()->thingClassId() == inputTypeMockThingClassId) {
|
||||
qCDebug(dcMock()) << "Setup InputType mock thing" << info->thing()->params();
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
}
|
||||
|
||||
if (info->thing()->thingClassId() == mockUserAndPassThingClassId) {
|
||||
qCDebug(dcMockDevice()) << "Setup User and password mock device";
|
||||
if (info->thing()->thingClassId() == userAndPassMockThingClassId) {
|
||||
qCDebug(dcMock()) << "Setup User and password mock thing";
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
}
|
||||
|
||||
if (info->thing()->thingClassId() == mockOAuthGoogleThingClassId) {
|
||||
qCDebug(dcMockDevice()) << "Google OAuth setup complete";
|
||||
if (info->thing()->thingClassId() == oAuthGoogleMockThingClassId) {
|
||||
qCDebug(dcMock()) << "Google OAuth setup complete";
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
}
|
||||
|
||||
if (info->thing()->thingClassId() == mockOAuthSonosThingClassId) {
|
||||
qCDebug(dcMockDevice()) << "Sonos OAuth setup complete";
|
||||
if (info->thing()->thingClassId() == oAuthSonosMockThingClassId) {
|
||||
qCDebug(dcMock()) << "Sonos OAuth setup complete";
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
}
|
||||
|
||||
qCWarning(dcMockDevice()) << "Unhandled device class" << info->thing()->thingClass();
|
||||
qCWarning(dcMock()) << "Unhandled thing class" << info->thing()->thingClass();
|
||||
info->finish(Thing::ThingErrorThingClassNotFound);
|
||||
}
|
||||
|
||||
void DevicePluginMock::postSetupThing(Thing *device)
|
||||
{
|
||||
qCDebug(dcMockDevice) << "Postsetup mockdevice" << device->name();
|
||||
if (device->thingClassId() == mockParentThingClassId) {
|
||||
qCDebug(dcMock()) << "Postsetup mock" << device->name();
|
||||
if (device->thingClassId() == parentMockThingClassId) {
|
||||
foreach (Thing *d, myThings()) {
|
||||
if (d->thingClassId() == mockChildThingClassId && d->parentId() == device->id()) {
|
||||
if (d->thingClassId() == childMockThingClassId && d->parentId() == device->id()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ThingDescriptor mockDescriptor(mockChildThingClassId, "Child Mock Device (Auto created)", "Child Mock Device (Auto created)", device->id());
|
||||
ThingDescriptor mockDescriptor(childMockThingClassId, "Mocked Thing Child (Auto created)", "Mocked Thing Child (Auto created)", device->id());
|
||||
emit autoThingsAppeared(ThingDescriptors() << mockDescriptor);
|
||||
}
|
||||
}
|
||||
@ -277,17 +277,17 @@ void DevicePluginMock::thingRemoved(Thing *device)
|
||||
void DevicePluginMock::startMonitoringAutoThings()
|
||||
{
|
||||
foreach (Thing *device, myThings()) {
|
||||
if (device->thingClassId() == mockDeviceAutoThingClassId) {
|
||||
if (device->thingClassId() == autoMockThingClassId) {
|
||||
return; // We already have a Auto Mock device... do nothing.
|
||||
}
|
||||
}
|
||||
|
||||
ThingDescriptor mockDescriptor(mockDeviceAutoThingClassId, "Mock Device (Auto created)");
|
||||
ThingDescriptor mockDescriptor(autoMockThingClassId, "Mocked Thing (Auto created)");
|
||||
|
||||
ParamList params;
|
||||
qsrand(QDateTime::currentMSecsSinceEpoch());
|
||||
int port = 4242 + (qrand() % 1000);
|
||||
Param param(mockDeviceAutoDeviceHttpportParamTypeId, port);
|
||||
Param param(autoMockThingHttpportParamTypeId, port);
|
||||
params.append(param);
|
||||
mockDescriptor.setParams(params);
|
||||
|
||||
@ -299,27 +299,27 @@ void DevicePluginMock::startMonitoringAutoThings()
|
||||
|
||||
void DevicePluginMock::startPairing(ThingPairingInfo *info)
|
||||
{
|
||||
if (info->thingClassId() == mockPushButtonThingClassId) {
|
||||
qCDebug(dcMockDevice) << "Push button. Pressing the button in 3 seconds.";
|
||||
if (info->thingClassId() == pushButtonMockThingClassId) {
|
||||
qCDebug(dcMock()) << "Push button. Pressing the button in 3 seconds.";
|
||||
info->finish(Thing::ThingErrorNoError, QT_TR_NOOP("Wait 3 second before you continue, the push button will be pressed automatically."));
|
||||
m_pushbuttonPressed = false;
|
||||
QTimer::singleShot(3000, this, SLOT(onPushButtonPressed()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (info->thingClassId() == mockDisplayPinThingClassId) {
|
||||
qCDebug(dcMockDevice) << "Display pin!! The pin is 243681";
|
||||
info->finish(Thing::ThingErrorNoError, QT_TR_NOOP("Please enter the secret which normaly will be displayed on the device. For the mockdevice the pin is 243681."));
|
||||
if (info->thingClassId() == displayPinMockThingClassId) {
|
||||
qCDebug(dcMock()) << "Display pin!! The pin is 243681";
|
||||
info->finish(Thing::ThingErrorNoError, QT_TR_NOOP("Please enter the secret which normaly will be displayed on the device. For this mocked thing the pin is 243681."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (info->thingClassId() == mockUserAndPassThingClassId) {
|
||||
qCDebug(dcMockDevice) << "User and password. Login is \"user\" and \"password\".";
|
||||
info->finish(Thing::ThingErrorNoError, QT_TR_NOOP("Please enter login credentials for the mock device (\"user\" and \"password\")."));
|
||||
if (info->thingClassId() == userAndPassMockThingClassId) {
|
||||
qCDebug(dcMock()) << "User and password. Login is \"user\" and \"password\".";
|
||||
info->finish(Thing::ThingErrorNoError, QT_TR_NOOP("Please enter login credentials for the mocked thing (\"user\" and \"password\")."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (info->thingClassId() == mockOAuthSonosThingClassId) {
|
||||
if (info->thingClassId() == oAuthSonosMockThingClassId) {
|
||||
QString clientId = "b15cbf8c-a39c-47aa-bd93-635a96e9696c";
|
||||
QString clientSecret = "c086ba71-e562-430b-a52f-867c6482fd11";
|
||||
|
||||
@ -332,14 +332,14 @@ void DevicePluginMock::startPairing(ThingPairingInfo *info)
|
||||
queryParams.addQueryItem("state", "ya-ya");
|
||||
url.setQuery(queryParams);
|
||||
|
||||
qCDebug(dcMockDevice()) << "Sonos url:" << url;
|
||||
qCDebug(dcMock()) << "Sonos url:" << url;
|
||||
|
||||
info->setOAuthUrl(url);
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
}
|
||||
|
||||
if (info->thingClassId() == mockOAuthGoogleThingClassId) {
|
||||
if (info->thingClassId() == oAuthGoogleMockThingClassId) {
|
||||
QString clientId= "937667874529-pr6s5ciu6sfnnqmt2sppvb6rokbkjjta.apps.googleusercontent.com";
|
||||
QString clientSecret = "1ByBRmNqaK08VC54eEVcnGf1";
|
||||
|
||||
@ -362,11 +362,11 @@ void DevicePluginMock::startPairing(ThingPairingInfo *info)
|
||||
|
||||
void DevicePluginMock::confirmPairing(ThingPairingInfo *info, const QString &username, const QString &secret)
|
||||
{
|
||||
qCDebug(dcMockDevice) << "Confirm pairing";
|
||||
qCDebug(dcMock()) << "Confirm pairing";
|
||||
|
||||
if (info->thingClassId() == mockPushButtonThingClassId) {
|
||||
if (info->thingClassId() == pushButtonMockThingClassId) {
|
||||
if (!m_pushbuttonPressed) {
|
||||
qCDebug(dcMockDevice) << "PushButton not pressed yet!";
|
||||
qCDebug(dcMock()) << "PushButton not pressed yet!";
|
||||
info->finish(Thing::ThingErrorAuthenticationFailure, QT_TR_NOOP("The push button has not been pressed."));
|
||||
return;
|
||||
}
|
||||
@ -377,21 +377,21 @@ void DevicePluginMock::confirmPairing(ThingPairingInfo *info, const QString &use
|
||||
return;
|
||||
}
|
||||
|
||||
if (info->thingClassId() == mockDisplayPinThingClassId) {
|
||||
if (info->thingClassId() == displayPinMockThingClassId) {
|
||||
if (secret != "243681") {
|
||||
qCWarning(dcMockDevice) << "Invalid pin:" << secret;
|
||||
qCWarning(dcMock()) << "Invalid pin:" << secret;
|
||||
info->finish(Thing::ThingErrorAuthenticationFailure, QT_TR_NOOP("Invalid PIN!"));
|
||||
return;
|
||||
}
|
||||
QTimer::singleShot(500, this, [info](){
|
||||
qCDebug(dcMockDevice()) << "Pairing finished.";
|
||||
qCDebug(dcMock()) << "Pairing finished.";
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (info->thingClassId() == mockUserAndPassThingClassId) {
|
||||
qCDebug(dcMockDevice()) << "Credentials received:" << username << secret;
|
||||
if (info->thingClassId() == userAndPassMockThingClassId) {
|
||||
qCDebug(dcMock()) << "Credentials received:" << username << secret;
|
||||
if (username == "user" && secret == "password") {
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
@ -402,11 +402,11 @@ void DevicePluginMock::confirmPairing(ThingPairingInfo *info, const QString &use
|
||||
}
|
||||
|
||||
|
||||
if (info->thingClassId() == mockOAuthSonosThingClassId) {
|
||||
qCDebug(dcMockDevice()) << "Secret is" << secret;
|
||||
if (info->thingClassId() == oAuthSonosMockThingClassId) {
|
||||
qCDebug(dcMock()) << "Secret is" << secret;
|
||||
QUrl url(secret);
|
||||
QUrlQuery query(url);
|
||||
qCDebug(dcMockDevice()) << "Acess code is:" << query.queryItemValue("code");
|
||||
qCDebug(dcMock()) << "Acess code is:" << query.queryItemValue("code");
|
||||
|
||||
QString accessCode = query.queryItemValue("code");
|
||||
|
||||
@ -432,10 +432,10 @@ void DevicePluginMock::confirmPairing(ThingPairingInfo *info, const QString &use
|
||||
reply->deleteLater();
|
||||
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll());
|
||||
qCDebug(dcMockDevice()) << "Sonos accessToken reply:" << this << reply->error() << reply->errorString() << jsonDoc.toJson();
|
||||
qCDebug(dcMockDevice()) << "Access token:" << jsonDoc.toVariant().toMap().value("access_token").toString();
|
||||
qCDebug(dcMockDevice()) << "expires at" << QDateTime::currentDateTime().addSecs(jsonDoc.toVariant().toMap().value("expires_in").toInt()).toString();
|
||||
qCDebug(dcMockDevice()) << "Refresh token:" << jsonDoc.toVariant().toMap().value("refresh_token").toString();
|
||||
qCDebug(dcMock()) << "Sonos accessToken reply:" << this << reply->error() << reply->errorString() << jsonDoc.toJson();
|
||||
qCDebug(dcMock()) << "Access token:" << jsonDoc.toVariant().toMap().value("access_token").toString();
|
||||
qCDebug(dcMock()) << "expires at" << QDateTime::currentDateTime().addSecs(jsonDoc.toVariant().toMap().value("expires_in").toInt()).toString();
|
||||
qCDebug(dcMock()) << "Refresh token:" << jsonDoc.toVariant().toMap().value("refresh_token").toString();
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
});
|
||||
|
||||
@ -443,11 +443,11 @@ void DevicePluginMock::confirmPairing(ThingPairingInfo *info, const QString &use
|
||||
}
|
||||
|
||||
|
||||
if (info->thingClassId() == mockOAuthGoogleThingClassId) {
|
||||
qCDebug(dcMockDevice()) << "Secret is" << secret;
|
||||
if (info->thingClassId() == oAuthGoogleMockThingClassId) {
|
||||
qCDebug(dcMock()) << "Secret is" << secret;
|
||||
QUrl url(secret);
|
||||
QUrlQuery query(url);
|
||||
qCDebug(dcMockDevice()) << "Acess code is:" << query.queryItemValue("code");
|
||||
qCDebug(dcMock()) << "Acess code is:" << query.queryItemValue("code");
|
||||
|
||||
QString accessCode = query.queryItemValue("code");
|
||||
|
||||
@ -472,29 +472,29 @@ void DevicePluginMock::confirmPairing(ThingPairingInfo *info, const QString &use
|
||||
reply->deleteLater();
|
||||
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll());
|
||||
qCDebug(dcMockDevice()) << "Sonos accessToken reply:" << this << reply->error() << reply->errorString() << jsonDoc.toJson();
|
||||
qCDebug(dcMockDevice()) << "Access token:" << jsonDoc.toVariant().toMap().value("access_token").toString();
|
||||
qCDebug(dcMockDevice()) << "expires at" << QDateTime::currentDateTime().addSecs(jsonDoc.toVariant().toMap().value("expires_in").toInt()).toString();
|
||||
qCDebug(dcMockDevice()) << "Refresh token:" << jsonDoc.toVariant().toMap().value("refresh_token").toString();
|
||||
qCDebug(dcMockDevice()) << "ID token:" << jsonDoc.toVariant().toMap().value("id_token").toString();
|
||||
qCDebug(dcMock()) << "Sonos accessToken reply:" << this << reply->error() << reply->errorString() << jsonDoc.toJson();
|
||||
qCDebug(dcMock()) << "Access token:" << jsonDoc.toVariant().toMap().value("access_token").toString();
|
||||
qCDebug(dcMock()) << "expires at" << QDateTime::currentDateTime().addSecs(jsonDoc.toVariant().toMap().value("expires_in").toInt()).toString();
|
||||
qCDebug(dcMock()) << "Refresh token:" << jsonDoc.toVariant().toMap().value("refresh_token").toString();
|
||||
qCDebug(dcMock()) << "ID token:" << jsonDoc.toVariant().toMap().value("id_token").toString();
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
qCWarning(dcMockDevice) << "Invalid ThingClassId -> no pairing possible with this device";
|
||||
qCWarning(dcMock()) << "Invalid ThingClassId -> no pairing possible with this thing";
|
||||
info->finish(Thing::ThingErrorThingClassNotFound);
|
||||
}
|
||||
|
||||
void DevicePluginMock::browseThing(BrowseResult *result)
|
||||
{
|
||||
qCDebug(dcMockDevice()) << "Browse device called" << result->thing();
|
||||
qCDebug(dcMock()) << "Browse thing called" << result->thing();
|
||||
if (result->thing()->thingClassId() == mockThingClassId) {
|
||||
if (result->thing()->paramValue(mockDeviceAsyncParamTypeId).toBool()) {
|
||||
if (result->thing()->paramValue(mockThingAsyncParamTypeId).toBool()) {
|
||||
|
||||
QTimer::singleShot(1000, result, [this, result]() {
|
||||
if (result->thing()->paramValue(mockDeviceBrokenParamTypeId).toBool()) {
|
||||
if (result->thing()->paramValue(mockThingBrokenParamTypeId).toBool()) {
|
||||
result->finish(Thing::ThingErrorHardwareFailure);
|
||||
return;
|
||||
}
|
||||
@ -515,7 +515,7 @@ void DevicePluginMock::browseThing(BrowseResult *result)
|
||||
return;
|
||||
}
|
||||
|
||||
if (result->thing()->paramValue(mockDeviceBrokenParamTypeId).toBool()) {
|
||||
if (result->thing()->paramValue(mockThingBrokenParamTypeId).toBool()) {
|
||||
result->finish(Thing::ThingErrorHardwareFailure);
|
||||
return;
|
||||
}
|
||||
@ -567,7 +567,7 @@ void DevicePluginMock::executeAction(ThingActionInfo *info)
|
||||
}
|
||||
|
||||
if (info->action().actionTypeId() == mockPowerActionTypeId) {
|
||||
qCDebug(dcMockDevice()) << "Setting power to" << info->action().param(mockPowerActionPowerParamTypeId).value().toBool();
|
||||
qCDebug(dcMock()) << "Setting power to" << info->action().param(mockPowerActionPowerParamTypeId).value().toBool();
|
||||
info->thing()->setStateValue(mockPowerStateTypeId, info->action().param(mockPowerActionPowerParamTypeId).value().toBool());
|
||||
}
|
||||
m_daemons.value(info->thing())->actionExecuted(info->action().actionTypeId());
|
||||
@ -575,10 +575,10 @@ void DevicePluginMock::executeAction(ThingActionInfo *info)
|
||||
return;
|
||||
}
|
||||
|
||||
if (info->thing()->thingClassId() == mockDeviceAutoThingClassId) {
|
||||
if (info->action().actionTypeId() == mockDeviceAutoMockActionAsyncActionTypeId || info->action().actionTypeId() == mockDeviceAutoMockActionAsyncBrokenActionTypeId) {
|
||||
if (info->thing()->thingClassId() == autoMockThingClassId) {
|
||||
if (info->action().actionTypeId() == autoMockMockActionAsyncActionTypeId || info->action().actionTypeId() == autoMockMockActionAsyncBrokenActionTypeId) {
|
||||
QTimer::singleShot(1000, info->thing(), [info](){
|
||||
if (info->action().actionTypeId() == mockDeviceAutoMockActionAsyncBrokenActionTypeId) {
|
||||
if (info->action().actionTypeId() == autoMockMockActionAsyncBrokenActionTypeId) {
|
||||
info->finish(Thing::ThingErrorSetupFailed, QT_TR_NOOP("This mock action is intentionally broken."));
|
||||
} else {
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
@ -586,124 +586,124 @@ void DevicePluginMock::executeAction(ThingActionInfo *info)
|
||||
});
|
||||
}
|
||||
|
||||
if (info->action().actionTypeId() == mockDeviceAutoMockActionBrokenActionTypeId) {
|
||||
if (info->action().actionTypeId() == autoMockMockActionBrokenActionTypeId) {
|
||||
info->finish(Thing::ThingErrorSetupFailed);
|
||||
return;
|
||||
}
|
||||
|
||||
m_daemons.value(info->thing())->actionExecuted(info->action().actionTypeId());
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
} else if (info->thing()->thingClassId() == mockPushButtonThingClassId) {
|
||||
if (info->action().actionTypeId() == mockPushButtonColorActionTypeId) {
|
||||
QString colorString = info->action().param(mockPushButtonColorActionColorParamTypeId).value().toString();
|
||||
} else if (info->thing()->thingClassId() == pushButtonMockThingClassId) {
|
||||
if (info->action().actionTypeId() == pushButtonMockColorActionTypeId) {
|
||||
QString colorString = info->action().param(pushButtonMockColorActionColorParamTypeId).value().toString();
|
||||
QColor color(colorString);
|
||||
if (!color.isValid()) {
|
||||
qCWarning(dcMockDevice) << "Invalid color parameter";
|
||||
qCWarning(dcMock()) << "Invalid color parameter";
|
||||
info->finish(Thing::ThingErrorInvalidParameter);
|
||||
return;
|
||||
}
|
||||
info->thing()->setStateValue(mockPushButtonColorStateTypeId, colorString);
|
||||
info->thing()->setStateValue(pushButtonMockColorStateTypeId, colorString);
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
} else if (info->action().actionTypeId() == mockPushButtonPercentageActionTypeId) {
|
||||
info->thing()->setStateValue(mockPushButtonPercentageStateTypeId, info->action().param(mockPushButtonPercentageActionPercentageParamTypeId).value().toInt());
|
||||
} else if (info->action().actionTypeId() == pushButtonMockPercentageActionTypeId) {
|
||||
info->thing()->setStateValue(pushButtonMockPercentageStateTypeId, info->action().param(pushButtonMockPercentageActionPercentageParamTypeId).value().toInt());
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
} else if (info->action().actionTypeId() == mockPushButtonAllowedValuesActionTypeId) {
|
||||
info->thing()->setStateValue(mockPushButtonAllowedValuesStateTypeId, info->action().param(mockPushButtonAllowedValuesActionAllowedValuesParamTypeId).value().toString());
|
||||
} else if (info->action().actionTypeId() == pushButtonMockAllowedValuesActionTypeId) {
|
||||
info->thing()->setStateValue(pushButtonMockAllowedValuesStateTypeId, info->action().param(pushButtonMockAllowedValuesActionAllowedValuesParamTypeId).value().toString());
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
} else if (info->action().actionTypeId() == mockPushButtonDoubleActionTypeId) {
|
||||
info->thing()->setStateValue(mockPushButtonDoubleStateTypeId, info->action().param(mockPushButtonDoubleActionDoubleParamTypeId).value().toDouble());
|
||||
} else if (info->action().actionTypeId() == pushButtonMockDoubleActionTypeId) {
|
||||
info->thing()->setStateValue(pushButtonMockDoubleStateTypeId, info->action().param(pushButtonMockDoubleActionDoubleParamTypeId).value().toDouble());
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
} else if (info->action().actionTypeId() == mockPushButtonBoolActionTypeId) {
|
||||
info->thing()->setStateValue(mockPushButtonBoolStateTypeId, info->action().param(mockPushButtonBoolActionBoolParamTypeId).value().toBool());
|
||||
} else if (info->action().actionTypeId() == pushButtonMockBoolActionTypeId) {
|
||||
info->thing()->setStateValue(pushButtonMockBoolStateTypeId, info->action().param(pushButtonMockBoolActionBoolParamTypeId).value().toBool());
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
} else if (info->action().actionTypeId() == mockPushButtonTimeoutActionTypeId) {
|
||||
} else if (info->action().actionTypeId() == pushButtonMockTimeoutActionTypeId) {
|
||||
// Not finishing action intentionally...
|
||||
return;
|
||||
}
|
||||
info->finish(Thing::ThingErrorActionTypeNotFound);
|
||||
return;
|
||||
} else if (info->thing()->thingClassId() == mockDisplayPinThingClassId) {
|
||||
if (info->action().actionTypeId() == mockDisplayPinColorActionTypeId) {
|
||||
QString colorString = info->action().param(mockDisplayPinColorActionColorParamTypeId).value().toString();
|
||||
} else if (info->thing()->thingClassId() == displayPinMockThingClassId) {
|
||||
if (info->action().actionTypeId() == displayPinMockColorActionTypeId) {
|
||||
QString colorString = info->action().param(displayPinMockColorActionColorParamTypeId).value().toString();
|
||||
QColor color(colorString);
|
||||
if (!color.isValid()) {
|
||||
qCWarning(dcMockDevice) << "Invalid color parameter";
|
||||
qCWarning(dcMock()) << "Invalid color parameter";
|
||||
info->finish(Thing::ThingErrorInvalidParameter);
|
||||
return;
|
||||
}
|
||||
info->thing()->setStateValue(mockDisplayPinColorStateTypeId, colorString);
|
||||
info->thing()->setStateValue(displayPinMockColorStateTypeId, colorString);
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
} else if (info->action().actionTypeId() == mockDisplayPinPercentageActionTypeId) {
|
||||
info->thing()->setStateValue(mockDisplayPinPercentageStateTypeId, info->action().param(mockDisplayPinPercentageActionPercentageParamTypeId).value().toInt());
|
||||
} else if (info->action().actionTypeId() == displayPinMockPercentageActionTypeId) {
|
||||
info->thing()->setStateValue(displayPinMockPercentageStateTypeId, info->action().param(displayPinMockPercentageActionPercentageParamTypeId).value().toInt());
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
} else if (info->action().actionTypeId() == mockDisplayPinAllowedValuesActionTypeId) {
|
||||
info->thing()->setStateValue(mockDisplayPinAllowedValuesStateTypeId, info->action().param(mockDisplayPinAllowedValuesActionAllowedValuesParamTypeId).value().toString());
|
||||
} else if (info->action().actionTypeId() == displayPinMockAllowedValuesActionTypeId) {
|
||||
info->thing()->setStateValue(displayPinMockAllowedValuesStateTypeId, info->action().param(displayPinMockAllowedValuesActionAllowedValuesParamTypeId).value().toString());
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
} else if (info->action().actionTypeId() == mockDisplayPinDoubleActionTypeId) {
|
||||
info->thing()->setStateValue(mockDisplayPinDoubleStateTypeId, info->action().param(mockDisplayPinDoubleActionDoubleParamTypeId).value().toDouble());
|
||||
} else if (info->action().actionTypeId() == displayPinMockDoubleActionTypeId) {
|
||||
info->thing()->setStateValue(displayPinMockDoubleStateTypeId, info->action().param(displayPinMockDoubleActionDoubleParamTypeId).value().toDouble());
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
} else if (info->action().actionTypeId() == mockDisplayPinBoolActionTypeId) {
|
||||
info->thing()->setStateValue(mockDisplayPinBoolStateTypeId, info->action().param(mockDisplayPinBoolActionBoolParamTypeId).value().toBool());
|
||||
} else if (info->action().actionTypeId() == displayPinMockBoolActionTypeId) {
|
||||
info->thing()->setStateValue(displayPinMockBoolStateTypeId, info->action().param(displayPinMockBoolActionBoolParamTypeId).value().toBool());
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
} else if (info->action().actionTypeId() == mockDisplayPinTimeoutActionTypeId) {
|
||||
} else if (info->action().actionTypeId() == displayPinMockTimeoutActionTypeId) {
|
||||
// Not finishing action intentionally...
|
||||
return;
|
||||
}
|
||||
info->finish(Thing::ThingErrorActionTypeNotFound);
|
||||
return;
|
||||
} else if (info->thing()->thingClassId() == mockParentThingClassId) {
|
||||
if (info->action().actionTypeId() == mockParentBoolValueActionTypeId) {
|
||||
info->thing()->setStateValue(mockParentBoolValueStateTypeId, info->action().param(mockParentBoolValueActionBoolValueParamTypeId).value().toBool());
|
||||
} else if (info->thing()->thingClassId() == parentMockThingClassId) {
|
||||
if (info->action().actionTypeId() == parentMockBoolValueActionTypeId) {
|
||||
info->thing()->setStateValue(parentMockBoolValueStateTypeId, info->action().param(parentMockBoolValueActionBoolValueParamTypeId).value().toBool());
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
}
|
||||
info->finish(Thing::ThingErrorActionTypeNotFound);
|
||||
return;
|
||||
} else if (info->thing()->thingClassId() == mockChildThingClassId) {
|
||||
if (info->action().actionTypeId() == mockChildBoolValueActionTypeId) {
|
||||
info->thing()->setStateValue(mockChildBoolValueStateTypeId, info->action().param(mockChildBoolValueActionBoolValueParamTypeId).value().toBool());
|
||||
} else if (info->thing()->thingClassId() == childMockThingClassId) {
|
||||
if (info->action().actionTypeId() == childMockBoolValueActionTypeId) {
|
||||
info->thing()->setStateValue(childMockBoolValueStateTypeId, info->action().param(childMockBoolValueActionBoolValueParamTypeId).value().toBool());
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
}
|
||||
info->finish(Thing::ThingErrorActionTypeNotFound);
|
||||
return;
|
||||
} else if (info->thing()->thingClassId() == mockInputTypeThingClassId) {
|
||||
if (info->action().actionTypeId() == mockInputTypeWritableBoolActionTypeId) {
|
||||
info->thing()->setStateValue(mockInputTypeWritableBoolStateTypeId, info->action().param(mockInputTypeWritableBoolActionWritableBoolParamTypeId).value().toULongLong());
|
||||
} else if (info->action().actionTypeId() == mockInputTypeWritableIntActionTypeId) {
|
||||
info->thing()->setStateValue(mockInputTypeWritableIntStateTypeId, info->action().param(mockInputTypeWritableIntActionWritableIntParamTypeId).value().toLongLong());
|
||||
} else if (info->action().actionTypeId() == mockInputTypeWritableIntMinMaxActionTypeId) {
|
||||
info->thing()->setStateValue(mockInputTypeWritableIntMinMaxStateTypeId, info->action().param(mockInputTypeWritableIntMinMaxActionWritableIntMinMaxParamTypeId).value().toLongLong());
|
||||
} else if (info->action().actionTypeId() == mockInputTypeWritableUIntActionTypeId) {
|
||||
info->thing()->setStateValue(mockInputTypeWritableUIntStateTypeId, info->action().param(mockInputTypeWritableUIntActionWritableUIntParamTypeId).value().toULongLong());
|
||||
} else if (info->action().actionTypeId() == mockInputTypeWritableUIntMinMaxActionTypeId) {
|
||||
info->thing()->setStateValue(mockInputTypeWritableUIntMinMaxStateTypeId, info->action().param(mockInputTypeWritableUIntMinMaxActionWritableUIntMinMaxParamTypeId).value().toLongLong());
|
||||
} else if (info->action().actionTypeId() == mockInputTypeWritableDoubleActionTypeId) {
|
||||
info->thing()->setStateValue(mockInputTypeWritableDoubleStateTypeId, info->action().param(mockInputTypeWritableDoubleActionWritableDoubleParamTypeId).value().toDouble());
|
||||
} else if (info->action().actionTypeId() == mockInputTypeWritableDoubleMinMaxActionTypeId) {
|
||||
info->thing()->setStateValue(mockInputTypeWritableDoubleMinMaxStateTypeId, info->action().param(mockInputTypeWritableDoubleMinMaxActionWritableDoubleMinMaxParamTypeId).value().toDouble());
|
||||
} else if (info->action().actionTypeId() == mockInputTypeWritableStringActionTypeId) {
|
||||
info->thing()->setStateValue(mockInputTypeWritableStringStateTypeId, info->action().param(mockInputTypeWritableStringActionWritableStringParamTypeId).value().toString());
|
||||
} else if (info->action().actionTypeId() == mockInputTypeWritableStringSelectionActionTypeId) {
|
||||
info->thing()->setStateValue(mockInputTypeWritableStringSelectionStateTypeId, info->action().param(mockInputTypeWritableStringSelectionActionWritableStringSelectionParamTypeId).value().toString());
|
||||
} else if (info->action().actionTypeId() == mockInputTypeWritableColorActionTypeId) {
|
||||
info->thing()->setStateValue(mockInputTypeWritableColorStateTypeId, info->action().param(mockInputTypeWritableColorActionWritableColorParamTypeId).value().toString());
|
||||
} else if (info->action().actionTypeId() == mockInputTypeWritableTimeActionTypeId) {
|
||||
info->thing()->setStateValue(mockInputTypeWritableTimeStateTypeId, info->action().param(mockInputTypeWritableTimeActionWritableTimeParamTypeId).value().toTime());
|
||||
} else if (info->action().actionTypeId() == mockInputTypeWritableTimestampIntActionTypeId) {
|
||||
info->thing()->setStateValue(mockInputTypeWritableTimestampIntStateTypeId, info->action().param(mockInputTypeWritableTimestampIntActionWritableTimestampIntParamTypeId).value().toLongLong());
|
||||
} else if (info->action().actionTypeId() == mockInputTypeWritableTimestampUIntActionTypeId) {
|
||||
info->thing()->setStateValue(mockInputTypeWritableTimestampUIntStateTypeId, info->action().param(mockInputTypeWritableTimestampUIntActionWritableTimestampUIntParamTypeId).value().toULongLong());
|
||||
} else if (info->thing()->thingClassId() == inputTypeMockThingClassId) {
|
||||
if (info->action().actionTypeId() == inputTypeMockWritableBoolActionTypeId) {
|
||||
info->thing()->setStateValue(inputTypeMockWritableBoolStateTypeId, info->action().param(inputTypeMockWritableBoolActionWritableBoolParamTypeId).value().toULongLong());
|
||||
} else if (info->action().actionTypeId() == inputTypeMockWritableIntActionTypeId) {
|
||||
info->thing()->setStateValue(inputTypeMockWritableIntStateTypeId, info->action().param(inputTypeMockWritableIntActionWritableIntParamTypeId).value().toLongLong());
|
||||
} else if (info->action().actionTypeId() == inputTypeMockWritableIntMinMaxActionTypeId) {
|
||||
info->thing()->setStateValue(inputTypeMockWritableIntMinMaxStateTypeId, info->action().param(inputTypeMockWritableIntMinMaxActionWritableIntMinMaxParamTypeId).value().toLongLong());
|
||||
} else if (info->action().actionTypeId() == inputTypeMockWritableUIntActionTypeId) {
|
||||
info->thing()->setStateValue(inputTypeMockWritableUIntStateTypeId, info->action().param(inputTypeMockWritableUIntActionWritableUIntParamTypeId).value().toULongLong());
|
||||
} else if (info->action().actionTypeId() == inputTypeMockWritableUIntMinMaxActionTypeId) {
|
||||
info->thing()->setStateValue(inputTypeMockWritableUIntMinMaxStateTypeId, info->action().param(inputTypeMockWritableUIntMinMaxActionWritableUIntMinMaxParamTypeId).value().toLongLong());
|
||||
} else if (info->action().actionTypeId() == inputTypeMockWritableDoubleActionTypeId) {
|
||||
info->thing()->setStateValue(inputTypeMockWritableDoubleStateTypeId, info->action().param(inputTypeMockWritableDoubleActionWritableDoubleParamTypeId).value().toDouble());
|
||||
} else if (info->action().actionTypeId() == inputTypeMockWritableDoubleMinMaxActionTypeId) {
|
||||
info->thing()->setStateValue(inputTypeMockWritableDoubleMinMaxStateTypeId, info->action().param(inputTypeMockWritableDoubleMinMaxActionWritableDoubleMinMaxParamTypeId).value().toDouble());
|
||||
} else if (info->action().actionTypeId() == inputTypeMockWritableStringActionTypeId) {
|
||||
info->thing()->setStateValue(inputTypeMockWritableStringStateTypeId, info->action().param(inputTypeMockWritableStringActionWritableStringParamTypeId).value().toString());
|
||||
} else if (info->action().actionTypeId() == inputTypeMockWritableStringSelectionActionTypeId) {
|
||||
info->thing()->setStateValue(inputTypeMockWritableStringSelectionStateTypeId, info->action().param(inputTypeMockWritableStringSelectionActionWritableStringSelectionParamTypeId).value().toString());
|
||||
} else if (info->action().actionTypeId() == inputTypeMockWritableColorActionTypeId) {
|
||||
info->thing()->setStateValue(inputTypeMockWritableColorStateTypeId, info->action().param(inputTypeMockWritableColorActionWritableColorParamTypeId).value().toString());
|
||||
} else if (info->action().actionTypeId() == inputTypeMockWritableTimeActionTypeId) {
|
||||
info->thing()->setStateValue(inputTypeMockWritableTimeStateTypeId, info->action().param(inputTypeMockWritableTimeActionWritableTimeParamTypeId).value().toTime());
|
||||
} else if (info->action().actionTypeId() == inputTypeMockWritableTimestampIntActionTypeId) {
|
||||
info->thing()->setStateValue(inputTypeMockWritableTimestampIntStateTypeId, info->action().param(inputTypeMockWritableTimestampIntActionWritableTimestampIntParamTypeId).value().toLongLong());
|
||||
} else if (info->action().actionTypeId() == inputTypeMockWritableTimestampUIntActionTypeId) {
|
||||
info->thing()->setStateValue(inputTypeMockWritableTimestampUIntStateTypeId, info->action().param(inputTypeMockWritableTimestampUIntActionWritableTimestampUIntParamTypeId).value().toULongLong());
|
||||
}
|
||||
return;
|
||||
|
||||
@ -713,9 +713,9 @@ void DevicePluginMock::executeAction(ThingActionInfo *info)
|
||||
|
||||
void DevicePluginMock::executeBrowserItem(BrowserActionInfo *info)
|
||||
{
|
||||
qCDebug(dcMockDevice()) << "ExecuteBrowserItem called" << info->browserAction().itemId();
|
||||
bool broken = info->thing()->paramValue(mockDeviceBrokenParamTypeId).toBool();
|
||||
bool async = info->thing()->paramValue(mockDeviceAsyncParamTypeId).toBool();
|
||||
qCDebug(dcMock()) << "ExecuteBrowserItem called" << info->browserAction().itemId();
|
||||
bool broken = info->thing()->paramValue(mockThingBrokenParamTypeId).toBool();
|
||||
bool async = info->thing()->paramValue(mockThingAsyncParamTypeId).toBool();
|
||||
|
||||
VirtualFsNode *node = m_virtualFs->findNode(info->browserAction().itemId());
|
||||
if (!node) {
|
||||
@ -745,7 +745,7 @@ void DevicePluginMock::executeBrowserItem(BrowserActionInfo *info)
|
||||
|
||||
void DevicePluginMock::executeBrowserItemAction(BrowserItemActionInfo *info)
|
||||
{
|
||||
qCDebug(dcMockDevice()) << "TODO" << info << info->browserItemAction().id();
|
||||
qCDebug(dcMock()) << "TODO" << info << info->browserItemAction().id();
|
||||
if (info->browserItemAction().actionTypeId() == mockAddToFavoritesBrowserItemActionTypeId) {
|
||||
|
||||
VirtualFsNode *node = m_virtualFs->findNode(info->browserItemAction().itemId());
|
||||
@ -803,7 +803,7 @@ void DevicePluginMock::triggerEvent(const EventTypeId &id)
|
||||
|
||||
Event event(id, device->id());
|
||||
|
||||
qCDebug(dcMockDevice) << "Emitting event " << event.eventTypeId();
|
||||
qCDebug(dcMock) << "Emitting event " << event.eventTypeId();
|
||||
emit emitEvent(event);
|
||||
}
|
||||
|
||||
@ -814,7 +814,7 @@ void DevicePluginMock::onDisappear()
|
||||
return;
|
||||
}
|
||||
Thing *device = m_daemons.key(daemon);
|
||||
qCDebug(dcMockDevice) << "Emitting autoDeviceDisappeared for device" << device->id();
|
||||
qCDebug(dcMock) << "Emitting autoDeviceDisappeared for device" << device->id();
|
||||
emit autoThingDisappeared(device->id());
|
||||
}
|
||||
|
||||
@ -825,15 +825,15 @@ void DevicePluginMock::onReconfigureAutoDevice()
|
||||
return;
|
||||
|
||||
Thing *device = m_daemons.key(daemon);
|
||||
qCDebug(dcMockDevice()) << "Reconfigure auto device for" << device << device->params();
|
||||
qCDebug(dcMock()) << "Reconfigure auto device for" << device << device->params();
|
||||
|
||||
int currentPort = device->params().paramValue(mockDeviceAutoDeviceHttpportParamTypeId).toInt();
|
||||
int currentPort = device->params().paramValue(autoMockThingHttpportParamTypeId).toInt();
|
||||
|
||||
// Note: the reconfigure makes the http server listen on port + 1
|
||||
ParamList params;
|
||||
params.append(Param(mockDeviceAutoDeviceHttpportParamTypeId, currentPort + 1));
|
||||
params.append(Param(autoMockThingHttpportParamTypeId, currentPort + 1));
|
||||
|
||||
ThingDescriptor deviceDescriptor(mockDeviceAutoThingClassId);
|
||||
ThingDescriptor deviceDescriptor(autoMockThingClassId);
|
||||
deviceDescriptor.setTitle(device->name() + " (reconfigured)");
|
||||
deviceDescriptor.setDescription("This auto device was reconfigured");
|
||||
deviceDescriptor.setThingId(device->id());
|
||||
@ -847,11 +847,11 @@ void DevicePluginMock::generateDiscoveredDevices(ThingDiscoveryInfo *info)
|
||||
if (m_discoveredDeviceCount > 0) {
|
||||
ThingDescriptor d1(mockThingClassId, "Mock Device 1 (Discovered)", "55555");
|
||||
ParamList params;
|
||||
Param httpParam(mockDeviceHttpportParamTypeId, "55555");
|
||||
Param httpParam(mockThingHttpportParamTypeId, "55555");
|
||||
params.append(httpParam);
|
||||
d1.setParams(params);
|
||||
foreach (Thing *d, myThings()) {
|
||||
if (d->thingClassId() == mockThingClassId && d->paramValue(mockDeviceHttpportParamTypeId).toInt() == 55555) {
|
||||
if (d->thingClassId() == mockThingClassId && d->paramValue(mockThingHttpportParamTypeId).toInt() == 55555) {
|
||||
d1.setThingId(d->id());
|
||||
break;
|
||||
}
|
||||
@ -862,11 +862,11 @@ void DevicePluginMock::generateDiscoveredDevices(ThingDiscoveryInfo *info)
|
||||
if (m_discoveredDeviceCount > 1) {
|
||||
ThingDescriptor d2(mockThingClassId, "Mock Device 2 (Discovered)", "55556");
|
||||
ParamList params;
|
||||
Param httpParam(mockDeviceHttpportParamTypeId, "55556");
|
||||
Param httpParam(mockThingHttpportParamTypeId, "55556");
|
||||
params.append(httpParam);
|
||||
d2.setParams(params);
|
||||
foreach (Thing *d, myThings()) {
|
||||
if (d->thingClassId() == mockThingClassId && d->paramValue(mockDeviceHttpportParamTypeId).toInt() == 55556) {
|
||||
if (d->thingClassId() == mockThingClassId && d->paramValue(mockThingHttpportParamTypeId).toInt() == 55556) {
|
||||
d2.setThingId(d->id());
|
||||
break;
|
||||
}
|
||||
@ -880,23 +880,23 @@ void DevicePluginMock::generateDiscoveredDevices(ThingDiscoveryInfo *info)
|
||||
void DevicePluginMock::generateDiscoveredPushButtonDevices(ThingDiscoveryInfo *info)
|
||||
{
|
||||
if (m_discoveredDeviceCount > 0) {
|
||||
ThingDescriptor d1(mockPushButtonThingClassId, "Mock Device (Push Button)", "1");
|
||||
ThingDescriptor d1(pushButtonMockThingClassId, "Mocked Thing (Push Button)", "1");
|
||||
info->addThingDescriptor(d1);
|
||||
}
|
||||
|
||||
if (m_discoveredDeviceCount > 1) {
|
||||
ThingDescriptor d2(mockPushButtonThingClassId, "Mock Device (Push Button)", "2");
|
||||
ThingDescriptor d2(pushButtonMockThingClassId, "Mocked Thhing (Push Button)", "2");
|
||||
info->addThingDescriptor(d2);
|
||||
}
|
||||
info->finish(Thing::ThingErrorNoError, QT_TR_NOOP("This device will simulate a push button press in 3 seconds."));
|
||||
info->finish(Thing::ThingErrorNoError, QT_TR_NOOP("This thing will simulate a push button press in 3 seconds."));
|
||||
}
|
||||
|
||||
void DevicePluginMock::generateDiscoveredDisplayPinDevices(ThingDiscoveryInfo *info)
|
||||
{
|
||||
if (m_discoveredDeviceCount > 0) {
|
||||
ThingDescriptor d1(mockDisplayPinThingClassId, "Mock Device (Display Pin)", "1");
|
||||
ThingDescriptor d1(displayPinMockThingClassId, "Mocked Thing (Display Pin)", "1");
|
||||
foreach (Thing *existingDev, myThings()) {
|
||||
if (existingDev->thingClassId() == mockDisplayPinThingClassId) {
|
||||
if (existingDev->thingClassId() == displayPinMockThingClassId) {
|
||||
d1.setThingId(existingDev->id());
|
||||
break;
|
||||
}
|
||||
@ -905,10 +905,10 @@ void DevicePluginMock::generateDiscoveredDisplayPinDevices(ThingDiscoveryInfo *i
|
||||
}
|
||||
|
||||
if (m_discoveredDeviceCount > 1) {
|
||||
ThingDescriptor d2(mockDisplayPinThingClassId, "Mock Device (Display Pin)", "2");
|
||||
ThingDescriptor d2(displayPinMockThingClassId, "Mocked Thing (Display Pin)", "2");
|
||||
int count = 0;
|
||||
foreach (Thing *existingDev, myThings()) {
|
||||
if (existingDev->thingClassId() == mockDisplayPinThingClassId && ++count > 1) {
|
||||
if (existingDev->thingClassId() == displayPinMockThingClassId && ++count > 1) {
|
||||
d2.setThingId(existingDev->id());
|
||||
break;
|
||||
}
|
||||
@ -921,7 +921,7 @@ void DevicePluginMock::generateDiscoveredDisplayPinDevices(ThingDiscoveryInfo *i
|
||||
|
||||
void DevicePluginMock::onPushButtonPressed()
|
||||
{
|
||||
qCDebug(dcMockDevice) << "PushButton pressed (automatically)";
|
||||
qCDebug(dcMock) << "PushButton pressed (automatically)";
|
||||
m_pushbuttonPressed = true;
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "mockDevice",
|
||||
"displayName": "Mock Devices",
|
||||
"name": "mock",
|
||||
"displayName": "Mocked things",
|
||||
"id": "727a4a9a-c187-446f-aadf-f1b2220607d1",
|
||||
"paramTypes": [
|
||||
{
|
||||
@ -29,7 +29,7 @@
|
||||
{
|
||||
"id": "753f0d32-0468-4d08-82ed-1964aab03298",
|
||||
"name": "mock",
|
||||
"displayName": "Mock Device",
|
||||
"displayName": "Mock Thing",
|
||||
"interfaces": ["system", "light", "battery"],
|
||||
"createMethods": ["user", "discovery"],
|
||||
"browsable": true,
|
||||
@ -210,8 +210,8 @@
|
||||
},
|
||||
{
|
||||
"id": "ab4257b3-7548-47ee-9bd4-7dc3004fd197",
|
||||
"name": "mockDeviceAuto",
|
||||
"displayName": "Mock Device (Auto created)",
|
||||
"name": "autoMock",
|
||||
"displayName": "Mocked Thing (Auto created)",
|
||||
"interfaces": ["system"],
|
||||
"createMethods": ["auto"],
|
||||
"paramTypes": [
|
||||
@ -321,8 +321,8 @@
|
||||
},
|
||||
{
|
||||
"id": "9e03144c-e436-4eea-82d9-ccb33ef778db",
|
||||
"name": "mockPushButton",
|
||||
"displayName": "Mock Device (Push Button)",
|
||||
"name": "pushButtonMock",
|
||||
"displayName": "Mocked Thing (Push Button)",
|
||||
"interfaces": ["system"],
|
||||
"createMethods": ["discovery"],
|
||||
"setupMethod": "pushButton",
|
||||
@ -410,8 +410,8 @@
|
||||
},
|
||||
{
|
||||
"id": "296f1fd4-e893-46b2-8a42-50d1bceb8730",
|
||||
"name": "mockDisplayPin",
|
||||
"displayName": "Mock Device (Display Pin)",
|
||||
"name": "displayPinMock",
|
||||
"displayName": "Mocked Thing (Display Pin)",
|
||||
"interfaces": ["system"],
|
||||
"createMethods": ["discovery"],
|
||||
"setupMethod": "displayPin",
|
||||
@ -509,8 +509,8 @@
|
||||
},
|
||||
{
|
||||
"id": "a71fbde9-9a38-4bf8-beab-c8aade2608ba",
|
||||
"name": "mockParent",
|
||||
"displayName": "Mock Device (Parent)",
|
||||
"name": "parentMock",
|
||||
"displayName": "Mocked Thing (Parent)",
|
||||
"interfaces": ["system"],
|
||||
"createMethods": ["user", "discovery"],
|
||||
"paramTypes": [ ],
|
||||
@ -529,8 +529,8 @@
|
||||
},
|
||||
{
|
||||
"id": "40893c9f-bc47-40c1-8bf7-b390c7c1b4fc",
|
||||
"name": "mockChild",
|
||||
"displayName": "Mock Device (Child)",
|
||||
"name": "childMock",
|
||||
"displayName": "Mocked Thing (Child)",
|
||||
"createMethods": ["auto", "discovery"],
|
||||
"paramTypes": [],
|
||||
"stateTypes": [
|
||||
@ -548,8 +548,8 @@
|
||||
},
|
||||
{
|
||||
"id": "515ffdf1-55e5-498d-9abc-4e2fe768f3a9",
|
||||
"name": "mockInputType",
|
||||
"displayName": "Mock Device (InputTypes)",
|
||||
"name": "inputTypeMock",
|
||||
"displayName": "Mocked Thing (InputTypes)",
|
||||
"createMethods": ["user"],
|
||||
"paramTypes": [
|
||||
{
|
||||
@ -850,22 +850,22 @@
|
||||
},
|
||||
{
|
||||
"id": "805d1692-7bd0-449a-9d5c-43a332ff58f4",
|
||||
"name": "mockOAuthGoogle",
|
||||
"displayName": "Mock Device (Google OAuth)",
|
||||
"name": "oAuthGoogleMock",
|
||||
"displayName": "Mocked Thing (Google OAuth)",
|
||||
"createMethods": ["user"],
|
||||
"setupMethod": "oauth"
|
||||
},
|
||||
{
|
||||
"id": "783c615b-7bd6-49a4-98b0-8d1deb3c7156",
|
||||
"name": "mockOAuthSonos",
|
||||
"displayName": "Mock Device (Sonos OAuth)",
|
||||
"name": "oAuthSonosMock",
|
||||
"displayName": "Mocked Thing (Sonos OAuth)",
|
||||
"createMethods": ["user"],
|
||||
"setupMethod": "oauth"
|
||||
},
|
||||
{
|
||||
"id": "6fe07a77-9c07-4736-81e2-d504314bbcb9",
|
||||
"name": "mockUserAndPass",
|
||||
"displayName": "Mock Device (User & Password)",
|
||||
"name": "userAndPassMock",
|
||||
"displayName": "Mocked Thing (User & Password)",
|
||||
"createMethods": ["discovery", "user"],
|
||||
"setupMethod": "userandpassword"
|
||||
}
|
||||
|
||||
@ -8,16 +8,16 @@
|
||||
|
||||
#include <QLoggingCategory>
|
||||
|
||||
Q_DECLARE_LOGGING_CATEGORY(dcMockDevice)
|
||||
Q_DECLARE_LOGGING_CATEGORY(dcMock)
|
||||
|
||||
extern PluginId pluginId;
|
||||
extern ParamTypeId mockDevicePluginConfigParamIntParamTypeId;
|
||||
extern ParamTypeId mockDevicePluginConfigParamBoolParamTypeId;
|
||||
extern ParamTypeId mockPluginConfigParamIntParamTypeId;
|
||||
extern ParamTypeId mockPluginConfigParamBoolParamTypeId;
|
||||
extern VendorId nymeaVendorId;
|
||||
extern ThingClassId mockThingClassId;
|
||||
extern ParamTypeId mockDeviceHttpportParamTypeId;
|
||||
extern ParamTypeId mockDeviceAsyncParamTypeId;
|
||||
extern ParamTypeId mockDeviceBrokenParamTypeId;
|
||||
extern ParamTypeId mockThingHttpportParamTypeId;
|
||||
extern ParamTypeId mockThingAsyncParamTypeId;
|
||||
extern ParamTypeId mockThingBrokenParamTypeId;
|
||||
extern ParamTypeId mockSettingsSetting1ParamTypeId;
|
||||
extern ParamTypeId mockDiscoveryResultCountParamTypeId;
|
||||
extern StateTypeId mockIntStateTypeId;
|
||||
@ -52,199 +52,199 @@ extern ActionTypeId mockFailingActionTypeId;
|
||||
extern ActionTypeId mockAsyncFailingActionTypeId;
|
||||
extern ActionTypeId mockAddToFavoritesBrowserItemActionTypeId;
|
||||
extern ActionTypeId mockRemoveFromFavoritesBrowserItemActionTypeId;
|
||||
extern ThingClassId mockDeviceAutoThingClassId;
|
||||
extern ParamTypeId mockDeviceAutoDeviceHttpportParamTypeId;
|
||||
extern ParamTypeId mockDeviceAutoDeviceAsyncParamTypeId;
|
||||
extern ParamTypeId mockDeviceAutoDeviceBrokenParamTypeId;
|
||||
extern StateTypeId mockDeviceAutoIntStateTypeId;
|
||||
extern StateTypeId mockDeviceAutoBoolValueStateTypeId;
|
||||
extern EventTypeId mockDeviceAutoIntEventTypeId;
|
||||
extern ParamTypeId mockDeviceAutoIntEventIntParamTypeId;
|
||||
extern EventTypeId mockDeviceAutoBoolValueEventTypeId;
|
||||
extern ParamTypeId mockDeviceAutoBoolValueEventBoolValueParamTypeId;
|
||||
extern EventTypeId mockDeviceAutoEvent1EventTypeId;
|
||||
extern EventTypeId mockDeviceAutoEvent2EventTypeId;
|
||||
extern ParamTypeId mockDeviceAutoEvent2EventIntParamParamTypeId;
|
||||
extern ActionTypeId mockDeviceAutoWithParamsActionTypeId;
|
||||
extern ParamTypeId mockDeviceAutoWithParamsActionMockActionParam1ParamTypeId;
|
||||
extern ParamTypeId mockDeviceAutoWithParamsActionMockActionParam2ParamTypeId;
|
||||
extern ActionTypeId mockDeviceAutoMockActionNoParmsActionTypeId;
|
||||
extern ActionTypeId mockDeviceAutoMockActionAsyncActionTypeId;
|
||||
extern ActionTypeId mockDeviceAutoMockActionBrokenActionTypeId;
|
||||
extern ActionTypeId mockDeviceAutoMockActionAsyncBrokenActionTypeId;
|
||||
extern ThingClassId mockPushButtonThingClassId;
|
||||
extern ParamTypeId mockPushButtonDiscoveryResultCountParamTypeId;
|
||||
extern StateTypeId mockPushButtonColorStateTypeId;
|
||||
extern StateTypeId mockPushButtonPercentageStateTypeId;
|
||||
extern StateTypeId mockPushButtonAllowedValuesStateTypeId;
|
||||
extern StateTypeId mockPushButtonDoubleStateTypeId;
|
||||
extern StateTypeId mockPushButtonBoolStateTypeId;
|
||||
extern EventTypeId mockPushButtonColorEventTypeId;
|
||||
extern ParamTypeId mockPushButtonColorEventColorParamTypeId;
|
||||
extern EventTypeId mockPushButtonPercentageEventTypeId;
|
||||
extern ParamTypeId mockPushButtonPercentageEventPercentageParamTypeId;
|
||||
extern EventTypeId mockPushButtonAllowedValuesEventTypeId;
|
||||
extern ParamTypeId mockPushButtonAllowedValuesEventAllowedValuesParamTypeId;
|
||||
extern EventTypeId mockPushButtonDoubleEventTypeId;
|
||||
extern ParamTypeId mockPushButtonDoubleEventDoubleParamTypeId;
|
||||
extern EventTypeId mockPushButtonBoolEventTypeId;
|
||||
extern ParamTypeId mockPushButtonBoolEventBoolParamTypeId;
|
||||
extern ActionTypeId mockPushButtonColorActionTypeId;
|
||||
extern ParamTypeId mockPushButtonColorActionColorParamTypeId;
|
||||
extern ActionTypeId mockPushButtonPercentageActionTypeId;
|
||||
extern ParamTypeId mockPushButtonPercentageActionPercentageParamTypeId;
|
||||
extern ActionTypeId mockPushButtonAllowedValuesActionTypeId;
|
||||
extern ParamTypeId mockPushButtonAllowedValuesActionAllowedValuesParamTypeId;
|
||||
extern ActionTypeId mockPushButtonDoubleActionTypeId;
|
||||
extern ParamTypeId mockPushButtonDoubleActionDoubleParamTypeId;
|
||||
extern ActionTypeId mockPushButtonBoolActionTypeId;
|
||||
extern ParamTypeId mockPushButtonBoolActionBoolParamTypeId;
|
||||
extern ActionTypeId mockPushButtonTimeoutActionTypeId;
|
||||
extern ThingClassId mockDisplayPinThingClassId;
|
||||
extern ParamTypeId mockDisplayPinDevicePinParamTypeId;
|
||||
extern ParamTypeId mockDisplayPinDiscoveryResultCountParamTypeId;
|
||||
extern StateTypeId mockDisplayPinColorStateTypeId;
|
||||
extern StateTypeId mockDisplayPinPercentageStateTypeId;
|
||||
extern StateTypeId mockDisplayPinAllowedValuesStateTypeId;
|
||||
extern StateTypeId mockDisplayPinDoubleStateTypeId;
|
||||
extern StateTypeId mockDisplayPinBoolStateTypeId;
|
||||
extern EventTypeId mockDisplayPinColorEventTypeId;
|
||||
extern ParamTypeId mockDisplayPinColorEventColorParamTypeId;
|
||||
extern EventTypeId mockDisplayPinPercentageEventTypeId;
|
||||
extern ParamTypeId mockDisplayPinPercentageEventPercentageParamTypeId;
|
||||
extern EventTypeId mockDisplayPinAllowedValuesEventTypeId;
|
||||
extern ParamTypeId mockDisplayPinAllowedValuesEventAllowedValuesParamTypeId;
|
||||
extern EventTypeId mockDisplayPinDoubleEventTypeId;
|
||||
extern ParamTypeId mockDisplayPinDoubleEventDoubleParamTypeId;
|
||||
extern EventTypeId mockDisplayPinBoolEventTypeId;
|
||||
extern ParamTypeId mockDisplayPinBoolEventBoolParamTypeId;
|
||||
extern ActionTypeId mockDisplayPinColorActionTypeId;
|
||||
extern ParamTypeId mockDisplayPinColorActionColorParamTypeId;
|
||||
extern ActionTypeId mockDisplayPinPercentageActionTypeId;
|
||||
extern ParamTypeId mockDisplayPinPercentageActionPercentageParamTypeId;
|
||||
extern ActionTypeId mockDisplayPinAllowedValuesActionTypeId;
|
||||
extern ParamTypeId mockDisplayPinAllowedValuesActionAllowedValuesParamTypeId;
|
||||
extern ActionTypeId mockDisplayPinDoubleActionTypeId;
|
||||
extern ParamTypeId mockDisplayPinDoubleActionDoubleParamTypeId;
|
||||
extern ActionTypeId mockDisplayPinBoolActionTypeId;
|
||||
extern ParamTypeId mockDisplayPinBoolActionBoolParamTypeId;
|
||||
extern ActionTypeId mockDisplayPinTimeoutActionTypeId;
|
||||
extern ThingClassId mockParentThingClassId;
|
||||
extern StateTypeId mockParentBoolValueStateTypeId;
|
||||
extern EventTypeId mockParentBoolValueEventTypeId;
|
||||
extern ParamTypeId mockParentBoolValueEventBoolValueParamTypeId;
|
||||
extern ActionTypeId mockParentBoolValueActionTypeId;
|
||||
extern ParamTypeId mockParentBoolValueActionBoolValueParamTypeId;
|
||||
extern ThingClassId mockChildThingClassId;
|
||||
extern StateTypeId mockChildBoolValueStateTypeId;
|
||||
extern EventTypeId mockChildBoolValueEventTypeId;
|
||||
extern ParamTypeId mockChildBoolValueEventBoolValueParamTypeId;
|
||||
extern ActionTypeId mockChildBoolValueActionTypeId;
|
||||
extern ParamTypeId mockChildBoolValueActionBoolValueParamTypeId;
|
||||
extern ThingClassId mockInputTypeThingClassId;
|
||||
extern ParamTypeId mockInputTypeDeviceTextLineParamTypeId;
|
||||
extern ParamTypeId mockInputTypeDeviceTextAreaParamTypeId;
|
||||
extern ParamTypeId mockInputTypeDevicePasswordParamTypeId;
|
||||
extern ParamTypeId mockInputTypeDeviceSearchParamTypeId;
|
||||
extern ParamTypeId mockInputTypeDeviceMailParamTypeId;
|
||||
extern ParamTypeId mockInputTypeDeviceIp4ParamTypeId;
|
||||
extern ParamTypeId mockInputTypeDeviceIp6ParamTypeId;
|
||||
extern ParamTypeId mockInputTypeDeviceUrlParamTypeId;
|
||||
extern ParamTypeId mockInputTypeDeviceMacParamTypeId;
|
||||
extern StateTypeId mockInputTypeBoolStateTypeId;
|
||||
extern StateTypeId mockInputTypeWritableBoolStateTypeId;
|
||||
extern StateTypeId mockInputTypeIntStateTypeId;
|
||||
extern StateTypeId mockInputTypeWritableIntStateTypeId;
|
||||
extern StateTypeId mockInputTypeWritableIntMinMaxStateTypeId;
|
||||
extern StateTypeId mockInputTypeUintStateTypeId;
|
||||
extern StateTypeId mockInputTypeWritableUIntStateTypeId;
|
||||
extern StateTypeId mockInputTypeWritableUIntMinMaxStateTypeId;
|
||||
extern StateTypeId mockInputTypeDoubleStateTypeId;
|
||||
extern StateTypeId mockInputTypeWritableDoubleStateTypeId;
|
||||
extern StateTypeId mockInputTypeWritableDoubleMinMaxStateTypeId;
|
||||
extern StateTypeId mockInputTypeStringStateTypeId;
|
||||
extern StateTypeId mockInputTypeWritableStringStateTypeId;
|
||||
extern StateTypeId mockInputTypeWritableStringSelectionStateTypeId;
|
||||
extern StateTypeId mockInputTypeColorStateTypeId;
|
||||
extern StateTypeId mockInputTypeWritableColorStateTypeId;
|
||||
extern StateTypeId mockInputTypeTimeStateTypeId;
|
||||
extern StateTypeId mockInputTypeWritableTimeStateTypeId;
|
||||
extern StateTypeId mockInputTypeTimestampIntStateTypeId;
|
||||
extern StateTypeId mockInputTypeWritableTimestampIntStateTypeId;
|
||||
extern StateTypeId mockInputTypeTimestampUIntStateTypeId;
|
||||
extern StateTypeId mockInputTypeWritableTimestampUIntStateTypeId;
|
||||
extern EventTypeId mockInputTypeBoolEventTypeId;
|
||||
extern ParamTypeId mockInputTypeBoolEventBoolParamTypeId;
|
||||
extern EventTypeId mockInputTypeWritableBoolEventTypeId;
|
||||
extern ParamTypeId mockInputTypeWritableBoolEventWritableBoolParamTypeId;
|
||||
extern EventTypeId mockInputTypeIntEventTypeId;
|
||||
extern ParamTypeId mockInputTypeIntEventIntParamTypeId;
|
||||
extern EventTypeId mockInputTypeWritableIntEventTypeId;
|
||||
extern ParamTypeId mockInputTypeWritableIntEventWritableIntParamTypeId;
|
||||
extern EventTypeId mockInputTypeWritableIntMinMaxEventTypeId;
|
||||
extern ParamTypeId mockInputTypeWritableIntMinMaxEventWritableIntMinMaxParamTypeId;
|
||||
extern EventTypeId mockInputTypeUintEventTypeId;
|
||||
extern ParamTypeId mockInputTypeUintEventUintParamTypeId;
|
||||
extern EventTypeId mockInputTypeWritableUIntEventTypeId;
|
||||
extern ParamTypeId mockInputTypeWritableUIntEventWritableUIntParamTypeId;
|
||||
extern EventTypeId mockInputTypeWritableUIntMinMaxEventTypeId;
|
||||
extern ParamTypeId mockInputTypeWritableUIntMinMaxEventWritableUIntMinMaxParamTypeId;
|
||||
extern EventTypeId mockInputTypeDoubleEventTypeId;
|
||||
extern ParamTypeId mockInputTypeDoubleEventDoubleParamTypeId;
|
||||
extern EventTypeId mockInputTypeWritableDoubleEventTypeId;
|
||||
extern ParamTypeId mockInputTypeWritableDoubleEventWritableDoubleParamTypeId;
|
||||
extern EventTypeId mockInputTypeWritableDoubleMinMaxEventTypeId;
|
||||
extern ParamTypeId mockInputTypeWritableDoubleMinMaxEventWritableDoubleMinMaxParamTypeId;
|
||||
extern EventTypeId mockInputTypeStringEventTypeId;
|
||||
extern ParamTypeId mockInputTypeStringEventStringParamTypeId;
|
||||
extern EventTypeId mockInputTypeWritableStringEventTypeId;
|
||||
extern ParamTypeId mockInputTypeWritableStringEventWritableStringParamTypeId;
|
||||
extern EventTypeId mockInputTypeWritableStringSelectionEventTypeId;
|
||||
extern ParamTypeId mockInputTypeWritableStringSelectionEventWritableStringSelectionParamTypeId;
|
||||
extern EventTypeId mockInputTypeColorEventTypeId;
|
||||
extern ParamTypeId mockInputTypeColorEventColorParamTypeId;
|
||||
extern EventTypeId mockInputTypeWritableColorEventTypeId;
|
||||
extern ParamTypeId mockInputTypeWritableColorEventWritableColorParamTypeId;
|
||||
extern EventTypeId mockInputTypeTimeEventTypeId;
|
||||
extern ParamTypeId mockInputTypeTimeEventTimeParamTypeId;
|
||||
extern EventTypeId mockInputTypeWritableTimeEventTypeId;
|
||||
extern ParamTypeId mockInputTypeWritableTimeEventWritableTimeParamTypeId;
|
||||
extern EventTypeId mockInputTypeTimestampIntEventTypeId;
|
||||
extern ParamTypeId mockInputTypeTimestampIntEventTimestampIntParamTypeId;
|
||||
extern EventTypeId mockInputTypeWritableTimestampIntEventTypeId;
|
||||
extern ParamTypeId mockInputTypeWritableTimestampIntEventWritableTimestampIntParamTypeId;
|
||||
extern EventTypeId mockInputTypeTimestampUIntEventTypeId;
|
||||
extern ParamTypeId mockInputTypeTimestampUIntEventTimestampUIntParamTypeId;
|
||||
extern EventTypeId mockInputTypeWritableTimestampUIntEventTypeId;
|
||||
extern ParamTypeId mockInputTypeWritableTimestampUIntEventWritableTimestampUIntParamTypeId;
|
||||
extern ActionTypeId mockInputTypeWritableBoolActionTypeId;
|
||||
extern ParamTypeId mockInputTypeWritableBoolActionWritableBoolParamTypeId;
|
||||
extern ActionTypeId mockInputTypeWritableIntActionTypeId;
|
||||
extern ParamTypeId mockInputTypeWritableIntActionWritableIntParamTypeId;
|
||||
extern ActionTypeId mockInputTypeWritableIntMinMaxActionTypeId;
|
||||
extern ParamTypeId mockInputTypeWritableIntMinMaxActionWritableIntMinMaxParamTypeId;
|
||||
extern ActionTypeId mockInputTypeWritableUIntActionTypeId;
|
||||
extern ParamTypeId mockInputTypeWritableUIntActionWritableUIntParamTypeId;
|
||||
extern ActionTypeId mockInputTypeWritableUIntMinMaxActionTypeId;
|
||||
extern ParamTypeId mockInputTypeWritableUIntMinMaxActionWritableUIntMinMaxParamTypeId;
|
||||
extern ActionTypeId mockInputTypeWritableDoubleActionTypeId;
|
||||
extern ParamTypeId mockInputTypeWritableDoubleActionWritableDoubleParamTypeId;
|
||||
extern ActionTypeId mockInputTypeWritableDoubleMinMaxActionTypeId;
|
||||
extern ParamTypeId mockInputTypeWritableDoubleMinMaxActionWritableDoubleMinMaxParamTypeId;
|
||||
extern ActionTypeId mockInputTypeWritableStringActionTypeId;
|
||||
extern ParamTypeId mockInputTypeWritableStringActionWritableStringParamTypeId;
|
||||
extern ActionTypeId mockInputTypeWritableStringSelectionActionTypeId;
|
||||
extern ParamTypeId mockInputTypeWritableStringSelectionActionWritableStringSelectionParamTypeId;
|
||||
extern ActionTypeId mockInputTypeWritableColorActionTypeId;
|
||||
extern ParamTypeId mockInputTypeWritableColorActionWritableColorParamTypeId;
|
||||
extern ActionTypeId mockInputTypeWritableTimeActionTypeId;
|
||||
extern ParamTypeId mockInputTypeWritableTimeActionWritableTimeParamTypeId;
|
||||
extern ActionTypeId mockInputTypeWritableTimestampIntActionTypeId;
|
||||
extern ParamTypeId mockInputTypeWritableTimestampIntActionWritableTimestampIntParamTypeId;
|
||||
extern ActionTypeId mockInputTypeWritableTimestampUIntActionTypeId;
|
||||
extern ParamTypeId mockInputTypeWritableTimestampUIntActionWritableTimestampUIntParamTypeId;
|
||||
extern ThingClassId mockOAuthGoogleThingClassId;
|
||||
extern ThingClassId mockOAuthSonosThingClassId;
|
||||
extern ThingClassId mockUserAndPassThingClassId;
|
||||
extern ThingClassId autoMockThingClassId;
|
||||
extern ParamTypeId autoMockThingHttpportParamTypeId;
|
||||
extern ParamTypeId autoMockThingAsyncParamTypeId;
|
||||
extern ParamTypeId autoMockThingBrokenParamTypeId;
|
||||
extern StateTypeId autoMockIntStateTypeId;
|
||||
extern StateTypeId autoMockBoolValueStateTypeId;
|
||||
extern EventTypeId autoMockIntEventTypeId;
|
||||
extern ParamTypeId autoMockIntEventIntParamTypeId;
|
||||
extern EventTypeId autoMockBoolValueEventTypeId;
|
||||
extern ParamTypeId autoMockBoolValueEventBoolValueParamTypeId;
|
||||
extern EventTypeId autoMockEvent1EventTypeId;
|
||||
extern EventTypeId autoMockEvent2EventTypeId;
|
||||
extern ParamTypeId autoMockEvent2EventIntParamParamTypeId;
|
||||
extern ActionTypeId autoMockWithParamsActionTypeId;
|
||||
extern ParamTypeId autoMockWithParamsActionMockActionParam1ParamTypeId;
|
||||
extern ParamTypeId autoMockWithParamsActionMockActionParam2ParamTypeId;
|
||||
extern ActionTypeId autoMockMockActionNoParmsActionTypeId;
|
||||
extern ActionTypeId autoMockMockActionAsyncActionTypeId;
|
||||
extern ActionTypeId autoMockMockActionBrokenActionTypeId;
|
||||
extern ActionTypeId autoMockMockActionAsyncBrokenActionTypeId;
|
||||
extern ThingClassId pushButtonMockThingClassId;
|
||||
extern ParamTypeId pushButtonMockDiscoveryResultCountParamTypeId;
|
||||
extern StateTypeId pushButtonMockColorStateTypeId;
|
||||
extern StateTypeId pushButtonMockPercentageStateTypeId;
|
||||
extern StateTypeId pushButtonMockAllowedValuesStateTypeId;
|
||||
extern StateTypeId pushButtonMockDoubleStateTypeId;
|
||||
extern StateTypeId pushButtonMockBoolStateTypeId;
|
||||
extern EventTypeId pushButtonMockColorEventTypeId;
|
||||
extern ParamTypeId pushButtonMockColorEventColorParamTypeId;
|
||||
extern EventTypeId pushButtonMockPercentageEventTypeId;
|
||||
extern ParamTypeId pushButtonMockPercentageEventPercentageParamTypeId;
|
||||
extern EventTypeId pushButtonMockAllowedValuesEventTypeId;
|
||||
extern ParamTypeId pushButtonMockAllowedValuesEventAllowedValuesParamTypeId;
|
||||
extern EventTypeId pushButtonMockDoubleEventTypeId;
|
||||
extern ParamTypeId pushButtonMockDoubleEventDoubleParamTypeId;
|
||||
extern EventTypeId pushButtonMockBoolEventTypeId;
|
||||
extern ParamTypeId pushButtonMockBoolEventBoolParamTypeId;
|
||||
extern ActionTypeId pushButtonMockColorActionTypeId;
|
||||
extern ParamTypeId pushButtonMockColorActionColorParamTypeId;
|
||||
extern ActionTypeId pushButtonMockPercentageActionTypeId;
|
||||
extern ParamTypeId pushButtonMockPercentageActionPercentageParamTypeId;
|
||||
extern ActionTypeId pushButtonMockAllowedValuesActionTypeId;
|
||||
extern ParamTypeId pushButtonMockAllowedValuesActionAllowedValuesParamTypeId;
|
||||
extern ActionTypeId pushButtonMockDoubleActionTypeId;
|
||||
extern ParamTypeId pushButtonMockDoubleActionDoubleParamTypeId;
|
||||
extern ActionTypeId pushButtonMockBoolActionTypeId;
|
||||
extern ParamTypeId pushButtonMockBoolActionBoolParamTypeId;
|
||||
extern ActionTypeId pushButtonMockTimeoutActionTypeId;
|
||||
extern ThingClassId displayPinMockThingClassId;
|
||||
extern ParamTypeId displayPinMockThingPinParamTypeId;
|
||||
extern ParamTypeId displayPinMockDiscoveryResultCountParamTypeId;
|
||||
extern StateTypeId displayPinMockColorStateTypeId;
|
||||
extern StateTypeId displayPinMockPercentageStateTypeId;
|
||||
extern StateTypeId displayPinMockAllowedValuesStateTypeId;
|
||||
extern StateTypeId displayPinMockDoubleStateTypeId;
|
||||
extern StateTypeId displayPinMockBoolStateTypeId;
|
||||
extern EventTypeId displayPinMockColorEventTypeId;
|
||||
extern ParamTypeId displayPinMockColorEventColorParamTypeId;
|
||||
extern EventTypeId displayPinMockPercentageEventTypeId;
|
||||
extern ParamTypeId displayPinMockPercentageEventPercentageParamTypeId;
|
||||
extern EventTypeId displayPinMockAllowedValuesEventTypeId;
|
||||
extern ParamTypeId displayPinMockAllowedValuesEventAllowedValuesParamTypeId;
|
||||
extern EventTypeId displayPinMockDoubleEventTypeId;
|
||||
extern ParamTypeId displayPinMockDoubleEventDoubleParamTypeId;
|
||||
extern EventTypeId displayPinMockBoolEventTypeId;
|
||||
extern ParamTypeId displayPinMockBoolEventBoolParamTypeId;
|
||||
extern ActionTypeId displayPinMockColorActionTypeId;
|
||||
extern ParamTypeId displayPinMockColorActionColorParamTypeId;
|
||||
extern ActionTypeId displayPinMockPercentageActionTypeId;
|
||||
extern ParamTypeId displayPinMockPercentageActionPercentageParamTypeId;
|
||||
extern ActionTypeId displayPinMockAllowedValuesActionTypeId;
|
||||
extern ParamTypeId displayPinMockAllowedValuesActionAllowedValuesParamTypeId;
|
||||
extern ActionTypeId displayPinMockDoubleActionTypeId;
|
||||
extern ParamTypeId displayPinMockDoubleActionDoubleParamTypeId;
|
||||
extern ActionTypeId displayPinMockBoolActionTypeId;
|
||||
extern ParamTypeId displayPinMockBoolActionBoolParamTypeId;
|
||||
extern ActionTypeId displayPinMockTimeoutActionTypeId;
|
||||
extern ThingClassId parentMockThingClassId;
|
||||
extern StateTypeId parentMockBoolValueStateTypeId;
|
||||
extern EventTypeId parentMockBoolValueEventTypeId;
|
||||
extern ParamTypeId parentMockBoolValueEventBoolValueParamTypeId;
|
||||
extern ActionTypeId parentMockBoolValueActionTypeId;
|
||||
extern ParamTypeId parentMockBoolValueActionBoolValueParamTypeId;
|
||||
extern ThingClassId childMockThingClassId;
|
||||
extern StateTypeId childMockBoolValueStateTypeId;
|
||||
extern EventTypeId childMockBoolValueEventTypeId;
|
||||
extern ParamTypeId childMockBoolValueEventBoolValueParamTypeId;
|
||||
extern ActionTypeId childMockBoolValueActionTypeId;
|
||||
extern ParamTypeId childMockBoolValueActionBoolValueParamTypeId;
|
||||
extern ThingClassId inputTypeMockThingClassId;
|
||||
extern ParamTypeId inputTypeMockThingTextLineParamTypeId;
|
||||
extern ParamTypeId inputTypeMockThingTextAreaParamTypeId;
|
||||
extern ParamTypeId inputTypeMockThingPasswordParamTypeId;
|
||||
extern ParamTypeId inputTypeMockThingSearchParamTypeId;
|
||||
extern ParamTypeId inputTypeMockThingMailParamTypeId;
|
||||
extern ParamTypeId inputTypeMockThingIp4ParamTypeId;
|
||||
extern ParamTypeId inputTypeMockThingIp6ParamTypeId;
|
||||
extern ParamTypeId inputTypeMockThingUrlParamTypeId;
|
||||
extern ParamTypeId inputTypeMockThingMacParamTypeId;
|
||||
extern StateTypeId inputTypeMockBoolStateTypeId;
|
||||
extern StateTypeId inputTypeMockWritableBoolStateTypeId;
|
||||
extern StateTypeId inputTypeMockIntStateTypeId;
|
||||
extern StateTypeId inputTypeMockWritableIntStateTypeId;
|
||||
extern StateTypeId inputTypeMockWritableIntMinMaxStateTypeId;
|
||||
extern StateTypeId inputTypeMockUintStateTypeId;
|
||||
extern StateTypeId inputTypeMockWritableUIntStateTypeId;
|
||||
extern StateTypeId inputTypeMockWritableUIntMinMaxStateTypeId;
|
||||
extern StateTypeId inputTypeMockDoubleStateTypeId;
|
||||
extern StateTypeId inputTypeMockWritableDoubleStateTypeId;
|
||||
extern StateTypeId inputTypeMockWritableDoubleMinMaxStateTypeId;
|
||||
extern StateTypeId inputTypeMockStringStateTypeId;
|
||||
extern StateTypeId inputTypeMockWritableStringStateTypeId;
|
||||
extern StateTypeId inputTypeMockWritableStringSelectionStateTypeId;
|
||||
extern StateTypeId inputTypeMockColorStateTypeId;
|
||||
extern StateTypeId inputTypeMockWritableColorStateTypeId;
|
||||
extern StateTypeId inputTypeMockTimeStateTypeId;
|
||||
extern StateTypeId inputTypeMockWritableTimeStateTypeId;
|
||||
extern StateTypeId inputTypeMockTimestampIntStateTypeId;
|
||||
extern StateTypeId inputTypeMockWritableTimestampIntStateTypeId;
|
||||
extern StateTypeId inputTypeMockTimestampUIntStateTypeId;
|
||||
extern StateTypeId inputTypeMockWritableTimestampUIntStateTypeId;
|
||||
extern EventTypeId inputTypeMockBoolEventTypeId;
|
||||
extern ParamTypeId inputTypeMockBoolEventBoolParamTypeId;
|
||||
extern EventTypeId inputTypeMockWritableBoolEventTypeId;
|
||||
extern ParamTypeId inputTypeMockWritableBoolEventWritableBoolParamTypeId;
|
||||
extern EventTypeId inputTypeMockIntEventTypeId;
|
||||
extern ParamTypeId inputTypeMockIntEventIntParamTypeId;
|
||||
extern EventTypeId inputTypeMockWritableIntEventTypeId;
|
||||
extern ParamTypeId inputTypeMockWritableIntEventWritableIntParamTypeId;
|
||||
extern EventTypeId inputTypeMockWritableIntMinMaxEventTypeId;
|
||||
extern ParamTypeId inputTypeMockWritableIntMinMaxEventWritableIntMinMaxParamTypeId;
|
||||
extern EventTypeId inputTypeMockUintEventTypeId;
|
||||
extern ParamTypeId inputTypeMockUintEventUintParamTypeId;
|
||||
extern EventTypeId inputTypeMockWritableUIntEventTypeId;
|
||||
extern ParamTypeId inputTypeMockWritableUIntEventWritableUIntParamTypeId;
|
||||
extern EventTypeId inputTypeMockWritableUIntMinMaxEventTypeId;
|
||||
extern ParamTypeId inputTypeMockWritableUIntMinMaxEventWritableUIntMinMaxParamTypeId;
|
||||
extern EventTypeId inputTypeMockDoubleEventTypeId;
|
||||
extern ParamTypeId inputTypeMockDoubleEventDoubleParamTypeId;
|
||||
extern EventTypeId inputTypeMockWritableDoubleEventTypeId;
|
||||
extern ParamTypeId inputTypeMockWritableDoubleEventWritableDoubleParamTypeId;
|
||||
extern EventTypeId inputTypeMockWritableDoubleMinMaxEventTypeId;
|
||||
extern ParamTypeId inputTypeMockWritableDoubleMinMaxEventWritableDoubleMinMaxParamTypeId;
|
||||
extern EventTypeId inputTypeMockStringEventTypeId;
|
||||
extern ParamTypeId inputTypeMockStringEventStringParamTypeId;
|
||||
extern EventTypeId inputTypeMockWritableStringEventTypeId;
|
||||
extern ParamTypeId inputTypeMockWritableStringEventWritableStringParamTypeId;
|
||||
extern EventTypeId inputTypeMockWritableStringSelectionEventTypeId;
|
||||
extern ParamTypeId inputTypeMockWritableStringSelectionEventWritableStringSelectionParamTypeId;
|
||||
extern EventTypeId inputTypeMockColorEventTypeId;
|
||||
extern ParamTypeId inputTypeMockColorEventColorParamTypeId;
|
||||
extern EventTypeId inputTypeMockWritableColorEventTypeId;
|
||||
extern ParamTypeId inputTypeMockWritableColorEventWritableColorParamTypeId;
|
||||
extern EventTypeId inputTypeMockTimeEventTypeId;
|
||||
extern ParamTypeId inputTypeMockTimeEventTimeParamTypeId;
|
||||
extern EventTypeId inputTypeMockWritableTimeEventTypeId;
|
||||
extern ParamTypeId inputTypeMockWritableTimeEventWritableTimeParamTypeId;
|
||||
extern EventTypeId inputTypeMockTimestampIntEventTypeId;
|
||||
extern ParamTypeId inputTypeMockTimestampIntEventTimestampIntParamTypeId;
|
||||
extern EventTypeId inputTypeMockWritableTimestampIntEventTypeId;
|
||||
extern ParamTypeId inputTypeMockWritableTimestampIntEventWritableTimestampIntParamTypeId;
|
||||
extern EventTypeId inputTypeMockTimestampUIntEventTypeId;
|
||||
extern ParamTypeId inputTypeMockTimestampUIntEventTimestampUIntParamTypeId;
|
||||
extern EventTypeId inputTypeMockWritableTimestampUIntEventTypeId;
|
||||
extern ParamTypeId inputTypeMockWritableTimestampUIntEventWritableTimestampUIntParamTypeId;
|
||||
extern ActionTypeId inputTypeMockWritableBoolActionTypeId;
|
||||
extern ParamTypeId inputTypeMockWritableBoolActionWritableBoolParamTypeId;
|
||||
extern ActionTypeId inputTypeMockWritableIntActionTypeId;
|
||||
extern ParamTypeId inputTypeMockWritableIntActionWritableIntParamTypeId;
|
||||
extern ActionTypeId inputTypeMockWritableIntMinMaxActionTypeId;
|
||||
extern ParamTypeId inputTypeMockWritableIntMinMaxActionWritableIntMinMaxParamTypeId;
|
||||
extern ActionTypeId inputTypeMockWritableUIntActionTypeId;
|
||||
extern ParamTypeId inputTypeMockWritableUIntActionWritableUIntParamTypeId;
|
||||
extern ActionTypeId inputTypeMockWritableUIntMinMaxActionTypeId;
|
||||
extern ParamTypeId inputTypeMockWritableUIntMinMaxActionWritableUIntMinMaxParamTypeId;
|
||||
extern ActionTypeId inputTypeMockWritableDoubleActionTypeId;
|
||||
extern ParamTypeId inputTypeMockWritableDoubleActionWritableDoubleParamTypeId;
|
||||
extern ActionTypeId inputTypeMockWritableDoubleMinMaxActionTypeId;
|
||||
extern ParamTypeId inputTypeMockWritableDoubleMinMaxActionWritableDoubleMinMaxParamTypeId;
|
||||
extern ActionTypeId inputTypeMockWritableStringActionTypeId;
|
||||
extern ParamTypeId inputTypeMockWritableStringActionWritableStringParamTypeId;
|
||||
extern ActionTypeId inputTypeMockWritableStringSelectionActionTypeId;
|
||||
extern ParamTypeId inputTypeMockWritableStringSelectionActionWritableStringSelectionParamTypeId;
|
||||
extern ActionTypeId inputTypeMockWritableColorActionTypeId;
|
||||
extern ParamTypeId inputTypeMockWritableColorActionWritableColorParamTypeId;
|
||||
extern ActionTypeId inputTypeMockWritableTimeActionTypeId;
|
||||
extern ParamTypeId inputTypeMockWritableTimeActionWritableTimeParamTypeId;
|
||||
extern ActionTypeId inputTypeMockWritableTimestampIntActionTypeId;
|
||||
extern ParamTypeId inputTypeMockWritableTimestampIntActionWritableTimestampIntParamTypeId;
|
||||
extern ActionTypeId inputTypeMockWritableTimestampUIntActionTypeId;
|
||||
extern ParamTypeId inputTypeMockWritableTimestampUIntActionWritableTimestampUIntParamTypeId;
|
||||
extern ThingClassId oAuthGoogleMockThingClassId;
|
||||
extern ThingClassId oAuthSonosMockThingClassId;
|
||||
extern ThingClassId userAndPassMockThingClassId;
|
||||
|
||||
#endif // EXTERNPLUGININFO_H
|
||||
|
||||
@ -47,8 +47,8 @@ HttpDaemon::HttpDaemon(Thing *thing, IntegrationPlugin *parent):
|
||||
QTcpServer(parent), disabled(false), m_plugin(parent), m_thing(thing)
|
||||
{
|
||||
QHash<ThingClassId, ParamTypeId> portMap;
|
||||
portMap.insert(mockThingClassId, mockDeviceHttpportParamTypeId);
|
||||
portMap.insert(mockDeviceAutoThingClassId, mockDeviceAutoDeviceHttpportParamTypeId);
|
||||
portMap.insert(mockThingClassId, mockThingHttpportParamTypeId);
|
||||
portMap.insert(autoMockThingClassId, autoMockThingHttpportParamTypeId);
|
||||
listen(QHostAddress::Any, thing->paramValue(portMap.value(thing->thingClassId())).toInt());
|
||||
}
|
||||
|
||||
@ -102,30 +102,30 @@ void HttpDaemon::readClient()
|
||||
} else if (stateTypeId == mockDoubleStateTypeId) {
|
||||
stateValue.convert(QVariant::Double);
|
||||
}
|
||||
qCDebug(dcMockDevice) << "Set state value" << stateValue;
|
||||
qCDebug(dcMock()) << "Set state value" << stateValue;
|
||||
emit setState(stateTypeId, stateValue);
|
||||
} else if (url.path() == "/generateevent") {
|
||||
emit triggerEvent(EventTypeId(query.queryItemValue("eventtypeid")));
|
||||
} else if (url.path() == "/actionhistory") {
|
||||
qCDebug(dcMockDevice) << "Get action history called";
|
||||
qCDebug(dcMock()) << "Get action history called";
|
||||
|
||||
QTextStream os(socket);
|
||||
os.setAutoDetectUnicode(true);
|
||||
os << generateHeader();
|
||||
for (int i = 0; i < m_actionList.count(); ++i) {
|
||||
os << m_actionList.at(i).first.toString() << '\n';
|
||||
qCDebug(dcMockDevice) << " " << m_actionList.at(i).first.toString();
|
||||
qCDebug(dcMock()) << " " << m_actionList.at(i).first.toString();
|
||||
}
|
||||
socket->close();
|
||||
return;
|
||||
} else if (url.path() == "/clearactionhistory") {
|
||||
qCDebug(dcMockDevice) << "Clear action history";
|
||||
qCDebug(dcMock()) << "Clear action history";
|
||||
m_actionList.clear();
|
||||
} else if (url.path() == "/disappear") {
|
||||
qCDebug(dcMockDevice) << "Should disappear";
|
||||
qCDebug(dcMock()) << "Should disappear";
|
||||
emit disappear();
|
||||
} else if (url.path() == "/reconfigureautodevice") {
|
||||
qCDebug(dcMockDevice) << "Reconfigure auto device";
|
||||
qCDebug(dcMock()) << "Reconfigure auto device";
|
||||
emit reconfigureAutodevice();
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -92,7 +92,7 @@ void TestActions::executeAction()
|
||||
QNetworkAccessManager nam;
|
||||
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
|
||||
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/actionhistory").arg(m_mockDevice1Port)));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/actionhistory").arg(m_mockThing1Port)));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -108,14 +108,14 @@ void TestActions::executeAction()
|
||||
|
||||
// cleanup for the next run
|
||||
spy.clear();
|
||||
request.setUrl(QUrl(QString("http://localhost:%1/clearactionhistory").arg(m_mockDevice1Port)));
|
||||
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_mockDevice1Port)));
|
||||
request.setUrl(QUrl(QString("http://localhost:%1/actionhistory").arg(m_mockThing1Port)));
|
||||
reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
|
||||
@ -3,6 +3,7 @@ TEMPLATE = subdirs
|
||||
SUBDIRS = \
|
||||
versioning \
|
||||
devices \
|
||||
integrations \
|
||||
jsonrpc \
|
||||
events \
|
||||
states \
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -65,7 +65,7 @@ void TestEvents::triggerEvent()
|
||||
QNetworkAccessManager nam;
|
||||
|
||||
// trigger event in mock device
|
||||
int port = device->paramValue(mockDeviceHttpportParamTypeId).toInt();
|
||||
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);
|
||||
@ -107,7 +107,7 @@ void TestEvents::triggerStateChangeEvent()
|
||||
QNetworkAccessManager nam;
|
||||
|
||||
// trigger state changed event in mock device
|
||||
int port = device->paramValue(mockDeviceHttpportParamTypeId).toInt();
|
||||
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);
|
||||
|
||||
5
tests/auto/integrations/integrations.pro
Normal file
5
tests/auto/integrations/integrations.pro
Normal file
@ -0,0 +1,5 @@
|
||||
include(../../../nymea.pri)
|
||||
include(../autotests.pri)
|
||||
|
||||
TARGET = testintegrations
|
||||
SOURCES += testintegrations.cpp
|
||||
2153
tests/auto/integrations/testintegrations.cpp
Normal file
2153
tests/auto/integrations/testintegrations.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -70,13 +70,10 @@ private slots:
|
||||
void enableDisableNotifications_legacy_data();
|
||||
void enableDisableNotifications_legacy();
|
||||
|
||||
void deviceAddedRemovedNotifications();
|
||||
void ruleAddedRemovedNotifications();
|
||||
|
||||
void ruleActiveChangedNotifications();
|
||||
|
||||
void deviceChangedNotifications();
|
||||
|
||||
void stateChangeEmitsNotifications();
|
||||
|
||||
void pluginConfigChangeEmitsNotification();
|
||||
@ -213,7 +210,7 @@ void TestJSONRPC::testHandshakeLocale()
|
||||
QVariantMap supportedDevices = injectAndWait("Devices.GetSupportedDevices").toMap();
|
||||
bool found = false;
|
||||
foreach (const QVariant &dcMap, supportedDevices.value("params").toMap().value("deviceClasses").toList()) {
|
||||
if (dcMap.toMap().value("id").toUuid() == mockDeviceAutoThingClassId) {
|
||||
if (dcMap.toMap().value("id").toUuid() == autoMockThingClassId) {
|
||||
QCOMPARE(dcMap.toMap().value("displayName").toString(), QString("Mock Device (Auto created)"));
|
||||
found = true;
|
||||
}
|
||||
@ -229,7 +226,7 @@ void TestJSONRPC::testHandshakeLocale()
|
||||
supportedDevices = injectAndWait("Devices.GetSupportedDevices").toMap();
|
||||
found = false;
|
||||
foreach (const QVariant &dcMap, supportedDevices.value("params").toMap().value("deviceClasses").toList()) {
|
||||
if (dcMap.toMap().value("id").toUuid() == mockDeviceAutoThingClassId) {
|
||||
if (dcMap.toMap().value("id").toUuid() == autoMockThingClassId) {
|
||||
QCOMPARE(dcMap.toMap().value("displayName").toString(), QString("Mock Gerät (Automatisch erzeugt)"));
|
||||
found = true;
|
||||
}
|
||||
@ -677,7 +674,7 @@ void TestJSONRPC::enableDisableNotifications_legacy()
|
||||
|
||||
QStringList expectedNamespaces;
|
||||
if (enabled == "true") {
|
||||
expectedNamespaces << "Actions" << "NetworkManager" << "Devices" << "System" << "Rules" << "States" << "Logging" << "Tags" << "JSONRPC" << "Configuration" << "Events" << "Scripts" << "Users";
|
||||
expectedNamespaces << "Actions" << "NetworkManager" << "Devices" << "Integrations" << "System" << "Rules" << "States" << "Logging" << "Tags" << "JSONRPC" << "Configuration" << "Events" << "Scripts" << "Users";
|
||||
}
|
||||
std::sort(expectedNamespaces.begin(), expectedNamespaces.end());
|
||||
|
||||
@ -690,51 +687,6 @@ void TestJSONRPC::enableDisableNotifications_legacy()
|
||||
QCOMPARE(expectedNamespaces, actualNamespaces);
|
||||
}
|
||||
|
||||
void TestJSONRPC::deviceAddedRemovedNotifications()
|
||||
{
|
||||
enableNotifications({"Devices"});
|
||||
|
||||
// Setup connection to mock client
|
||||
QSignalSpy clientSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray)));
|
||||
|
||||
// add device and wait for notification
|
||||
QVariantList deviceParams;
|
||||
QVariantMap httpportParam;
|
||||
httpportParam.insert("paramTypeId", mockDeviceHttpportParamTypeId);
|
||||
httpportParam.insert("value", 8765);
|
||||
deviceParams.append(httpportParam);
|
||||
|
||||
QVariantMap params; clientSpy.clear();
|
||||
params.insert("ddeviceClassId", mockThingClassId);
|
||||
params.insert("name", "Mock device");
|
||||
params.insert("deviceParams", deviceParams);
|
||||
QVariant response = injectAndWait("Devices.AddConfiguredDevice", params);
|
||||
if (clientSpy.count() == 0) clientSpy.wait();
|
||||
verifyDeviceError(response);
|
||||
QVariantMap notificationDeviceMap = checkNotification(clientSpy, "Devices.DeviceAdded").toMap().value("params").toMap().value("device").toMap();
|
||||
|
||||
ThingId deviceId = ThingId(response.toMap().value("params").toMap().value("deviceId").toString());
|
||||
QVERIFY(!deviceId.isNull());
|
||||
|
||||
// check the DeviceAdded notification
|
||||
QCOMPARE(notificationDeviceMap.value("deviceClassId").toString(), mockThingClassId.toString());
|
||||
QCOMPARE(notificationDeviceMap.value("id").toString(), deviceId.toString());
|
||||
foreach (const QVariant ¶m, notificationDeviceMap.value("params").toList()) {
|
||||
if (param.toMap().value("name").toString() == "httpport") {
|
||||
QCOMPARE(param.toMap().value("value").toInt(), httpportParam.value("value").toInt());
|
||||
}
|
||||
}
|
||||
|
||||
// now remove the device and check the device removed notification
|
||||
params.clear(); response.clear(); clientSpy.clear();
|
||||
params.insert("deviceId", deviceId);
|
||||
response = injectAndWait("Devices.RemoveConfiguredDevice", params);
|
||||
if (clientSpy.count() == 0) clientSpy.wait();
|
||||
verifyDeviceError(response);
|
||||
checkNotification(clientSpy, "Devices.DeviceRemoved");
|
||||
|
||||
QCOMPARE(disableNotifications(), true);
|
||||
}
|
||||
|
||||
void TestJSONRPC::ruleAddedRemovedNotifications()
|
||||
{
|
||||
@ -747,9 +699,14 @@ void TestJSONRPC::ruleAddedRemovedNotifications()
|
||||
// StateDescriptor
|
||||
QVariantMap stateDescriptor;
|
||||
stateDescriptor.insert("stateTypeId", mockIntStateTypeId);
|
||||
stateDescriptor.insert("deviceId", m_mockThingId);
|
||||
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
|
||||
// .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
|
||||
stateDescriptor = QJsonDocument::fromVariant(stateDescriptor).toVariant().toMap();
|
||||
|
||||
QVariantMap stateEvaluator;
|
||||
stateEvaluator.insert("stateDescriptor", stateDescriptor);
|
||||
@ -757,17 +714,26 @@ void TestJSONRPC::ruleAddedRemovedNotifications()
|
||||
// RuleAction
|
||||
QVariantMap actionNoParams;
|
||||
actionNoParams.insert("actionTypeId", mockWithoutParamsActionTypeId);
|
||||
actionNoParams.insert("deviceId", m_mockThingId);
|
||||
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
|
||||
QVariantList actions = QVariantList() << QJsonDocument::fromVariant(actionNoParams).toVariant().toMap();
|
||||
|
||||
// EventDescriptor
|
||||
QVariantMap eventDescriptor;
|
||||
eventDescriptor.insert("eventTypeId", mockEvent1EventTypeId);
|
||||
eventDescriptor.insert("deviceId", m_mockThingId);
|
||||
QVariantList eventDescriptors = QVariantList() << eventDescriptor;
|
||||
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
|
||||
QVariantList eventDescriptors = QVariantList() << QJsonDocument::fromVariant(eventDescriptor).toVariant().toMap();
|
||||
|
||||
QVariantMap params;
|
||||
params.insert("name", "Test Rule notifications");
|
||||
params.insert("actions", QVariantList() << actionNoParams);
|
||||
params.insert("actions", actions);
|
||||
params.insert("eventDescriptors", eventDescriptors);
|
||||
params.insert("stateEvaluator", stateEvaluator);
|
||||
|
||||
@ -781,9 +747,17 @@ void TestJSONRPC::ruleAddedRemovedNotifications()
|
||||
|
||||
QCOMPARE(notificationRuleMap.value("enabled").toBool(), true);
|
||||
QCOMPARE(notificationRuleMap.value("name").toString(), params.value("name").toString());
|
||||
QCOMPARE(notificationRuleMap.value("id").toString(), ruleId.toString());
|
||||
QCOMPARE(notificationRuleMap.value("actions").toList(), QVariantList() << actionNoParams);
|
||||
QCOMPARE(notificationRuleMap.value("stateEvaluator").toMap().value("stateDescriptor").toMap(), stateDescriptor);
|
||||
QCOMPARE(notificationRuleMap.value("id").toUuid(), QUuid(ruleId));
|
||||
QVERIFY2(notificationRuleMap.value("actions").toList() == actions,
|
||||
QString("actions not matching.\nExpected: %1\nGot %2")
|
||||
.arg(QString(QJsonDocument::fromVariant(actions).toJson()))
|
||||
.arg(QString(QJsonDocument::fromVariant(notificationRuleMap.value("actions").toList()).toJson()))
|
||||
.toUtf8());
|
||||
QVERIFY2(notificationRuleMap.value("stateEvaluator").toMap().value("stateDescriptor").toMap() == stateDescriptor,
|
||||
QString("stateDescriptor not matching.\nExpected: %1\nGot %2")
|
||||
.arg(QString(QJsonDocument::fromVariant(stateDescriptor).toJson()))
|
||||
.arg(QString(QJsonDocument::fromVariant(notificationRuleMap.value("stateEvaluator").toMap().value("stateDescriptor").toMap()).toJson()))
|
||||
.toUtf8());
|
||||
QVERIFY2(notificationRuleMap.value("eventDescriptors").toList() == eventDescriptors,
|
||||
QString("eventDescriptors not matching.\nExpected: %1\nGot %2")
|
||||
.arg(QString(QJsonDocument::fromVariant(eventDescriptors).toJson()))
|
||||
@ -814,9 +788,14 @@ void TestJSONRPC::ruleActiveChangedNotifications()
|
||||
// StateDescriptor
|
||||
QVariantMap stateDescriptor;
|
||||
stateDescriptor.insert("stateTypeId", mockIntStateTypeId);
|
||||
stateDescriptor.insert("deviceId", m_mockThingId);
|
||||
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
|
||||
// .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
|
||||
stateDescriptor = QJsonDocument::fromVariant(stateDescriptor).toVariant().toMap();
|
||||
|
||||
QVariantMap stateEvaluator;
|
||||
stateEvaluator.insert("stateDescriptor", stateDescriptor);
|
||||
@ -824,11 +803,16 @@ void TestJSONRPC::ruleActiveChangedNotifications()
|
||||
// RuleAction
|
||||
QVariantMap actionNoParams;
|
||||
actionNoParams.insert("actionTypeId", mockWithoutParamsActionTypeId);
|
||||
actionNoParams.insert("deviceId", m_mockThingId);
|
||||
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
|
||||
QVariantList actions = QVariantList() << QJsonDocument::fromVariant(actionNoParams).toVariant().toMap();
|
||||
|
||||
params.clear(); response.clear();
|
||||
params.insert("name", "Test Rule notifications");
|
||||
params.insert("actions", QVariantList() << actionNoParams);
|
||||
params.insert("actions", actions);
|
||||
params.insert("stateEvaluator", stateEvaluator);
|
||||
|
||||
// Setup connection to mock client
|
||||
@ -844,8 +828,8 @@ void TestJSONRPC::ruleActiveChangedNotifications()
|
||||
QVERIFY(!ruleId.isNull());
|
||||
QCOMPARE(notificationRuleMap.value("enabled").toBool(), true);
|
||||
QCOMPARE(notificationRuleMap.value("name").toString(), params.value("name").toString());
|
||||
QCOMPARE(notificationRuleMap.value("id").toString(), ruleId.toString());
|
||||
QCOMPARE(notificationRuleMap.value("actions").toList(), QVariantList() << actionNoParams);
|
||||
QCOMPARE(notificationRuleMap.value("id").toUuid(), QUuid(ruleId));
|
||||
QCOMPARE(notificationRuleMap.value("actions").toList(), actions);
|
||||
QCOMPARE(notificationRuleMap.value("stateEvaluator").toMap().value("stateDescriptor").toMap(), stateDescriptor);
|
||||
QCOMPARE(notificationRuleMap.value("exitActions").toList(), QVariantList());
|
||||
|
||||
@ -855,7 +839,7 @@ void TestJSONRPC::ruleActiveChangedNotifications()
|
||||
|
||||
// state state to 20
|
||||
qDebug() << "setting mock int state to 20";
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(mockIntStateTypeId.toString()).arg(20)));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(mockIntStateTypeId.toString()).arg(20)));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
connect(reply, SIGNAL(finished()), reply, SLOT(deleteLater()));
|
||||
|
||||
@ -868,6 +852,8 @@ void TestJSONRPC::ruleActiveChangedNotifications()
|
||||
|
||||
clientSpy.wait();
|
||||
|
||||
waitForDBSync();
|
||||
|
||||
// Make sure the logg notification contains all the stuff we expect
|
||||
QVariantList logEntryAddedVariants = checkNotifications(clientSpy, "Logging.LogEntryAdded");
|
||||
QVERIFY2(!logEntryAddedVariants.isEmpty(), "Did not get Logging.LogEntryAdded notification.");
|
||||
@ -886,7 +872,7 @@ void TestJSONRPC::ruleActiveChangedNotifications()
|
||||
|
||||
// set the rule inactive
|
||||
qDebug() << "setting mock int state to 42";
|
||||
QNetworkRequest request2(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(mockIntStateTypeId.toString()).arg(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()));
|
||||
|
||||
@ -907,11 +893,12 @@ void TestJSONRPC::ruleActiveChangedNotifications()
|
||||
logEntryAddedVariants = checkNotifications(clientSpy, "Logging.LogEntryAdded");
|
||||
QVERIFY2(!logEntryAddedVariants.isEmpty(), "Did not get Logging.LogEntryAdded notification.");
|
||||
found = false;
|
||||
foreach (const QVariant &loggEntryAddedVariant, logEntryAddedVariants) {
|
||||
if (loggEntryAddedVariant.toMap().value("params").toMap().value("logEntry").toMap().value("typeId").toUuid() == mockIntStateTypeId) {
|
||||
foreach (const QVariant &logEntryAddedVariant, logEntryAddedVariants) {
|
||||
qCDebug(dcTests()) << "Checking log entry" << mockIntStateTypeId << qUtf8Printable(QJsonDocument::fromVariant(logEntryAddedVariant).toJson());
|
||||
if (logEntryAddedVariant.toMap().value("params").toMap().value("logEntry").toMap().value("typeId").toUuid() == mockIntStateTypeId) {
|
||||
found = true;
|
||||
QCOMPARE(loggEntryAddedVariant.toMap().value("params").toMap().value("logEntry").toMap().value("source").toString(), QString("LoggingSourceStates"));
|
||||
QCOMPARE(loggEntryAddedVariant.toMap().value("params").toMap().value("logEntry").toMap().value("value").toInt(), 42);
|
||||
QCOMPARE(logEntryAddedVariant.toMap().value("params").toMap().value("logEntry").toMap().value("source").toString(), QString("LoggingSourceStates"));
|
||||
QCOMPARE(logEntryAddedVariant.toMap().value("params").toMap().value("logEntry").toMap().value("value").toInt(), 42);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -937,91 +924,6 @@ void TestJSONRPC::ruleActiveChangedNotifications()
|
||||
QCOMPARE(notificationVariant.toMap().value("params").toMap().value("ruleId").toUuid().toString(), ruleId.toString());
|
||||
}
|
||||
|
||||
void TestJSONRPC::deviceChangedNotifications()
|
||||
{
|
||||
// enable notificartions
|
||||
QVariantMap params;
|
||||
params.insert("enabled", true);
|
||||
QVariant response = injectAndWait("JSONRPC.SetNotificationStatus", params);
|
||||
QCOMPARE(response.toMap().value("params").toMap().value("enabled").toBool(), true);
|
||||
|
||||
// Setup connection to mock client
|
||||
QSignalSpy clientSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray)));
|
||||
|
||||
// ADD
|
||||
// add device and wait for notification
|
||||
QVariantList deviceParams;
|
||||
QVariantMap httpportParam;
|
||||
httpportParam.insert("paramTypeId", mockDeviceHttpportParamTypeId);
|
||||
httpportParam.insert("value", 23234);
|
||||
deviceParams.append(httpportParam);
|
||||
|
||||
params.clear(); response.clear(); clientSpy.clear();
|
||||
params.insert("deviceClassId", mockThingClassId);
|
||||
params.insert("name", "Mock");
|
||||
params.insert("deviceParams", deviceParams);
|
||||
response = injectAndWait("Devices.AddConfiguredDevice", params);
|
||||
ThingId deviceId = ThingId(response.toMap().value("params").toMap().value("deviceId").toString());
|
||||
QVERIFY(!deviceId.isNull());
|
||||
if (clientSpy.count() == 0) clientSpy.wait();
|
||||
verifyDeviceError(response);
|
||||
QVariantMap notificationDeviceMap = checkNotification(clientSpy, "Devices.DeviceAdded").toMap().value("params").toMap().value("device").toMap();
|
||||
|
||||
QCOMPARE(notificationDeviceMap.value("deviceClassId").toString(), mockThingClassId.toString());
|
||||
QCOMPARE(notificationDeviceMap.value("id").toString(), deviceId.toString());
|
||||
foreach (const QVariant ¶m, notificationDeviceMap.value("params").toList()) {
|
||||
if (param.toMap().value("name").toString() == "httpport") {
|
||||
QCOMPARE(param.toMap().value("value").toInt(), httpportParam.value("value").toInt());
|
||||
}
|
||||
}
|
||||
|
||||
// RECONFIGURE
|
||||
// now reconfigure the device and check the deviceChanged notification
|
||||
QVariantList newDeviceParams;
|
||||
QVariantMap newHttpportParam;
|
||||
newHttpportParam.insert("paramTypeId", mockDeviceHttpportParamTypeId);
|
||||
newHttpportParam.insert("value", 45473);
|
||||
newDeviceParams.append(newHttpportParam);
|
||||
|
||||
params.clear(); response.clear(); clientSpy.clear();
|
||||
params.insert("deviceId", deviceId);
|
||||
params.insert("deviceParams", newDeviceParams);
|
||||
response = injectAndWait("Devices.ReconfigureDevice", params);
|
||||
if (clientSpy.count() == 0) clientSpy.wait();
|
||||
verifyDeviceError(response);
|
||||
QVariantMap reconfigureDeviceNotificationMap = checkNotification(clientSpy, "Devices.DeviceChanged").toMap().value("params").toMap().value("device").toMap();
|
||||
QCOMPARE(reconfigureDeviceNotificationMap.value("deviceClassId").toString(), mockThingClassId.toString());
|
||||
QCOMPARE(reconfigureDeviceNotificationMap.value("id").toString(), deviceId.toString());
|
||||
foreach (const QVariant ¶m, reconfigureDeviceNotificationMap.value("params").toList()) {
|
||||
if (param.toMap().value("name").toString() == "httpport") {
|
||||
QCOMPARE(param.toMap().value("value").toInt(), newHttpportParam.value("value").toInt());
|
||||
}
|
||||
}
|
||||
|
||||
// EDIT device name
|
||||
QString deviceName = "Test device 1234";
|
||||
params.clear(); response.clear(); clientSpy.clear();
|
||||
params.insert("deviceId", deviceId);
|
||||
params.insert("name", deviceName);
|
||||
response = injectAndWait("Devices.EditDevice", params);
|
||||
if (clientSpy.count() == 0) clientSpy.wait();
|
||||
verifyDeviceError(response);
|
||||
QVariantMap editDeviceNotificationMap = checkNotification(clientSpy, "Devices.DeviceChanged").toMap().value("params").toMap().value("device").toMap();
|
||||
QCOMPARE(editDeviceNotificationMap.value("deviceClassId").toString(), mockThingClassId.toString());
|
||||
QCOMPARE(editDeviceNotificationMap.value("id").toString(), deviceId.toString());
|
||||
QCOMPARE(editDeviceNotificationMap.value("name").toString(), deviceName);
|
||||
|
||||
// REMOVE
|
||||
// now remove the device and check the device removed notification
|
||||
params.clear(); response.clear(); clientSpy.clear();
|
||||
params.insert("deviceId", deviceId);
|
||||
response = injectAndWait("Devices.RemoveConfiguredDevice", params);
|
||||
if (clientSpy.count() == 0) clientSpy.wait();
|
||||
verifyDeviceError(response);
|
||||
checkNotification(clientSpy, "Devices.DeviceRemoved");
|
||||
checkNotification(clientSpy, "Logging.LogDatabaseUpdated");
|
||||
}
|
||||
|
||||
void TestJSONRPC::stateChangeEmitsNotifications()
|
||||
{
|
||||
enableNotifications({"Devices", "States", "Logging", "Events"});
|
||||
@ -1034,7 +936,7 @@ void TestJSONRPC::stateChangeEmitsNotifications()
|
||||
// trigger state change in mock device
|
||||
int newVal = 38;
|
||||
QUuid stateTypeId("80baec19-54de-4948-ac46-31eabfaceb83");
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(stateTypeId.toString()).arg(QString::number(newVal))));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(stateTypeId.toString()).arg(QString::number(newVal))));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
connect(reply, SIGNAL(finished()), reply, SLOT(deleteLater()));
|
||||
QSignalSpy replySpy(reply, SIGNAL(finished()));
|
||||
@ -1098,7 +1000,7 @@ void TestJSONRPC::stateChangeEmitsNotifications()
|
||||
// Fire the a statechange once again
|
||||
clientSpy.clear();
|
||||
newVal = 42;
|
||||
request.setUrl(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(stateTypeId.toString()).arg(newVal)));
|
||||
request.setUrl(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(stateTypeId.toString()).arg(newVal)));
|
||||
reply = nam.get(request);
|
||||
connect(reply, SIGNAL(finished()), reply, SLOT(deleteLater()));
|
||||
|
||||
@ -1129,7 +1031,7 @@ void TestJSONRPC::pluginConfigChangeEmitsNotification()
|
||||
params.insert("pluginId", mockPluginId);
|
||||
QVariantList pluginParams;
|
||||
QVariantMap param1;
|
||||
param1.insert("paramTypeId", mockDevicePluginConfigParamIntParamTypeId);
|
||||
param1.insert("paramTypeId", mockPluginConfigParamIntParamTypeId);
|
||||
param1.insert("value", 42);
|
||||
pluginParams.append(param1);
|
||||
params.insert("configuration", pluginParams);
|
||||
|
||||
@ -47,13 +47,12 @@ private:
|
||||
inline void verifyLoggingError(const QVariant &response, Logging::LoggingError error = Logging::LoggingErrorNoError) {
|
||||
verifyError(response, "loggingError", enumValueName(error));
|
||||
}
|
||||
inline void verifyDeviceError(const QVariant &response, Thing::ThingError error = Thing::ThingErrorNoError) {
|
||||
verifyError(response, "deviceError", enumValueName(error));
|
||||
inline void verifyThingError(const QVariant &response, Thing::ThingError error = Thing::ThingErrorNoError) {
|
||||
verifyError(response, "thingError", enumValueName(error));
|
||||
}
|
||||
inline void waitForDBSync() {
|
||||
while (NymeaCore::instance()->logEngine()->jobsRunning()) {
|
||||
qApp->processEvents();
|
||||
}
|
||||
// DEPRECTATED
|
||||
inline void verifyDeviceError(const QVariant &response, Thing::ThingError error = Thing::ThingErrorNoError) {
|
||||
verifyError(response, "deviceError", enumValueName(error).replace("Thing", "Device"));
|
||||
}
|
||||
|
||||
private slots:
|
||||
@ -277,7 +276,7 @@ void TestLogging::eventLogs()
|
||||
QSignalSpy clientSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray)));
|
||||
|
||||
// trigger event in mock device
|
||||
int port = device->paramValue(mockDeviceHttpportParamTypeId).toInt();
|
||||
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);
|
||||
|
||||
@ -343,7 +342,7 @@ void TestLogging::actionLog()
|
||||
|
||||
QVariantMap params;
|
||||
params.insert("actionTypeId", mockWithParamsActionTypeId);
|
||||
params.insert("deviceId", m_mockThingId);
|
||||
params.insert("thingId", m_mockThingId);
|
||||
params.insert("params", actionParams);
|
||||
|
||||
enableNotifications({"Logging"});
|
||||
@ -351,8 +350,8 @@ void TestLogging::actionLog()
|
||||
QSignalSpy clientSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray)));
|
||||
|
||||
// EXECUTE with params
|
||||
QVariant response = injectAndWait("Actions.ExecuteAction", params);
|
||||
verifyDeviceError(response);
|
||||
QVariant response = injectAndWait("Integrations.ExecuteAction", params);
|
||||
verifyThingError(response);
|
||||
|
||||
// wait for the outgoing data
|
||||
// 3 packets: ExecuteAction reply, LogDatabaseUpdated signal and LogEntryAdded signal
|
||||
@ -484,7 +483,7 @@ void TestLogging::actionLog()
|
||||
void TestLogging::deviceLogs()
|
||||
{
|
||||
QVariantMap params;
|
||||
params.insert("deviceClassId", mockParentThingClassId);
|
||||
params.insert("deviceClassId", parentMockThingClassId);
|
||||
params.insert("name", "Parent device");
|
||||
|
||||
QVariant response = injectAndWait("Devices.AddConfiguredDevice", params);
|
||||
@ -526,12 +525,12 @@ void TestLogging::testDoubleValues()
|
||||
// Discover device
|
||||
QVariantList discoveryParams;
|
||||
QVariantMap resultCountParam;
|
||||
resultCountParam.insert("paramTypeId", mockDisplayPinDiscoveryResultCountParamTypeId);
|
||||
resultCountParam.insert("paramTypeId", displayPinMockDiscoveryResultCountParamTypeId);
|
||||
resultCountParam.insert("value", 1);
|
||||
discoveryParams.append(resultCountParam);
|
||||
|
||||
QVariantMap params;
|
||||
params.insert("deviceClassId", mockDisplayPinThingClassId);
|
||||
params.insert("deviceClassId", displayPinMockThingClassId);
|
||||
params.insert("discoveryParams", discoveryParams);
|
||||
QVariant response = injectAndWait("Devices.GetDiscoveredDevices", params);
|
||||
|
||||
@ -540,7 +539,7 @@ void TestLogging::testDoubleValues()
|
||||
// Pair device
|
||||
ThingDescriptorId descriptorId = ThingDescriptorId(response.toMap().value("params").toMap().value("deviceDescriptors").toList().first().toMap().value("id").toString());
|
||||
params.clear();
|
||||
params.insert("deviceClassId", mockDisplayPinThingClassId);
|
||||
params.insert("deviceClassId", displayPinMockThingClassId);
|
||||
params.insert("name", "Display pin mock device");
|
||||
params.insert("deviceDescriptorId", descriptorId.toString());
|
||||
response = injectAndWait("Devices.PairDevice", params);
|
||||
@ -566,12 +565,12 @@ void TestLogging::testDoubleValues()
|
||||
// Set the double state value and sniff for LogEntryAdded notification
|
||||
double value = 23.80;
|
||||
QVariantMap actionParam;
|
||||
actionParam.insert("paramTypeId", mockDisplayPinDoubleActionDoubleParamTypeId.toString());
|
||||
actionParam.insert("paramTypeId", displayPinMockDoubleActionDoubleParamTypeId.toString());
|
||||
actionParam.insert("value", value);
|
||||
|
||||
params.clear(); response.clear();
|
||||
params.insert("deviceId", deviceId);
|
||||
params.insert("actionTypeId", mockDisplayPinDoubleActionTypeId.toString());
|
||||
params.insert("actionTypeId", displayPinMockDoubleActionTypeId.toString());
|
||||
params.insert("params", QVariantList() << actionParam);
|
||||
|
||||
response = injectAndWait("Actions.ExecuteAction", params);
|
||||
@ -584,8 +583,8 @@ void TestLogging::testDoubleValues()
|
||||
foreach (const QVariant &logNotificationVariant, logNotificationsList) {
|
||||
QVariantMap logNotification = logNotificationVariant.toMap().value("params").toMap().value("logEntry").toMap();
|
||||
|
||||
if (logNotification.value("typeId").toString() == mockDisplayPinDoubleActionDoubleParamTypeId.toString()) {
|
||||
if (logNotification.value("typeId").toString() == mockDisplayPinDoubleActionDoubleParamTypeId.toString()) {
|
||||
if (logNotification.value("typeId").toString() == displayPinMockDoubleActionDoubleParamTypeId.toString()) {
|
||||
if (logNotification.value("typeId").toString() == displayPinMockDoubleActionDoubleParamTypeId.toString()) {
|
||||
|
||||
// If state source
|
||||
if (logNotification.value("source").toString() == enumValueName(Logging::LoggingSourceStates)) {
|
||||
@ -619,7 +618,7 @@ void TestLogging::testHouseKeeping()
|
||||
params.insert("name", "TestDeviceToBeRemoved");
|
||||
QVariantList deviceParams;
|
||||
QVariantMap httpParam;
|
||||
httpParam.insert("paramTypeId", mockDeviceHttpportParamTypeId);
|
||||
httpParam.insert("paramTypeId", mockThingHttpportParamTypeId);
|
||||
httpParam.insert("value", 6667);
|
||||
deviceParams.append(httpParam);
|
||||
params.insert("deviceParams", deviceParams);
|
||||
|
||||
@ -141,7 +141,7 @@ private slots:
|
||||
void TestRules::cleanupMockHistory() {
|
||||
QNetworkAccessManager nam;
|
||||
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/clearactionhistory").arg(QString::number(m_mockDevice1Port))));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/clearactionhistory").arg(QString::number(m_mockThing1Port))));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -162,12 +162,12 @@ ThingId TestRules::addDisplayPinDevice()
|
||||
// Discover device
|
||||
QVariantList discoveryParams;
|
||||
QVariantMap resultCountParam;
|
||||
resultCountParam.insert("paramTypeId", mockDisplayPinDiscoveryResultCountParamTypeId);
|
||||
resultCountParam.insert("paramTypeId", displayPinMockDiscoveryResultCountParamTypeId);
|
||||
resultCountParam.insert("value", 1);
|
||||
discoveryParams.append(resultCountParam);
|
||||
|
||||
QVariantMap params;
|
||||
params.insert("deviceClassId", mockDisplayPinThingClassId);
|
||||
params.insert("deviceClassId", displayPinMockThingClassId);
|
||||
params.insert("discoveryParams", discoveryParams);
|
||||
QVariant response = injectAndWait("Devices.GetDiscoveredDevices", params);
|
||||
|
||||
@ -176,7 +176,7 @@ ThingId TestRules::addDisplayPinDevice()
|
||||
// Pair device
|
||||
ThingDescriptorId descriptorId = ThingDescriptorId(response.toMap().value("params").toMap().value("deviceDescriptors").toList().first().toMap().value("id").toString());
|
||||
params.clear();
|
||||
params.insert("deviceClassId", mockDisplayPinThingClassId);
|
||||
params.insert("deviceClassId", displayPinMockThingClassId);
|
||||
params.insert("name", "Display pin mock device");
|
||||
params.insert("deviceDescriptorId", descriptorId.toString());
|
||||
response = injectAndWait("Devices.PairDevice", params);
|
||||
@ -285,7 +285,7 @@ void TestRules::verifyRuleExecuted(const ActionTypeId &actionTypeId)
|
||||
while (!actionFound && i < 50) {
|
||||
QNetworkAccessManager nam;
|
||||
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/actionhistory").arg(QString::number(m_mockDevice1Port))));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/actionhistory").arg(QString::number(m_mockThing1Port))));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -305,7 +305,7 @@ void TestRules::verifyRuleNotExecuted()
|
||||
{
|
||||
QNetworkAccessManager nam;
|
||||
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/actionhistory").arg(QString::number(m_mockDevice1Port))));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/actionhistory").arg(QString::number(m_mockThing1Port))));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -394,7 +394,7 @@ void TestRules::generateEvent(const EventTypeId &eventTypeId)
|
||||
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
|
||||
|
||||
// trigger event in mock device
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(m_mockDevice1Port).arg(eventTypeId.toString())));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(m_mockThing1Port).arg(eventTypeId.toString())));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -1588,7 +1588,7 @@ void TestRules::evaluateEvent()
|
||||
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
|
||||
|
||||
// trigger event in mock device
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(m_mockDevice1Port).arg(mockEvent1EventTypeId.toString())));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(m_mockThing1Port).arg(mockEvent1EventTypeId.toString())));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -1602,7 +1602,7 @@ void TestRules::evaluateEventParams()
|
||||
// Init bool state to true
|
||||
QNetworkAccessManager nam;
|
||||
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(mockBoolStateTypeId.toString()).arg("true")));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(mockBoolStateTypeId.toString()).arg("true")));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -1641,7 +1641,7 @@ void TestRules::evaluateEventParams()
|
||||
|
||||
// Trigger a non matching param
|
||||
spy.clear();
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(mockBoolStateTypeId.toString()).arg("false")));
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(mockBoolStateTypeId.toString()).arg("false")));
|
||||
reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -1651,7 +1651,7 @@ void TestRules::evaluateEventParams()
|
||||
|
||||
// Trigger a matching param
|
||||
spy.clear();
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(mockBoolStateTypeId.toString()).arg("true")));
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(mockBoolStateTypeId.toString()).arg("true")));
|
||||
reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -1661,7 +1661,7 @@ void TestRules::evaluateEventParams()
|
||||
|
||||
// Reset back to false to not mess with other tests
|
||||
spy.clear();
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(mockBoolStateTypeId.toString()).arg("false")));
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(mockBoolStateTypeId.toString()).arg("false")));
|
||||
reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -1698,7 +1698,7 @@ void TestRules::testStateChange() {
|
||||
|
||||
// state state to 42
|
||||
qDebug() << "setting mock int state to 42";
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(mockIntStateTypeId.toString()).arg(42)));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(mockIntStateTypeId.toString()).arg(42)));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -1711,7 +1711,7 @@ void TestRules::testStateChange() {
|
||||
// set state to 45
|
||||
qDebug() << "setting mock int state to 45";
|
||||
spy.clear();
|
||||
request.setUrl(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(mockIntStateTypeId.toString()).arg(45)));
|
||||
request.setUrl(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(mockIntStateTypeId.toString()).arg(45)));
|
||||
reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -1724,7 +1724,7 @@ void TestRules::testStateChange() {
|
||||
// set state to 30
|
||||
qDebug() << "setting mock int state to 30";
|
||||
spy.clear();
|
||||
request.setUrl(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(mockIntStateTypeId.toString()).arg(30)));
|
||||
request.setUrl(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(mockIntStateTypeId.toString()).arg(30)));
|
||||
reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -1737,7 +1737,7 @@ void TestRules::testStateChange() {
|
||||
// set state to 100
|
||||
qDebug() << "setting mock int state to 100";
|
||||
spy.clear();
|
||||
request.setUrl(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(mockIntStateTypeId.toString()).arg(100)));
|
||||
request.setUrl(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(mockIntStateTypeId.toString()).arg(100)));
|
||||
reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -1903,25 +1903,25 @@ void TestRules::testChildEvaluator_data()
|
||||
QVariantMap stateDescriptorPercentage;
|
||||
stateDescriptorPercentage.insert("deviceId", testDeviceId);
|
||||
stateDescriptorPercentage.insert("operator", enumValueName(Types::ValueOperatorGreaterOrEqual));
|
||||
stateDescriptorPercentage.insert("stateTypeId", mockDisplayPinPercentageStateTypeId);
|
||||
stateDescriptorPercentage.insert("stateTypeId", displayPinMockPercentageStateTypeId);
|
||||
stateDescriptorPercentage.insert("value", 50);
|
||||
|
||||
QVariantMap stateDescriptorDouble;
|
||||
stateDescriptorDouble.insert("deviceId", testDeviceId);
|
||||
stateDescriptorDouble.insert("operator", enumValueName(Types::ValueOperatorEquals));
|
||||
stateDescriptorDouble.insert("stateTypeId", mockDisplayPinDoubleActionDoubleParamTypeId);
|
||||
stateDescriptorDouble.insert("stateTypeId", displayPinMockDoubleActionDoubleParamTypeId);
|
||||
stateDescriptorDouble.insert("value", 20.5);
|
||||
|
||||
QVariantMap stateDescriptorAllowedValues;
|
||||
stateDescriptorAllowedValues.insert("deviceId", testDeviceId);
|
||||
stateDescriptorAllowedValues.insert("operator", enumValueName(Types::ValueOperatorEquals));
|
||||
stateDescriptorAllowedValues.insert("stateTypeId", mockDisplayPinAllowedValuesStateTypeId);
|
||||
stateDescriptorAllowedValues.insert("stateTypeId", displayPinMockAllowedValuesStateTypeId);
|
||||
stateDescriptorAllowedValues.insert("value", "String value 2");
|
||||
|
||||
QVariantMap stateDescriptorColor;
|
||||
stateDescriptorColor.insert("deviceId", testDeviceId);
|
||||
stateDescriptorColor.insert("operator", enumValueName(Types::ValueOperatorEquals));
|
||||
stateDescriptorColor.insert("stateTypeId", mockDisplayPinColorStateTypeId);
|
||||
stateDescriptorColor.insert("stateTypeId", displayPinMockColorStateTypeId);
|
||||
stateDescriptorColor.insert("value", "#00FF00");
|
||||
|
||||
QVariantMap firstStateEvaluator;
|
||||
@ -1976,10 +1976,10 @@ void TestRules::testChildEvaluator()
|
||||
QFETCH(bool, active);
|
||||
|
||||
// Init the states
|
||||
setWritableStateValue(deviceId, StateTypeId(mockDisplayPinPercentageStateTypeId.toString()), QVariant(0));
|
||||
setWritableStateValue(deviceId, StateTypeId(mockDisplayPinDoubleActionDoubleParamTypeId.toString()), QVariant(0));
|
||||
setWritableStateValue(deviceId, StateTypeId(mockDisplayPinAllowedValuesStateTypeId.toString()), QVariant("String value 1"));
|
||||
setWritableStateValue(deviceId, StateTypeId(mockDisplayPinColorStateTypeId.toString()), QVariant("#000000"));
|
||||
setWritableStateValue(deviceId, StateTypeId(displayPinMockPercentageStateTypeId.toString()), QVariant(0));
|
||||
setWritableStateValue(deviceId, StateTypeId(displayPinMockDoubleActionDoubleParamTypeId.toString()), QVariant(0));
|
||||
setWritableStateValue(deviceId, StateTypeId(displayPinMockAllowedValuesStateTypeId.toString()), QVariant("String value 1"));
|
||||
setWritableStateValue(deviceId, StateTypeId(displayPinMockColorStateTypeId.toString()), QVariant("#000000"));
|
||||
|
||||
qCDebug(dcTests()) << "Adding rule";
|
||||
|
||||
@ -1991,13 +1991,13 @@ void TestRules::testChildEvaluator()
|
||||
|
||||
// Set the states
|
||||
qCDebug(dcTests()) << "Setting state 1";
|
||||
setWritableStateValue(deviceId, StateTypeId(mockDisplayPinPercentageStateTypeId.toString()), QVariant::fromValue(percentageValue));
|
||||
setWritableStateValue(deviceId, StateTypeId(displayPinMockPercentageStateTypeId.toString()), QVariant::fromValue(percentageValue));
|
||||
qCDebug(dcTests()) << "Setting state 2";
|
||||
setWritableStateValue(deviceId, StateTypeId(mockDisplayPinDoubleActionDoubleParamTypeId.toString()), QVariant::fromValue(doubleValue));
|
||||
setWritableStateValue(deviceId, StateTypeId(displayPinMockDoubleActionDoubleParamTypeId.toString()), QVariant::fromValue(doubleValue));
|
||||
qCDebug(dcTests()) << "Setting state 3";
|
||||
setWritableStateValue(deviceId, StateTypeId(mockDisplayPinAllowedValuesStateTypeId.toString()), QVariant::fromValue(allowedValue));
|
||||
setWritableStateValue(deviceId, StateTypeId(displayPinMockAllowedValuesStateTypeId.toString()), QVariant::fromValue(allowedValue));
|
||||
qCDebug(dcTests()) << "Setting state 4";
|
||||
setWritableStateValue(deviceId, StateTypeId(mockDisplayPinColorStateTypeId.toString()), QVariant::fromValue(colorValue));
|
||||
setWritableStateValue(deviceId, StateTypeId(displayPinMockColorStateTypeId.toString()), QVariant::fromValue(colorValue));
|
||||
|
||||
// Verfiy if the rule executed successfully
|
||||
// Actions
|
||||
@ -2055,7 +2055,7 @@ void TestRules::enableDisableRule()
|
||||
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
|
||||
|
||||
// trigger event in mock device
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(m_mockDevice1Port).arg(mockEvent1EventTypeId.toString())));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(m_mockThing1Port).arg(mockEvent1EventTypeId.toString())));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -2079,7 +2079,7 @@ void TestRules::enableDisableRule()
|
||||
|
||||
// trigger event in mock device
|
||||
spy.clear();
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(m_mockDevice1Port).arg(mockEvent1EventTypeId.toString())));
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(m_mockThing1Port).arg(mockEvent1EventTypeId.toString())));
|
||||
reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -2103,7 +2103,7 @@ void TestRules::enableDisableRule()
|
||||
|
||||
// trigger event in mock device
|
||||
spy.clear();
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(m_mockDevice1Port).arg(mockEvent1EventTypeId.toString())));
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(m_mockThing1Port).arg(mockEvent1EventTypeId.toString())));
|
||||
reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -2152,7 +2152,7 @@ void TestRules::testEventBasedAction()
|
||||
|
||||
// state state to 42
|
||||
qDebug() << "setting mock int state to 42";
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(mockIntStateTypeId.toString()).arg(42)));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(mockIntStateTypeId.toString()).arg(42)));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -2169,7 +2169,7 @@ void TestRules::testEventBasedRuleWithExitAction()
|
||||
|
||||
// Init bool state to true
|
||||
spy.clear();
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(mockBoolStateTypeId.toString()).arg(true)));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(mockBoolStateTypeId.toString()).arg(true)));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -2224,7 +2224,7 @@ void TestRules::testEventBasedRuleWithExitAction()
|
||||
|
||||
// trigger event
|
||||
spy.clear();
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(m_mockDevice1Port).arg(mockEvent1EventTypeId.toString())));
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(m_mockThing1Port).arg(mockEvent1EventTypeId.toString())));
|
||||
reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -2235,7 +2235,7 @@ void TestRules::testEventBasedRuleWithExitAction()
|
||||
|
||||
// set bool state to false
|
||||
spy.clear();
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(mockBoolStateTypeId.toString()).arg(false)));
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(mockBoolStateTypeId.toString()).arg(false)));
|
||||
reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -2243,7 +2243,7 @@ void TestRules::testEventBasedRuleWithExitAction()
|
||||
|
||||
// trigger event
|
||||
spy.clear();
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(m_mockDevice1Port).arg(mockEvent1EventTypeId.toString())));
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(m_mockThing1Port).arg(mockEvent1EventTypeId.toString())));
|
||||
reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -2261,7 +2261,7 @@ void TestRules::testStateBasedAction()
|
||||
|
||||
// Init bool state to true
|
||||
spy.clear();
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(mockBoolStateTypeId.toString()).arg(true)));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(mockBoolStateTypeId.toString()).arg(true)));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -2269,7 +2269,7 @@ void TestRules::testStateBasedAction()
|
||||
|
||||
// Init int state to 11
|
||||
spy.clear();
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(mockIntStateTypeId.toString()).arg(11)));
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(mockIntStateTypeId.toString()).arg(11)));
|
||||
reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -2312,7 +2312,7 @@ void TestRules::testStateBasedAction()
|
||||
|
||||
// trigger event
|
||||
spy.clear();
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(m_mockDevice1Port).arg(mockEvent1EventTypeId.toString())));
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(m_mockThing1Port).arg(mockEvent1EventTypeId.toString())));
|
||||
reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -2330,7 +2330,7 @@ void TestRules::testStateBasedAction()
|
||||
|
||||
// set bool state to false
|
||||
spy.clear();
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(mockBoolStateTypeId.toString()).arg(false)));
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(mockBoolStateTypeId.toString()).arg(false)));
|
||||
reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -2338,7 +2338,7 @@ void TestRules::testStateBasedAction()
|
||||
|
||||
// trigger event
|
||||
spy.clear();
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(m_mockDevice1Port).arg(mockEvent1EventTypeId.toString())));
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(m_mockThing1Port).arg(mockEvent1EventTypeId.toString())));
|
||||
reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -2356,7 +2356,7 @@ void TestRules::removePolicyUpdate()
|
||||
{
|
||||
// ADD parent device
|
||||
QVariantMap params;
|
||||
params.insert("deviceClassId", mockParentThingClassId);
|
||||
params.insert("deviceClassId", parentMockThingClassId);
|
||||
params.insert("name", "Parent device");
|
||||
|
||||
QSignalSpy addedSpy(NymeaCore::instance()->thingManager(), &ThingManager::thingAdded);
|
||||
@ -2378,7 +2378,7 @@ void TestRules::removePolicyUpdate()
|
||||
foreach (const QVariant deviceVariant, devices) {
|
||||
QVariantMap deviceMap = deviceVariant.toMap();
|
||||
|
||||
if (deviceMap.value("deviceClassId").toString() == mockChildThingClassId.toString()) {
|
||||
if (deviceMap.value("deviceClassId").toString() == childMockThingClassId.toString()) {
|
||||
if (deviceMap.value("parentId") == parentId.toString()) {
|
||||
//qDebug() << QJsonDocument::fromVariant(deviceVariant).toJson();
|
||||
childId = ThingId(deviceMap.value("id").toString());
|
||||
@ -2389,8 +2389,8 @@ void TestRules::removePolicyUpdate()
|
||||
|
||||
// Add rule with child device
|
||||
QVariantList eventDescriptors;
|
||||
eventDescriptors.append(createEventDescriptor(childId, mockChildBoolValueEventTypeId));
|
||||
eventDescriptors.append(createEventDescriptor(parentId, mockParentBoolValueEventTypeId));
|
||||
eventDescriptors.append(createEventDescriptor(childId, childMockBoolValueEventTypeId));
|
||||
eventDescriptors.append(createEventDescriptor(parentId, parentMockBoolValueEventTypeId));
|
||||
eventDescriptors.append(createEventDescriptor(m_mockThingId, mockEvent1EventTypeId));
|
||||
|
||||
params.clear(); response.clear();
|
||||
@ -2443,7 +2443,7 @@ void TestRules::removePolicyCascade()
|
||||
{
|
||||
// ADD parent device
|
||||
QVariantMap params;
|
||||
params.insert("deviceClassId", mockParentThingClassId);
|
||||
params.insert("deviceClassId", parentMockThingClassId);
|
||||
params.insert("name", "Parent device");
|
||||
|
||||
QSignalSpy addedSpy(NymeaCore::instance()->thingManager(), &ThingManager::thingAdded);
|
||||
@ -2465,7 +2465,7 @@ void TestRules::removePolicyCascade()
|
||||
foreach (const QVariant deviceVariant, devices) {
|
||||
QVariantMap deviceMap = deviceVariant.toMap();
|
||||
|
||||
if (deviceMap.value("deviceClassId").toString() == mockChildThingClassId.toString()) {
|
||||
if (deviceMap.value("deviceClassId").toString() == childMockThingClassId.toString()) {
|
||||
if (deviceMap.value("parentId") == parentId.toString()) {
|
||||
//qDebug() << QJsonDocument::fromVariant(deviceVariant).toJson();
|
||||
childId = ThingId(deviceMap.value("id").toString());
|
||||
@ -2476,8 +2476,8 @@ void TestRules::removePolicyCascade()
|
||||
|
||||
// Add rule with child device
|
||||
QVariantList eventDescriptors;
|
||||
eventDescriptors.append(createEventDescriptor(childId, mockChildBoolValueEventTypeId));
|
||||
eventDescriptors.append(createEventDescriptor(parentId, mockParentBoolValueEventTypeId));
|
||||
eventDescriptors.append(createEventDescriptor(childId, childMockBoolValueEventTypeId));
|
||||
eventDescriptors.append(createEventDescriptor(parentId, parentMockBoolValueEventTypeId));
|
||||
eventDescriptors.append(createEventDescriptor(m_mockThingId, mockEvent1EventTypeId));
|
||||
|
||||
params.clear(); response.clear();
|
||||
@ -2520,7 +2520,7 @@ void TestRules::removePolicyUpdateRendersUselessRule()
|
||||
{
|
||||
// ADD parent device
|
||||
QVariantMap params;
|
||||
params.insert("deviceClassId", mockParentThingClassId);
|
||||
params.insert("deviceClassId", parentMockThingClassId);
|
||||
params.insert("name", "Parent device");
|
||||
|
||||
QSignalSpy addedSpy(NymeaCore::instance()->thingManager(), &ThingManager::thingAdded);
|
||||
@ -2543,7 +2543,7 @@ void TestRules::removePolicyUpdateRendersUselessRule()
|
||||
foreach (const QVariant deviceVariant, devices) {
|
||||
QVariantMap deviceMap = deviceVariant.toMap();
|
||||
|
||||
if (deviceMap.value("deviceClassId").toString() == mockChildThingClassId.toString()) {
|
||||
if (deviceMap.value("deviceClassId").toString() == childMockThingClassId.toString()) {
|
||||
if (deviceMap.value("parentId") == parentId.toString()) {
|
||||
//qDebug() << QJsonDocument::fromVariant(deviceVariant).toJson();
|
||||
childId = ThingId(deviceMap.value("id").toString());
|
||||
@ -2554,8 +2554,8 @@ void TestRules::removePolicyUpdateRendersUselessRule()
|
||||
|
||||
// Add rule with child device
|
||||
QVariantList eventDescriptors;
|
||||
eventDescriptors.append(createEventDescriptor(childId, mockChildBoolValueEventTypeId));
|
||||
eventDescriptors.append(createEventDescriptor(parentId, mockParentBoolValueEventTypeId));
|
||||
eventDescriptors.append(createEventDescriptor(childId, childMockBoolValueEventTypeId));
|
||||
eventDescriptors.append(createEventDescriptor(parentId, parentMockBoolValueEventTypeId));
|
||||
eventDescriptors.append(createEventDescriptor(m_mockThingId, mockEvent1EventTypeId));
|
||||
|
||||
params.clear(); response.clear();
|
||||
@ -2564,9 +2564,9 @@ void TestRules::removePolicyUpdateRendersUselessRule()
|
||||
|
||||
QVariantMap action;
|
||||
action.insert("deviceId", childId);
|
||||
action.insert("actionTypeId", mockChildBoolValueActionTypeId);
|
||||
action.insert("actionTypeId", childMockBoolValueActionTypeId);
|
||||
QVariantMap ruleActionParam;
|
||||
ruleActionParam.insert("paramTypeId", mockChildBoolValueActionBoolValueParamTypeId);
|
||||
ruleActionParam.insert("paramTypeId", childMockBoolValueActionBoolValueParamTypeId);
|
||||
ruleActionParam.insert("value", true);
|
||||
action.insert("ruleActionParams", QVariantList() << ruleActionParam);
|
||||
params.insert("actions", QVariantList() << action);
|
||||
@ -2826,7 +2826,7 @@ void TestRules::testInterfaceBasedEventRule()
|
||||
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
|
||||
|
||||
// state battery critical state to false initially
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(mockBatteryCriticalStateTypeId.toString()).arg(false)));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(mockBatteryCriticalStateTypeId.toString()).arg(false)));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -2882,13 +2882,13 @@ void TestRules::testInterfaceBasedEventRule()
|
||||
|
||||
// Change the state to true, action should trigger
|
||||
spy.clear();
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/clearactionhistory").arg(m_mockDevice1Port)));
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/clearactionhistory").arg(m_mockThing1Port)));
|
||||
reply = nam.get(request);
|
||||
|
||||
qDebug(dcTests) << "Changing battery state -> true";
|
||||
|
||||
spy.wait(); spy.clear();
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(mockBatteryCriticalStateTypeId.toString()).arg(true)));
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(mockBatteryCriticalStateTypeId.toString()).arg(true)));
|
||||
reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -2900,13 +2900,13 @@ void TestRules::testInterfaceBasedEventRule()
|
||||
|
||||
// Change the state to false, action should not trigger
|
||||
spy.clear();
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/clearactionhistory").arg(m_mockDevice1Port)));
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/clearactionhistory").arg(m_mockThing1Port)));
|
||||
reply = nam.get(request);
|
||||
|
||||
qDebug(dcTests) << "Changing battery state -> false";
|
||||
|
||||
spy.wait(); spy.clear();
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(mockBatteryCriticalStateTypeId.toString()).arg(false)));
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(mockBatteryCriticalStateTypeId.toString()).arg(false)));
|
||||
reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -2920,7 +2920,7 @@ void TestRules::testInterfaceBasedStateRule()
|
||||
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
|
||||
|
||||
// state battery critical state to false initially
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(mockBatteryCriticalStateTypeId.toString()).arg(false)));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(mockBatteryCriticalStateTypeId.toString()).arg(false)));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -2974,7 +2974,7 @@ void TestRules::testInterfaceBasedStateRule()
|
||||
|
||||
// Change the state
|
||||
spy.clear();
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(mockBatteryCriticalStateTypeId.toString()).arg(true)));
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(mockBatteryCriticalStateTypeId.toString()).arg(true)));
|
||||
reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -3070,7 +3070,7 @@ void TestRules::testScene()
|
||||
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
|
||||
|
||||
// state power state to false initially
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(mockPowerStateTypeId.toString()).arg(false)));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(mockPowerStateTypeId.toString()).arg(false)));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -3078,7 +3078,7 @@ void TestRules::testScene()
|
||||
|
||||
// state battery critical state to false initially
|
||||
spy.clear();
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(mockBatteryCriticalStateTypeId.toString()).arg(false)));
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(mockBatteryCriticalStateTypeId.toString()).arg(false)));
|
||||
reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -3105,7 +3105,7 @@ void TestRules::testScene()
|
||||
|
||||
// trigger state change on battery critical
|
||||
spy.clear();
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(mockBatteryCriticalStateTypeId.toString()).arg(true)));
|
||||
request = QNetworkRequest(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(mockBatteryCriticalStateTypeId.toString()).arg(true)));
|
||||
reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -3144,7 +3144,7 @@ void TestRules::testHousekeeping()
|
||||
params.insert("name", "TestDeviceToBeRemoved");
|
||||
QVariantList deviceParams;
|
||||
QVariantMap httpParam;
|
||||
httpParam.insert("paramTypeId", mockDeviceHttpportParamTypeId);
|
||||
httpParam.insert("paramTypeId", mockThingHttpportParamTypeId);
|
||||
httpParam.insert("value", 6667);
|
||||
deviceParams.append(httpParam);
|
||||
params.insert("deviceParams", deviceParams);
|
||||
|
||||
@ -94,7 +94,7 @@ void TestStates::save_load_states()
|
||||
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(mockDeviceHttpportParamTypeId).toInt();
|
||||
int port = device->paramValue(mockThingHttpportParamTypeId).toInt();
|
||||
QNetworkAccessManager nam;
|
||||
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
|
||||
|
||||
|
||||
@ -2038,7 +2038,7 @@ void TestTimeManager::verifyRuleExecuted(const ActionTypeId &actionTypeId)
|
||||
// Verify rule got executed
|
||||
QNetworkAccessManager nam;
|
||||
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/actionhistory").arg(QString::number(m_mockDevice1Port))));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/actionhistory").arg(QString::number(m_mockThing1Port))));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -2052,7 +2052,7 @@ void TestTimeManager::verifyRuleNotExecuted()
|
||||
{
|
||||
QNetworkAccessManager nam;
|
||||
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/actionhistory").arg(QString::number(m_mockDevice1Port))));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/actionhistory").arg(QString::number(m_mockThing1Port))));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -2065,7 +2065,7 @@ void TestTimeManager::verifyRuleNotExecuted()
|
||||
void TestTimeManager::cleanupMockHistory() {
|
||||
QNetworkAccessManager nam;
|
||||
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/clearactionhistory").arg(QString::number(m_mockDevice1Port))));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/clearactionhistory").arg(QString::number(m_mockThing1Port))));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -2103,7 +2103,7 @@ void TestTimeManager::setIntState(const int &value)
|
||||
QSignalSpy stateSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray)));
|
||||
|
||||
spy.clear();
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(mockIntStateTypeId.toString()).arg(value)));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(mockIntStateTypeId.toString()).arg(value)));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -2143,7 +2143,7 @@ void TestTimeManager::setBoolState(const bool &value)
|
||||
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
|
||||
QSignalSpy stateSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray)));
|
||||
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(mockBoolStateTypeId.toString()).arg(value)));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockThing1Port).arg(mockBoolStateTypeId.toString()).arg(value)));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
@ -2174,7 +2174,7 @@ void TestTimeManager::triggerMockEvent1()
|
||||
|
||||
QSignalSpy eventSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray)));
|
||||
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(m_mockDevice1Port).arg(mockEvent1EventTypeId.toString())));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(m_mockThing1Port).arg(mockEvent1EventTypeId.toString())));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
|
||||
@ -46,8 +46,8 @@ NymeaTestBase::NymeaTestBase(QObject *parent) :
|
||||
{
|
||||
qRegisterMetaType<QNetworkReply*>();
|
||||
qsrand(QDateTime::currentMSecsSinceEpoch());
|
||||
m_mockDevice1Port = 1337 + (qrand() % 10000);
|
||||
m_mockDevice2Port = 7331 + (qrand() % 10000);
|
||||
m_mockThing1Port = 1337 + (qrand() % 10000);
|
||||
m_mockThing2Port = 7331 + (qrand() % 10000);
|
||||
|
||||
// Important for settings
|
||||
QCoreApplication::instance()->setOrganizationName("nymea-test");
|
||||
@ -105,7 +105,7 @@ void NymeaTestBase::initTestCase()
|
||||
|
||||
response = injectAndWait("Devices.GetConfiguredDevices", {});
|
||||
foreach (const QVariant &device, response.toMap().value("params").toMap().value("devices").toList()) {
|
||||
if (device.toMap().value("deviceClassId").toUuid() == mockDeviceAutoThingClassId) {
|
||||
if (device.toMap().value("deviceClassId").toUuid() == autoMockThingClassId) {
|
||||
m_mockThingAutoId = ThingId(device.toMap().value("id").toString());
|
||||
}
|
||||
}
|
||||
@ -404,6 +404,13 @@ bool NymeaTestBase::disableNotifications()
|
||||
return true;
|
||||
}
|
||||
|
||||
void NymeaTestBase::waitForDBSync()
|
||||
{
|
||||
while (NymeaCore::instance()->logEngine()->jobsRunning()) {
|
||||
qApp->processEvents();
|
||||
}
|
||||
}
|
||||
|
||||
void NymeaTestBase::restartServer()
|
||||
{
|
||||
// Destroy and recreate the core instance...
|
||||
@ -430,8 +437,8 @@ void NymeaTestBase::createMockDevice()
|
||||
|
||||
QVariantList deviceParams;
|
||||
QVariantMap httpPortParam;
|
||||
httpPortParam.insert("paramTypeId", mockDeviceHttpportParamTypeId.toString());
|
||||
httpPortParam.insert("value", m_mockDevice1Port);
|
||||
httpPortParam.insert("paramTypeId", mockThingHttpportParamTypeId.toString());
|
||||
httpPortParam.insert("value", m_mockThing1Port);
|
||||
deviceParams.append(httpPortParam);
|
||||
params.insert("deviceParams", deviceParams);
|
||||
|
||||
|
||||
@ -121,6 +121,7 @@ protected:
|
||||
qDebug() << jsonDoc.toJson();
|
||||
}
|
||||
|
||||
void waitForDBSync();
|
||||
void restartServer();
|
||||
void clearLoggingDatabase();
|
||||
|
||||
@ -129,14 +130,14 @@ private:
|
||||
|
||||
protected:
|
||||
PluginId mockPluginId = PluginId("727a4a9a-c187-446f-aadf-f1b2220607d1");
|
||||
VendorId guhVendorId = VendorId("2062d64d-3232-433c-88bc-0d33c0ba2ba6");
|
||||
VendorId nymeaVendorId = VendorId("2062d64d-3232-433c-88bc-0d33c0ba2ba6");
|
||||
|
||||
MockTcpServer *m_mockTcpServer;
|
||||
QUuid m_clientId;
|
||||
int m_commandId;
|
||||
|
||||
int m_mockDevice1Port;
|
||||
int m_mockDevice2Port;
|
||||
int m_mockThing1Port;
|
||||
int m_mockThing2Port;
|
||||
|
||||
ThingId m_mockThingId;
|
||||
ThingId m_mockThingAutoId;
|
||||
|
||||
@ -244,7 +244,7 @@ void PluginInfoCompiler::writeParams(const ParamTypes ¶mTypes, const QString
|
||||
m_variableNames.append(variableName);
|
||||
|
||||
write(QString("ParamTypeId %1 = ParamTypeId(\"%2\");").arg(variableName).arg(paramType.id().toString()));
|
||||
m_translationStrings.insert(paramType.displayName(), QString("The name of the ParamType (DeviceClass: %1, %2Type: %3, ID: %4)").arg(thingClassName).arg(typeClass).arg(typeName).arg(paramType.id().toString()));
|
||||
m_translationStrings.insert(paramType.displayName(), QString("The name of the ParamType (ThingClass: %1, %2Type: %3, ID: %4)").arg(thingClassName).arg(typeClass).arg(typeName).arg(paramType.id().toString()));
|
||||
writeExtern(QString("extern ParamTypeId %1;").arg(variableName));
|
||||
}
|
||||
}
|
||||
@ -276,7 +276,7 @@ void PluginInfoCompiler::writeThingClass(const ThingClass &thingClass)
|
||||
m_translationStrings.insert(thingClass.displayName(), QString("The name of the ThingClass (%1)").arg(thingClass.id().toString()));
|
||||
writeExtern(QString("extern ThingClassId %1;").arg(variableName));
|
||||
|
||||
writeParams(thingClass.paramTypes(), thingClass.name(), "", "device");
|
||||
writeParams(thingClass.paramTypes(), thingClass.name(), "", "thing");
|
||||
writeParams(thingClass.settingsTypes(), thingClass.name(), "", "settings");
|
||||
writeParams(thingClass.discoveryParamTypes(), thingClass.name(), "", "discovery");
|
||||
|
||||
@ -291,12 +291,12 @@ void PluginInfoCompiler::writeStateTypes(const StateTypes &stateTypes, const QSt
|
||||
foreach (const StateType &stateType, stateTypes) {
|
||||
QString variableName = QString("%1%2StateTypeId").arg(thingClassName, stateType.name()[0].toUpper() + stateType.name().right(stateType.name().length() - 1));
|
||||
if (m_variableNames.contains(variableName)) {
|
||||
qWarning().nospace() << "Error: Duplicate name " << variableName << " for StateType " << stateType.name() << " in DeviceClass " << thingClassName << ". Skipping entry.";
|
||||
qWarning().nospace() << "Error: Duplicate name " << variableName << " for StateType " << stateType.name() << " in ThingClass " << thingClassName << ". Skipping entry.";
|
||||
return;
|
||||
}
|
||||
m_variableNames.append(variableName);
|
||||
write(QString("StateTypeId %1 = StateTypeId(\"%2\");").arg(variableName).arg(stateType.id().toString()));
|
||||
m_translationStrings.insert(stateType.displayName(), QString("The name of the StateType (%1) of DeviceClass %2").arg(stateType.id().toString()).arg(thingClassName));
|
||||
m_translationStrings.insert(stateType.displayName(), QString("The name of the StateType (%1) of ThingClass %2").arg(stateType.id().toString()).arg(thingClassName));
|
||||
writeExtern(QString("extern StateTypeId %1;").arg(variableName));
|
||||
}
|
||||
}
|
||||
@ -306,12 +306,12 @@ void PluginInfoCompiler::writeEventTypes(const EventTypes &eventTypes, const QSt
|
||||
foreach (const EventType &eventType, eventTypes) {
|
||||
QString variableName = QString("%1%2EventTypeId").arg(thingClassName, eventType.name()[0].toUpper() + eventType.name().right(eventType.name().length() - 1));
|
||||
if (m_variableNames.contains(variableName)) {
|
||||
qWarning().nospace() << "Error: Duplicate name " << variableName << " for EventType " << eventType.name() << " in DeviceClass " << thingClassName << ". Skipping entry.";
|
||||
qWarning().nospace() << "Error: Duplicate name " << variableName << " for EventType " << eventType.name() << " in ThingClass " << thingClassName << ". Skipping entry.";
|
||||
return;
|
||||
}
|
||||
m_variableNames.append(variableName);
|
||||
write(QString("EventTypeId %1 = EventTypeId(\"%2\");").arg(variableName).arg(eventType.id().toString()));
|
||||
m_translationStrings.insert(eventType.displayName(), QString("The name of the EventType (%1) of DeviceClass %2").arg(eventType.id().toString()).arg(thingClassName));
|
||||
m_translationStrings.insert(eventType.displayName(), QString("The name of the EventType (%1) of ThingClass %2").arg(eventType.id().toString()).arg(thingClassName));
|
||||
writeExtern(QString("extern EventTypeId %1;").arg(variableName));
|
||||
|
||||
writeParams(eventType.paramTypes(), thingClassName, "Event", eventType.name());
|
||||
@ -323,12 +323,12 @@ void PluginInfoCompiler::writeActionTypes(const ActionTypes &actionTypes, const
|
||||
foreach (const ActionType &actionType, actionTypes) {
|
||||
QString variableName = QString("%1%2ActionTypeId").arg(thingClassName, actionType.name()[0].toUpper() + actionType.name().right(actionType.name().length() - 1));
|
||||
if (m_variableNames.contains(variableName)) {
|
||||
qWarning().nospace() << "Error: Duplicate name " << variableName << " for ActionType " << actionType.name() << " in DeviceClass " << thingClassName << ". Skipping entry.";
|
||||
qWarning().nospace() << "Error: Duplicate name " << variableName << " for ActionType " << actionType.name() << " in ThingClass " << thingClassName << ". Skipping entry.";
|
||||
return;
|
||||
}
|
||||
m_variableNames.append(variableName);
|
||||
write(QString("ActionTypeId %1 = ActionTypeId(\"%2\");").arg(variableName).arg(actionType.id().toString()));
|
||||
m_translationStrings.insert(actionType.displayName(), QString("The name of the ActionType (%1) of DeviceClass %2").arg(actionType.id().toString()).arg(thingClassName));
|
||||
m_translationStrings.insert(actionType.displayName(), QString("The name of the ActionType (%1) of ThingClass %2").arg(actionType.id().toString()).arg(thingClassName));
|
||||
writeExtern(QString("extern ActionTypeId %1;").arg(variableName));
|
||||
|
||||
writeParams(actionType.paramTypes(), thingClassName, "Action", actionType.name());
|
||||
@ -340,12 +340,12 @@ void PluginInfoCompiler::writeBrowserItemActionTypes(const ActionTypes &actionTy
|
||||
foreach (const ActionType &actionType, actionTypes) {
|
||||
QString variableName = QString("%1%2BrowserItemActionTypeId").arg(thingClassName, actionType.name()[0].toUpper() + actionType.name().right(actionType.name().length() - 1));
|
||||
if (m_variableNames.contains(variableName)) {
|
||||
qWarning().nospace() << "Error: Duplicate name " << variableName << " for Browser Item ActionType " << actionType.name() << " in DeviceClass " << thingClassName << ". Skipping entry.";
|
||||
qWarning().nospace() << "Error: Duplicate name " << variableName << " for Browser Item ActionType " << actionType.name() << " in ThingClass " << thingClassName << ". Skipping entry.";
|
||||
return;
|
||||
}
|
||||
m_variableNames.append(variableName);
|
||||
write(QString("ActionTypeId %1 = ActionTypeId(\"%2\");").arg(variableName).arg(actionType.id().toString()));
|
||||
m_translationStrings.insert(actionType.displayName(), QString("The name of the Browser Item ActionType (%1) of DeviceClass %2").arg(actionType.id().toString()).arg(thingClassName));
|
||||
m_translationStrings.insert(actionType.displayName(), QString("The name of the Browser Item ActionType (%1) of ThingClass %2").arg(actionType.id().toString()).arg(thingClassName));
|
||||
writeExtern(QString("extern ActionTypeId %1;").arg(variableName));
|
||||
|
||||
writeParams(actionType.paramTypes(), thingClassName, "BrowserItemAction", actionType.name());
|
||||
|
||||
Reference in New Issue
Block a user