More work

This commit is contained in:
Michael Zanetti 2020-03-03 15:08:22 +01:00
parent 3e425fc55b
commit 2fbbaeda97
26 changed files with 4015 additions and 1785 deletions

View File

@ -110,7 +110,7 @@ JsonReply* ActionHandler::ExecuteAction(const QVariantMap &params, const JsonCon
ThingActionInfo *info = NymeaCore::instance()->executeAction(action); ThingActionInfo *info = NymeaCore::instance()->executeAction(action);
connect(info, &ThingActionInfo::finished, jsonReply, [info, jsonReply, locale](){ connect(info, &ThingActionInfo::finished, jsonReply, [info, jsonReply, locale](){
QVariantMap data; QVariantMap data;
data.insert("deviceError", enumValueName(info->status()).replace("ThingError", "DeviceError")); data.insert("deviceError", enumValueName(info->status()).replace("Thing", "Device"));
if (!info->displayMessage().isEmpty()) { if (!info->displayMessage().isEmpty()) {
data.insert("displayMessage", info->translatedDisplayMessage(locale)); data.insert("displayMessage", info->translatedDisplayMessage(locale));
} }

View File

@ -75,6 +75,7 @@ DeviceHandler::DeviceHandler(QObject *parent) :
registerObject<ActionType, ActionTypes>(); registerObject<ActionType, ActionTypes>();
registerObject<DeviceClass, DeviceClasses>(); registerObject<DeviceClass, DeviceClasses>();
registerObject<DeviceDescriptor, DeviceDescriptors>(); registerObject<DeviceDescriptor, DeviceDescriptors>();
registerObject<ThingDescriptor, ThingDescriptors>();
registerObject<Event>(); registerObject<Event>();
registerObject<Action>(); registerObject<Action>();
registerObject<State, States>(); registerObject<State, States>();
@ -426,12 +427,16 @@ JsonReply *DeviceHandler::GetDiscoveredDevices(const QVariantMap &params, const
ThingDiscoveryInfo *info = NymeaCore::instance()->thingManager()->discoverThings(thingClassId, discoveryParams); ThingDiscoveryInfo *info = NymeaCore::instance()->thingManager()->discoverThings(thingClassId, discoveryParams);
connect(info, &ThingDiscoveryInfo::finished, reply, [this, reply, info, locale](){ connect(info, &ThingDiscoveryInfo::finished, reply, [this, reply, info, locale](){
QVariantMap returns; 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) { if (info->status() == Device::ThingErrorNoError) {
QVariantList deviceDescriptorList; QVariantList deviceDescriptorList;
foreach (const ThingDescriptor &deviceDescriptor, info->thingDescriptors()) { foreach (const ThingDescriptor &thingDescriptor, info->thingDescriptors()) {
deviceDescriptorList.append(pack(deviceDescriptor)); QVariantMap packedDescriptor = pack(thingDescriptor).toMap();
if (packedDescriptor.contains("thingId")) {
packedDescriptor.insert("deviceId", packedDescriptor.value("thingId"));
}
deviceDescriptorList.append(packedDescriptor);
} }
returns.insert("deviceDescriptors", deviceDescriptorList); returns.insert("deviceDescriptors", deviceDescriptorList);
} }
@ -468,7 +473,7 @@ JsonReply *DeviceHandler::GetPluginConfiguration(const QVariantMap &params) cons
IntegrationPlugin *plugin = NymeaCore::instance()->thingManager()->plugins().findById(PluginId(params.value("pluginId").toString())); IntegrationPlugin *plugin = NymeaCore::instance()->thingManager()->plugins().findById(PluginId(params.value("pluginId").toString()));
if (!plugin) { 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); return createReply(returns);
} }
@ -477,7 +482,7 @@ JsonReply *DeviceHandler::GetPluginConfiguration(const QVariantMap &params) cons
paramVariantList.append(pack(param)); paramVariantList.append(pack(param));
} }
returns.insert("configuration", paramVariantList); 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); return createReply(returns);
} }
@ -487,7 +492,7 @@ JsonReply* DeviceHandler::SetPluginConfiguration(const QVariantMap &params)
PluginId pluginId = PluginId(params.value("pluginId").toString()); PluginId pluginId = PluginId(params.value("pluginId").toString());
ParamList pluginParams = unpack<ParamList>(params.value("configuration")); ParamList pluginParams = unpack<ParamList>(params.value("configuration"));
Device::ThingError result = NymeaCore::instance()->thingManager()->setPluginConfig(pluginId, pluginParams); 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); return createReply(returns);
} }
@ -509,7 +514,7 @@ JsonReply* DeviceHandler::AddConfiguredDevice(const QVariantMap &params, const J
} }
connect(info, &ThingSetupInfo::finished, jsonReply, [info, jsonReply, locale](){ connect(info, &ThingSetupInfo::finished, jsonReply, [info, jsonReply, locale](){
QVariantMap returns; 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()) { if (!info->displayMessage().isEmpty()) {
returns.insert("displayMessage", info->translatedDisplayMessage(locale)); returns.insert("displayMessage", info->translatedDisplayMessage(locale));
@ -547,7 +552,7 @@ JsonReply *DeviceHandler::PairDevice(const QVariantMap &params, const JsonContex
connect(info, &ThingPairingInfo::finished, jsonReply, [jsonReply, info, locale](){ connect(info, &ThingPairingInfo::finished, jsonReply, [jsonReply, info, locale](){
QVariantMap returns; 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()); returns.insert("pairingTransactionId", info->transactionId().toString());
if (info->status() == Device::ThingErrorNoError) { if (info->status() == Device::ThingErrorNoError) {
@ -583,7 +588,7 @@ JsonReply *DeviceHandler::ConfirmPairing(const QVariantMap &params, const JsonCo
connect(info, &ThingPairingInfo::finished, jsonReply, [info, jsonReply, locale](){ connect(info, &ThingPairingInfo::finished, jsonReply, [info, jsonReply, locale](){
QVariantMap returns; 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()) { if (!info->displayMessage().isEmpty()) {
returns.insert("displayMessage", info->translatedDisplayMessage(locale)); returns.insert("displayMessage", info->translatedDisplayMessage(locale));
} }
@ -683,7 +688,7 @@ JsonReply* DeviceHandler::RemoveConfiguredDevice(const QVariantMap &params)
if (params.contains("removePolicy")) { if (params.contains("removePolicy")) {
RuleEngine::RemovePolicy removePolicy = params.value("removePolicy").toString() == "RemovePolicyCascade" ? RuleEngine::RemovePolicyCascade : RuleEngine::RemovePolicyUpdate; RuleEngine::RemovePolicy removePolicy = params.value("removePolicy").toString() == "RemovePolicyCascade" ? RuleEngine::RemovePolicyCascade : RuleEngine::RemovePolicyUpdate;
Device::ThingError status = NymeaCore::instance()->removeConfiguredThing(thingId, removePolicy); 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); return createReply(returns);
} }
@ -833,7 +838,7 @@ JsonReply *DeviceHandler::ExecuteAction(const QVariantMap &params, const JsonCon
ThingActionInfo *info = NymeaCore::instance()->executeAction(action); ThingActionInfo *info = NymeaCore::instance()->executeAction(action);
connect(info, &ThingActionInfo::finished, jsonReply, [info, jsonReply, locale](){ connect(info, &ThingActionInfo::finished, jsonReply, [info, jsonReply, locale](){
QVariantMap data; QVariantMap data;
data.insert("deviceError", enumValueName(info->status()).replace("ThingError", "DeviceError")); data.insert("deviceError", enumValueName(info->status()).replace("Thing", "Device"));
if (!info->displayMessage().isEmpty()) { if (!info->displayMessage().isEmpty()) {
data.insert("displayMessage", info->translatedDisplayMessage(locale)); data.insert("displayMessage", info->translatedDisplayMessage(locale));
} }
@ -855,7 +860,7 @@ JsonReply *DeviceHandler::ExecuteBrowserItem(const QVariantMap &params)
BrowserActionInfo *info = NymeaCore::instance()->executeBrowserItem(action); BrowserActionInfo *info = NymeaCore::instance()->executeBrowserItem(action);
connect(info, &BrowserActionInfo::finished, jsonReply, [info, jsonReply](){ connect(info, &BrowserActionInfo::finished, jsonReply, [info, jsonReply](){
QVariantMap data; 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->setData(data);
jsonReply->finished(); jsonReply->finished();
}); });
@ -876,7 +881,7 @@ JsonReply *DeviceHandler::ExecuteBrowserItemAction(const QVariantMap &params)
BrowserItemActionInfo *info = NymeaCore::instance()->executeBrowserItemAction(browserItemAction); BrowserItemActionInfo *info = NymeaCore::instance()->executeBrowserItemAction(browserItemAction);
connect(info, &BrowserItemActionInfo::finished, jsonReply, [info, jsonReply](){ connect(info, &BrowserItemActionInfo::finished, jsonReply, [info, jsonReply](){
QVariantMap data; 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->setData(data);
jsonReply->finished(); jsonReply->finished();
}); });
@ -938,15 +943,19 @@ void DeviceHandler::deviceAddedNotification(Thing *thing)
{ {
QVariantMap params; QVariantMap params;
QVariantMap deviceMap = pack(thing).toMap(); QVariantMap deviceMap = pack(thing).toMap();
// Patch in deviceClassId
deviceMap.insert("deviceClassId", deviceMap.value("thingClassId")); deviceMap.insert("deviceClassId", deviceMap.value("thingClassId"));
params.insert("device", deviceMap); params.insert("device", deviceMap);
emit DeviceAdded(params); emit DeviceAdded(params);
} }
void DeviceHandler::deviceChangedNotification(Thing *device) void DeviceHandler::deviceChangedNotification(Thing *thing)
{ {
QVariantMap params; 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); emit DeviceChanged(params);
} }

View File

@ -190,7 +190,7 @@ private slots:
void deviceAddedNotification(Thing *thing); void deviceAddedNotification(Thing *thing);
void deviceChangedNotification(Thing *device); void deviceChangedNotification(Thing *thing);
void deviceSettingChangedNotification(const ThingId &thingId, const ParamTypeId &paramTypeId, const QVariant &value); void deviceSettingChangedNotification(const ThingId &thingId, const ParamTypeId &paramTypeId, const QVariant &value);

View File

@ -48,10 +48,9 @@
namespace nymeaserver { namespace nymeaserver {
/*! Constructs a new \l DeviceHandler with the given \a parent. */ IntegrationsHandler::IntegrationsHandler(ThingManager *thingManager, QObject *parent) :
IntegrationsHandler::IntegrationsHandler(ThingManager *deviceManager, QObject *parent) :
JsonHandler(parent), JsonHandler(parent),
m_deviceManager(deviceManager) m_thingManager(thingManager)
{ {
// Enums // Enums
registerEnum<Thing::ThingError>(); registerEnum<Thing::ThingError>();
@ -79,8 +78,8 @@ IntegrationsHandler::IntegrationsHandler(ThingManager *deviceManager, QObject *p
registerObject<State, States>(); registerObject<State, States>();
registerUncreatableObject<Thing, Things>(); registerUncreatableObject<Thing, Things>();
// Regsitering browseritem manually for now. Not sure how to deal with the // Registering browseritem manually for now. Not sure how to deal with the
// polymorphism in int (e.g MediaBrowserItem) // polymorphism in it (e.g MediaBrowserItem)
QVariantMap browserItem; QVariantMap browserItem;
browserItem.insert("id", enumValueName(String)); browserItem.insert("id", enumValueName(String));
browserItem.insert("displayName", enumValueName(String)); browserItem.insert("displayName", enumValueName(String));
@ -99,13 +98,14 @@ IntegrationsHandler::IntegrationsHandler(ThingManager *deviceManager, QObject *p
QString description; QVariantMap returns; QVariantMap params; QString description; QVariantMap returns; QVariantMap params;
description = "Returns a list of supported Vendors."; description = "Returns a list of supported Vendors.";
returns.insert("vendors", objectRef<Vendors>()); returns.insert("vendors", objectRef<Vendors>());
registerMethod("GetSupportedVendors", description, params, returns); registerMethod("GetVendors", description, params, returns);
params.clear(); returns.clear(); 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)); params.insert("o:vendorId", enumValueName(Uuid));
returns.insert("deviceClasses", objectRef<ThingClass>()); returns.insert("thingError", enumRef<Thing::ThingError>());
registerMethod("GetSupportedDevices", description, params, returns); returns.insert("o:thingClasses", objectRef<ThingClasses>());
registerMethod("GetThingClasses", description, params, returns);
params.clear(); returns.clear(); params.clear(); returns.clear();
description = "Returns a list of loaded plugins."; description = "Returns a list of loaded plugins.";
@ -115,7 +115,7 @@ IntegrationsHandler::IntegrationsHandler(ThingManager *deviceManager, QObject *p
params.clear(); returns.clear(); params.clear(); returns.clear();
description = "Get a plugin's params."; description = "Get a plugin's params.";
params.insert("pluginId", enumValueName(Uuid)); params.insert("pluginId", enumValueName(Uuid));
returns.insert("deviceError", enumRef<Thing::ThingError>()); returns.insert("thingError", enumRef<Thing::ThingError>());
returns.insert("o:configuration", objectRef<ParamList>()); returns.insert("o:configuration", objectRef<ParamList>());
registerMethod("GetPluginConfiguration", description, params, returns); registerMethod("GetPluginConfiguration", description, params, returns);
@ -123,55 +123,56 @@ IntegrationsHandler::IntegrationsHandler(ThingManager *deviceManager, QObject *p
description = "Set a plugin's params."; description = "Set a plugin's params.";
params.insert("pluginId", enumValueName(Uuid)); params.insert("pluginId", enumValueName(Uuid));
params.insert("configuration", objectRef<ParamList>()); params.insert("configuration", objectRef<ParamList>());
returns.insert("deviceError", enumRef<Thing::ThingError>()); returns.insert("thingError", enumRef<Thing::ThingError>());
registerMethod("SetPluginConfiguration", description, params, returns); registerMethod("SetPluginConfiguration", description, params, returns);
params.clear(); returns.clear(); params.clear(); returns.clear();
description = "Add a configured device with a setupMethod of SetupMethodJustAdd. " description = "Add a new thing to the system. "
"For devices with a setupMethod different than SetupMethodJustAdd, use PairDevice. " "Only things with a setupMethod of SetupMethodJustAdd can be added this way. "
"Devices with CreateMethodJustAdd require all parameters to be supplied here. " "For things with a setupMethod different than SetupMethodJustAdd, use PairThing. "
"Devices with CreateMethodDiscovery require the use of a deviceDescriptorId. For discovered " "Things with CreateMethodJustAdd require all parameters to be supplied here. "
"devices params are not required and will be taken from the DeviceDescriptor, however, they " "Things with CreateMethodDiscovery require the use of a thingDescriptorId. For discovered "
"may be overridden by supplying deviceParams."; "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("thingClassId", enumValueName(Uuid));
params.insert("name", enumValueName(String)); params.insert("name", enumValueName(String));
params.insert("o:deviceDescriptorId", enumValueName(Uuid)); params.insert("o:thingDescriptorId", enumValueName(Uuid));
params.insert("o:deviceParams", objectRef<ParamList>()); params.insert("o:thingParams", objectRef<ParamList>());
returns.insert("deviceError", enumRef<Thing::ThingError>()); returns.insert("thingError", enumRef<Thing::ThingError>());
returns.insert("o:deviceId", enumValueName(Uuid)); returns.insert("o:thingId", enumValueName(Uuid));
returns.insert("o:displayMessage", enumValueName(String)); returns.insert("o:displayMessage", enumValueName(String));
registerMethod("AddConfiguredDevice", description, params, returns); registerMethod("AddThing", description, params, returns);
params.clear(); returns.clear(); params.clear(); returns.clear();
description = "Pair a device. " description = "Pair a new thing. "
"Use this to set up or reconfigure devices for DeviceClasses with a setupMethod different than SetupMethodJustAdd. " "Use this to set up or reconfigure things for ThingClasses 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 " "Depending on the CreateMethod and whether a new thing is set up or an existing one is reconfigured, different parameters "
"are required:\n" "are required:\n"
"CreateMethodJustAdd takes the thingClassId and the parameters you want to have with that device.\n" "CreateMethodJustAdd takes the thingClassId and the parameters you want to have with that thing.\n"
"CreateMethodDiscovery requires the use of a deviceDescriptorId, previously obtained with DiscoverDevices. Optionally, " "CreateMethodDiscovery requires the use of a thingDescriptorId, previously obtained with DiscoverThings. Optionally, "
"parameters can be overridden with the give deviceParams.\n" "parameters can be overridden with the give thingParams.\n"
"If an existing device should be reconfigured, the deviceId of said device should be given additionally.\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 " "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, " "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 " "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. For SetupMethodPushButton, the displayMessage " "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 " "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 " "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" "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 " "Once the login procedure has completed, the application shall proceed with ConfirmPairing, providing the results of the pairing "
"procedure."; "procedure.";
params.insert("o:ThingClassId", enumValueName(Uuid)); params.insert("o:thingClassId", enumValueName(Uuid));
params.insert("o:name", enumValueName(String)); params.insert("o:name", enumValueName(String));
params.insert("o:deviceDescriptorId", enumValueName(Uuid)); params.insert("o:thingDescriptorId", enumValueName(Uuid));
params.insert("o:deviceParams", objectRef<ParamList>()); params.insert("o:thingParams", objectRef<ParamList>());
params.insert("o:deviceId", enumValueName(Uuid)); params.insert("o:thingId", enumValueName(Uuid));
returns.insert("deviceError", enumRef<Thing::ThingError>()); returns.insert("thingError", enumRef<Thing::ThingError>());
returns.insert("o:setupMethod", enumRef<ThingClass::SetupMethod>()); returns.insert("o:setupMethod", enumRef<ThingClass::SetupMethod>());
returns.insert("o:pairingTransactionId", enumValueName(Uuid)); returns.insert("o:pairingTransactionId", enumValueName(Uuid));
returns.insert("o:displayMessage", enumValueName(String)); returns.insert("o:displayMessage", enumValueName(String));
returns.insert("o:oAuthUrl", enumValueName(String)); returns.insert("o:oAuthUrl", enumValueName(String));
returns.insert("o:pin", enumValueName(String)); returns.insert("o:pin", enumValueName(String));
registerMethod("PairDevice", description, params, returns); registerMethod("PairThing", description, params, returns);
params.clear(); returns.clear(); params.clear(); returns.clear();
description = "Confirm an ongoing pairing. For SetupMethodUserAndPassword, provide the username in the \"username\" field " 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("pairingTransactionId", enumValueName(Uuid));
params.insert("o:username", enumValueName(String)); params.insert("o:username", enumValueName(String));
params.insert("o:secret", 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:displayMessage", enumValueName(String));
returns.insert("o:deviceId", enumValueName(Uuid)); returns.insert("o:thingId", enumValueName(Uuid));
registerMethod("ConfirmPairing", description, params, returns); registerMethod("ConfirmPairing", description, params, returns);
// FIXME: Add thingError!!!
params.clear(); returns.clear(); params.clear(); returns.clear();
description = "Returns a list of configured devices, optionally filtered by deviceId."; description = "Returns a list of configured things, optionally filtered by thingId.";
params.insert("o:deviceId", enumValueName(Uuid)); params.insert("o:thingId", enumValueName(Uuid));
returns.insert("devices", objectRef<Things>()); returns.insert("o:things", objectRef<Things>());
registerMethod("GetConfiguredDevices", description, params, returns); returns.insert("thingError", enumRef<Thing::ThingError>());
registerMethod("GetThings", description, params, returns);
params.clear(); returns.clear(); params.clear(); returns.clear();
description = "Performs a device discovery and returns the results. This function may take a while to return. " description = "Performs a thing discovery for things of the given thingClassId and returns the results. "
"Note that this method will include all the found devices, that is, including devices that may " "This function may take a while to return. Note that this method will include all the found "
"already have been added. Those devices will have deviceId set to the device id of the already " "things, that is, including things that may already have been added. Those things will have "
"added device. Such results may be used to reconfigure existing devices and might be filtered " "thingId set to the id of the already added thing. Such results may be used to reconfigure "
"in cases where only unknown devices are of interest."; "existing things and might be filtered in cases where only unknown things are of interest.";
params.insert("thingClassId", enumValueName(Uuid)); params.insert("thingClassId", enumValueName(Uuid));
params.insert("o:discoveryParams", objectRef<ParamList>()); 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:displayMessage", enumValueName(String));
returns.insert("o:deviceDescriptors", objectRef<ThingDescriptors>()); returns.insert("o:thingDescriptors", objectRef<ThingDescriptors>());
registerMethod("GetDiscoveredDevices", description, params, returns); registerMethod("DiscoverThings", description, params, returns);
params.clear(); returns.clear(); params.clear(); returns.clear();
description = "Reconfigure a device. This comes down to removing and recreating a device with new parameters " description = "Reconfigure a thing. This comes down to removing and recreating a thing with new parameters "
"but keeping its device id the same (and with that keeping rules, tags etc). For devices with " "but keeping its thing id the same (and with that keeping rules, tags etc). For things with "
"create method CreateMethodDiscovery, a discovery (GetDiscoveredDevices) shall be performed first " "create method CreateMethodDiscovery, a discovery (DiscoverThings) shall be performed first "
"and this method is to be called with a deviceDescriptorId of the re-discovered device instead of " "and this method is to be called with a thingDescriptorId of the re-discovered thing instead of "
"the deviceId directly. Device parameters will be taken from the discovery, but can be overridden " "the thingId directly. Thing parameters will be taken from the discovery, but can be overridden "
"individually here by providing them in the deviceParams parameter. Only writable parameters can " "individually here by providing them in the thingParams parameter. Only writable parameters can "
"be changed."; "be changed.";
params.insert("o:deviceId", enumValueName(Uuid)); params.insert("o:thingId", enumValueName(Uuid));
params.insert("o:deviceDescriptorId", enumValueName(Uuid)); params.insert("o:thingDescriptorId", enumValueName(Uuid));
params.insert("o:deviceParams", objectRef<ParamList>()); params.insert("o:thingParams", objectRef<ParamList>());
returns.insert("deviceError", enumRef<Thing::ThingError>()); returns.insert("thingError", enumRef<Thing::ThingError>());
returns.insert("o:displayMessage", enumValueName(String)); returns.insert("o:displayMessage", enumValueName(String));
registerMethod("ReconfigureDevice", description, params, returns); registerMethod("ReconfigureThing", description, params, returns);
params.clear(); returns.clear(); params.clear(); returns.clear();
description = "Edit the name of a device. This method does not change the " description = "Edit the name of a thing.";
"configuration of the device."; params.insert("thingId", enumValueName(Uuid));
params.insert("deviceId", enumValueName(Uuid));
params.insert("name", enumValueName(String)); params.insert("name", enumValueName(String));
returns.insert("deviceError", enumRef<Thing::ThingError>()); returns.insert("thingError", enumRef<Thing::ThingError>());
registerMethod("EditDevice", description, params, returns); registerMethod("EditThing", description, params, returns);
params.clear(); returns.clear(); params.clear(); returns.clear();
description = "Change the settings of a device."; description = "Change the settings of a thing.";
params.insert("deviceId", enumValueName(Uuid)); params.insert("thingId", enumValueName(Uuid));
params.insert("settings", objectRef<ParamList>()); params.insert("settings", objectRef<ParamList>());
returns.insert("deviceError", enumRef<Thing::ThingError>()); returns.insert("thingError", enumRef<Thing::ThingError>());
registerMethod("SetDeviceSettings", description, params, returns); registerMethod("SetThingSettings", description, params, returns);
params.clear(); returns.clear(); params.clear(); returns.clear();
description = "Remove a device from the system."; description = "Remove a thing from the system.";
params.insert("deviceId", enumValueName(Uuid)); params.insert("thingId", enumValueName(Uuid));
params.insert("o:removePolicy", enumRef<RuleEngine::RemovePolicy>()); params.insert("o:removePolicy", enumRef<RuleEngine::RemovePolicy>());
QVariantMap policy; QVariantMap policy;
policy.insert("ruleId", enumValueName(Uuid)); policy.insert("ruleId", enumValueName(Uuid));
@ -246,9 +246,9 @@ IntegrationsHandler::IntegrationsHandler(ThingManager *deviceManager, QObject *p
QVariantList removePolicyList; QVariantList removePolicyList;
removePolicyList.append(policy); removePolicyList.append(policy);
params.insert("o:removePolicyList", removePolicyList); params.insert("o:removePolicyList", removePolicyList);
returns.insert("deviceError", enumRef<Thing::ThingError>()); returns.insert("thingError", enumRef<Thing::ThingError>());
returns.insert("o:ruleIds", QVariantList() << enumValueName(Uuid)); returns.insert("o:ruleIds", QVariantList() << enumValueName(Uuid));
registerMethod("RemoveConfiguredDevice", description, params, returns); registerMethod("RemoveThing", description, params, returns);
params.clear(); returns.clear(); params.clear(); returns.clear();
description = "Get event types for a specified thingClassId."; description = "Get event types for a specified thingClassId.";
@ -269,90 +269,95 @@ IntegrationsHandler::IntegrationsHandler(ThingManager *deviceManager, QObject *p
registerMethod("GetStateTypes", description, params, returns); registerMethod("GetStateTypes", description, params, returns);
params.clear(); returns.clear(); params.clear(); returns.clear();
description = "Get the value of the given device and the given stateType"; description = "Get the value of the given thing and the given stateType";
params.insert("deviceId", enumValueName(Uuid)); params.insert("thingId", enumValueName(Uuid));
params.insert("stateTypeId", 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)); returns.insert("o:value", enumValueName(Variant));
registerMethod("GetStateValue", description, params, returns); registerMethod("GetStateValue", description, params, returns);
params.clear(); returns.clear(); params.clear(); returns.clear();
description = "Get all the state values of the given device."; description = "Get all the state values of the given thing.";
params.insert("deviceId", enumValueName(Uuid)); params.insert("thingId", enumValueName(Uuid));
returns.insert("deviceError", enumRef<Thing::ThingError>()); returns.insert("thingError", enumRef<Thing::ThingError>());
returns.insert("o:values", objectRef<States>()); returns.insert("o:values", objectRef<States>());
registerMethod("GetStateValues", description, params, returns); registerMethod("GetStateValues", description, params, returns);
params.clear(); returns.clear(); 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."; description = "Browse a thing. "
params.insert("deviceId", enumValueName(Uuid)); "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)); params.insert("o:itemId", enumValueName(String));
returns.insert("deviceError", enumRef<Thing::ThingError>()); returns.insert("thingError", enumRef<Thing::ThingError>());
returns.insert("items", QVariantList() << objectRef("BrowserItem")); returns.insert("items", QVariantList() << objectRef("BrowserItem"));
registerMethod("BrowseDevice", description, params, returns); registerMethod("BrowseThing", description, params, returns);
params.clear(); returns.clear(); 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."; description = "Get a single item from the browser. "
params.insert("deviceId", enumValueName(Uuid)); "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)); params.insert("o:itemId", enumValueName(String));
returns.insert("deviceError", enumRef<Thing::ThingError>()); returns.insert("thingError", enumRef<Thing::ThingError>());
returns.insert("o:item", objectRef("BrowserItem")); returns.insert("o:item", objectRef("BrowserItem"));
registerMethod("GetBrowserItem", description, params, returns); registerMethod("GetBrowserItem", description, params, returns);
params.clear(); returns.clear(); params.clear(); returns.clear();
description = "Execute a single action."; description = "Execute a single action.";
params.insert("actionTypeId", enumValueName(Uuid)); params.insert("actionTypeId", enumValueName(Uuid));
params.insert("deviceId", enumValueName(Uuid)); params.insert("thingId", enumValueName(Uuid));
params.insert("o:params", objectRef<ParamList>()); params.insert("o:params", objectRef<ParamList>());
returns.insert("deviceError", enumRef<Thing::ThingError>()); returns.insert("thingError", enumRef<Thing::ThingError>());
returns.insert("o:displayMessage", enumValueName(String)); returns.insert("o:displayMessage", enumValueName(String));
registerMethod("ExecuteAction", description, params, returns); registerMethod("ExecuteAction", description, params, returns);
params.clear(); returns.clear(); params.clear(); returns.clear();
description = "Execute the item identified by itemId on the given device."; description = "Execute the item identified by itemId on the given thing.";
params.insert("deviceId", enumValueName(Uuid)); params.insert("thingId", enumValueName(Uuid));
params.insert("itemId", enumValueName(String)); params.insert("itemId", enumValueName(String));
returns.insert("deviceError", enumRef<Thing::ThingError>()); returns.insert("thingError", enumRef<Thing::ThingError>());
registerMethod("ExecuteBrowserItem", description, params, returns); registerMethod("ExecuteBrowserItem", description, params, returns);
params.clear(); returns.clear(); params.clear(); returns.clear();
description = "Execute the action for the browser item identified by actionTypeId and the itemId on the given device."; description = "Execute the action for the browser item identified by actionTypeId and the itemId on the given thing.";
params.insert("deviceId", enumValueName(Uuid)); params.insert("thingId", enumValueName(Uuid));
params.insert("itemId", enumValueName(String)); params.insert("itemId", enumValueName(String));
params.insert("actionTypeId", enumValueName(Uuid)); params.insert("actionTypeId", enumValueName(Uuid));
params.insert("o:params", objectRef<ParamList>()); params.insert("o:params", objectRef<ParamList>());
returns.insert("deviceError", enumRef<Thing::ThingError>()); returns.insert("thingError", enumRef<Thing::ThingError>());
registerMethod("ExecuteBrowserItemAction", description, params, returns); registerMethod("ExecuteBrowserItemAction", description, params, returns);
// Notifications // Notifications
params.clear(); returns.clear(); params.clear(); returns.clear();
description = "Emitted whenever a State of a device changes."; description = "Emitted whenever a state of a thing changes.";
params.insert("deviceId", enumValueName(Uuid)); params.insert("thingId", enumValueName(Uuid));
params.insert("stateTypeId", enumValueName(Uuid)); params.insert("stateTypeId", enumValueName(Uuid));
params.insert("value", enumValueName(Variant)); params.insert("value", enumValueName(Variant));
registerNotification("StateChanged", description, params); registerNotification("StateChanged", description, params);
params.clear(); returns.clear(); params.clear(); returns.clear();
description = "Emitted whenever a Device was removed."; description = "Emitted whenever a thing was removed.";
params.insert("deviceId", enumValueName(Uuid)); params.insert("thingId", enumValueName(Uuid));
registerNotification("DeviceRemoved", description, params); registerNotification("ThingRemoved", description, params);
params.clear(); returns.clear(); params.clear(); returns.clear();
description = "Emitted whenever a Device was added."; description = "Emitted whenever a thing was added.";
params.insert("device", objectRef<Thing>()); params.insert("thing", objectRef<Thing>());
registerNotification("DeviceAdded", description, params); registerNotification("ThingAdded", description, params);
params.clear(); returns.clear(); params.clear(); returns.clear();
description = "Emitted whenever the params or name of a Device are changed (by EditDevice or ReconfigureDevice)."; description = "Emitted whenever the params or name of a thing are changed (by EditThing or ReconfigureThing).";
params.insert("device", objectRef<Thing>()); params.insert("thing", objectRef<Thing>());
registerNotification("DeviceChanged", description, params); registerNotification("ThingChanged", description, params);
params.clear(); returns.clear(); params.clear(); returns.clear();
description = "Emitted whenever the setting of a Device is changed."; description = "Emitted whenever the setting of a thing is changed.";
params.insert("deviceId", enumValueName(Uuid)); params.insert("thingId", enumValueName(Uuid));
params.insert("paramTypeId", enumValueName(Uuid)); params.insert("paramTypeId", enumValueName(Uuid));
params.insert("value", enumValueName(Variant)); params.insert("value", enumValueName(Variant));
registerNotification("DeviceSettingChanged", description, params); registerNotification("ThingSettingChanged", description, params);
params.clear(); returns.clear(); params.clear(); returns.clear();
description = "Emitted whenever a plugin's configuration is changed."; 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::pluginConfigChanged, this, &IntegrationsHandler::pluginConfigChanged);
connect(NymeaCore::instance(), &NymeaCore::thingStateChanged, this, &IntegrationsHandler::thingStateChanged); connect(NymeaCore::instance(), &NymeaCore::thingStateChanged, this, &IntegrationsHandler::thingStateChanged);
connect(NymeaCore::instance(), &NymeaCore::thingRemoved, this, &IntegrationsHandler::thingRemovedNotification); connect(NymeaCore::instance(), &NymeaCore::thingRemoved, this, &IntegrationsHandler::thingRemovedNotification);
connect(NymeaCore::instance(), &NymeaCore::thingAdded, this, &IntegrationsHandler::deviceAddedNotification); connect(NymeaCore::instance(), &NymeaCore::thingAdded, this, &IntegrationsHandler::thingAddedNotification);
connect(NymeaCore::instance(), &NymeaCore::thingChanged, this, &IntegrationsHandler::deviceChangedNotification); connect(NymeaCore::instance(), &NymeaCore::thingChanged, this, &IntegrationsHandler::thingChangedNotification);
connect(NymeaCore::instance(), &NymeaCore::thingSettingChanged, this, &IntegrationsHandler::deviceSettingChangedNotification); connect(NymeaCore::instance(), &NymeaCore::thingSettingChanged, this, &IntegrationsHandler::thingSettingChangedNotification);
} }
/*! Returns the name of the \l{IntegrationsHandler}. In this case \b Devices.*/
QString IntegrationsHandler::name() const QString IntegrationsHandler::name() const
{ {
return "Integrations"; return "Integrations";
} }
JsonReply* IntegrationsHandler::GetSupportedVendors(const QVariantMap &params) const JsonReply* IntegrationsHandler::GetVendors(const QVariantMap &params, const JsonContext &context) const
{ {
QLocale locale = params.value("locale").toLocale(); Q_UNUSED(params)
QVariantList vendors; QVariantList vendors;
foreach (const Vendor &vendor, NymeaCore::instance()->thingManager()->supportedVendors()) { 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)); vendors.append(pack(translatedVendor));
} }
@ -399,42 +402,54 @@ JsonReply* IntegrationsHandler::GetSupportedVendors(const QVariantMap &params) c
return createReply(returns); return createReply(returns);
} }
JsonReply* IntegrationsHandler::GetSupportedDevices(const QVariantMap &params) const JsonReply* IntegrationsHandler::GetThingClasses(const QVariantMap &params, const JsonContext &context) const
{ {
QLocale locale = params.value("locale").toLocale();
VendorId vendorId = VendorId(params.value("vendorId").toString());
QVariantMap returns; QVariantMap returns;
QVariantList deviceClasses; QVariantList thingClasses;
foreach (const ThingClass &deviceClass, NymeaCore::instance()->thingManager()->supportedThings(vendorId)) {
ThingClass translatedDeviceClass = NymeaCore::instance()->thingManager()->translateThingClass(deviceClass, locale); if (params.contains("vendorId")) {
deviceClasses.append(pack(translatedDeviceClass)); 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); return createReply(returns);
} }
JsonReply *IntegrationsHandler::GetDiscoveredDevices(const QVariantMap &params) const JsonReply *IntegrationsHandler::DiscoverThings(const QVariantMap &params, const JsonContext &context) const
{ {
QLocale locale = params.value("locale").toLocale(); QLocale locale = context.locale();
QVariantMap returns; QVariantMap returns;
ThingClassId thingClassId = ThingClassId(params.value("thingClassId").toString()); ThingClassId thingClassId = ThingClassId(params.value("thingClassId").toString());
ParamList discoveryParams = unpack<ParamList>(params.value("discoveryParams")); ParamList discoveryParams = unpack<ParamList>(params.value("discoveryParams"));
JsonReply *reply = createAsyncReply("GetDiscoveredDevices"); JsonReply *reply = createAsyncReply("DiscoverThings");
ThingDiscoveryInfo *info = NymeaCore::instance()->thingManager()->discoverThings(thingClassId, discoveryParams); ThingDiscoveryInfo *info = NymeaCore::instance()->thingManager()->discoverThings(thingClassId, discoveryParams);
connect(info, &ThingDiscoveryInfo::finished, reply, [this, reply, info, locale](){ connect(info, &ThingDiscoveryInfo::finished, reply, [this, reply, info, locale](){
QVariantMap returns; QVariantMap returns;
returns.insert("deviceError", enumValueName<Thing::ThingError>(info->status())); returns.insert("thingError", enumValueName<Thing::ThingError>(info->status()));
if (info->status() == Thing::ThingErrorNoError) { if (info->status() == Thing::ThingErrorNoError) {
QVariantList deviceDescriptorList; QVariantList thingDescriptorList;
foreach (const ThingDescriptor &deviceDescriptor, info->thingDescriptors()) { foreach (const ThingDescriptor &thingDescriptor, info->thingDescriptors()) {
deviceDescriptorList.append(pack(deviceDescriptor)); thingDescriptorList.append(pack(thingDescriptor));
} }
returns.insert("deviceDescriptors", deviceDescriptorList); returns.insert("thingDescriptors", thingDescriptorList);
} }
if (!info->displayMessage().isEmpty()) { if (!info->displayMessage().isEmpty()) {
@ -448,14 +463,13 @@ JsonReply *IntegrationsHandler::GetDiscoveredDevices(const QVariantMap &params)
return reply; return reply;
} }
JsonReply* IntegrationsHandler::GetPlugins(const QVariantMap &params) const JsonReply* IntegrationsHandler::GetPlugins(const QVariantMap &params, const JsonContext &context) const
{ {
QLocale locale = params.value("locale").toLocale(); Q_UNUSED(params)
QVariantList plugins; QVariantList plugins;
foreach (IntegrationPlugin* plugin, NymeaCore::instance()->thingManager()->plugins()) { foreach (IntegrationPlugin* plugin, NymeaCore::instance()->thingManager()->plugins()) {
QVariantMap packedPlugin = pack(*plugin).toMap(); 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); plugins.append(packedPlugin);
} }
@ -470,7 +484,7 @@ JsonReply *IntegrationsHandler::GetPluginConfiguration(const QVariantMap &params
IntegrationPlugin *plugin = NymeaCore::instance()->thingManager()->plugins().findById(PluginId(params.value("pluginId").toString())); IntegrationPlugin *plugin = NymeaCore::instance()->thingManager()->plugins().findById(PluginId(params.value("pluginId").toString()));
if (!plugin) { if (!plugin) {
returns.insert("deviceError", enumValueName<Thing::ThingError>(Thing::ThingErrorPluginNotFound)); returns.insert("thingError", enumValueName<Thing::ThingError>(Thing::ThingErrorPluginNotFound));
return createReply(returns); return createReply(returns);
} }
@ -479,7 +493,7 @@ JsonReply *IntegrationsHandler::GetPluginConfiguration(const QVariantMap &params
paramVariantList.append(pack(param)); paramVariantList.append(pack(param));
} }
returns.insert("configuration", paramVariantList); returns.insert("configuration", paramVariantList);
returns.insert("deviceError", enumValueName<Thing::ThingError>(Thing::ThingErrorNoError)); returns.insert("thingError", enumValueName<Thing::ThingError>(Thing::ThingErrorNoError));
return createReply(returns); return createReply(returns);
} }
@ -489,36 +503,36 @@ JsonReply* IntegrationsHandler::SetPluginConfiguration(const QVariantMap &params
PluginId pluginId = PluginId(params.value("pluginId").toString()); PluginId pluginId = PluginId(params.value("pluginId").toString());
ParamList pluginParams = unpack<ParamList>(params.value("configuration")); ParamList pluginParams = unpack<ParamList>(params.value("configuration"));
Thing::ThingError result = NymeaCore::instance()->thingManager()->setPluginConfig(pluginId, pluginParams); 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); return createReply(returns);
} }
JsonReply* IntegrationsHandler::AddConfiguredDevice(const QVariantMap &params) JsonReply* IntegrationsHandler::AddThing(const QVariantMap &params, const JsonContext &context)
{ {
ThingClassId ThingClassId(params.value("thingClassId").toString()); ThingClassId ThingClassId(params.value("thingClassId").toString());
QString deviceName = params.value("name").toString(); QString thingName = params.value("name").toString();
ParamList deviceParams = unpack<ParamList>(params.value("deviceParams")); ParamList thingParams = unpack<ParamList>(params.value("thingParams"));
ThingDescriptorId deviceDescriptorId(params.value("deviceDescriptorId").toString()); ThingDescriptorId thingDescriptorId(params.value("thingDescriptorId").toString());
QLocale locale = params.value("locale").toLocale(); QLocale locale = context.locale();
JsonReply *jsonReply = createAsyncReply("AddConfiguredDevice"); JsonReply *jsonReply = createAsyncReply("AddThing");
ThingSetupInfo *info; ThingSetupInfo *info;
if (deviceDescriptorId.isNull()) { if (thingDescriptorId.isNull()) {
info = NymeaCore::instance()->thingManager()->addConfiguredThing(ThingClassId, deviceParams, deviceName); info = NymeaCore::instance()->thingManager()->addConfiguredThing(ThingClassId, thingParams, thingName);
} else { } 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](){ connect(info, &ThingSetupInfo::finished, jsonReply, [info, jsonReply, locale](){
QVariantMap returns; QVariantMap returns;
returns.insert("deviceError", enumValueName<Thing::ThingError>(info->status())); returns.insert("thingError", enumValueName<Thing::ThingError>(info->status()));
if (!info->displayMessage().isEmpty()) { if (!info->displayMessage().isEmpty()) {
returns.insert("displayMessage", info->translatedDisplayMessage(locale)); returns.insert("displayMessage", info->translatedDisplayMessage(locale));
} }
if(info->status() == Thing::ThingErrorNoError) { if(info->status() == Thing::ThingErrorNoError) {
returns.insert("deviceId", info->thing()->id()); returns.insert("thingId", info->thing()->id());
} }
jsonReply->setData(returns); jsonReply->setData(returns);
jsonReply->finished(); jsonReply->finished();
@ -527,29 +541,29 @@ JsonReply* IntegrationsHandler::AddConfiguredDevice(const QVariantMap &params)
return jsonReply; return jsonReply;
} }
JsonReply *IntegrationsHandler::PairDevice(const QVariantMap &params) JsonReply *IntegrationsHandler::PairThing(const QVariantMap &params, const JsonContext &context)
{ {
QString deviceName = params.value("name").toString(); QString thingName = params.value("name").toString();
ParamList deviceParams = unpack<ParamList>(params.value("deviceParams")); ParamList thingParams = unpack<ParamList>(params.value("thingParams"));
QLocale locale = params.value("locale").toLocale(); QLocale locale = context.locale();
ThingPairingInfo *info; ThingPairingInfo *info;
if (params.contains("deviceDescriptorId")) { if (params.contains("thingDescriptorId")) {
ThingDescriptorId deviceDescriptorId = ThingDescriptorId(params.value("deviceDescriptorId").toString()); ThingDescriptorId thingDescriptorId = ThingDescriptorId(params.value("thingDescriptorId").toString());
info = NymeaCore::instance()->thingManager()->pairThing(deviceDescriptorId, deviceParams, deviceName); info = NymeaCore::instance()->thingManager()->pairThing(thingDescriptorId, thingParams, thingName);
} else if (params.contains("deviceId")) { } else if (params.contains("thingId")) {
ThingId deviceId = ThingId(params.value("deviceId").toString()); ThingId thingId = ThingId(params.value("thingId").toString());
info = NymeaCore::instance()->thingManager()->pairThing(deviceId, deviceParams, deviceName); info = NymeaCore::instance()->thingManager()->pairThing(thingId, thingParams, thingName);
} else { } else {
ThingClassId thingClassId(params.value("thingClassId").toString()); 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](){ connect(info, &ThingPairingInfo::finished, jsonReply, [jsonReply, info, locale](){
QVariantMap returns; QVariantMap returns;
returns.insert("deviceError", enumValueName<Thing::ThingError>(info->status())); returns.insert("thingError", enumValueName<Thing::ThingError>(info->status()));
returns.insert("pairingTransactionId", info->transactionId().toString()); returns.insert("pairingTransactionId", info->transactionId().toString());
if (info->status() == Thing::ThingErrorNoError) { if (info->status() == Thing::ThingErrorNoError) {
@ -585,12 +599,12 @@ JsonReply *IntegrationsHandler::ConfirmPairing(const QVariantMap &params)
connect(info, &ThingPairingInfo::finished, jsonReply, [info, jsonReply, locale](){ connect(info, &ThingPairingInfo::finished, jsonReply, [info, jsonReply, locale](){
QVariantMap returns; QVariantMap returns;
returns.insert("deviceError", enumValueName<Thing::ThingError>(info->status())); returns.insert("thingError", enumValueName<Thing::ThingError>(info->status()));
if (!info->displayMessage().isEmpty()) { if (!info->displayMessage().isEmpty()) {
returns.insert("displayMessage", info->translatedDisplayMessage(locale)); returns.insert("displayMessage", info->translatedDisplayMessage(locale));
} }
if (info->status() == Thing::ThingErrorNoError) { if (info->status() == Thing::ThingErrorNoError) {
returns.insert("deviceId", info->thingId().toString()); returns.insert("thingId", info->thingId().toString());
} }
jsonReply->setData(returns); jsonReply->setData(returns);
jsonReply->finished(); jsonReply->finished();
@ -599,52 +613,63 @@ JsonReply *IntegrationsHandler::ConfirmPairing(const QVariantMap &params)
return jsonReply; return jsonReply;
} }
JsonReply* IntegrationsHandler::GetConfiguredDevices(const QVariantMap &params) const JsonReply* IntegrationsHandler::GetThings(const QVariantMap &params, const JsonContext &context) const
{ {
QVariantMap returns; QVariantMap returns;
QVariantList configuredDeviceList; QVariantList things;
if (params.contains("deviceId")) { if (params.contains("thingId")) {
Thing *device = NymeaCore::instance()->thingManager()->findConfiguredThing(ThingId(params.value("deviceId").toString())); Thing *thing = NymeaCore::instance()->thingManager()->findConfiguredThing(ThingId(params.value("thingId").toString()));
if (!device) { if (!thing) {
returns.insert("deviceError", enumValueName<Thing::ThingError>(Thing::ThingErrorThingNotFound)); returns.insert("thingError", enumValueName<Thing::ThingError>(Thing::ThingErrorThingNotFound));
return createReply(returns); return createReply(returns);
} else { } 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 { } else {
foreach (Thing *device, NymeaCore::instance()->thingManager()->configuredThings()) { foreach (Thing *thing, NymeaCore::instance()->thingManager()->configuredThings()) {
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);
} }
} }
returns.insert("devices", configuredDeviceList); returns.insert("thingError", enumValueName<Thing::ThingError>(Thing::ThingErrorNoError));
returns.insert("things", things);
return createReply(returns); return createReply(returns);
} }
JsonReply *IntegrationsHandler::ReconfigureDevice(const QVariantMap &params) JsonReply *IntegrationsHandler::ReconfigureThing(const QVariantMap &params, const JsonContext &context)
{ {
ThingId thingId = ThingId(params.value("deviceId").toString()); ThingId thingId = ThingId(params.value("thingId").toString());
ParamList deviceParams = unpack<ParamList>(params.value("deviceParams")); ParamList thingParams = unpack<ParamList>(params.value("thingParams"));
ThingDescriptorId deviceDescriptorId(params.value("deviceDescriptorId").toString()); ThingDescriptorId thingDescriptorId(params.value("thingDescriptorId").toString());
QLocale locale = params.value("locale").toLocale(); QLocale locale = context.locale();
JsonReply *jsonReply = createAsyncReply("ReconfigureDevice"); JsonReply *jsonReply = createAsyncReply("ReconfigureThing");
ThingSetupInfo *info; ThingSetupInfo *info;
if (!deviceDescriptorId.isNull()) { if (!thingDescriptorId.isNull()) {
info = NymeaCore::instance()->thingManager()->reconfigureThing(deviceDescriptorId, deviceParams); info = NymeaCore::instance()->thingManager()->reconfigureThing(thingDescriptorId, thingParams);
} else if (!thingId.isNull()){ } else if (!thingId.isNull()){
info = NymeaCore::instance()->thingManager()->reconfigureThing(thingId, deviceParams); info = NymeaCore::instance()->thingManager()->reconfigureThing(thingId, thingParams);
} else { } else {
qCWarning(dcJsonRpc()) << "Either deviceId or deviceDescriptorId are required"; qCWarning(dcJsonRpc()) << "Either thingId or thingDescriptorId are required";
QVariantMap ret; QVariantMap ret;
ret.insert("deviceError", enumValueName(Thing::ThingErrorMissingParameter)); ret.insert("thingError", enumValueName(Thing::ThingErrorMissingParameter));
return createReply(ret); return createReply(ret);
} }
connect(info, &ThingSetupInfo::finished, jsonReply, [info, jsonReply, locale](){ connect(info, &ThingSetupInfo::finished, jsonReply, [info, jsonReply, locale](){
QVariantMap returns; QVariantMap returns;
returns.insert("deviceError", enumValueName<Thing::ThingError>(info->status())); returns.insert("thingError", enumValueName<Thing::ThingError>(info->status()));
returns.insert("displayMessage", info->translatedDisplayMessage(locale)); returns.insert("displayMessage", info->translatedDisplayMessage(locale));
jsonReply->setData(returns); jsonReply->setData(returns);
jsonReply->finished(); jsonReply->finished();
@ -654,28 +679,28 @@ JsonReply *IntegrationsHandler::ReconfigureDevice(const QVariantMap &params)
return jsonReply; return jsonReply;
} }
JsonReply *IntegrationsHandler::EditDevice(const QVariantMap &params) JsonReply *IntegrationsHandler::EditThing(const QVariantMap &params)
{ {
ThingId thingId = ThingId(params.value("deviceId").toString()); ThingId thingId = ThingId(params.value("thingId").toString());
QString name = params.value("name").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); Thing::ThingError status = NymeaCore::instance()->thingManager()->editThing(thingId, name);
return createReply(statusToReply(status)); return createReply(statusToReply(status));
} }
JsonReply* IntegrationsHandler::RemoveConfiguredDevice(const QVariantMap &params) JsonReply* IntegrationsHandler::RemoveThing(const QVariantMap &params)
{ {
QVariantMap returns; QVariantMap returns;
ThingId thingId = ThingId(params.value("deviceId").toString()); ThingId thingId = ThingId(params.value("thingId").toString());
// global removePolicy has priority // global removePolicy has priority
if (params.contains("removePolicy")) { if (params.contains("removePolicy")) {
RuleEngine::RemovePolicy removePolicy = params.value("removePolicy").toString() == "RemovePolicyCascade" ? RuleEngine::RemovePolicyCascade : RuleEngine::RemovePolicyUpdate; RuleEngine::RemovePolicy removePolicy = params.value("removePolicy").toString() == "RemovePolicyCascade" ? RuleEngine::RemovePolicyCascade : RuleEngine::RemovePolicyUpdate;
Thing::ThingError status = NymeaCore::instance()->removeConfiguredThing(thingId, removePolicy); 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); return createReply(returns);
} }
@ -687,7 +712,7 @@ JsonReply* IntegrationsHandler::RemoveConfiguredDevice(const QVariantMap &params
} }
QPair<Thing::ThingError, QList<RuleId> > status = NymeaCore::instance()->removeConfiguredThing(thingId, removePolicyList); 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()) { if (!status.second.isEmpty()) {
QVariantList ruleIdList; QVariantList ruleIdList;
@ -700,53 +725,47 @@ JsonReply* IntegrationsHandler::RemoveConfiguredDevice(const QVariantMap &params
return createReply(returns); return createReply(returns);
} }
JsonReply *IntegrationsHandler::SetDeviceSettings(const QVariantMap &params) JsonReply *IntegrationsHandler::SetThingSettings(const QVariantMap &params)
{ {
ThingId thingId = ThingId(params.value("deviceId").toString()); ThingId thingId = ThingId(params.value("thingId").toString());
ParamList settings = unpack<ParamList>(params.value("settings")); ParamList settings = unpack<ParamList>(params.value("settings"));
Thing::ThingError status = NymeaCore::instance()->thingManager()->setThingSettings(thingId, settings); Thing::ThingError status = NymeaCore::instance()->thingManager()->setThingSettings(thingId, settings);
return createReply(statusToReply(status)); return createReply(statusToReply(status));
} }
JsonReply* IntegrationsHandler::GetEventTypes(const QVariantMap &params) const JsonReply* IntegrationsHandler::GetEventTypes(const QVariantMap &params, const JsonContext &context) const
{ {
QLocale locale = params.value("locale").toLocale(); ThingClass thingClass = NymeaCore::instance()->thingManager()->findThingClass(ThingClassId(params.value("thingClassId").toString()));
ThingClass translatedThingClass = NymeaCore::instance()->thingManager()->translateThingClass(thingClass, context.locale());
ThingClass deviceClass = NymeaCore::instance()->thingManager()->findThingClass(ThingClassId(params.value("thingClassId").toString()));
ThingClass translatedDeviceClass = NymeaCore::instance()->thingManager()->translateThingClass(deviceClass, locale);
QVariantMap returns; QVariantMap returns;
returns.insert("eventTypes", pack(translatedDeviceClass.eventTypes())); returns.insert("eventTypes", pack(translatedThingClass.eventTypes()));
return createReply(returns); return createReply(returns);
} }
JsonReply* IntegrationsHandler::GetActionTypes(const QVariantMap &params) const JsonReply* IntegrationsHandler::GetActionTypes(const QVariantMap &params, const JsonContext &context) const
{ {
QLocale locale = params.value("locale").toLocale(); ThingClass thingClass = NymeaCore::instance()->thingManager()->findThingClass(ThingClassId(params.value("thingClassId").toString()));
ThingClass translatedThingClass = NymeaCore::instance()->thingManager()->translateThingClass(thingClass, context.locale());
ThingClass deviceClass = NymeaCore::instance()->thingManager()->findThingClass(ThingClassId(params.value("thingClassId").toString()));
ThingClass translatedDeviceClass = NymeaCore::instance()->thingManager()->translateThingClass(deviceClass, locale);
QVariantMap returns; QVariantMap returns;
returns.insert("actionTypes", pack(translatedDeviceClass.actionTypes())); returns.insert("actionTypes", pack(translatedThingClass.actionTypes()));
return createReply(returns); return createReply(returns);
} }
JsonReply* IntegrationsHandler::GetStateTypes(const QVariantMap &params) const JsonReply* IntegrationsHandler::GetStateTypes(const QVariantMap &params, const JsonContext &context) const
{ {
QLocale locale = params.value("locale").toLocale(); ThingClass thingClass = NymeaCore::instance()->thingManager()->findThingClass(ThingClassId(params.value("thingClassId").toString()));
ThingClass translatedThingClass = NymeaCore::instance()->thingManager()->translateThingClass(thingClass, context.locale());
ThingClass deviceClass = NymeaCore::instance()->thingManager()->findThingClass(ThingClassId(params.value("thingClassId").toString()));
ThingClass translatedDeviceClass = NymeaCore::instance()->thingManager()->translateThingClass(deviceClass, locale);
QVariantMap returns; QVariantMap returns;
returns.insert("stateTypes", pack(translatedDeviceClass.stateTypes())); returns.insert("stateTypes", pack(translatedThingClass.stateTypes()));
return createReply(returns); return createReply(returns);
} }
JsonReply* IntegrationsHandler::GetStateValue(const QVariantMap &params) const JsonReply* IntegrationsHandler::GetStateValue(const QVariantMap &params) 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) { if (!thing) {
return createReply(statusToReply(Thing::ThingErrorThingNotFound)); return createReply(statusToReply(Thing::ThingErrorThingNotFound));
} }
@ -762,7 +781,7 @@ JsonReply* IntegrationsHandler::GetStateValue(const QVariantMap &params) const
JsonReply *IntegrationsHandler::GetStateValues(const QVariantMap &params) const JsonReply *IntegrationsHandler::GetStateValues(const QVariantMap &params) 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) { if (!thing) {
return createReply(statusToReply(Thing::ThingErrorThingNotFound)); return createReply(statusToReply(Thing::ThingErrorThingNotFound));
} }
@ -772,14 +791,14 @@ JsonReply *IntegrationsHandler::GetStateValues(const QVariantMap &params) const
return createReply(returns); return createReply(returns);
} }
JsonReply *IntegrationsHandler::BrowseDevice(const QVariantMap &params) const JsonReply *IntegrationsHandler::BrowseThing(const QVariantMap &params, const JsonContext &context) const
{ {
ThingId thingId = ThingId(params.value("deviceId").toString()); ThingId thingId = ThingId(params.value("thingId").toString());
QString itemId = params.value("itemId").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](){ connect(result, &BrowseResult::finished, jsonReply, [this, jsonReply, result](){
QVariantMap returns = statusToReply(result->status()); QVariantMap returns = statusToReply(result->status());
@ -795,15 +814,15 @@ JsonReply *IntegrationsHandler::BrowseDevice(const QVariantMap &params) const
return jsonReply; return jsonReply;
} }
JsonReply *IntegrationsHandler::GetBrowserItem(const QVariantMap &params) const JsonReply *IntegrationsHandler::GetBrowserItem(const QVariantMap &params, const JsonContext &context) const
{ {
QVariantMap returns; QVariantMap returns;
ThingId thingId = ThingId(params.value("deviceId").toString()); ThingId thingId = ThingId(params.value("thingId").toString());
QString itemId = params.value("itemId").toString(); QString itemId = params.value("itemId").toString();
JsonReply *jsonReply = createAsyncReply("GetBrowserItem"); 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](){ connect(result, &BrowserItemResult::finished, jsonReply, [this, jsonReply, result](){
QVariantMap params = statusToReply(result->status()); QVariantMap params = statusToReply(result->status());
if (result->status() == Thing::ThingErrorNoError) { if (result->status() == Thing::ThingErrorNoError) {
@ -816,12 +835,12 @@ JsonReply *IntegrationsHandler::GetBrowserItem(const QVariantMap &params) const
return jsonReply; return jsonReply;
} }
JsonReply *IntegrationsHandler::ExecuteAction(const QVariantMap &params) JsonReply *IntegrationsHandler::ExecuteAction(const QVariantMap &params, const JsonContext &context)
{ {
ThingId thingId(params.value("deviceId").toString()); ThingId thingId(params.value("thingId").toString());
ActionTypeId actionTypeId(params.value("actionTypeId").toString()); ActionTypeId actionTypeId(params.value("actionTypeId").toString());
ParamList actionParams = unpack<ParamList>(params.value("params")); ParamList actionParams = unpack<ParamList>(params.value("params"));
QLocale locale = params.value("locale").toLocale(); QLocale locale = context.locale();
Action action(actionTypeId, thingId); Action action(actionTypeId, thingId);
action.setParams(actionParams); action.setParams(actionParams);
@ -831,7 +850,7 @@ JsonReply *IntegrationsHandler::ExecuteAction(const QVariantMap &params)
ThingActionInfo *info = NymeaCore::instance()->executeAction(action); ThingActionInfo *info = NymeaCore::instance()->executeAction(action);
connect(info, &ThingActionInfo::finished, jsonReply, [info, jsonReply, locale](){ connect(info, &ThingActionInfo::finished, jsonReply, [info, jsonReply, locale](){
QVariantMap data; QVariantMap data;
data.insert("deviceError", enumValueName(info->status())); data.insert("thingError", enumValueName(info->status()));
if (!info->displayMessage().isEmpty()) { if (!info->displayMessage().isEmpty()) {
data.insert("displayMessage", info->translatedDisplayMessage(locale)); data.insert("displayMessage", info->translatedDisplayMessage(locale));
} }
@ -844,7 +863,7 @@ JsonReply *IntegrationsHandler::ExecuteAction(const QVariantMap &params)
JsonReply *IntegrationsHandler::ExecuteBrowserItem(const QVariantMap &params) JsonReply *IntegrationsHandler::ExecuteBrowserItem(const QVariantMap &params)
{ {
ThingId thingId = ThingId(params.value("deviceId").toString()); ThingId thingId = ThingId(params.value("thingId").toString());
QString itemId = params.value("itemId").toString(); QString itemId = params.value("itemId").toString();
BrowserAction action(thingId, itemId); BrowserAction action(thingId, itemId);
@ -853,7 +872,7 @@ JsonReply *IntegrationsHandler::ExecuteBrowserItem(const QVariantMap &params)
BrowserActionInfo *info = NymeaCore::instance()->executeBrowserItem(action); BrowserActionInfo *info = NymeaCore::instance()->executeBrowserItem(action);
connect(info, &BrowserActionInfo::finished, jsonReply, [info, jsonReply](){ connect(info, &BrowserActionInfo::finished, jsonReply, [info, jsonReply](){
QVariantMap data; QVariantMap data;
data.insert("deviceError", enumValueName<Thing::ThingError>(info->status())); data.insert("thingError", enumValueName<Thing::ThingError>(info->status()));
jsonReply->setData(data); jsonReply->setData(data);
jsonReply->finished(); jsonReply->finished();
}); });
@ -863,7 +882,7 @@ JsonReply *IntegrationsHandler::ExecuteBrowserItem(const QVariantMap &params)
JsonReply *IntegrationsHandler::ExecuteBrowserItemAction(const QVariantMap &params) JsonReply *IntegrationsHandler::ExecuteBrowserItemAction(const QVariantMap &params)
{ {
ThingId thingId = ThingId(params.value("deviceId").toString()); ThingId thingId = ThingId(params.value("thingId").toString());
QString itemId = params.value("itemId").toString(); QString itemId = params.value("itemId").toString();
ActionTypeId actionTypeId = ActionTypeId(params.value("actionTypeId").toString()); ActionTypeId actionTypeId = ActionTypeId(params.value("actionTypeId").toString());
ParamList paramList = unpack<ParamList>(params.value("params")); ParamList paramList = unpack<ParamList>(params.value("params"));
@ -874,7 +893,7 @@ JsonReply *IntegrationsHandler::ExecuteBrowserItemAction(const QVariantMap &para
BrowserItemActionInfo *info = NymeaCore::instance()->executeBrowserItemAction(browserItemAction); BrowserItemActionInfo *info = NymeaCore::instance()->executeBrowserItemAction(browserItemAction);
connect(info, &BrowserItemActionInfo::finished, jsonReply, [info, jsonReply](){ connect(info, &BrowserItemActionInfo::finished, jsonReply, [info, jsonReply](){
QVariantMap data; QVariantMap data;
data.insert("deviceError", enumValueName<Thing::ThingError>(info->status())); data.insert("thingError", enumValueName<Thing::ThingError>(info->status()));
jsonReply->setData(data); jsonReply->setData(data);
jsonReply->finished(); jsonReply->finished();
}); });
@ -929,36 +948,36 @@ void IntegrationsHandler::thingRemovedNotification(const ThingId &thingId)
{ {
QVariantMap params; QVariantMap params;
params.insert("thingId", thingId); params.insert("thingId", thingId);
emit DeviceRemoved(params); emit ThingRemoved(params);
} }
void IntegrationsHandler::deviceAddedNotification(Thing *device) void IntegrationsHandler::thingAddedNotification(Thing *thing)
{ {
QVariantMap params; QVariantMap params;
params.insert("device", pack(device)); params.insert("thing", pack(thing));
emit DeviceAdded(params); emit ThingAdded(params);
} }
void IntegrationsHandler::deviceChangedNotification(Thing *device) void IntegrationsHandler::thingChangedNotification(Thing *thing)
{ {
QVariantMap params; QVariantMap params;
params.insert("device", pack(device)); params.insert("thing", pack(thing));
emit DeviceChanged(params); emit ThingChanged(params);
} }
void IntegrationsHandler::deviceSettingChangedNotification(const ThingId &thingId, const ParamTypeId &paramTypeId, const QVariant &value) void IntegrationsHandler::thingSettingChangedNotification(const ThingId &thingId, const ParamTypeId &paramTypeId, const QVariant &value)
{ {
QVariantMap params; QVariantMap params;
params.insert("deviceId", thingId); params.insert("thingId", thingId);
params.insert("paramTypeId", paramTypeId.toString()); params.insert("paramTypeId", paramTypeId.toString());
params.insert("value", value); params.insert("value", value);
emit DeviceSettingChanged(params); emit ThingSettingChanged(params);
} }
QVariantMap IntegrationsHandler::statusToReply(Thing::ThingError status) const QVariantMap IntegrationsHandler::statusToReply(Thing::ThingError status) const
{ {
QVariantMap returns; QVariantMap returns;
returns.insert("deviceError", enumValueName<Thing::ThingError>(status)); returns.insert("thingError", enumValueName<Thing::ThingError>(status));
return returns; return returns;
} }

View File

@ -40,36 +40,35 @@ class IntegrationsHandler : public JsonHandler
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit IntegrationsHandler(ThingManager *deviceManager, QObject *parent = nullptr); explicit IntegrationsHandler(ThingManager *thingManager, QObject *parent = nullptr);
QString name() const override; QString name() const override;
Q_INVOKABLE JsonReply *GetSupportedVendors(const QVariantMap &params) const; Q_INVOKABLE JsonReply *GetVendors(const QVariantMap &params, const JsonContext &context) const;
Q_INVOKABLE JsonReply *GetSupportedDevices(const QVariantMap &params) const; Q_INVOKABLE JsonReply *GetThingClasses(const QVariantMap &params, const JsonContext &context) const;
Q_INVOKABLE JsonReply *GetDiscoveredDevices(const QVariantMap &params) const; Q_INVOKABLE JsonReply *DiscoverThings(const QVariantMap &params, const JsonContext &context) const;
Q_INVOKABLE JsonReply *GetPlugins(const QVariantMap &params) const; Q_INVOKABLE JsonReply *GetPlugins(const QVariantMap &params, const JsonContext &context) const;
Q_INVOKABLE JsonReply *GetPluginConfiguration(const QVariantMap &params) const; Q_INVOKABLE JsonReply *GetPluginConfiguration(const QVariantMap &params) const;
Q_INVOKABLE JsonReply *SetPluginConfiguration(const QVariantMap &params); Q_INVOKABLE JsonReply *SetPluginConfiguration(const QVariantMap &params);
Q_INVOKABLE JsonReply *AddThing(const QVariantMap &params, const JsonContext &context);
Q_INVOKABLE JsonReply *AddConfiguredDevice(const QVariantMap &params); Q_INVOKABLE JsonReply *PairThing(const QVariantMap &params, const JsonContext &context);
Q_INVOKABLE JsonReply *PairDevice(const QVariantMap &params);
Q_INVOKABLE JsonReply *ConfirmPairing(const QVariantMap &params); Q_INVOKABLE JsonReply *ConfirmPairing(const QVariantMap &params);
Q_INVOKABLE JsonReply *GetConfiguredDevices(const QVariantMap &params) const; Q_INVOKABLE JsonReply *GetThings(const QVariantMap &params, const JsonContext &context) const;
Q_INVOKABLE JsonReply *ReconfigureDevice(const QVariantMap &params); Q_INVOKABLE JsonReply *ReconfigureThing(const QVariantMap &params, const JsonContext &context);
Q_INVOKABLE JsonReply *EditDevice(const QVariantMap &params); Q_INVOKABLE JsonReply *EditThing(const QVariantMap &params);
Q_INVOKABLE JsonReply *RemoveConfiguredDevice(const QVariantMap &params); Q_INVOKABLE JsonReply *RemoveThing(const QVariantMap &params);
Q_INVOKABLE JsonReply *SetDeviceSettings(const QVariantMap &params); Q_INVOKABLE JsonReply *SetThingSettings(const QVariantMap &params);
Q_INVOKABLE JsonReply *GetEventTypes(const QVariantMap &params) const; Q_INVOKABLE JsonReply *GetEventTypes(const QVariantMap &params, const JsonContext &context) const;
Q_INVOKABLE JsonReply *GetActionTypes(const QVariantMap &params) const; Q_INVOKABLE JsonReply *GetActionTypes(const QVariantMap &params, const JsonContext &context) const;
Q_INVOKABLE JsonReply *GetStateTypes(const QVariantMap &params) const; Q_INVOKABLE JsonReply *GetStateTypes(const QVariantMap &params, const JsonContext &context) const;
Q_INVOKABLE JsonReply *GetStateValue(const QVariantMap &params) const; Q_INVOKABLE JsonReply *GetStateValue(const QVariantMap &params) const;
Q_INVOKABLE JsonReply *GetStateValues(const QVariantMap &params) const; Q_INVOKABLE JsonReply *GetStateValues(const QVariantMap &params) const;
Q_INVOKABLE JsonReply *BrowseDevice(const QVariantMap &params) const; Q_INVOKABLE JsonReply *BrowseThing(const QVariantMap &params, const JsonContext &context) const;
Q_INVOKABLE JsonReply *GetBrowserItem(const QVariantMap &params) const; Q_INVOKABLE JsonReply *GetBrowserItem(const QVariantMap &params, const JsonContext &context) const;
Q_INVOKABLE JsonReply *ExecuteAction(const QVariantMap &params); Q_INVOKABLE JsonReply *ExecuteAction(const QVariantMap &params, const JsonContext &context);
Q_INVOKABLE JsonReply *ExecuteBrowserItem(const QVariantMap &params); Q_INVOKABLE JsonReply *ExecuteBrowserItem(const QVariantMap &params);
Q_INVOKABLE JsonReply *ExecuteBrowserItemAction(const QVariantMap &params); Q_INVOKABLE JsonReply *ExecuteBrowserItemAction(const QVariantMap &params);
@ -78,10 +77,10 @@ public:
signals: signals:
void PluginConfigurationChanged(const QVariantMap &params); void PluginConfigurationChanged(const QVariantMap &params);
void StateChanged(const QVariantMap &params); void StateChanged(const QVariantMap &params);
void DeviceRemoved(const QVariantMap &params); void ThingRemoved(const QVariantMap &params);
void DeviceAdded(const QVariantMap &params); void ThingAdded(const QVariantMap &params);
void DeviceChanged(const QVariantMap &params); void ThingChanged(const QVariantMap &params);
void DeviceSettingChanged(const QVariantMap &params); void ThingSettingChanged(const QVariantMap &params);
void EventTriggered(const QVariantMap &params); void EventTriggered(const QVariantMap &params);
private slots: private slots:
@ -91,14 +90,14 @@ private slots:
void thingRemovedNotification(const ThingId &thingId); 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 &paramTypeId, const QVariant &value); void thingSettingChangedNotification(const ThingId &thingId, const ParamTypeId &paramTypeId, const QVariant &value);
private: private:
ThingManager *m_deviceManager = nullptr; ThingManager *m_thingManager = nullptr;
QVariantMap statusToReply(Thing::ThingError status) const; QVariantMap statusToReply(Thing::ThingError status) const;
}; };

View File

@ -17,7 +17,6 @@ RESOURCES += $$top_srcdir/icons.qrc \
HEADERS += nymeacore.h \ HEADERS += nymeacore.h \
integrations/plugininfocache.h \ integrations/plugininfocache.h \
integrations/scriptintegrationplugin.h \
integrations/thingmanagerimplementation.h \ integrations/thingmanagerimplementation.h \
integrations/translator.h \ integrations/translator.h \
experiences/experiencemanager.h \ experiences/experiencemanager.h \
@ -104,7 +103,6 @@ HEADERS += nymeacore.h \
SOURCES += nymeacore.cpp \ SOURCES += nymeacore.cpp \
integrations/plugininfocache.cpp \ integrations/plugininfocache.cpp \
integrations/scriptintegrationplugin.cpp \
integrations/thingmanagerimplementation.cpp \ integrations/thingmanagerimplementation.cpp \
integrations/translator.cpp \ integrations/translator.cpp \
experiences/experiencemanager.cpp \ experiences/experiencemanager.cpp \
@ -189,6 +187,8 @@ SOURCES += nymeacore.cpp \
versionAtLeast(QT_VERSION, 5.12.0) { versionAtLeast(QT_VERSION, 5.12.0) {
HEADERS += \ HEADERS += \
integrations/scriptintegrationplugin.h
SOURCES += \ SOURCES += \
integrations/scriptintegrationplugin.cpp
} }

View File

@ -194,9 +194,9 @@ void PluginMetadata::parse(const QJsonObject &jsonObject)
// Check mandatory fields // Check mandatory fields
if (!verificationResult.first.isEmpty()) { 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; 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; continue;
} }
@ -210,11 +210,11 @@ void PluginMetadata::parse(const QJsonObject &jsonObject)
} }
if (thingClassId.isNull()) { 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; hasError = true;
} }
if (!verifyDuplicateUuid(thingClassId)) { 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; hasError = true;
} }
@ -306,7 +306,7 @@ void PluginMetadata::parse(const QJsonObject &jsonObject)
// Check mandatory fields // Check mandatory fields
if (!verificationResult.first.isEmpty()) { 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; hasError = true;
// Not processing further as mandatory fields are expected to be here // Not processing further as mandatory fields are expected to be here
continue; continue;

View File

@ -84,7 +84,7 @@ DevicePluginMock::~DevicePluginMock()
void DevicePluginMock::discoverThings(ThingDiscoveryInfo *info) void DevicePluginMock::discoverThings(ThingDiscoveryInfo *info)
{ {
if (info->thingClassId() == mockThingClassId) { 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(); m_discoveredDeviceCount = info->params().paramValue(mockDiscoveryResultCountParamTypeId).toInt();
QTimer::singleShot(1000, info, [this, info](){ QTimer::singleShot(1000, info, [this, info](){
generateDiscoveredDevices(info); generateDiscoveredDevices(info);
@ -92,39 +92,39 @@ void DevicePluginMock::discoverThings(ThingDiscoveryInfo *info)
return; return;
} }
if (info->thingClassId() == mockPushButtonThingClassId) { if (info->thingClassId() == pushButtonMockThingClassId) {
qCDebug(dcMockDevice) << "starting mock push button discovery:" << info->params(); qCDebug(dcMock()) << "starting mock push button discovery:" << info->params();
m_discoveredDeviceCount = info->params().paramValue(mockPushButtonDiscoveryResultCountParamTypeId).toInt(); m_discoveredDeviceCount = info->params().paramValue(pushButtonMockDiscoveryResultCountParamTypeId).toInt();
QTimer::singleShot(1000, info, [this, info]() { QTimer::singleShot(1000, info, [this, info]() {
generateDiscoveredPushButtonDevices(info); generateDiscoveredPushButtonDevices(info);
}); });
return; return;
} }
if (info->thingClassId() == mockDisplayPinThingClassId) { if (info->thingClassId() == displayPinMockThingClassId) {
qCDebug(dcMockDevice) << "starting mock display pin discovery:" << info->params(); qCDebug(dcMock()) << "starting mock display pin discovery:" << info->params();
m_discoveredDeviceCount = info->params().paramValue(mockDisplayPinDiscoveryResultCountParamTypeId).toInt(); m_discoveredDeviceCount = info->params().paramValue(displayPinMockDiscoveryResultCountParamTypeId).toInt();
QTimer::singleShot(1000, info, [this, info]() { QTimer::singleShot(1000, info, [this, info]() {
generateDiscoveredDisplayPinDevices(info); generateDiscoveredDisplayPinDevices(info);
}); });
return; return;
} }
if (info->thingClassId() == mockParentThingClassId) { if (info->thingClassId() == parentMockThingClassId) {
qCDebug(dcMockDevice()) << "Starting discovery for mock device parent"; qCDebug(dcMock()) << "Starting discovery for mocked parent thing";
QTimer::singleShot(1000, info, [info](){ QTimer::singleShot(1000, info, [info](){
ThingDescriptor descriptor(mockParentThingClassId, "Mock Parent (Discovered)"); ThingDescriptor descriptor(parentMockThingClassId, "Mocked Thing Parent (Discovered)");
info->addThingDescriptor(descriptor); info->addThingDescriptor(descriptor);
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
}); });
return; return;
} }
if (info->thingClassId() == mockChildThingClassId) { if (info->thingClassId() == childMockThingClassId) {
QTimer::singleShot(1000, info, [this, info](){ QTimer::singleShot(1000, info, [this, info](){
if (!myThings().filterByThingClassId(mockParentThingClassId).isEmpty()) { if (!myThings().filterByThingClassId(parentMockThingClassId).isEmpty()) {
Thing *parent = myThings().filterByThingClassId(mockParentThingClassId).first(); Thing *parent = myThings().filterByThingClassId(parentMockThingClassId).first();
ThingDescriptor descriptor(mockChildThingClassId, "Mock Child (Discovered)", QString(), parent->id()); ThingDescriptor descriptor(childMockThingClassId, "Mocked Thing Child (Discovered)", QString(), parent->id());
info->addThingDescriptor(descriptor); info->addThingDescriptor(descriptor);
} }
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
@ -132,10 +132,10 @@ void DevicePluginMock::discoverThings(ThingDiscoveryInfo *info)
return; return;
} }
if (info->thingClassId() == mockUserAndPassThingClassId) { if (info->thingClassId() == userAndPassMockThingClassId) {
QTimer::singleShot(1000, info, [this, info](){ QTimer::singleShot(1000, info, [this, info](){
if (myThings().filterByThingClassId(mockUserAndPassThingClassId).isEmpty()) { if (myThings().filterByThingClassId(userAndPassMockThingClassId).isEmpty()) {
ThingDescriptor descriptor(mockUserAndPassThingClassId, "Mock User & Password (Discovered)", QString()); ThingDescriptor descriptor(userAndPassMockThingClassId, "Mocked Thing User & Password (Discovered)", QString());
info->addThingDescriptor(descriptor); info->addThingDescriptor(descriptor);
} }
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
@ -143,27 +143,27 @@ void DevicePluginMock::discoverThings(ThingDiscoveryInfo *info)
return; return;
} }
qCWarning(dcMockDevice()) << "Cannot discover for ThingClassId" << info->thingClassId(); qCWarning(dcMock()) << "Cannot discover for ThingClassId" << info->thingClassId();
info->finish(Thing::ThingErrorThingNotFound); info->finish(Thing::ThingErrorThingNotFound);
} }
void DevicePluginMock::setupThing(ThingSetupInfo *info) 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 async = false;
bool broken = false; bool broken = false;
if (info->thing()->thingClassId() == mockThingClassId) { if (info->thing()->thingClassId() == mockThingClassId) {
async = info->thing()->paramValue(mockDeviceAsyncParamTypeId).toBool(); async = info->thing()->paramValue(mockThingAsyncParamTypeId).toBool();
broken = info->thing()->paramValue(mockDeviceBrokenParamTypeId).toBool(); broken = info->thing()->paramValue(mockThingBrokenParamTypeId).toBool();
} else { } else {
async = info->thing()->paramValue(mockDeviceAutoDeviceAsyncParamTypeId).toBool(); async = info->thing()->paramValue(autoMockThingAsyncParamTypeId).toBool();
broken = info->thing()->paramValue(mockDeviceAutoDeviceBrokenParamTypeId).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) { if (!async && broken) {
qCWarning(dcMockDevice) << "This device is intentionally broken."; qCWarning(dcMock()) << "This thing is intentionally broken.";
info->finish(Thing::ThingErrorSetupFailed, QT_TR_NOOP("This mock device is intentionally broken.")); info->finish(Thing::ThingErrorSetupFailed, QT_TR_NOOP("This mocked thing is intentionally broken."));
return; return;
} }
@ -172,7 +172,7 @@ void DevicePluginMock::setupThing(ThingSetupInfo *info)
m_daemons.insert(info->thing(), daemon); m_daemons.insert(info->thing(), daemon);
if (!daemon->isListening()) { 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?")); info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("Failed to open HTTP port. Port in use?"));
return; return;
} }
@ -188,83 +188,83 @@ void DevicePluginMock::setupThing(ThingSetupInfo *info)
if (async) { if (async) {
Thing *device = info->thing(); Thing *device = info->thing();
QTimer::singleShot(1000, device, [info](){ QTimer::singleShot(1000, device, [info](){
qCDebug(dcMockDevice) << "Finishing device setup for mock device" << info->thing()->name(); qCDebug(dcMock()) << "Finishing thing setup for mocked thing" << info->thing()->name();
if (info->thing()->paramValue(mockDeviceBrokenParamTypeId).toBool()) { if (info->thing()->paramValue(mockThingBrokenParamTypeId).toBool()) {
info->finish(Thing::ThingErrorSetupFailed, QT_TR_NOOP("This mock device is intentionally broken.")); info->finish(Thing::ThingErrorSetupFailed, QT_TR_NOOP("This mocked thing is intentionally broken."));
} else { } else {
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
} }
}); });
return; return;
} }
qCDebug(dcMockDevice()) << "Setup complete" << info->thing()->name(); qCDebug(dcMock()) << "Setup complete" << info->thing()->name();
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
return; return;
} }
if (info->thing()->thingClassId() == mockPushButtonThingClassId) { if (info->thing()->thingClassId() == pushButtonMockThingClassId) {
qCDebug(dcMockDevice) << "Setup PushButton mock device" << info->thing()->params(); qCDebug(dcMock()) << "Setup PushButton mock thing" << info->thing()->params();
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
return; return;
} }
if (info->thing()->thingClassId() == mockDisplayPinThingClassId) { if (info->thing()->thingClassId() == displayPinMockThingClassId) {
qCDebug(dcMockDevice) << "Setup DisplayPin mock device" << info->thing()->params(); qCDebug(dcMock()) << "Setup DisplayPin mock thing" << info->thing()->params();
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
return; return;
} }
if (info->thing()->thingClassId() == mockParentThingClassId) { if (info->thing()->thingClassId() == parentMockThingClassId) {
qCDebug(dcMockDevice) << "Setup Parent mock device" << info->thing()->params(); qCDebug(dcMock()) << "Setup Parent mock thing" << info->thing()->params();
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
return; return;
} }
if (info->thing()->thingClassId() == mockChildThingClassId) { if (info->thing()->thingClassId() == childMockThingClassId) {
qCDebug(dcMockDevice) << "Setup Child mock device" << info->thing()->params(); qCDebug(dcMock()) << "Setup Child mock thing" << info->thing()->params();
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
return; return;
} }
if (info->thing()->thingClassId() == mockInputTypeThingClassId) { if (info->thing()->thingClassId() == inputTypeMockThingClassId) {
qCDebug(dcMockDevice) << "Setup InputType mock device" << info->thing()->params(); qCDebug(dcMock()) << "Setup InputType mock thing" << info->thing()->params();
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
return; return;
} }
if (info->thing()->thingClassId() == mockUserAndPassThingClassId) { if (info->thing()->thingClassId() == userAndPassMockThingClassId) {
qCDebug(dcMockDevice()) << "Setup User and password mock device"; qCDebug(dcMock()) << "Setup User and password mock thing";
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
return; return;
} }
if (info->thing()->thingClassId() == mockOAuthGoogleThingClassId) { if (info->thing()->thingClassId() == oAuthGoogleMockThingClassId) {
qCDebug(dcMockDevice()) << "Google OAuth setup complete"; qCDebug(dcMock()) << "Google OAuth setup complete";
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
return; return;
} }
if (info->thing()->thingClassId() == mockOAuthSonosThingClassId) { if (info->thing()->thingClassId() == oAuthSonosMockThingClassId) {
qCDebug(dcMockDevice()) << "Sonos OAuth setup complete"; qCDebug(dcMock()) << "Sonos OAuth setup complete";
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
return; return;
} }
qCWarning(dcMockDevice()) << "Unhandled device class" << info->thing()->thingClass(); qCWarning(dcMock()) << "Unhandled thing class" << info->thing()->thingClass();
info->finish(Thing::ThingErrorThingClassNotFound); info->finish(Thing::ThingErrorThingClassNotFound);
} }
void DevicePluginMock::postSetupThing(Thing *device) void DevicePluginMock::postSetupThing(Thing *device)
{ {
qCDebug(dcMockDevice) << "Postsetup mockdevice" << device->name(); qCDebug(dcMock()) << "Postsetup mock" << device->name();
if (device->thingClassId() == mockParentThingClassId) { if (device->thingClassId() == parentMockThingClassId) {
foreach (Thing *d, myThings()) { foreach (Thing *d, myThings()) {
if (d->thingClassId() == mockChildThingClassId && d->parentId() == device->id()) { if (d->thingClassId() == childMockThingClassId && d->parentId() == device->id()) {
return; 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); emit autoThingsAppeared(ThingDescriptors() << mockDescriptor);
} }
} }
@ -277,17 +277,17 @@ void DevicePluginMock::thingRemoved(Thing *device)
void DevicePluginMock::startMonitoringAutoThings() void DevicePluginMock::startMonitoringAutoThings()
{ {
foreach (Thing *device, myThings()) { foreach (Thing *device, myThings()) {
if (device->thingClassId() == mockDeviceAutoThingClassId) { if (device->thingClassId() == autoMockThingClassId) {
return; // We already have a Auto Mock device... do nothing. 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; ParamList params;
qsrand(QDateTime::currentMSecsSinceEpoch()); qsrand(QDateTime::currentMSecsSinceEpoch());
int port = 4242 + (qrand() % 1000); int port = 4242 + (qrand() % 1000);
Param param(mockDeviceAutoDeviceHttpportParamTypeId, port); Param param(autoMockThingHttpportParamTypeId, port);
params.append(param); params.append(param);
mockDescriptor.setParams(params); mockDescriptor.setParams(params);
@ -299,27 +299,27 @@ void DevicePluginMock::startMonitoringAutoThings()
void DevicePluginMock::startPairing(ThingPairingInfo *info) void DevicePluginMock::startPairing(ThingPairingInfo *info)
{ {
if (info->thingClassId() == mockPushButtonThingClassId) { if (info->thingClassId() == pushButtonMockThingClassId) {
qCDebug(dcMockDevice) << "Push button. Pressing the button in 3 seconds."; 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.")); info->finish(Thing::ThingErrorNoError, QT_TR_NOOP("Wait 3 second before you continue, the push button will be pressed automatically."));
m_pushbuttonPressed = false; m_pushbuttonPressed = false;
QTimer::singleShot(3000, this, SLOT(onPushButtonPressed())); QTimer::singleShot(3000, this, SLOT(onPushButtonPressed()));
return; return;
} }
if (info->thingClassId() == mockDisplayPinThingClassId) { if (info->thingClassId() == displayPinMockThingClassId) {
qCDebug(dcMockDevice) << "Display pin!! The pin is 243681"; 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 the mockdevice 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; return;
} }
if (info->thingClassId() == mockUserAndPassThingClassId) { if (info->thingClassId() == userAndPassMockThingClassId) {
qCDebug(dcMockDevice) << "User and password. Login is \"user\" and \"password\"."; qCDebug(dcMock()) << "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\").")); info->finish(Thing::ThingErrorNoError, QT_TR_NOOP("Please enter login credentials for the mocked thing (\"user\" and \"password\")."));
return; return;
} }
if (info->thingClassId() == mockOAuthSonosThingClassId) { if (info->thingClassId() == oAuthSonosMockThingClassId) {
QString clientId = "b15cbf8c-a39c-47aa-bd93-635a96e9696c"; QString clientId = "b15cbf8c-a39c-47aa-bd93-635a96e9696c";
QString clientSecret = "c086ba71-e562-430b-a52f-867c6482fd11"; QString clientSecret = "c086ba71-e562-430b-a52f-867c6482fd11";
@ -332,14 +332,14 @@ void DevicePluginMock::startPairing(ThingPairingInfo *info)
queryParams.addQueryItem("state", "ya-ya"); queryParams.addQueryItem("state", "ya-ya");
url.setQuery(queryParams); url.setQuery(queryParams);
qCDebug(dcMockDevice()) << "Sonos url:" << url; qCDebug(dcMock()) << "Sonos url:" << url;
info->setOAuthUrl(url); info->setOAuthUrl(url);
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
return; return;
} }
if (info->thingClassId() == mockOAuthGoogleThingClassId) { if (info->thingClassId() == oAuthGoogleMockThingClassId) {
QString clientId= "937667874529-pr6s5ciu6sfnnqmt2sppvb6rokbkjjta.apps.googleusercontent.com"; QString clientId= "937667874529-pr6s5ciu6sfnnqmt2sppvb6rokbkjjta.apps.googleusercontent.com";
QString clientSecret = "1ByBRmNqaK08VC54eEVcnGf1"; QString clientSecret = "1ByBRmNqaK08VC54eEVcnGf1";
@ -362,11 +362,11 @@ void DevicePluginMock::startPairing(ThingPairingInfo *info)
void DevicePluginMock::confirmPairing(ThingPairingInfo *info, const QString &username, const QString &secret) 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) { 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.")); info->finish(Thing::ThingErrorAuthenticationFailure, QT_TR_NOOP("The push button has not been pressed."));
return; return;
} }
@ -377,21 +377,21 @@ void DevicePluginMock::confirmPairing(ThingPairingInfo *info, const QString &use
return; return;
} }
if (info->thingClassId() == mockDisplayPinThingClassId) { if (info->thingClassId() == displayPinMockThingClassId) {
if (secret != "243681") { if (secret != "243681") {
qCWarning(dcMockDevice) << "Invalid pin:" << secret; qCWarning(dcMock()) << "Invalid pin:" << secret;
info->finish(Thing::ThingErrorAuthenticationFailure, QT_TR_NOOP("Invalid PIN!")); info->finish(Thing::ThingErrorAuthenticationFailure, QT_TR_NOOP("Invalid PIN!"));
return; return;
} }
QTimer::singleShot(500, this, [info](){ QTimer::singleShot(500, this, [info](){
qCDebug(dcMockDevice()) << "Pairing finished."; qCDebug(dcMock()) << "Pairing finished.";
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
}); });
return; return;
} }
if (info->thingClassId() == mockUserAndPassThingClassId) { if (info->thingClassId() == userAndPassMockThingClassId) {
qCDebug(dcMockDevice()) << "Credentials received:" << username << secret; qCDebug(dcMock()) << "Credentials received:" << username << secret;
if (username == "user" && secret == "password") { if (username == "user" && secret == "password") {
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
return; return;
@ -402,11 +402,11 @@ void DevicePluginMock::confirmPairing(ThingPairingInfo *info, const QString &use
} }
if (info->thingClassId() == mockOAuthSonosThingClassId) { if (info->thingClassId() == oAuthSonosMockThingClassId) {
qCDebug(dcMockDevice()) << "Secret is" << secret; qCDebug(dcMock()) << "Secret is" << secret;
QUrl url(secret); QUrl url(secret);
QUrlQuery query(url); QUrlQuery query(url);
qCDebug(dcMockDevice()) << "Acess code is:" << query.queryItemValue("code"); qCDebug(dcMock()) << "Acess code is:" << query.queryItemValue("code");
QString accessCode = query.queryItemValue("code"); QString accessCode = query.queryItemValue("code");
@ -432,10 +432,10 @@ void DevicePluginMock::confirmPairing(ThingPairingInfo *info, const QString &use
reply->deleteLater(); reply->deleteLater();
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll()); QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll());
qCDebug(dcMockDevice()) << "Sonos accessToken reply:" << this << reply->error() << reply->errorString() << jsonDoc.toJson(); qCDebug(dcMock()) << "Sonos accessToken reply:" << this << reply->error() << reply->errorString() << jsonDoc.toJson();
qCDebug(dcMockDevice()) << "Access token:" << jsonDoc.toVariant().toMap().value("access_token").toString(); qCDebug(dcMock()) << "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(dcMock()) << "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()) << "Refresh token:" << jsonDoc.toVariant().toMap().value("refresh_token").toString();
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
}); });
@ -443,11 +443,11 @@ void DevicePluginMock::confirmPairing(ThingPairingInfo *info, const QString &use
} }
if (info->thingClassId() == mockOAuthGoogleThingClassId) { if (info->thingClassId() == oAuthGoogleMockThingClassId) {
qCDebug(dcMockDevice()) << "Secret is" << secret; qCDebug(dcMock()) << "Secret is" << secret;
QUrl url(secret); QUrl url(secret);
QUrlQuery query(url); QUrlQuery query(url);
qCDebug(dcMockDevice()) << "Acess code is:" << query.queryItemValue("code"); qCDebug(dcMock()) << "Acess code is:" << query.queryItemValue("code");
QString accessCode = query.queryItemValue("code"); QString accessCode = query.queryItemValue("code");
@ -472,29 +472,29 @@ void DevicePluginMock::confirmPairing(ThingPairingInfo *info, const QString &use
reply->deleteLater(); reply->deleteLater();
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll()); QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll());
qCDebug(dcMockDevice()) << "Sonos accessToken reply:" << this << reply->error() << reply->errorString() << jsonDoc.toJson(); qCDebug(dcMock()) << "Sonos accessToken reply:" << this << reply->error() << reply->errorString() << jsonDoc.toJson();
qCDebug(dcMockDevice()) << "Access token:" << jsonDoc.toVariant().toMap().value("access_token").toString(); qCDebug(dcMock()) << "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(dcMock()) << "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()) << "Refresh token:" << jsonDoc.toVariant().toMap().value("refresh_token").toString();
qCDebug(dcMockDevice()) << "ID token:" << jsonDoc.toVariant().toMap().value("id_token").toString(); qCDebug(dcMock()) << "ID token:" << jsonDoc.toVariant().toMap().value("id_token").toString();
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
}); });
return; 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); info->finish(Thing::ThingErrorThingClassNotFound);
} }
void DevicePluginMock::browseThing(BrowseResult *result) 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()->thingClassId() == mockThingClassId) {
if (result->thing()->paramValue(mockDeviceAsyncParamTypeId).toBool()) { if (result->thing()->paramValue(mockThingAsyncParamTypeId).toBool()) {
QTimer::singleShot(1000, result, [this, result]() { QTimer::singleShot(1000, result, [this, result]() {
if (result->thing()->paramValue(mockDeviceBrokenParamTypeId).toBool()) { if (result->thing()->paramValue(mockThingBrokenParamTypeId).toBool()) {
result->finish(Thing::ThingErrorHardwareFailure); result->finish(Thing::ThingErrorHardwareFailure);
return; return;
} }
@ -515,7 +515,7 @@ void DevicePluginMock::browseThing(BrowseResult *result)
return; return;
} }
if (result->thing()->paramValue(mockDeviceBrokenParamTypeId).toBool()) { if (result->thing()->paramValue(mockThingBrokenParamTypeId).toBool()) {
result->finish(Thing::ThingErrorHardwareFailure); result->finish(Thing::ThingErrorHardwareFailure);
return; return;
} }
@ -567,7 +567,7 @@ void DevicePluginMock::executeAction(ThingActionInfo *info)
} }
if (info->action().actionTypeId() == mockPowerActionTypeId) { 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()); info->thing()->setStateValue(mockPowerStateTypeId, info->action().param(mockPowerActionPowerParamTypeId).value().toBool());
} }
m_daemons.value(info->thing())->actionExecuted(info->action().actionTypeId()); m_daemons.value(info->thing())->actionExecuted(info->action().actionTypeId());
@ -575,10 +575,10 @@ void DevicePluginMock::executeAction(ThingActionInfo *info)
return; return;
} }
if (info->thing()->thingClassId() == mockDeviceAutoThingClassId) { if (info->thing()->thingClassId() == autoMockThingClassId) {
if (info->action().actionTypeId() == mockDeviceAutoMockActionAsyncActionTypeId || info->action().actionTypeId() == mockDeviceAutoMockActionAsyncBrokenActionTypeId) { if (info->action().actionTypeId() == autoMockMockActionAsyncActionTypeId || info->action().actionTypeId() == autoMockMockActionAsyncBrokenActionTypeId) {
QTimer::singleShot(1000, info->thing(), [info](){ 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.")); info->finish(Thing::ThingErrorSetupFailed, QT_TR_NOOP("This mock action is intentionally broken."));
} else { } else {
info->finish(Thing::ThingErrorNoError); 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); info->finish(Thing::ThingErrorSetupFailed);
return; return;
} }
m_daemons.value(info->thing())->actionExecuted(info->action().actionTypeId()); m_daemons.value(info->thing())->actionExecuted(info->action().actionTypeId());
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
} else if (info->thing()->thingClassId() == mockPushButtonThingClassId) { } else if (info->thing()->thingClassId() == pushButtonMockThingClassId) {
if (info->action().actionTypeId() == mockPushButtonColorActionTypeId) { if (info->action().actionTypeId() == pushButtonMockColorActionTypeId) {
QString colorString = info->action().param(mockPushButtonColorActionColorParamTypeId).value().toString(); QString colorString = info->action().param(pushButtonMockColorActionColorParamTypeId).value().toString();
QColor color(colorString); QColor color(colorString);
if (!color.isValid()) { if (!color.isValid()) {
qCWarning(dcMockDevice) << "Invalid color parameter"; qCWarning(dcMock()) << "Invalid color parameter";
info->finish(Thing::ThingErrorInvalidParameter); info->finish(Thing::ThingErrorInvalidParameter);
return; return;
} }
info->thing()->setStateValue(mockPushButtonColorStateTypeId, colorString); info->thing()->setStateValue(pushButtonMockColorStateTypeId, colorString);
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
return; return;
} else if (info->action().actionTypeId() == mockPushButtonPercentageActionTypeId) { } else if (info->action().actionTypeId() == pushButtonMockPercentageActionTypeId) {
info->thing()->setStateValue(mockPushButtonPercentageStateTypeId, info->action().param(mockPushButtonPercentageActionPercentageParamTypeId).value().toInt()); info->thing()->setStateValue(pushButtonMockPercentageStateTypeId, info->action().param(pushButtonMockPercentageActionPercentageParamTypeId).value().toInt());
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
return; return;
} else if (info->action().actionTypeId() == mockPushButtonAllowedValuesActionTypeId) { } else if (info->action().actionTypeId() == pushButtonMockAllowedValuesActionTypeId) {
info->thing()->setStateValue(mockPushButtonAllowedValuesStateTypeId, info->action().param(mockPushButtonAllowedValuesActionAllowedValuesParamTypeId).value().toString()); info->thing()->setStateValue(pushButtonMockAllowedValuesStateTypeId, info->action().param(pushButtonMockAllowedValuesActionAllowedValuesParamTypeId).value().toString());
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
return; return;
} else if (info->action().actionTypeId() == mockPushButtonDoubleActionTypeId) { } else if (info->action().actionTypeId() == pushButtonMockDoubleActionTypeId) {
info->thing()->setStateValue(mockPushButtonDoubleStateTypeId, info->action().param(mockPushButtonDoubleActionDoubleParamTypeId).value().toDouble()); info->thing()->setStateValue(pushButtonMockDoubleStateTypeId, info->action().param(pushButtonMockDoubleActionDoubleParamTypeId).value().toDouble());
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
return; return;
} else if (info->action().actionTypeId() == mockPushButtonBoolActionTypeId) { } else if (info->action().actionTypeId() == pushButtonMockBoolActionTypeId) {
info->thing()->setStateValue(mockPushButtonBoolStateTypeId, info->action().param(mockPushButtonBoolActionBoolParamTypeId).value().toBool()); info->thing()->setStateValue(pushButtonMockBoolStateTypeId, info->action().param(pushButtonMockBoolActionBoolParamTypeId).value().toBool());
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
return; return;
} else if (info->action().actionTypeId() == mockPushButtonTimeoutActionTypeId) { } else if (info->action().actionTypeId() == pushButtonMockTimeoutActionTypeId) {
// Not finishing action intentionally... // Not finishing action intentionally...
return; return;
} }
info->finish(Thing::ThingErrorActionTypeNotFound); info->finish(Thing::ThingErrorActionTypeNotFound);
return; return;
} else if (info->thing()->thingClassId() == mockDisplayPinThingClassId) { } else if (info->thing()->thingClassId() == displayPinMockThingClassId) {
if (info->action().actionTypeId() == mockDisplayPinColorActionTypeId) { if (info->action().actionTypeId() == displayPinMockColorActionTypeId) {
QString colorString = info->action().param(mockDisplayPinColorActionColorParamTypeId).value().toString(); QString colorString = info->action().param(displayPinMockColorActionColorParamTypeId).value().toString();
QColor color(colorString); QColor color(colorString);
if (!color.isValid()) { if (!color.isValid()) {
qCWarning(dcMockDevice) << "Invalid color parameter"; qCWarning(dcMock()) << "Invalid color parameter";
info->finish(Thing::ThingErrorInvalidParameter); info->finish(Thing::ThingErrorInvalidParameter);
return; return;
} }
info->thing()->setStateValue(mockDisplayPinColorStateTypeId, colorString); info->thing()->setStateValue(displayPinMockColorStateTypeId, colorString);
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
return; return;
} else if (info->action().actionTypeId() == mockDisplayPinPercentageActionTypeId) { } else if (info->action().actionTypeId() == displayPinMockPercentageActionTypeId) {
info->thing()->setStateValue(mockDisplayPinPercentageStateTypeId, info->action().param(mockDisplayPinPercentageActionPercentageParamTypeId).value().toInt()); info->thing()->setStateValue(displayPinMockPercentageStateTypeId, info->action().param(displayPinMockPercentageActionPercentageParamTypeId).value().toInt());
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
return; return;
} else if (info->action().actionTypeId() == mockDisplayPinAllowedValuesActionTypeId) { } else if (info->action().actionTypeId() == displayPinMockAllowedValuesActionTypeId) {
info->thing()->setStateValue(mockDisplayPinAllowedValuesStateTypeId, info->action().param(mockDisplayPinAllowedValuesActionAllowedValuesParamTypeId).value().toString()); info->thing()->setStateValue(displayPinMockAllowedValuesStateTypeId, info->action().param(displayPinMockAllowedValuesActionAllowedValuesParamTypeId).value().toString());
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
return; return;
} else if (info->action().actionTypeId() == mockDisplayPinDoubleActionTypeId) { } else if (info->action().actionTypeId() == displayPinMockDoubleActionTypeId) {
info->thing()->setStateValue(mockDisplayPinDoubleStateTypeId, info->action().param(mockDisplayPinDoubleActionDoubleParamTypeId).value().toDouble()); info->thing()->setStateValue(displayPinMockDoubleStateTypeId, info->action().param(displayPinMockDoubleActionDoubleParamTypeId).value().toDouble());
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
return; return;
} else if (info->action().actionTypeId() == mockDisplayPinBoolActionTypeId) { } else if (info->action().actionTypeId() == displayPinMockBoolActionTypeId) {
info->thing()->setStateValue(mockDisplayPinBoolStateTypeId, info->action().param(mockDisplayPinBoolActionBoolParamTypeId).value().toBool()); info->thing()->setStateValue(displayPinMockBoolStateTypeId, info->action().param(displayPinMockBoolActionBoolParamTypeId).value().toBool());
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
return; return;
} else if (info->action().actionTypeId() == mockDisplayPinTimeoutActionTypeId) { } else if (info->action().actionTypeId() == displayPinMockTimeoutActionTypeId) {
// Not finishing action intentionally... // Not finishing action intentionally...
return; return;
} }
info->finish(Thing::ThingErrorActionTypeNotFound); info->finish(Thing::ThingErrorActionTypeNotFound);
return; return;
} else if (info->thing()->thingClassId() == mockParentThingClassId) { } else if (info->thing()->thingClassId() == parentMockThingClassId) {
if (info->action().actionTypeId() == mockParentBoolValueActionTypeId) { if (info->action().actionTypeId() == parentMockBoolValueActionTypeId) {
info->thing()->setStateValue(mockParentBoolValueStateTypeId, info->action().param(mockParentBoolValueActionBoolValueParamTypeId).value().toBool()); info->thing()->setStateValue(parentMockBoolValueStateTypeId, info->action().param(parentMockBoolValueActionBoolValueParamTypeId).value().toBool());
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
return; return;
} }
info->finish(Thing::ThingErrorActionTypeNotFound); info->finish(Thing::ThingErrorActionTypeNotFound);
return; return;
} else if (info->thing()->thingClassId() == mockChildThingClassId) { } else if (info->thing()->thingClassId() == childMockThingClassId) {
if (info->action().actionTypeId() == mockChildBoolValueActionTypeId) { if (info->action().actionTypeId() == childMockBoolValueActionTypeId) {
info->thing()->setStateValue(mockChildBoolValueStateTypeId, info->action().param(mockChildBoolValueActionBoolValueParamTypeId).value().toBool()); info->thing()->setStateValue(childMockBoolValueStateTypeId, info->action().param(childMockBoolValueActionBoolValueParamTypeId).value().toBool());
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
return; return;
} }
info->finish(Thing::ThingErrorActionTypeNotFound); info->finish(Thing::ThingErrorActionTypeNotFound);
return; return;
} else if (info->thing()->thingClassId() == mockInputTypeThingClassId) { } else if (info->thing()->thingClassId() == inputTypeMockThingClassId) {
if (info->action().actionTypeId() == mockInputTypeWritableBoolActionTypeId) { if (info->action().actionTypeId() == inputTypeMockWritableBoolActionTypeId) {
info->thing()->setStateValue(mockInputTypeWritableBoolStateTypeId, info->action().param(mockInputTypeWritableBoolActionWritableBoolParamTypeId).value().toULongLong()); info->thing()->setStateValue(inputTypeMockWritableBoolStateTypeId, info->action().param(inputTypeMockWritableBoolActionWritableBoolParamTypeId).value().toULongLong());
} else if (info->action().actionTypeId() == mockInputTypeWritableIntActionTypeId) { } else if (info->action().actionTypeId() == inputTypeMockWritableIntActionTypeId) {
info->thing()->setStateValue(mockInputTypeWritableIntStateTypeId, info->action().param(mockInputTypeWritableIntActionWritableIntParamTypeId).value().toLongLong()); info->thing()->setStateValue(inputTypeMockWritableIntStateTypeId, info->action().param(inputTypeMockWritableIntActionWritableIntParamTypeId).value().toLongLong());
} else if (info->action().actionTypeId() == mockInputTypeWritableIntMinMaxActionTypeId) { } else if (info->action().actionTypeId() == inputTypeMockWritableIntMinMaxActionTypeId) {
info->thing()->setStateValue(mockInputTypeWritableIntMinMaxStateTypeId, info->action().param(mockInputTypeWritableIntMinMaxActionWritableIntMinMaxParamTypeId).value().toLongLong()); info->thing()->setStateValue(inputTypeMockWritableIntMinMaxStateTypeId, info->action().param(inputTypeMockWritableIntMinMaxActionWritableIntMinMaxParamTypeId).value().toLongLong());
} else if (info->action().actionTypeId() == mockInputTypeWritableUIntActionTypeId) { } else if (info->action().actionTypeId() == inputTypeMockWritableUIntActionTypeId) {
info->thing()->setStateValue(mockInputTypeWritableUIntStateTypeId, info->action().param(mockInputTypeWritableUIntActionWritableUIntParamTypeId).value().toULongLong()); info->thing()->setStateValue(inputTypeMockWritableUIntStateTypeId, info->action().param(inputTypeMockWritableUIntActionWritableUIntParamTypeId).value().toULongLong());
} else if (info->action().actionTypeId() == mockInputTypeWritableUIntMinMaxActionTypeId) { } else if (info->action().actionTypeId() == inputTypeMockWritableUIntMinMaxActionTypeId) {
info->thing()->setStateValue(mockInputTypeWritableUIntMinMaxStateTypeId, info->action().param(mockInputTypeWritableUIntMinMaxActionWritableUIntMinMaxParamTypeId).value().toLongLong()); info->thing()->setStateValue(inputTypeMockWritableUIntMinMaxStateTypeId, info->action().param(inputTypeMockWritableUIntMinMaxActionWritableUIntMinMaxParamTypeId).value().toLongLong());
} else if (info->action().actionTypeId() == mockInputTypeWritableDoubleActionTypeId) { } else if (info->action().actionTypeId() == inputTypeMockWritableDoubleActionTypeId) {
info->thing()->setStateValue(mockInputTypeWritableDoubleStateTypeId, info->action().param(mockInputTypeWritableDoubleActionWritableDoubleParamTypeId).value().toDouble()); info->thing()->setStateValue(inputTypeMockWritableDoubleStateTypeId, info->action().param(inputTypeMockWritableDoubleActionWritableDoubleParamTypeId).value().toDouble());
} else if (info->action().actionTypeId() == mockInputTypeWritableDoubleMinMaxActionTypeId) { } else if (info->action().actionTypeId() == inputTypeMockWritableDoubleMinMaxActionTypeId) {
info->thing()->setStateValue(mockInputTypeWritableDoubleMinMaxStateTypeId, info->action().param(mockInputTypeWritableDoubleMinMaxActionWritableDoubleMinMaxParamTypeId).value().toDouble()); info->thing()->setStateValue(inputTypeMockWritableDoubleMinMaxStateTypeId, info->action().param(inputTypeMockWritableDoubleMinMaxActionWritableDoubleMinMaxParamTypeId).value().toDouble());
} else if (info->action().actionTypeId() == mockInputTypeWritableStringActionTypeId) { } else if (info->action().actionTypeId() == inputTypeMockWritableStringActionTypeId) {
info->thing()->setStateValue(mockInputTypeWritableStringStateTypeId, info->action().param(mockInputTypeWritableStringActionWritableStringParamTypeId).value().toString()); info->thing()->setStateValue(inputTypeMockWritableStringStateTypeId, info->action().param(inputTypeMockWritableStringActionWritableStringParamTypeId).value().toString());
} else if (info->action().actionTypeId() == mockInputTypeWritableStringSelectionActionTypeId) { } else if (info->action().actionTypeId() == inputTypeMockWritableStringSelectionActionTypeId) {
info->thing()->setStateValue(mockInputTypeWritableStringSelectionStateTypeId, info->action().param(mockInputTypeWritableStringSelectionActionWritableStringSelectionParamTypeId).value().toString()); info->thing()->setStateValue(inputTypeMockWritableStringSelectionStateTypeId, info->action().param(inputTypeMockWritableStringSelectionActionWritableStringSelectionParamTypeId).value().toString());
} else if (info->action().actionTypeId() == mockInputTypeWritableColorActionTypeId) { } else if (info->action().actionTypeId() == inputTypeMockWritableColorActionTypeId) {
info->thing()->setStateValue(mockInputTypeWritableColorStateTypeId, info->action().param(mockInputTypeWritableColorActionWritableColorParamTypeId).value().toString()); info->thing()->setStateValue(inputTypeMockWritableColorStateTypeId, info->action().param(inputTypeMockWritableColorActionWritableColorParamTypeId).value().toString());
} else if (info->action().actionTypeId() == mockInputTypeWritableTimeActionTypeId) { } else if (info->action().actionTypeId() == inputTypeMockWritableTimeActionTypeId) {
info->thing()->setStateValue(mockInputTypeWritableTimeStateTypeId, info->action().param(mockInputTypeWritableTimeActionWritableTimeParamTypeId).value().toTime()); info->thing()->setStateValue(inputTypeMockWritableTimeStateTypeId, info->action().param(inputTypeMockWritableTimeActionWritableTimeParamTypeId).value().toTime());
} else if (info->action().actionTypeId() == mockInputTypeWritableTimestampIntActionTypeId) { } else if (info->action().actionTypeId() == inputTypeMockWritableTimestampIntActionTypeId) {
info->thing()->setStateValue(mockInputTypeWritableTimestampIntStateTypeId, info->action().param(mockInputTypeWritableTimestampIntActionWritableTimestampIntParamTypeId).value().toLongLong()); info->thing()->setStateValue(inputTypeMockWritableTimestampIntStateTypeId, info->action().param(inputTypeMockWritableTimestampIntActionWritableTimestampIntParamTypeId).value().toLongLong());
} else if (info->action().actionTypeId() == mockInputTypeWritableTimestampUIntActionTypeId) { } else if (info->action().actionTypeId() == inputTypeMockWritableTimestampUIntActionTypeId) {
info->thing()->setStateValue(mockInputTypeWritableTimestampUIntStateTypeId, info->action().param(mockInputTypeWritableTimestampUIntActionWritableTimestampUIntParamTypeId).value().toULongLong()); info->thing()->setStateValue(inputTypeMockWritableTimestampUIntStateTypeId, info->action().param(inputTypeMockWritableTimestampUIntActionWritableTimestampUIntParamTypeId).value().toULongLong());
} }
return; return;
@ -713,9 +713,9 @@ void DevicePluginMock::executeAction(ThingActionInfo *info)
void DevicePluginMock::executeBrowserItem(BrowserActionInfo *info) void DevicePluginMock::executeBrowserItem(BrowserActionInfo *info)
{ {
qCDebug(dcMockDevice()) << "ExecuteBrowserItem called" << info->browserAction().itemId(); qCDebug(dcMock()) << "ExecuteBrowserItem called" << info->browserAction().itemId();
bool broken = info->thing()->paramValue(mockDeviceBrokenParamTypeId).toBool(); bool broken = info->thing()->paramValue(mockThingBrokenParamTypeId).toBool();
bool async = info->thing()->paramValue(mockDeviceAsyncParamTypeId).toBool(); bool async = info->thing()->paramValue(mockThingAsyncParamTypeId).toBool();
VirtualFsNode *node = m_virtualFs->findNode(info->browserAction().itemId()); VirtualFsNode *node = m_virtualFs->findNode(info->browserAction().itemId());
if (!node) { if (!node) {
@ -745,7 +745,7 @@ void DevicePluginMock::executeBrowserItem(BrowserActionInfo *info)
void DevicePluginMock::executeBrowserItemAction(BrowserItemActionInfo *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) { if (info->browserItemAction().actionTypeId() == mockAddToFavoritesBrowserItemActionTypeId) {
VirtualFsNode *node = m_virtualFs->findNode(info->browserItemAction().itemId()); VirtualFsNode *node = m_virtualFs->findNode(info->browserItemAction().itemId());
@ -803,7 +803,7 @@ void DevicePluginMock::triggerEvent(const EventTypeId &id)
Event event(id, device->id()); Event event(id, device->id());
qCDebug(dcMockDevice) << "Emitting event " << event.eventTypeId(); qCDebug(dcMock) << "Emitting event " << event.eventTypeId();
emit emitEvent(event); emit emitEvent(event);
} }
@ -814,7 +814,7 @@ void DevicePluginMock::onDisappear()
return; return;
} }
Thing *device = m_daemons.key(daemon); 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()); emit autoThingDisappeared(device->id());
} }
@ -825,15 +825,15 @@ void DevicePluginMock::onReconfigureAutoDevice()
return; return;
Thing *device = m_daemons.key(daemon); 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 // Note: the reconfigure makes the http server listen on port + 1
ParamList params; 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.setTitle(device->name() + " (reconfigured)");
deviceDescriptor.setDescription("This auto device was reconfigured"); deviceDescriptor.setDescription("This auto device was reconfigured");
deviceDescriptor.setThingId(device->id()); deviceDescriptor.setThingId(device->id());
@ -847,11 +847,11 @@ void DevicePluginMock::generateDiscoveredDevices(ThingDiscoveryInfo *info)
if (m_discoveredDeviceCount > 0) { if (m_discoveredDeviceCount > 0) {
ThingDescriptor d1(mockThingClassId, "Mock Device 1 (Discovered)", "55555"); ThingDescriptor d1(mockThingClassId, "Mock Device 1 (Discovered)", "55555");
ParamList params; ParamList params;
Param httpParam(mockDeviceHttpportParamTypeId, "55555"); Param httpParam(mockThingHttpportParamTypeId, "55555");
params.append(httpParam); params.append(httpParam);
d1.setParams(params); d1.setParams(params);
foreach (Thing *d, myThings()) { 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()); d1.setThingId(d->id());
break; break;
} }
@ -862,11 +862,11 @@ void DevicePluginMock::generateDiscoveredDevices(ThingDiscoveryInfo *info)
if (m_discoveredDeviceCount > 1) { if (m_discoveredDeviceCount > 1) {
ThingDescriptor d2(mockThingClassId, "Mock Device 2 (Discovered)", "55556"); ThingDescriptor d2(mockThingClassId, "Mock Device 2 (Discovered)", "55556");
ParamList params; ParamList params;
Param httpParam(mockDeviceHttpportParamTypeId, "55556"); Param httpParam(mockThingHttpportParamTypeId, "55556");
params.append(httpParam); params.append(httpParam);
d2.setParams(params); d2.setParams(params);
foreach (Thing *d, myThings()) { 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()); d2.setThingId(d->id());
break; break;
} }
@ -880,23 +880,23 @@ void DevicePluginMock::generateDiscoveredDevices(ThingDiscoveryInfo *info)
void DevicePluginMock::generateDiscoveredPushButtonDevices(ThingDiscoveryInfo *info) void DevicePluginMock::generateDiscoveredPushButtonDevices(ThingDiscoveryInfo *info)
{ {
if (m_discoveredDeviceCount > 0) { if (m_discoveredDeviceCount > 0) {
ThingDescriptor d1(mockPushButtonThingClassId, "Mock Device (Push Button)", "1"); ThingDescriptor d1(pushButtonMockThingClassId, "Mocked Thing (Push Button)", "1");
info->addThingDescriptor(d1); info->addThingDescriptor(d1);
} }
if (m_discoveredDeviceCount > 1) { if (m_discoveredDeviceCount > 1) {
ThingDescriptor d2(mockPushButtonThingClassId, "Mock Device (Push Button)", "2"); ThingDescriptor d2(pushButtonMockThingClassId, "Mocked Thhing (Push Button)", "2");
info->addThingDescriptor(d2); 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) void DevicePluginMock::generateDiscoveredDisplayPinDevices(ThingDiscoveryInfo *info)
{ {
if (m_discoveredDeviceCount > 0) { if (m_discoveredDeviceCount > 0) {
ThingDescriptor d1(mockDisplayPinThingClassId, "Mock Device (Display Pin)", "1"); ThingDescriptor d1(displayPinMockThingClassId, "Mocked Thing (Display Pin)", "1");
foreach (Thing *existingDev, myThings()) { foreach (Thing *existingDev, myThings()) {
if (existingDev->thingClassId() == mockDisplayPinThingClassId) { if (existingDev->thingClassId() == displayPinMockThingClassId) {
d1.setThingId(existingDev->id()); d1.setThingId(existingDev->id());
break; break;
} }
@ -905,10 +905,10 @@ void DevicePluginMock::generateDiscoveredDisplayPinDevices(ThingDiscoveryInfo *i
} }
if (m_discoveredDeviceCount > 1) { if (m_discoveredDeviceCount > 1) {
ThingDescriptor d2(mockDisplayPinThingClassId, "Mock Device (Display Pin)", "2"); ThingDescriptor d2(displayPinMockThingClassId, "Mocked Thing (Display Pin)", "2");
int count = 0; int count = 0;
foreach (Thing *existingDev, myThings()) { foreach (Thing *existingDev, myThings()) {
if (existingDev->thingClassId() == mockDisplayPinThingClassId && ++count > 1) { if (existingDev->thingClassId() == displayPinMockThingClassId && ++count > 1) {
d2.setThingId(existingDev->id()); d2.setThingId(existingDev->id());
break; break;
} }
@ -921,7 +921,7 @@ void DevicePluginMock::generateDiscoveredDisplayPinDevices(ThingDiscoveryInfo *i
void DevicePluginMock::onPushButtonPressed() void DevicePluginMock::onPushButtonPressed()
{ {
qCDebug(dcMockDevice) << "PushButton pressed (automatically)"; qCDebug(dcMock) << "PushButton pressed (automatically)";
m_pushbuttonPressed = true; m_pushbuttonPressed = true;
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "mockDevice", "name": "mock",
"displayName": "Mock Devices", "displayName": "Mocked things",
"id": "727a4a9a-c187-446f-aadf-f1b2220607d1", "id": "727a4a9a-c187-446f-aadf-f1b2220607d1",
"paramTypes": [ "paramTypes": [
{ {
@ -29,7 +29,7 @@
{ {
"id": "753f0d32-0468-4d08-82ed-1964aab03298", "id": "753f0d32-0468-4d08-82ed-1964aab03298",
"name": "mock", "name": "mock",
"displayName": "Mock Device", "displayName": "Mock Thing",
"interfaces": ["system", "light", "battery"], "interfaces": ["system", "light", "battery"],
"createMethods": ["user", "discovery"], "createMethods": ["user", "discovery"],
"browsable": true, "browsable": true,
@ -210,8 +210,8 @@
}, },
{ {
"id": "ab4257b3-7548-47ee-9bd4-7dc3004fd197", "id": "ab4257b3-7548-47ee-9bd4-7dc3004fd197",
"name": "mockDeviceAuto", "name": "autoMock",
"displayName": "Mock Device (Auto created)", "displayName": "Mocked Thing (Auto created)",
"interfaces": ["system"], "interfaces": ["system"],
"createMethods": ["auto"], "createMethods": ["auto"],
"paramTypes": [ "paramTypes": [
@ -321,8 +321,8 @@
}, },
{ {
"id": "9e03144c-e436-4eea-82d9-ccb33ef778db", "id": "9e03144c-e436-4eea-82d9-ccb33ef778db",
"name": "mockPushButton", "name": "pushButtonMock",
"displayName": "Mock Device (Push Button)", "displayName": "Mocked Thing (Push Button)",
"interfaces": ["system"], "interfaces": ["system"],
"createMethods": ["discovery"], "createMethods": ["discovery"],
"setupMethod": "pushButton", "setupMethod": "pushButton",
@ -410,8 +410,8 @@
}, },
{ {
"id": "296f1fd4-e893-46b2-8a42-50d1bceb8730", "id": "296f1fd4-e893-46b2-8a42-50d1bceb8730",
"name": "mockDisplayPin", "name": "displayPinMock",
"displayName": "Mock Device (Display Pin)", "displayName": "Mocked Thing (Display Pin)",
"interfaces": ["system"], "interfaces": ["system"],
"createMethods": ["discovery"], "createMethods": ["discovery"],
"setupMethod": "displayPin", "setupMethod": "displayPin",
@ -509,8 +509,8 @@
}, },
{ {
"id": "a71fbde9-9a38-4bf8-beab-c8aade2608ba", "id": "a71fbde9-9a38-4bf8-beab-c8aade2608ba",
"name": "mockParent", "name": "parentMock",
"displayName": "Mock Device (Parent)", "displayName": "Mocked Thing (Parent)",
"interfaces": ["system"], "interfaces": ["system"],
"createMethods": ["user", "discovery"], "createMethods": ["user", "discovery"],
"paramTypes": [ ], "paramTypes": [ ],
@ -529,8 +529,8 @@
}, },
{ {
"id": "40893c9f-bc47-40c1-8bf7-b390c7c1b4fc", "id": "40893c9f-bc47-40c1-8bf7-b390c7c1b4fc",
"name": "mockChild", "name": "childMock",
"displayName": "Mock Device (Child)", "displayName": "Mocked Thing (Child)",
"createMethods": ["auto", "discovery"], "createMethods": ["auto", "discovery"],
"paramTypes": [], "paramTypes": [],
"stateTypes": [ "stateTypes": [
@ -548,8 +548,8 @@
}, },
{ {
"id": "515ffdf1-55e5-498d-9abc-4e2fe768f3a9", "id": "515ffdf1-55e5-498d-9abc-4e2fe768f3a9",
"name": "mockInputType", "name": "inputTypeMock",
"displayName": "Mock Device (InputTypes)", "displayName": "Mocked Thing (InputTypes)",
"createMethods": ["user"], "createMethods": ["user"],
"paramTypes": [ "paramTypes": [
{ {
@ -850,22 +850,22 @@
}, },
{ {
"id": "805d1692-7bd0-449a-9d5c-43a332ff58f4", "id": "805d1692-7bd0-449a-9d5c-43a332ff58f4",
"name": "mockOAuthGoogle", "name": "oAuthGoogleMock",
"displayName": "Mock Device (Google OAuth)", "displayName": "Mocked Thing (Google OAuth)",
"createMethods": ["user"], "createMethods": ["user"],
"setupMethod": "oauth" "setupMethod": "oauth"
}, },
{ {
"id": "783c615b-7bd6-49a4-98b0-8d1deb3c7156", "id": "783c615b-7bd6-49a4-98b0-8d1deb3c7156",
"name": "mockOAuthSonos", "name": "oAuthSonosMock",
"displayName": "Mock Device (Sonos OAuth)", "displayName": "Mocked Thing (Sonos OAuth)",
"createMethods": ["user"], "createMethods": ["user"],
"setupMethod": "oauth" "setupMethod": "oauth"
}, },
{ {
"id": "6fe07a77-9c07-4736-81e2-d504314bbcb9", "id": "6fe07a77-9c07-4736-81e2-d504314bbcb9",
"name": "mockUserAndPass", "name": "userAndPassMock",
"displayName": "Mock Device (User & Password)", "displayName": "Mocked Thing (User & Password)",
"createMethods": ["discovery", "user"], "createMethods": ["discovery", "user"],
"setupMethod": "userandpassword" "setupMethod": "userandpassword"
} }

View File

@ -8,16 +8,16 @@
#include <QLoggingCategory> #include <QLoggingCategory>
Q_DECLARE_LOGGING_CATEGORY(dcMockDevice) Q_DECLARE_LOGGING_CATEGORY(dcMock)
extern PluginId pluginId; extern PluginId pluginId;
extern ParamTypeId mockDevicePluginConfigParamIntParamTypeId; extern ParamTypeId mockPluginConfigParamIntParamTypeId;
extern ParamTypeId mockDevicePluginConfigParamBoolParamTypeId; extern ParamTypeId mockPluginConfigParamBoolParamTypeId;
extern VendorId nymeaVendorId; extern VendorId nymeaVendorId;
extern ThingClassId mockThingClassId; extern ThingClassId mockThingClassId;
extern ParamTypeId mockDeviceHttpportParamTypeId; extern ParamTypeId mockThingHttpportParamTypeId;
extern ParamTypeId mockDeviceAsyncParamTypeId; extern ParamTypeId mockThingAsyncParamTypeId;
extern ParamTypeId mockDeviceBrokenParamTypeId; extern ParamTypeId mockThingBrokenParamTypeId;
extern ParamTypeId mockSettingsSetting1ParamTypeId; extern ParamTypeId mockSettingsSetting1ParamTypeId;
extern ParamTypeId mockDiscoveryResultCountParamTypeId; extern ParamTypeId mockDiscoveryResultCountParamTypeId;
extern StateTypeId mockIntStateTypeId; extern StateTypeId mockIntStateTypeId;
@ -52,199 +52,199 @@ extern ActionTypeId mockFailingActionTypeId;
extern ActionTypeId mockAsyncFailingActionTypeId; extern ActionTypeId mockAsyncFailingActionTypeId;
extern ActionTypeId mockAddToFavoritesBrowserItemActionTypeId; extern ActionTypeId mockAddToFavoritesBrowserItemActionTypeId;
extern ActionTypeId mockRemoveFromFavoritesBrowserItemActionTypeId; extern ActionTypeId mockRemoveFromFavoritesBrowserItemActionTypeId;
extern ThingClassId mockDeviceAutoThingClassId; extern ThingClassId autoMockThingClassId;
extern ParamTypeId mockDeviceAutoDeviceHttpportParamTypeId; extern ParamTypeId autoMockThingHttpportParamTypeId;
extern ParamTypeId mockDeviceAutoDeviceAsyncParamTypeId; extern ParamTypeId autoMockThingAsyncParamTypeId;
extern ParamTypeId mockDeviceAutoDeviceBrokenParamTypeId; extern ParamTypeId autoMockThingBrokenParamTypeId;
extern StateTypeId mockDeviceAutoIntStateTypeId; extern StateTypeId autoMockIntStateTypeId;
extern StateTypeId mockDeviceAutoBoolValueStateTypeId; extern StateTypeId autoMockBoolValueStateTypeId;
extern EventTypeId mockDeviceAutoIntEventTypeId; extern EventTypeId autoMockIntEventTypeId;
extern ParamTypeId mockDeviceAutoIntEventIntParamTypeId; extern ParamTypeId autoMockIntEventIntParamTypeId;
extern EventTypeId mockDeviceAutoBoolValueEventTypeId; extern EventTypeId autoMockBoolValueEventTypeId;
extern ParamTypeId mockDeviceAutoBoolValueEventBoolValueParamTypeId; extern ParamTypeId autoMockBoolValueEventBoolValueParamTypeId;
extern EventTypeId mockDeviceAutoEvent1EventTypeId; extern EventTypeId autoMockEvent1EventTypeId;
extern EventTypeId mockDeviceAutoEvent2EventTypeId; extern EventTypeId autoMockEvent2EventTypeId;
extern ParamTypeId mockDeviceAutoEvent2EventIntParamParamTypeId; extern ParamTypeId autoMockEvent2EventIntParamParamTypeId;
extern ActionTypeId mockDeviceAutoWithParamsActionTypeId; extern ActionTypeId autoMockWithParamsActionTypeId;
extern ParamTypeId mockDeviceAutoWithParamsActionMockActionParam1ParamTypeId; extern ParamTypeId autoMockWithParamsActionMockActionParam1ParamTypeId;
extern ParamTypeId mockDeviceAutoWithParamsActionMockActionParam2ParamTypeId; extern ParamTypeId autoMockWithParamsActionMockActionParam2ParamTypeId;
extern ActionTypeId mockDeviceAutoMockActionNoParmsActionTypeId; extern ActionTypeId autoMockMockActionNoParmsActionTypeId;
extern ActionTypeId mockDeviceAutoMockActionAsyncActionTypeId; extern ActionTypeId autoMockMockActionAsyncActionTypeId;
extern ActionTypeId mockDeviceAutoMockActionBrokenActionTypeId; extern ActionTypeId autoMockMockActionBrokenActionTypeId;
extern ActionTypeId mockDeviceAutoMockActionAsyncBrokenActionTypeId; extern ActionTypeId autoMockMockActionAsyncBrokenActionTypeId;
extern ThingClassId mockPushButtonThingClassId; extern ThingClassId pushButtonMockThingClassId;
extern ParamTypeId mockPushButtonDiscoveryResultCountParamTypeId; extern ParamTypeId pushButtonMockDiscoveryResultCountParamTypeId;
extern StateTypeId mockPushButtonColorStateTypeId; extern StateTypeId pushButtonMockColorStateTypeId;
extern StateTypeId mockPushButtonPercentageStateTypeId; extern StateTypeId pushButtonMockPercentageStateTypeId;
extern StateTypeId mockPushButtonAllowedValuesStateTypeId; extern StateTypeId pushButtonMockAllowedValuesStateTypeId;
extern StateTypeId mockPushButtonDoubleStateTypeId; extern StateTypeId pushButtonMockDoubleStateTypeId;
extern StateTypeId mockPushButtonBoolStateTypeId; extern StateTypeId pushButtonMockBoolStateTypeId;
extern EventTypeId mockPushButtonColorEventTypeId; extern EventTypeId pushButtonMockColorEventTypeId;
extern ParamTypeId mockPushButtonColorEventColorParamTypeId; extern ParamTypeId pushButtonMockColorEventColorParamTypeId;
extern EventTypeId mockPushButtonPercentageEventTypeId; extern EventTypeId pushButtonMockPercentageEventTypeId;
extern ParamTypeId mockPushButtonPercentageEventPercentageParamTypeId; extern ParamTypeId pushButtonMockPercentageEventPercentageParamTypeId;
extern EventTypeId mockPushButtonAllowedValuesEventTypeId; extern EventTypeId pushButtonMockAllowedValuesEventTypeId;
extern ParamTypeId mockPushButtonAllowedValuesEventAllowedValuesParamTypeId; extern ParamTypeId pushButtonMockAllowedValuesEventAllowedValuesParamTypeId;
extern EventTypeId mockPushButtonDoubleEventTypeId; extern EventTypeId pushButtonMockDoubleEventTypeId;
extern ParamTypeId mockPushButtonDoubleEventDoubleParamTypeId; extern ParamTypeId pushButtonMockDoubleEventDoubleParamTypeId;
extern EventTypeId mockPushButtonBoolEventTypeId; extern EventTypeId pushButtonMockBoolEventTypeId;
extern ParamTypeId mockPushButtonBoolEventBoolParamTypeId; extern ParamTypeId pushButtonMockBoolEventBoolParamTypeId;
extern ActionTypeId mockPushButtonColorActionTypeId; extern ActionTypeId pushButtonMockColorActionTypeId;
extern ParamTypeId mockPushButtonColorActionColorParamTypeId; extern ParamTypeId pushButtonMockColorActionColorParamTypeId;
extern ActionTypeId mockPushButtonPercentageActionTypeId; extern ActionTypeId pushButtonMockPercentageActionTypeId;
extern ParamTypeId mockPushButtonPercentageActionPercentageParamTypeId; extern ParamTypeId pushButtonMockPercentageActionPercentageParamTypeId;
extern ActionTypeId mockPushButtonAllowedValuesActionTypeId; extern ActionTypeId pushButtonMockAllowedValuesActionTypeId;
extern ParamTypeId mockPushButtonAllowedValuesActionAllowedValuesParamTypeId; extern ParamTypeId pushButtonMockAllowedValuesActionAllowedValuesParamTypeId;
extern ActionTypeId mockPushButtonDoubleActionTypeId; extern ActionTypeId pushButtonMockDoubleActionTypeId;
extern ParamTypeId mockPushButtonDoubleActionDoubleParamTypeId; extern ParamTypeId pushButtonMockDoubleActionDoubleParamTypeId;
extern ActionTypeId mockPushButtonBoolActionTypeId; extern ActionTypeId pushButtonMockBoolActionTypeId;
extern ParamTypeId mockPushButtonBoolActionBoolParamTypeId; extern ParamTypeId pushButtonMockBoolActionBoolParamTypeId;
extern ActionTypeId mockPushButtonTimeoutActionTypeId; extern ActionTypeId pushButtonMockTimeoutActionTypeId;
extern ThingClassId mockDisplayPinThingClassId; extern ThingClassId displayPinMockThingClassId;
extern ParamTypeId mockDisplayPinDevicePinParamTypeId; extern ParamTypeId displayPinMockThingPinParamTypeId;
extern ParamTypeId mockDisplayPinDiscoveryResultCountParamTypeId; extern ParamTypeId displayPinMockDiscoveryResultCountParamTypeId;
extern StateTypeId mockDisplayPinColorStateTypeId; extern StateTypeId displayPinMockColorStateTypeId;
extern StateTypeId mockDisplayPinPercentageStateTypeId; extern StateTypeId displayPinMockPercentageStateTypeId;
extern StateTypeId mockDisplayPinAllowedValuesStateTypeId; extern StateTypeId displayPinMockAllowedValuesStateTypeId;
extern StateTypeId mockDisplayPinDoubleStateTypeId; extern StateTypeId displayPinMockDoubleStateTypeId;
extern StateTypeId mockDisplayPinBoolStateTypeId; extern StateTypeId displayPinMockBoolStateTypeId;
extern EventTypeId mockDisplayPinColorEventTypeId; extern EventTypeId displayPinMockColorEventTypeId;
extern ParamTypeId mockDisplayPinColorEventColorParamTypeId; extern ParamTypeId displayPinMockColorEventColorParamTypeId;
extern EventTypeId mockDisplayPinPercentageEventTypeId; extern EventTypeId displayPinMockPercentageEventTypeId;
extern ParamTypeId mockDisplayPinPercentageEventPercentageParamTypeId; extern ParamTypeId displayPinMockPercentageEventPercentageParamTypeId;
extern EventTypeId mockDisplayPinAllowedValuesEventTypeId; extern EventTypeId displayPinMockAllowedValuesEventTypeId;
extern ParamTypeId mockDisplayPinAllowedValuesEventAllowedValuesParamTypeId; extern ParamTypeId displayPinMockAllowedValuesEventAllowedValuesParamTypeId;
extern EventTypeId mockDisplayPinDoubleEventTypeId; extern EventTypeId displayPinMockDoubleEventTypeId;
extern ParamTypeId mockDisplayPinDoubleEventDoubleParamTypeId; extern ParamTypeId displayPinMockDoubleEventDoubleParamTypeId;
extern EventTypeId mockDisplayPinBoolEventTypeId; extern EventTypeId displayPinMockBoolEventTypeId;
extern ParamTypeId mockDisplayPinBoolEventBoolParamTypeId; extern ParamTypeId displayPinMockBoolEventBoolParamTypeId;
extern ActionTypeId mockDisplayPinColorActionTypeId; extern ActionTypeId displayPinMockColorActionTypeId;
extern ParamTypeId mockDisplayPinColorActionColorParamTypeId; extern ParamTypeId displayPinMockColorActionColorParamTypeId;
extern ActionTypeId mockDisplayPinPercentageActionTypeId; extern ActionTypeId displayPinMockPercentageActionTypeId;
extern ParamTypeId mockDisplayPinPercentageActionPercentageParamTypeId; extern ParamTypeId displayPinMockPercentageActionPercentageParamTypeId;
extern ActionTypeId mockDisplayPinAllowedValuesActionTypeId; extern ActionTypeId displayPinMockAllowedValuesActionTypeId;
extern ParamTypeId mockDisplayPinAllowedValuesActionAllowedValuesParamTypeId; extern ParamTypeId displayPinMockAllowedValuesActionAllowedValuesParamTypeId;
extern ActionTypeId mockDisplayPinDoubleActionTypeId; extern ActionTypeId displayPinMockDoubleActionTypeId;
extern ParamTypeId mockDisplayPinDoubleActionDoubleParamTypeId; extern ParamTypeId displayPinMockDoubleActionDoubleParamTypeId;
extern ActionTypeId mockDisplayPinBoolActionTypeId; extern ActionTypeId displayPinMockBoolActionTypeId;
extern ParamTypeId mockDisplayPinBoolActionBoolParamTypeId; extern ParamTypeId displayPinMockBoolActionBoolParamTypeId;
extern ActionTypeId mockDisplayPinTimeoutActionTypeId; extern ActionTypeId displayPinMockTimeoutActionTypeId;
extern ThingClassId mockParentThingClassId; extern ThingClassId parentMockThingClassId;
extern StateTypeId mockParentBoolValueStateTypeId; extern StateTypeId parentMockBoolValueStateTypeId;
extern EventTypeId mockParentBoolValueEventTypeId; extern EventTypeId parentMockBoolValueEventTypeId;
extern ParamTypeId mockParentBoolValueEventBoolValueParamTypeId; extern ParamTypeId parentMockBoolValueEventBoolValueParamTypeId;
extern ActionTypeId mockParentBoolValueActionTypeId; extern ActionTypeId parentMockBoolValueActionTypeId;
extern ParamTypeId mockParentBoolValueActionBoolValueParamTypeId; extern ParamTypeId parentMockBoolValueActionBoolValueParamTypeId;
extern ThingClassId mockChildThingClassId; extern ThingClassId childMockThingClassId;
extern StateTypeId mockChildBoolValueStateTypeId; extern StateTypeId childMockBoolValueStateTypeId;
extern EventTypeId mockChildBoolValueEventTypeId; extern EventTypeId childMockBoolValueEventTypeId;
extern ParamTypeId mockChildBoolValueEventBoolValueParamTypeId; extern ParamTypeId childMockBoolValueEventBoolValueParamTypeId;
extern ActionTypeId mockChildBoolValueActionTypeId; extern ActionTypeId childMockBoolValueActionTypeId;
extern ParamTypeId mockChildBoolValueActionBoolValueParamTypeId; extern ParamTypeId childMockBoolValueActionBoolValueParamTypeId;
extern ThingClassId mockInputTypeThingClassId; extern ThingClassId inputTypeMockThingClassId;
extern ParamTypeId mockInputTypeDeviceTextLineParamTypeId; extern ParamTypeId inputTypeMockThingTextLineParamTypeId;
extern ParamTypeId mockInputTypeDeviceTextAreaParamTypeId; extern ParamTypeId inputTypeMockThingTextAreaParamTypeId;
extern ParamTypeId mockInputTypeDevicePasswordParamTypeId; extern ParamTypeId inputTypeMockThingPasswordParamTypeId;
extern ParamTypeId mockInputTypeDeviceSearchParamTypeId; extern ParamTypeId inputTypeMockThingSearchParamTypeId;
extern ParamTypeId mockInputTypeDeviceMailParamTypeId; extern ParamTypeId inputTypeMockThingMailParamTypeId;
extern ParamTypeId mockInputTypeDeviceIp4ParamTypeId; extern ParamTypeId inputTypeMockThingIp4ParamTypeId;
extern ParamTypeId mockInputTypeDeviceIp6ParamTypeId; extern ParamTypeId inputTypeMockThingIp6ParamTypeId;
extern ParamTypeId mockInputTypeDeviceUrlParamTypeId; extern ParamTypeId inputTypeMockThingUrlParamTypeId;
extern ParamTypeId mockInputTypeDeviceMacParamTypeId; extern ParamTypeId inputTypeMockThingMacParamTypeId;
extern StateTypeId mockInputTypeBoolStateTypeId; extern StateTypeId inputTypeMockBoolStateTypeId;
extern StateTypeId mockInputTypeWritableBoolStateTypeId; extern StateTypeId inputTypeMockWritableBoolStateTypeId;
extern StateTypeId mockInputTypeIntStateTypeId; extern StateTypeId inputTypeMockIntStateTypeId;
extern StateTypeId mockInputTypeWritableIntStateTypeId; extern StateTypeId inputTypeMockWritableIntStateTypeId;
extern StateTypeId mockInputTypeWritableIntMinMaxStateTypeId; extern StateTypeId inputTypeMockWritableIntMinMaxStateTypeId;
extern StateTypeId mockInputTypeUintStateTypeId; extern StateTypeId inputTypeMockUintStateTypeId;
extern StateTypeId mockInputTypeWritableUIntStateTypeId; extern StateTypeId inputTypeMockWritableUIntStateTypeId;
extern StateTypeId mockInputTypeWritableUIntMinMaxStateTypeId; extern StateTypeId inputTypeMockWritableUIntMinMaxStateTypeId;
extern StateTypeId mockInputTypeDoubleStateTypeId; extern StateTypeId inputTypeMockDoubleStateTypeId;
extern StateTypeId mockInputTypeWritableDoubleStateTypeId; extern StateTypeId inputTypeMockWritableDoubleStateTypeId;
extern StateTypeId mockInputTypeWritableDoubleMinMaxStateTypeId; extern StateTypeId inputTypeMockWritableDoubleMinMaxStateTypeId;
extern StateTypeId mockInputTypeStringStateTypeId; extern StateTypeId inputTypeMockStringStateTypeId;
extern StateTypeId mockInputTypeWritableStringStateTypeId; extern StateTypeId inputTypeMockWritableStringStateTypeId;
extern StateTypeId mockInputTypeWritableStringSelectionStateTypeId; extern StateTypeId inputTypeMockWritableStringSelectionStateTypeId;
extern StateTypeId mockInputTypeColorStateTypeId; extern StateTypeId inputTypeMockColorStateTypeId;
extern StateTypeId mockInputTypeWritableColorStateTypeId; extern StateTypeId inputTypeMockWritableColorStateTypeId;
extern StateTypeId mockInputTypeTimeStateTypeId; extern StateTypeId inputTypeMockTimeStateTypeId;
extern StateTypeId mockInputTypeWritableTimeStateTypeId; extern StateTypeId inputTypeMockWritableTimeStateTypeId;
extern StateTypeId mockInputTypeTimestampIntStateTypeId; extern StateTypeId inputTypeMockTimestampIntStateTypeId;
extern StateTypeId mockInputTypeWritableTimestampIntStateTypeId; extern StateTypeId inputTypeMockWritableTimestampIntStateTypeId;
extern StateTypeId mockInputTypeTimestampUIntStateTypeId; extern StateTypeId inputTypeMockTimestampUIntStateTypeId;
extern StateTypeId mockInputTypeWritableTimestampUIntStateTypeId; extern StateTypeId inputTypeMockWritableTimestampUIntStateTypeId;
extern EventTypeId mockInputTypeBoolEventTypeId; extern EventTypeId inputTypeMockBoolEventTypeId;
extern ParamTypeId mockInputTypeBoolEventBoolParamTypeId; extern ParamTypeId inputTypeMockBoolEventBoolParamTypeId;
extern EventTypeId mockInputTypeWritableBoolEventTypeId; extern EventTypeId inputTypeMockWritableBoolEventTypeId;
extern ParamTypeId mockInputTypeWritableBoolEventWritableBoolParamTypeId; extern ParamTypeId inputTypeMockWritableBoolEventWritableBoolParamTypeId;
extern EventTypeId mockInputTypeIntEventTypeId; extern EventTypeId inputTypeMockIntEventTypeId;
extern ParamTypeId mockInputTypeIntEventIntParamTypeId; extern ParamTypeId inputTypeMockIntEventIntParamTypeId;
extern EventTypeId mockInputTypeWritableIntEventTypeId; extern EventTypeId inputTypeMockWritableIntEventTypeId;
extern ParamTypeId mockInputTypeWritableIntEventWritableIntParamTypeId; extern ParamTypeId inputTypeMockWritableIntEventWritableIntParamTypeId;
extern EventTypeId mockInputTypeWritableIntMinMaxEventTypeId; extern EventTypeId inputTypeMockWritableIntMinMaxEventTypeId;
extern ParamTypeId mockInputTypeWritableIntMinMaxEventWritableIntMinMaxParamTypeId; extern ParamTypeId inputTypeMockWritableIntMinMaxEventWritableIntMinMaxParamTypeId;
extern EventTypeId mockInputTypeUintEventTypeId; extern EventTypeId inputTypeMockUintEventTypeId;
extern ParamTypeId mockInputTypeUintEventUintParamTypeId; extern ParamTypeId inputTypeMockUintEventUintParamTypeId;
extern EventTypeId mockInputTypeWritableUIntEventTypeId; extern EventTypeId inputTypeMockWritableUIntEventTypeId;
extern ParamTypeId mockInputTypeWritableUIntEventWritableUIntParamTypeId; extern ParamTypeId inputTypeMockWritableUIntEventWritableUIntParamTypeId;
extern EventTypeId mockInputTypeWritableUIntMinMaxEventTypeId; extern EventTypeId inputTypeMockWritableUIntMinMaxEventTypeId;
extern ParamTypeId mockInputTypeWritableUIntMinMaxEventWritableUIntMinMaxParamTypeId; extern ParamTypeId inputTypeMockWritableUIntMinMaxEventWritableUIntMinMaxParamTypeId;
extern EventTypeId mockInputTypeDoubleEventTypeId; extern EventTypeId inputTypeMockDoubleEventTypeId;
extern ParamTypeId mockInputTypeDoubleEventDoubleParamTypeId; extern ParamTypeId inputTypeMockDoubleEventDoubleParamTypeId;
extern EventTypeId mockInputTypeWritableDoubleEventTypeId; extern EventTypeId inputTypeMockWritableDoubleEventTypeId;
extern ParamTypeId mockInputTypeWritableDoubleEventWritableDoubleParamTypeId; extern ParamTypeId inputTypeMockWritableDoubleEventWritableDoubleParamTypeId;
extern EventTypeId mockInputTypeWritableDoubleMinMaxEventTypeId; extern EventTypeId inputTypeMockWritableDoubleMinMaxEventTypeId;
extern ParamTypeId mockInputTypeWritableDoubleMinMaxEventWritableDoubleMinMaxParamTypeId; extern ParamTypeId inputTypeMockWritableDoubleMinMaxEventWritableDoubleMinMaxParamTypeId;
extern EventTypeId mockInputTypeStringEventTypeId; extern EventTypeId inputTypeMockStringEventTypeId;
extern ParamTypeId mockInputTypeStringEventStringParamTypeId; extern ParamTypeId inputTypeMockStringEventStringParamTypeId;
extern EventTypeId mockInputTypeWritableStringEventTypeId; extern EventTypeId inputTypeMockWritableStringEventTypeId;
extern ParamTypeId mockInputTypeWritableStringEventWritableStringParamTypeId; extern ParamTypeId inputTypeMockWritableStringEventWritableStringParamTypeId;
extern EventTypeId mockInputTypeWritableStringSelectionEventTypeId; extern EventTypeId inputTypeMockWritableStringSelectionEventTypeId;
extern ParamTypeId mockInputTypeWritableStringSelectionEventWritableStringSelectionParamTypeId; extern ParamTypeId inputTypeMockWritableStringSelectionEventWritableStringSelectionParamTypeId;
extern EventTypeId mockInputTypeColorEventTypeId; extern EventTypeId inputTypeMockColorEventTypeId;
extern ParamTypeId mockInputTypeColorEventColorParamTypeId; extern ParamTypeId inputTypeMockColorEventColorParamTypeId;
extern EventTypeId mockInputTypeWritableColorEventTypeId; extern EventTypeId inputTypeMockWritableColorEventTypeId;
extern ParamTypeId mockInputTypeWritableColorEventWritableColorParamTypeId; extern ParamTypeId inputTypeMockWritableColorEventWritableColorParamTypeId;
extern EventTypeId mockInputTypeTimeEventTypeId; extern EventTypeId inputTypeMockTimeEventTypeId;
extern ParamTypeId mockInputTypeTimeEventTimeParamTypeId; extern ParamTypeId inputTypeMockTimeEventTimeParamTypeId;
extern EventTypeId mockInputTypeWritableTimeEventTypeId; extern EventTypeId inputTypeMockWritableTimeEventTypeId;
extern ParamTypeId mockInputTypeWritableTimeEventWritableTimeParamTypeId; extern ParamTypeId inputTypeMockWritableTimeEventWritableTimeParamTypeId;
extern EventTypeId mockInputTypeTimestampIntEventTypeId; extern EventTypeId inputTypeMockTimestampIntEventTypeId;
extern ParamTypeId mockInputTypeTimestampIntEventTimestampIntParamTypeId; extern ParamTypeId inputTypeMockTimestampIntEventTimestampIntParamTypeId;
extern EventTypeId mockInputTypeWritableTimestampIntEventTypeId; extern EventTypeId inputTypeMockWritableTimestampIntEventTypeId;
extern ParamTypeId mockInputTypeWritableTimestampIntEventWritableTimestampIntParamTypeId; extern ParamTypeId inputTypeMockWritableTimestampIntEventWritableTimestampIntParamTypeId;
extern EventTypeId mockInputTypeTimestampUIntEventTypeId; extern EventTypeId inputTypeMockTimestampUIntEventTypeId;
extern ParamTypeId mockInputTypeTimestampUIntEventTimestampUIntParamTypeId; extern ParamTypeId inputTypeMockTimestampUIntEventTimestampUIntParamTypeId;
extern EventTypeId mockInputTypeWritableTimestampUIntEventTypeId; extern EventTypeId inputTypeMockWritableTimestampUIntEventTypeId;
extern ParamTypeId mockInputTypeWritableTimestampUIntEventWritableTimestampUIntParamTypeId; extern ParamTypeId inputTypeMockWritableTimestampUIntEventWritableTimestampUIntParamTypeId;
extern ActionTypeId mockInputTypeWritableBoolActionTypeId; extern ActionTypeId inputTypeMockWritableBoolActionTypeId;
extern ParamTypeId mockInputTypeWritableBoolActionWritableBoolParamTypeId; extern ParamTypeId inputTypeMockWritableBoolActionWritableBoolParamTypeId;
extern ActionTypeId mockInputTypeWritableIntActionTypeId; extern ActionTypeId inputTypeMockWritableIntActionTypeId;
extern ParamTypeId mockInputTypeWritableIntActionWritableIntParamTypeId; extern ParamTypeId inputTypeMockWritableIntActionWritableIntParamTypeId;
extern ActionTypeId mockInputTypeWritableIntMinMaxActionTypeId; extern ActionTypeId inputTypeMockWritableIntMinMaxActionTypeId;
extern ParamTypeId mockInputTypeWritableIntMinMaxActionWritableIntMinMaxParamTypeId; extern ParamTypeId inputTypeMockWritableIntMinMaxActionWritableIntMinMaxParamTypeId;
extern ActionTypeId mockInputTypeWritableUIntActionTypeId; extern ActionTypeId inputTypeMockWritableUIntActionTypeId;
extern ParamTypeId mockInputTypeWritableUIntActionWritableUIntParamTypeId; extern ParamTypeId inputTypeMockWritableUIntActionWritableUIntParamTypeId;
extern ActionTypeId mockInputTypeWritableUIntMinMaxActionTypeId; extern ActionTypeId inputTypeMockWritableUIntMinMaxActionTypeId;
extern ParamTypeId mockInputTypeWritableUIntMinMaxActionWritableUIntMinMaxParamTypeId; extern ParamTypeId inputTypeMockWritableUIntMinMaxActionWritableUIntMinMaxParamTypeId;
extern ActionTypeId mockInputTypeWritableDoubleActionTypeId; extern ActionTypeId inputTypeMockWritableDoubleActionTypeId;
extern ParamTypeId mockInputTypeWritableDoubleActionWritableDoubleParamTypeId; extern ParamTypeId inputTypeMockWritableDoubleActionWritableDoubleParamTypeId;
extern ActionTypeId mockInputTypeWritableDoubleMinMaxActionTypeId; extern ActionTypeId inputTypeMockWritableDoubleMinMaxActionTypeId;
extern ParamTypeId mockInputTypeWritableDoubleMinMaxActionWritableDoubleMinMaxParamTypeId; extern ParamTypeId inputTypeMockWritableDoubleMinMaxActionWritableDoubleMinMaxParamTypeId;
extern ActionTypeId mockInputTypeWritableStringActionTypeId; extern ActionTypeId inputTypeMockWritableStringActionTypeId;
extern ParamTypeId mockInputTypeWritableStringActionWritableStringParamTypeId; extern ParamTypeId inputTypeMockWritableStringActionWritableStringParamTypeId;
extern ActionTypeId mockInputTypeWritableStringSelectionActionTypeId; extern ActionTypeId inputTypeMockWritableStringSelectionActionTypeId;
extern ParamTypeId mockInputTypeWritableStringSelectionActionWritableStringSelectionParamTypeId; extern ParamTypeId inputTypeMockWritableStringSelectionActionWritableStringSelectionParamTypeId;
extern ActionTypeId mockInputTypeWritableColorActionTypeId; extern ActionTypeId inputTypeMockWritableColorActionTypeId;
extern ParamTypeId mockInputTypeWritableColorActionWritableColorParamTypeId; extern ParamTypeId inputTypeMockWritableColorActionWritableColorParamTypeId;
extern ActionTypeId mockInputTypeWritableTimeActionTypeId; extern ActionTypeId inputTypeMockWritableTimeActionTypeId;
extern ParamTypeId mockInputTypeWritableTimeActionWritableTimeParamTypeId; extern ParamTypeId inputTypeMockWritableTimeActionWritableTimeParamTypeId;
extern ActionTypeId mockInputTypeWritableTimestampIntActionTypeId; extern ActionTypeId inputTypeMockWritableTimestampIntActionTypeId;
extern ParamTypeId mockInputTypeWritableTimestampIntActionWritableTimestampIntParamTypeId; extern ParamTypeId inputTypeMockWritableTimestampIntActionWritableTimestampIntParamTypeId;
extern ActionTypeId mockInputTypeWritableTimestampUIntActionTypeId; extern ActionTypeId inputTypeMockWritableTimestampUIntActionTypeId;
extern ParamTypeId mockInputTypeWritableTimestampUIntActionWritableTimestampUIntParamTypeId; extern ParamTypeId inputTypeMockWritableTimestampUIntActionWritableTimestampUIntParamTypeId;
extern ThingClassId mockOAuthGoogleThingClassId; extern ThingClassId oAuthGoogleMockThingClassId;
extern ThingClassId mockOAuthSonosThingClassId; extern ThingClassId oAuthSonosMockThingClassId;
extern ThingClassId mockUserAndPassThingClassId; extern ThingClassId userAndPassMockThingClassId;
#endif // EXTERNPLUGININFO_H #endif // EXTERNPLUGININFO_H

View File

@ -47,8 +47,8 @@ HttpDaemon::HttpDaemon(Thing *thing, IntegrationPlugin *parent):
QTcpServer(parent), disabled(false), m_plugin(parent), m_thing(thing) QTcpServer(parent), disabled(false), m_plugin(parent), m_thing(thing)
{ {
QHash<ThingClassId, ParamTypeId> portMap; QHash<ThingClassId, ParamTypeId> portMap;
portMap.insert(mockThingClassId, mockDeviceHttpportParamTypeId); portMap.insert(mockThingClassId, mockThingHttpportParamTypeId);
portMap.insert(mockDeviceAutoThingClassId, mockDeviceAutoDeviceHttpportParamTypeId); portMap.insert(autoMockThingClassId, autoMockThingHttpportParamTypeId);
listen(QHostAddress::Any, thing->paramValue(portMap.value(thing->thingClassId())).toInt()); listen(QHostAddress::Any, thing->paramValue(portMap.value(thing->thingClassId())).toInt());
} }
@ -102,30 +102,30 @@ void HttpDaemon::readClient()
} else if (stateTypeId == mockDoubleStateTypeId) { } else if (stateTypeId == mockDoubleStateTypeId) {
stateValue.convert(QVariant::Double); stateValue.convert(QVariant::Double);
} }
qCDebug(dcMockDevice) << "Set state value" << stateValue; qCDebug(dcMock()) << "Set state value" << stateValue;
emit setState(stateTypeId, stateValue); emit setState(stateTypeId, stateValue);
} else if (url.path() == "/generateevent") { } else if (url.path() == "/generateevent") {
emit triggerEvent(EventTypeId(query.queryItemValue("eventtypeid"))); emit triggerEvent(EventTypeId(query.queryItemValue("eventtypeid")));
} else if (url.path() == "/actionhistory") { } else if (url.path() == "/actionhistory") {
qCDebug(dcMockDevice) << "Get action history called"; qCDebug(dcMock()) << "Get action history called";
QTextStream os(socket); QTextStream os(socket);
os.setAutoDetectUnicode(true); os.setAutoDetectUnicode(true);
os << generateHeader(); os << generateHeader();
for (int i = 0; i < m_actionList.count(); ++i) { for (int i = 0; i < m_actionList.count(); ++i) {
os << m_actionList.at(i).first.toString() << '\n'; 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(); socket->close();
return; return;
} else if (url.path() == "/clearactionhistory") { } else if (url.path() == "/clearactionhistory") {
qCDebug(dcMockDevice) << "Clear action history"; qCDebug(dcMock()) << "Clear action history";
m_actionList.clear(); m_actionList.clear();
} else if (url.path() == "/disappear") { } else if (url.path() == "/disappear") {
qCDebug(dcMockDevice) << "Should disappear"; qCDebug(dcMock()) << "Should disappear";
emit disappear(); emit disappear();
} else if (url.path() == "/reconfigureautodevice") { } else if (url.path() == "/reconfigureautodevice") {
qCDebug(dcMockDevice) << "Reconfigure auto device"; qCDebug(dcMock()) << "Reconfigure auto device";
emit reconfigureAutodevice(); emit reconfigureAutodevice();
} }

File diff suppressed because it is too large Load Diff

View File

@ -92,7 +92,7 @@ void TestActions::executeAction()
QNetworkAccessManager nam; QNetworkAccessManager nam;
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*))); 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); QNetworkReply *reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -108,14 +108,14 @@ void TestActions::executeAction()
// cleanup for the next run // cleanup for the next run
spy.clear(); 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); reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
reply->deleteLater(); reply->deleteLater();
spy.clear(); 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); reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);

View File

@ -3,6 +3,7 @@ TEMPLATE = subdirs
SUBDIRS = \ SUBDIRS = \
versioning \ versioning \
devices \ devices \
integrations \
jsonrpc \ jsonrpc \
events \ events \
states \ states \

File diff suppressed because it is too large Load Diff

View File

@ -65,7 +65,7 @@ void TestEvents::triggerEvent()
QNetworkAccessManager nam; QNetworkAccessManager nam;
// trigger event in mock device // 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()))); QNetworkRequest request(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(port).arg(mockEvent1EventTypeId.toString())));
QNetworkReply *reply = nam.get(request); QNetworkReply *reply = nam.get(request);
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater); connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
@ -107,7 +107,7 @@ void TestEvents::triggerStateChangeEvent()
QNetworkAccessManager nam; QNetworkAccessManager nam;
// trigger state changed event in mock device // 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))); QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(port).arg(mockIntStateTypeId.toString()).arg(11)));
QNetworkReply *reply = nam.get(request); QNetworkReply *reply = nam.get(request);
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater); connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);

View File

@ -0,0 +1,5 @@
include(../../../nymea.pri)
include(../autotests.pri)
TARGET = testintegrations
SOURCES += testintegrations.cpp

File diff suppressed because it is too large Load Diff

View File

@ -70,13 +70,10 @@ private slots:
void enableDisableNotifications_legacy_data(); void enableDisableNotifications_legacy_data();
void enableDisableNotifications_legacy(); void enableDisableNotifications_legacy();
void deviceAddedRemovedNotifications();
void ruleAddedRemovedNotifications(); void ruleAddedRemovedNotifications();
void ruleActiveChangedNotifications(); void ruleActiveChangedNotifications();
void deviceChangedNotifications();
void stateChangeEmitsNotifications(); void stateChangeEmitsNotifications();
void pluginConfigChangeEmitsNotification(); void pluginConfigChangeEmitsNotification();
@ -213,7 +210,7 @@ void TestJSONRPC::testHandshakeLocale()
QVariantMap supportedDevices = injectAndWait("Devices.GetSupportedDevices").toMap(); QVariantMap supportedDevices = injectAndWait("Devices.GetSupportedDevices").toMap();
bool found = false; bool found = false;
foreach (const QVariant &dcMap, supportedDevices.value("params").toMap().value("deviceClasses").toList()) { 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)")); QCOMPARE(dcMap.toMap().value("displayName").toString(), QString("Mock Device (Auto created)"));
found = true; found = true;
} }
@ -229,7 +226,7 @@ void TestJSONRPC::testHandshakeLocale()
supportedDevices = injectAndWait("Devices.GetSupportedDevices").toMap(); supportedDevices = injectAndWait("Devices.GetSupportedDevices").toMap();
found = false; found = false;
foreach (const QVariant &dcMap, supportedDevices.value("params").toMap().value("deviceClasses").toList()) { 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)")); QCOMPARE(dcMap.toMap().value("displayName").toString(), QString("Mock Gerät (Automatisch erzeugt)"));
found = true; found = true;
} }
@ -677,7 +674,7 @@ void TestJSONRPC::enableDisableNotifications_legacy()
QStringList expectedNamespaces; QStringList expectedNamespaces;
if (enabled == "true") { 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()); std::sort(expectedNamespaces.begin(), expectedNamespaces.end());
@ -690,51 +687,6 @@ void TestJSONRPC::enableDisableNotifications_legacy()
QCOMPARE(expectedNamespaces, actualNamespaces); 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 &param, 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() void TestJSONRPC::ruleAddedRemovedNotifications()
{ {
@ -747,9 +699,14 @@ void TestJSONRPC::ruleAddedRemovedNotifications()
// StateDescriptor // StateDescriptor
QVariantMap stateDescriptor; QVariantMap stateDescriptor;
stateDescriptor.insert("stateTypeId", mockIntStateTypeId); 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("operator", enumValueName(Types::ValueOperatorLess));
stateDescriptor.insert("value", "20"); 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; QVariantMap stateEvaluator;
stateEvaluator.insert("stateDescriptor", stateDescriptor); stateEvaluator.insert("stateDescriptor", stateDescriptor);
@ -757,17 +714,26 @@ void TestJSONRPC::ruleAddedRemovedNotifications()
// RuleAction // RuleAction
QVariantMap actionNoParams; QVariantMap actionNoParams;
actionNoParams.insert("actionTypeId", mockWithoutParamsActionTypeId); 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 // EventDescriptor
QVariantMap eventDescriptor; QVariantMap eventDescriptor;
eventDescriptor.insert("eventTypeId", mockEvent1EventTypeId); eventDescriptor.insert("eventTypeId", mockEvent1EventTypeId);
eventDescriptor.insert("deviceId", m_mockThingId); eventDescriptor.insert("thingId", m_mockThingId);
QVariantList eventDescriptors = QVariantList() << eventDescriptor; 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; QVariantMap params;
params.insert("name", "Test Rule notifications"); params.insert("name", "Test Rule notifications");
params.insert("actions", QVariantList() << actionNoParams); params.insert("actions", actions);
params.insert("eventDescriptors", eventDescriptors); params.insert("eventDescriptors", eventDescriptors);
params.insert("stateEvaluator", stateEvaluator); params.insert("stateEvaluator", stateEvaluator);
@ -781,9 +747,17 @@ void TestJSONRPC::ruleAddedRemovedNotifications()
QCOMPARE(notificationRuleMap.value("enabled").toBool(), true); QCOMPARE(notificationRuleMap.value("enabled").toBool(), true);
QCOMPARE(notificationRuleMap.value("name").toString(), params.value("name").toString()); QCOMPARE(notificationRuleMap.value("name").toString(), params.value("name").toString());
QCOMPARE(notificationRuleMap.value("id").toString(), ruleId.toString()); QCOMPARE(notificationRuleMap.value("id").toUuid(), QUuid(ruleId));
QCOMPARE(notificationRuleMap.value("actions").toList(), QVariantList() << actionNoParams); QVERIFY2(notificationRuleMap.value("actions").toList() == actions,
QCOMPARE(notificationRuleMap.value("stateEvaluator").toMap().value("stateDescriptor").toMap(), stateDescriptor); 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, QVERIFY2(notificationRuleMap.value("eventDescriptors").toList() == eventDescriptors,
QString("eventDescriptors not matching.\nExpected: %1\nGot %2") QString("eventDescriptors not matching.\nExpected: %1\nGot %2")
.arg(QString(QJsonDocument::fromVariant(eventDescriptors).toJson())) .arg(QString(QJsonDocument::fromVariant(eventDescriptors).toJson()))
@ -814,9 +788,14 @@ void TestJSONRPC::ruleActiveChangedNotifications()
// StateDescriptor // StateDescriptor
QVariantMap stateDescriptor; QVariantMap stateDescriptor;
stateDescriptor.insert("stateTypeId", mockIntStateTypeId); 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("operator", enumValueName(Types::ValueOperatorEquals));
stateDescriptor.insert("value", "20"); 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; QVariantMap stateEvaluator;
stateEvaluator.insert("stateDescriptor", stateDescriptor); stateEvaluator.insert("stateDescriptor", stateDescriptor);
@ -824,11 +803,16 @@ void TestJSONRPC::ruleActiveChangedNotifications()
// RuleAction // RuleAction
QVariantMap actionNoParams; QVariantMap actionNoParams;
actionNoParams.insert("actionTypeId", mockWithoutParamsActionTypeId); 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.clear(); response.clear();
params.insert("name", "Test Rule notifications"); params.insert("name", "Test Rule notifications");
params.insert("actions", QVariantList() << actionNoParams); params.insert("actions", actions);
params.insert("stateEvaluator", stateEvaluator); params.insert("stateEvaluator", stateEvaluator);
// Setup connection to mock client // Setup connection to mock client
@ -844,8 +828,8 @@ void TestJSONRPC::ruleActiveChangedNotifications()
QVERIFY(!ruleId.isNull()); QVERIFY(!ruleId.isNull());
QCOMPARE(notificationRuleMap.value("enabled").toBool(), true); QCOMPARE(notificationRuleMap.value("enabled").toBool(), true);
QCOMPARE(notificationRuleMap.value("name").toString(), params.value("name").toString()); QCOMPARE(notificationRuleMap.value("name").toString(), params.value("name").toString());
QCOMPARE(notificationRuleMap.value("id").toString(), ruleId.toString()); QCOMPARE(notificationRuleMap.value("id").toUuid(), QUuid(ruleId));
QCOMPARE(notificationRuleMap.value("actions").toList(), QVariantList() << actionNoParams); QCOMPARE(notificationRuleMap.value("actions").toList(), actions);
QCOMPARE(notificationRuleMap.value("stateEvaluator").toMap().value("stateDescriptor").toMap(), stateDescriptor); QCOMPARE(notificationRuleMap.value("stateEvaluator").toMap().value("stateDescriptor").toMap(), stateDescriptor);
QCOMPARE(notificationRuleMap.value("exitActions").toList(), QVariantList()); QCOMPARE(notificationRuleMap.value("exitActions").toList(), QVariantList());
@ -855,7 +839,7 @@ void TestJSONRPC::ruleActiveChangedNotifications()
// state state to 20 // state state to 20
qDebug() << "setting mock int 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); QNetworkReply *reply = nam.get(request);
connect(reply, SIGNAL(finished()), reply, SLOT(deleteLater())); connect(reply, SIGNAL(finished()), reply, SLOT(deleteLater()));
@ -868,6 +852,8 @@ void TestJSONRPC::ruleActiveChangedNotifications()
clientSpy.wait(); clientSpy.wait();
waitForDBSync();
// Make sure the logg notification contains all the stuff we expect // Make sure the logg notification contains all the stuff we expect
QVariantList logEntryAddedVariants = checkNotifications(clientSpy, "Logging.LogEntryAdded"); QVariantList logEntryAddedVariants = checkNotifications(clientSpy, "Logging.LogEntryAdded");
QVERIFY2(!logEntryAddedVariants.isEmpty(), "Did not get Logging.LogEntryAdded notification."); QVERIFY2(!logEntryAddedVariants.isEmpty(), "Did not get Logging.LogEntryAdded notification.");
@ -886,7 +872,7 @@ void TestJSONRPC::ruleActiveChangedNotifications()
// set the rule inactive // set the rule inactive
qDebug() << "setting mock int state to 42"; 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); QNetworkReply *reply2 = nam.get(request2);
connect(reply2, SIGNAL(finished()), reply2, SLOT(deleteLater())); connect(reply2, SIGNAL(finished()), reply2, SLOT(deleteLater()));
@ -907,11 +893,12 @@ void TestJSONRPC::ruleActiveChangedNotifications()
logEntryAddedVariants = checkNotifications(clientSpy, "Logging.LogEntryAdded"); logEntryAddedVariants = checkNotifications(clientSpy, "Logging.LogEntryAdded");
QVERIFY2(!logEntryAddedVariants.isEmpty(), "Did not get Logging.LogEntryAdded notification."); QVERIFY2(!logEntryAddedVariants.isEmpty(), "Did not get Logging.LogEntryAdded notification.");
found = false; found = false;
foreach (const QVariant &loggEntryAddedVariant, logEntryAddedVariants) { foreach (const QVariant &logEntryAddedVariant, logEntryAddedVariants) {
if (loggEntryAddedVariant.toMap().value("params").toMap().value("logEntry").toMap().value("typeId").toUuid() == mockIntStateTypeId) { 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; found = true;
QCOMPARE(loggEntryAddedVariant.toMap().value("params").toMap().value("logEntry").toMap().value("source").toString(), QString("LoggingSourceStates")); QCOMPARE(logEntryAddedVariant.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("value").toInt(), 42);
break; break;
} }
} }
@ -937,91 +924,6 @@ void TestJSONRPC::ruleActiveChangedNotifications()
QCOMPARE(notificationVariant.toMap().value("params").toMap().value("ruleId").toUuid().toString(), ruleId.toString()); 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 &param, 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 &param, 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() void TestJSONRPC::stateChangeEmitsNotifications()
{ {
enableNotifications({"Devices", "States", "Logging", "Events"}); enableNotifications({"Devices", "States", "Logging", "Events"});
@ -1034,7 +936,7 @@ void TestJSONRPC::stateChangeEmitsNotifications()
// trigger state change in mock device // trigger state change in mock device
int newVal = 38; int newVal = 38;
QUuid stateTypeId("80baec19-54de-4948-ac46-31eabfaceb83"); 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); QNetworkReply *reply = nam.get(request);
connect(reply, SIGNAL(finished()), reply, SLOT(deleteLater())); connect(reply, SIGNAL(finished()), reply, SLOT(deleteLater()));
QSignalSpy replySpy(reply, SIGNAL(finished())); QSignalSpy replySpy(reply, SIGNAL(finished()));
@ -1098,7 +1000,7 @@ void TestJSONRPC::stateChangeEmitsNotifications()
// Fire the a statechange once again // Fire the a statechange once again
clientSpy.clear(); clientSpy.clear();
newVal = 42; 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); reply = nam.get(request);
connect(reply, SIGNAL(finished()), reply, SLOT(deleteLater())); connect(reply, SIGNAL(finished()), reply, SLOT(deleteLater()));
@ -1129,7 +1031,7 @@ void TestJSONRPC::pluginConfigChangeEmitsNotification()
params.insert("pluginId", mockPluginId); params.insert("pluginId", mockPluginId);
QVariantList pluginParams; QVariantList pluginParams;
QVariantMap param1; QVariantMap param1;
param1.insert("paramTypeId", mockDevicePluginConfigParamIntParamTypeId); param1.insert("paramTypeId", mockPluginConfigParamIntParamTypeId);
param1.insert("value", 42); param1.insert("value", 42);
pluginParams.append(param1); pluginParams.append(param1);
params.insert("configuration", pluginParams); params.insert("configuration", pluginParams);

View File

@ -47,13 +47,12 @@ private:
inline void verifyLoggingError(const QVariant &response, Logging::LoggingError error = Logging::LoggingErrorNoError) { inline void verifyLoggingError(const QVariant &response, Logging::LoggingError error = Logging::LoggingErrorNoError) {
verifyError(response, "loggingError", enumValueName(error)); verifyError(response, "loggingError", enumValueName(error));
} }
inline void verifyDeviceError(const QVariant &response, Thing::ThingError error = Thing::ThingErrorNoError) { inline void verifyThingError(const QVariant &response, Thing::ThingError error = Thing::ThingErrorNoError) {
verifyError(response, "deviceError", enumValueName(error)); verifyError(response, "thingError", enumValueName(error));
} }
inline void waitForDBSync() { // DEPRECTATED
while (NymeaCore::instance()->logEngine()->jobsRunning()) { inline void verifyDeviceError(const QVariant &response, Thing::ThingError error = Thing::ThingErrorNoError) {
qApp->processEvents(); verifyError(response, "deviceError", enumValueName(error).replace("Thing", "Device"));
}
} }
private slots: private slots:
@ -277,7 +276,7 @@ void TestLogging::eventLogs()
QSignalSpy clientSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray))); QSignalSpy clientSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray)));
// trigger event in mock device // 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()))); QNetworkRequest request(QUrl(QString("http://localhost:%1/generateevent?eventtypeid=%2").arg(port).arg(mockEvent1EventTypeId.toString())));
QNetworkReply *reply = nam.get(request); QNetworkReply *reply = nam.get(request);
@ -343,7 +342,7 @@ void TestLogging::actionLog()
QVariantMap params; QVariantMap params;
params.insert("actionTypeId", mockWithParamsActionTypeId); params.insert("actionTypeId", mockWithParamsActionTypeId);
params.insert("deviceId", m_mockThingId); params.insert("thingId", m_mockThingId);
params.insert("params", actionParams); params.insert("params", actionParams);
enableNotifications({"Logging"}); enableNotifications({"Logging"});
@ -351,8 +350,8 @@ void TestLogging::actionLog()
QSignalSpy clientSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray))); QSignalSpy clientSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray)));
// EXECUTE with params // EXECUTE with params
QVariant response = injectAndWait("Actions.ExecuteAction", params); QVariant response = injectAndWait("Integrations.ExecuteAction", params);
verifyDeviceError(response); verifyThingError(response);
// wait for the outgoing data // wait for the outgoing data
// 3 packets: ExecuteAction reply, LogDatabaseUpdated signal and LogEntryAdded signal // 3 packets: ExecuteAction reply, LogDatabaseUpdated signal and LogEntryAdded signal
@ -484,7 +483,7 @@ void TestLogging::actionLog()
void TestLogging::deviceLogs() void TestLogging::deviceLogs()
{ {
QVariantMap params; QVariantMap params;
params.insert("deviceClassId", mockParentThingClassId); params.insert("deviceClassId", parentMockThingClassId);
params.insert("name", "Parent device"); params.insert("name", "Parent device");
QVariant response = injectAndWait("Devices.AddConfiguredDevice", params); QVariant response = injectAndWait("Devices.AddConfiguredDevice", params);
@ -526,12 +525,12 @@ void TestLogging::testDoubleValues()
// Discover device // Discover device
QVariantList discoveryParams; QVariantList discoveryParams;
QVariantMap resultCountParam; QVariantMap resultCountParam;
resultCountParam.insert("paramTypeId", mockDisplayPinDiscoveryResultCountParamTypeId); resultCountParam.insert("paramTypeId", displayPinMockDiscoveryResultCountParamTypeId);
resultCountParam.insert("value", 1); resultCountParam.insert("value", 1);
discoveryParams.append(resultCountParam); discoveryParams.append(resultCountParam);
QVariantMap params; QVariantMap params;
params.insert("deviceClassId", mockDisplayPinThingClassId); params.insert("deviceClassId", displayPinMockThingClassId);
params.insert("discoveryParams", discoveryParams); params.insert("discoveryParams", discoveryParams);
QVariant response = injectAndWait("Devices.GetDiscoveredDevices", params); QVariant response = injectAndWait("Devices.GetDiscoveredDevices", params);
@ -540,7 +539,7 @@ void TestLogging::testDoubleValues()
// Pair device // Pair device
ThingDescriptorId descriptorId = ThingDescriptorId(response.toMap().value("params").toMap().value("deviceDescriptors").toList().first().toMap().value("id").toString()); ThingDescriptorId descriptorId = ThingDescriptorId(response.toMap().value("params").toMap().value("deviceDescriptors").toList().first().toMap().value("id").toString());
params.clear(); params.clear();
params.insert("deviceClassId", mockDisplayPinThingClassId); params.insert("deviceClassId", displayPinMockThingClassId);
params.insert("name", "Display pin mock device"); params.insert("name", "Display pin mock device");
params.insert("deviceDescriptorId", descriptorId.toString()); params.insert("deviceDescriptorId", descriptorId.toString());
response = injectAndWait("Devices.PairDevice", params); response = injectAndWait("Devices.PairDevice", params);
@ -566,12 +565,12 @@ void TestLogging::testDoubleValues()
// Set the double state value and sniff for LogEntryAdded notification // Set the double state value and sniff for LogEntryAdded notification
double value = 23.80; double value = 23.80;
QVariantMap actionParam; QVariantMap actionParam;
actionParam.insert("paramTypeId", mockDisplayPinDoubleActionDoubleParamTypeId.toString()); actionParam.insert("paramTypeId", displayPinMockDoubleActionDoubleParamTypeId.toString());
actionParam.insert("value", value); actionParam.insert("value", value);
params.clear(); response.clear(); params.clear(); response.clear();
params.insert("deviceId", deviceId); params.insert("deviceId", deviceId);
params.insert("actionTypeId", mockDisplayPinDoubleActionTypeId.toString()); params.insert("actionTypeId", displayPinMockDoubleActionTypeId.toString());
params.insert("params", QVariantList() << actionParam); params.insert("params", QVariantList() << actionParam);
response = injectAndWait("Actions.ExecuteAction", params); response = injectAndWait("Actions.ExecuteAction", params);
@ -584,8 +583,8 @@ void TestLogging::testDoubleValues()
foreach (const QVariant &logNotificationVariant, logNotificationsList) { foreach (const QVariant &logNotificationVariant, logNotificationsList) {
QVariantMap logNotification = logNotificationVariant.toMap().value("params").toMap().value("logEntry").toMap(); QVariantMap logNotification = logNotificationVariant.toMap().value("params").toMap().value("logEntry").toMap();
if (logNotification.value("typeId").toString() == mockDisplayPinDoubleActionDoubleParamTypeId.toString()) { if (logNotification.value("typeId").toString() == displayPinMockDoubleActionDoubleParamTypeId.toString()) {
if (logNotification.value("typeId").toString() == mockDisplayPinDoubleActionDoubleParamTypeId.toString()) { if (logNotification.value("typeId").toString() == displayPinMockDoubleActionDoubleParamTypeId.toString()) {
// If state source // If state source
if (logNotification.value("source").toString() == enumValueName(Logging::LoggingSourceStates)) { if (logNotification.value("source").toString() == enumValueName(Logging::LoggingSourceStates)) {
@ -619,7 +618,7 @@ void TestLogging::testHouseKeeping()
params.insert("name", "TestDeviceToBeRemoved"); params.insert("name", "TestDeviceToBeRemoved");
QVariantList deviceParams; QVariantList deviceParams;
QVariantMap httpParam; QVariantMap httpParam;
httpParam.insert("paramTypeId", mockDeviceHttpportParamTypeId); httpParam.insert("paramTypeId", mockThingHttpportParamTypeId);
httpParam.insert("value", 6667); httpParam.insert("value", 6667);
deviceParams.append(httpParam); deviceParams.append(httpParam);
params.insert("deviceParams", deviceParams); params.insert("deviceParams", deviceParams);

View File

@ -141,7 +141,7 @@ private slots:
void TestRules::cleanupMockHistory() { void TestRules::cleanupMockHistory() {
QNetworkAccessManager nam; QNetworkAccessManager nam;
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*))); 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); QNetworkReply *reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -162,12 +162,12 @@ ThingId TestRules::addDisplayPinDevice()
// Discover device // Discover device
QVariantList discoveryParams; QVariantList discoveryParams;
QVariantMap resultCountParam; QVariantMap resultCountParam;
resultCountParam.insert("paramTypeId", mockDisplayPinDiscoveryResultCountParamTypeId); resultCountParam.insert("paramTypeId", displayPinMockDiscoveryResultCountParamTypeId);
resultCountParam.insert("value", 1); resultCountParam.insert("value", 1);
discoveryParams.append(resultCountParam); discoveryParams.append(resultCountParam);
QVariantMap params; QVariantMap params;
params.insert("deviceClassId", mockDisplayPinThingClassId); params.insert("deviceClassId", displayPinMockThingClassId);
params.insert("discoveryParams", discoveryParams); params.insert("discoveryParams", discoveryParams);
QVariant response = injectAndWait("Devices.GetDiscoveredDevices", params); QVariant response = injectAndWait("Devices.GetDiscoveredDevices", params);
@ -176,7 +176,7 @@ ThingId TestRules::addDisplayPinDevice()
// Pair device // Pair device
ThingDescriptorId descriptorId = ThingDescriptorId(response.toMap().value("params").toMap().value("deviceDescriptors").toList().first().toMap().value("id").toString()); ThingDescriptorId descriptorId = ThingDescriptorId(response.toMap().value("params").toMap().value("deviceDescriptors").toList().first().toMap().value("id").toString());
params.clear(); params.clear();
params.insert("deviceClassId", mockDisplayPinThingClassId); params.insert("deviceClassId", displayPinMockThingClassId);
params.insert("name", "Display pin mock device"); params.insert("name", "Display pin mock device");
params.insert("deviceDescriptorId", descriptorId.toString()); params.insert("deviceDescriptorId", descriptorId.toString());
response = injectAndWait("Devices.PairDevice", params); response = injectAndWait("Devices.PairDevice", params);
@ -285,7 +285,7 @@ void TestRules::verifyRuleExecuted(const ActionTypeId &actionTypeId)
while (!actionFound && i < 50) { while (!actionFound && i < 50) {
QNetworkAccessManager nam; QNetworkAccessManager nam;
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*))); 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); QNetworkReply *reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -305,7 +305,7 @@ void TestRules::verifyRuleNotExecuted()
{ {
QNetworkAccessManager nam; QNetworkAccessManager nam;
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*))); 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); QNetworkReply *reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -394,7 +394,7 @@ void TestRules::generateEvent(const EventTypeId &eventTypeId)
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*))); QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
// trigger event in mock device // 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); QNetworkReply *reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -1588,7 +1588,7 @@ void TestRules::evaluateEvent()
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*))); QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
// trigger event in mock device // 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); QNetworkReply *reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -1602,7 +1602,7 @@ void TestRules::evaluateEventParams()
// Init bool state to true // Init bool state to true
QNetworkAccessManager nam; QNetworkAccessManager nam;
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*))); 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); QNetworkReply *reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -1641,7 +1641,7 @@ void TestRules::evaluateEventParams()
// Trigger a non matching param // Trigger a non matching param
spy.clear(); 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); reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -1651,7 +1651,7 @@ void TestRules::evaluateEventParams()
// Trigger a matching param // Trigger a matching param
spy.clear(); 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); reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -1661,7 +1661,7 @@ void TestRules::evaluateEventParams()
// Reset back to false to not mess with other tests // Reset back to false to not mess with other tests
spy.clear(); 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); reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -1698,7 +1698,7 @@ void TestRules::testStateChange() {
// state state to 42 // state state to 42
qDebug() << "setting mock int 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); QNetworkReply *reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -1711,7 +1711,7 @@ void TestRules::testStateChange() {
// set state to 45 // set state to 45
qDebug() << "setting mock int state to 45"; qDebug() << "setting mock int state to 45";
spy.clear(); 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); reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -1724,7 +1724,7 @@ void TestRules::testStateChange() {
// set state to 30 // set state to 30
qDebug() << "setting mock int state to 30"; qDebug() << "setting mock int state to 30";
spy.clear(); 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); reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -1737,7 +1737,7 @@ void TestRules::testStateChange() {
// set state to 100 // set state to 100
qDebug() << "setting mock int state to 100"; qDebug() << "setting mock int state to 100";
spy.clear(); 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); reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -1903,25 +1903,25 @@ void TestRules::testChildEvaluator_data()
QVariantMap stateDescriptorPercentage; QVariantMap stateDescriptorPercentage;
stateDescriptorPercentage.insert("deviceId", testDeviceId); stateDescriptorPercentage.insert("deviceId", testDeviceId);
stateDescriptorPercentage.insert("operator", enumValueName(Types::ValueOperatorGreaterOrEqual)); stateDescriptorPercentage.insert("operator", enumValueName(Types::ValueOperatorGreaterOrEqual));
stateDescriptorPercentage.insert("stateTypeId", mockDisplayPinPercentageStateTypeId); stateDescriptorPercentage.insert("stateTypeId", displayPinMockPercentageStateTypeId);
stateDescriptorPercentage.insert("value", 50); stateDescriptorPercentage.insert("value", 50);
QVariantMap stateDescriptorDouble; QVariantMap stateDescriptorDouble;
stateDescriptorDouble.insert("deviceId", testDeviceId); stateDescriptorDouble.insert("deviceId", testDeviceId);
stateDescriptorDouble.insert("operator", enumValueName(Types::ValueOperatorEquals)); stateDescriptorDouble.insert("operator", enumValueName(Types::ValueOperatorEquals));
stateDescriptorDouble.insert("stateTypeId", mockDisplayPinDoubleActionDoubleParamTypeId); stateDescriptorDouble.insert("stateTypeId", displayPinMockDoubleActionDoubleParamTypeId);
stateDescriptorDouble.insert("value", 20.5); stateDescriptorDouble.insert("value", 20.5);
QVariantMap stateDescriptorAllowedValues; QVariantMap stateDescriptorAllowedValues;
stateDescriptorAllowedValues.insert("deviceId", testDeviceId); stateDescriptorAllowedValues.insert("deviceId", testDeviceId);
stateDescriptorAllowedValues.insert("operator", enumValueName(Types::ValueOperatorEquals)); stateDescriptorAllowedValues.insert("operator", enumValueName(Types::ValueOperatorEquals));
stateDescriptorAllowedValues.insert("stateTypeId", mockDisplayPinAllowedValuesStateTypeId); stateDescriptorAllowedValues.insert("stateTypeId", displayPinMockAllowedValuesStateTypeId);
stateDescriptorAllowedValues.insert("value", "String value 2"); stateDescriptorAllowedValues.insert("value", "String value 2");
QVariantMap stateDescriptorColor; QVariantMap stateDescriptorColor;
stateDescriptorColor.insert("deviceId", testDeviceId); stateDescriptorColor.insert("deviceId", testDeviceId);
stateDescriptorColor.insert("operator", enumValueName(Types::ValueOperatorEquals)); stateDescriptorColor.insert("operator", enumValueName(Types::ValueOperatorEquals));
stateDescriptorColor.insert("stateTypeId", mockDisplayPinColorStateTypeId); stateDescriptorColor.insert("stateTypeId", displayPinMockColorStateTypeId);
stateDescriptorColor.insert("value", "#00FF00"); stateDescriptorColor.insert("value", "#00FF00");
QVariantMap firstStateEvaluator; QVariantMap firstStateEvaluator;
@ -1976,10 +1976,10 @@ void TestRules::testChildEvaluator()
QFETCH(bool, active); QFETCH(bool, active);
// Init the states // Init the states
setWritableStateValue(deviceId, StateTypeId(mockDisplayPinPercentageStateTypeId.toString()), QVariant(0)); setWritableStateValue(deviceId, StateTypeId(displayPinMockPercentageStateTypeId.toString()), QVariant(0));
setWritableStateValue(deviceId, StateTypeId(mockDisplayPinDoubleActionDoubleParamTypeId.toString()), QVariant(0)); setWritableStateValue(deviceId, StateTypeId(displayPinMockDoubleActionDoubleParamTypeId.toString()), QVariant(0));
setWritableStateValue(deviceId, StateTypeId(mockDisplayPinAllowedValuesStateTypeId.toString()), QVariant("String value 1")); setWritableStateValue(deviceId, StateTypeId(displayPinMockAllowedValuesStateTypeId.toString()), QVariant("String value 1"));
setWritableStateValue(deviceId, StateTypeId(mockDisplayPinColorStateTypeId.toString()), QVariant("#000000")); setWritableStateValue(deviceId, StateTypeId(displayPinMockColorStateTypeId.toString()), QVariant("#000000"));
qCDebug(dcTests()) << "Adding rule"; qCDebug(dcTests()) << "Adding rule";
@ -1991,13 +1991,13 @@ void TestRules::testChildEvaluator()
// Set the states // Set the states
qCDebug(dcTests()) << "Setting state 1"; 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"; 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"; 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"; 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 // Verfiy if the rule executed successfully
// Actions // Actions
@ -2055,7 +2055,7 @@ void TestRules::enableDisableRule()
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*))); QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
// trigger event in mock device // 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); QNetworkReply *reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -2079,7 +2079,7 @@ void TestRules::enableDisableRule()
// trigger event in mock device // trigger event in mock device
spy.clear(); 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); reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -2103,7 +2103,7 @@ void TestRules::enableDisableRule()
// trigger event in mock device // trigger event in mock device
spy.clear(); 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); reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -2152,7 +2152,7 @@ void TestRules::testEventBasedAction()
// state state to 42 // state state to 42
qDebug() << "setting mock int 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); QNetworkReply *reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -2169,7 +2169,7 @@ void TestRules::testEventBasedRuleWithExitAction()
// Init bool state to true // Init bool state to true
spy.clear(); 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); QNetworkReply *reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -2224,7 +2224,7 @@ void TestRules::testEventBasedRuleWithExitAction()
// trigger event // trigger event
spy.clear(); 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); reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -2235,7 +2235,7 @@ void TestRules::testEventBasedRuleWithExitAction()
// set bool state to false // set bool state to false
spy.clear(); 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); reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -2243,7 +2243,7 @@ void TestRules::testEventBasedRuleWithExitAction()
// trigger event // trigger event
spy.clear(); 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); reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -2261,7 +2261,7 @@ void TestRules::testStateBasedAction()
// Init bool state to true // Init bool state to true
spy.clear(); 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); QNetworkReply *reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -2269,7 +2269,7 @@ void TestRules::testStateBasedAction()
// Init int state to 11 // Init int state to 11
spy.clear(); 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); reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -2312,7 +2312,7 @@ void TestRules::testStateBasedAction()
// trigger event // trigger event
spy.clear(); 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); reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -2330,7 +2330,7 @@ void TestRules::testStateBasedAction()
// set bool state to false // set bool state to false
spy.clear(); 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); reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -2338,7 +2338,7 @@ void TestRules::testStateBasedAction()
// trigger event // trigger event
spy.clear(); 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); reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -2356,7 +2356,7 @@ void TestRules::removePolicyUpdate()
{ {
// ADD parent device // ADD parent device
QVariantMap params; QVariantMap params;
params.insert("deviceClassId", mockParentThingClassId); params.insert("deviceClassId", parentMockThingClassId);
params.insert("name", "Parent device"); params.insert("name", "Parent device");
QSignalSpy addedSpy(NymeaCore::instance()->thingManager(), &ThingManager::thingAdded); QSignalSpy addedSpy(NymeaCore::instance()->thingManager(), &ThingManager::thingAdded);
@ -2378,7 +2378,7 @@ void TestRules::removePolicyUpdate()
foreach (const QVariant deviceVariant, devices) { foreach (const QVariant deviceVariant, devices) {
QVariantMap deviceMap = deviceVariant.toMap(); QVariantMap deviceMap = deviceVariant.toMap();
if (deviceMap.value("deviceClassId").toString() == mockChildThingClassId.toString()) { if (deviceMap.value("deviceClassId").toString() == childMockThingClassId.toString()) {
if (deviceMap.value("parentId") == parentId.toString()) { if (deviceMap.value("parentId") == parentId.toString()) {
//qDebug() << QJsonDocument::fromVariant(deviceVariant).toJson(); //qDebug() << QJsonDocument::fromVariant(deviceVariant).toJson();
childId = ThingId(deviceMap.value("id").toString()); childId = ThingId(deviceMap.value("id").toString());
@ -2389,8 +2389,8 @@ void TestRules::removePolicyUpdate()
// Add rule with child device // Add rule with child device
QVariantList eventDescriptors; QVariantList eventDescriptors;
eventDescriptors.append(createEventDescriptor(childId, mockChildBoolValueEventTypeId)); eventDescriptors.append(createEventDescriptor(childId, childMockBoolValueEventTypeId));
eventDescriptors.append(createEventDescriptor(parentId, mockParentBoolValueEventTypeId)); eventDescriptors.append(createEventDescriptor(parentId, parentMockBoolValueEventTypeId));
eventDescriptors.append(createEventDescriptor(m_mockThingId, mockEvent1EventTypeId)); eventDescriptors.append(createEventDescriptor(m_mockThingId, mockEvent1EventTypeId));
params.clear(); response.clear(); params.clear(); response.clear();
@ -2443,7 +2443,7 @@ void TestRules::removePolicyCascade()
{ {
// ADD parent device // ADD parent device
QVariantMap params; QVariantMap params;
params.insert("deviceClassId", mockParentThingClassId); params.insert("deviceClassId", parentMockThingClassId);
params.insert("name", "Parent device"); params.insert("name", "Parent device");
QSignalSpy addedSpy(NymeaCore::instance()->thingManager(), &ThingManager::thingAdded); QSignalSpy addedSpy(NymeaCore::instance()->thingManager(), &ThingManager::thingAdded);
@ -2465,7 +2465,7 @@ void TestRules::removePolicyCascade()
foreach (const QVariant deviceVariant, devices) { foreach (const QVariant deviceVariant, devices) {
QVariantMap deviceMap = deviceVariant.toMap(); QVariantMap deviceMap = deviceVariant.toMap();
if (deviceMap.value("deviceClassId").toString() == mockChildThingClassId.toString()) { if (deviceMap.value("deviceClassId").toString() == childMockThingClassId.toString()) {
if (deviceMap.value("parentId") == parentId.toString()) { if (deviceMap.value("parentId") == parentId.toString()) {
//qDebug() << QJsonDocument::fromVariant(deviceVariant).toJson(); //qDebug() << QJsonDocument::fromVariant(deviceVariant).toJson();
childId = ThingId(deviceMap.value("id").toString()); childId = ThingId(deviceMap.value("id").toString());
@ -2476,8 +2476,8 @@ void TestRules::removePolicyCascade()
// Add rule with child device // Add rule with child device
QVariantList eventDescriptors; QVariantList eventDescriptors;
eventDescriptors.append(createEventDescriptor(childId, mockChildBoolValueEventTypeId)); eventDescriptors.append(createEventDescriptor(childId, childMockBoolValueEventTypeId));
eventDescriptors.append(createEventDescriptor(parentId, mockParentBoolValueEventTypeId)); eventDescriptors.append(createEventDescriptor(parentId, parentMockBoolValueEventTypeId));
eventDescriptors.append(createEventDescriptor(m_mockThingId, mockEvent1EventTypeId)); eventDescriptors.append(createEventDescriptor(m_mockThingId, mockEvent1EventTypeId));
params.clear(); response.clear(); params.clear(); response.clear();
@ -2520,7 +2520,7 @@ void TestRules::removePolicyUpdateRendersUselessRule()
{ {
// ADD parent device // ADD parent device
QVariantMap params; QVariantMap params;
params.insert("deviceClassId", mockParentThingClassId); params.insert("deviceClassId", parentMockThingClassId);
params.insert("name", "Parent device"); params.insert("name", "Parent device");
QSignalSpy addedSpy(NymeaCore::instance()->thingManager(), &ThingManager::thingAdded); QSignalSpy addedSpy(NymeaCore::instance()->thingManager(), &ThingManager::thingAdded);
@ -2543,7 +2543,7 @@ void TestRules::removePolicyUpdateRendersUselessRule()
foreach (const QVariant deviceVariant, devices) { foreach (const QVariant deviceVariant, devices) {
QVariantMap deviceMap = deviceVariant.toMap(); QVariantMap deviceMap = deviceVariant.toMap();
if (deviceMap.value("deviceClassId").toString() == mockChildThingClassId.toString()) { if (deviceMap.value("deviceClassId").toString() == childMockThingClassId.toString()) {
if (deviceMap.value("parentId") == parentId.toString()) { if (deviceMap.value("parentId") == parentId.toString()) {
//qDebug() << QJsonDocument::fromVariant(deviceVariant).toJson(); //qDebug() << QJsonDocument::fromVariant(deviceVariant).toJson();
childId = ThingId(deviceMap.value("id").toString()); childId = ThingId(deviceMap.value("id").toString());
@ -2554,8 +2554,8 @@ void TestRules::removePolicyUpdateRendersUselessRule()
// Add rule with child device // Add rule with child device
QVariantList eventDescriptors; QVariantList eventDescriptors;
eventDescriptors.append(createEventDescriptor(childId, mockChildBoolValueEventTypeId)); eventDescriptors.append(createEventDescriptor(childId, childMockBoolValueEventTypeId));
eventDescriptors.append(createEventDescriptor(parentId, mockParentBoolValueEventTypeId)); eventDescriptors.append(createEventDescriptor(parentId, parentMockBoolValueEventTypeId));
eventDescriptors.append(createEventDescriptor(m_mockThingId, mockEvent1EventTypeId)); eventDescriptors.append(createEventDescriptor(m_mockThingId, mockEvent1EventTypeId));
params.clear(); response.clear(); params.clear(); response.clear();
@ -2564,9 +2564,9 @@ void TestRules::removePolicyUpdateRendersUselessRule()
QVariantMap action; QVariantMap action;
action.insert("deviceId", childId); action.insert("deviceId", childId);
action.insert("actionTypeId", mockChildBoolValueActionTypeId); action.insert("actionTypeId", childMockBoolValueActionTypeId);
QVariantMap ruleActionParam; QVariantMap ruleActionParam;
ruleActionParam.insert("paramTypeId", mockChildBoolValueActionBoolValueParamTypeId); ruleActionParam.insert("paramTypeId", childMockBoolValueActionBoolValueParamTypeId);
ruleActionParam.insert("value", true); ruleActionParam.insert("value", true);
action.insert("ruleActionParams", QVariantList() << ruleActionParam); action.insert("ruleActionParams", QVariantList() << ruleActionParam);
params.insert("actions", QVariantList() << action); params.insert("actions", QVariantList() << action);
@ -2826,7 +2826,7 @@ void TestRules::testInterfaceBasedEventRule()
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*))); QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
// state battery critical state to false initially // 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); QNetworkReply *reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -2882,13 +2882,13 @@ void TestRules::testInterfaceBasedEventRule()
// Change the state to true, action should trigger // Change the state to true, action should trigger
spy.clear(); 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); reply = nam.get(request);
qDebug(dcTests) << "Changing battery state -> true"; qDebug(dcTests) << "Changing battery state -> true";
spy.wait(); spy.clear(); 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); reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -2900,13 +2900,13 @@ void TestRules::testInterfaceBasedEventRule()
// Change the state to false, action should not trigger // Change the state to false, action should not trigger
spy.clear(); 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); reply = nam.get(request);
qDebug(dcTests) << "Changing battery state -> false"; qDebug(dcTests) << "Changing battery state -> false";
spy.wait(); spy.clear(); 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); reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -2920,7 +2920,7 @@ void TestRules::testInterfaceBasedStateRule()
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*))); QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
// state battery critical state to false initially // 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); QNetworkReply *reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -2974,7 +2974,7 @@ void TestRules::testInterfaceBasedStateRule()
// Change the state // Change the state
spy.clear(); 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); reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -3070,7 +3070,7 @@ void TestRules::testScene()
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*))); QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
// state power state to false initially // 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); QNetworkReply *reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -3078,7 +3078,7 @@ void TestRules::testScene()
// state battery critical state to false initially // state battery critical state to false initially
spy.clear(); 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); reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -3105,7 +3105,7 @@ void TestRules::testScene()
// trigger state change on battery critical // trigger state change on battery critical
spy.clear(); 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); reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -3144,7 +3144,7 @@ void TestRules::testHousekeeping()
params.insert("name", "TestDeviceToBeRemoved"); params.insert("name", "TestDeviceToBeRemoved");
QVariantList deviceParams; QVariantList deviceParams;
QVariantMap httpParam; QVariantMap httpParam;
httpParam.insert("paramTypeId", mockDeviceHttpportParamTypeId); httpParam.insert("paramTypeId", mockThingHttpportParamTypeId);
httpParam.insert("value", 6667); httpParam.insert("value", 6667);
deviceParams.append(httpParam); deviceParams.append(httpParam);
params.insert("deviceParams", deviceParams); params.insert("deviceParams", deviceParams);

View File

@ -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)"); 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(); Thing* device = NymeaCore::instance()->thingManager()->findConfiguredThings(mockThingClassId).first();
int port = device->paramValue(mockDeviceHttpportParamTypeId).toInt(); int port = device->paramValue(mockThingHttpportParamTypeId).toInt();
QNetworkAccessManager nam; QNetworkAccessManager nam;
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*))); QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));

View File

@ -2038,7 +2038,7 @@ void TestTimeManager::verifyRuleExecuted(const ActionTypeId &actionTypeId)
// Verify rule got executed // Verify rule got executed
QNetworkAccessManager nam; QNetworkAccessManager nam;
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*))); 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); QNetworkReply *reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -2052,7 +2052,7 @@ void TestTimeManager::verifyRuleNotExecuted()
{ {
QNetworkAccessManager nam; QNetworkAccessManager nam;
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*))); 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); QNetworkReply *reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -2065,7 +2065,7 @@ void TestTimeManager::verifyRuleNotExecuted()
void TestTimeManager::cleanupMockHistory() { void TestTimeManager::cleanupMockHistory() {
QNetworkAccessManager nam; QNetworkAccessManager nam;
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*))); 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); QNetworkReply *reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -2103,7 +2103,7 @@ void TestTimeManager::setIntState(const int &value)
QSignalSpy stateSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray))); QSignalSpy stateSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray)));
spy.clear(); 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); QNetworkReply *reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -2143,7 +2143,7 @@ void TestTimeManager::setBoolState(const bool &value)
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*))); QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
QSignalSpy stateSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray))); 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); QNetworkReply *reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
@ -2174,7 +2174,7 @@ void TestTimeManager::triggerMockEvent1()
QSignalSpy eventSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray))); 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); QNetworkReply *reply = nam.get(request);
spy.wait(); spy.wait();
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);

View File

@ -46,8 +46,8 @@ NymeaTestBase::NymeaTestBase(QObject *parent) :
{ {
qRegisterMetaType<QNetworkReply*>(); qRegisterMetaType<QNetworkReply*>();
qsrand(QDateTime::currentMSecsSinceEpoch()); qsrand(QDateTime::currentMSecsSinceEpoch());
m_mockDevice1Port = 1337 + (qrand() % 10000); m_mockThing1Port = 1337 + (qrand() % 10000);
m_mockDevice2Port = 7331 + (qrand() % 10000); m_mockThing2Port = 7331 + (qrand() % 10000);
// Important for settings // Important for settings
QCoreApplication::instance()->setOrganizationName("nymea-test"); QCoreApplication::instance()->setOrganizationName("nymea-test");
@ -105,7 +105,7 @@ void NymeaTestBase::initTestCase()
response = injectAndWait("Devices.GetConfiguredDevices", {}); response = injectAndWait("Devices.GetConfiguredDevices", {});
foreach (const QVariant &device, response.toMap().value("params").toMap().value("devices").toList()) { 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()); m_mockThingAutoId = ThingId(device.toMap().value("id").toString());
} }
} }
@ -404,6 +404,13 @@ bool NymeaTestBase::disableNotifications()
return true; return true;
} }
void NymeaTestBase::waitForDBSync()
{
while (NymeaCore::instance()->logEngine()->jobsRunning()) {
qApp->processEvents();
}
}
void NymeaTestBase::restartServer() void NymeaTestBase::restartServer()
{ {
// Destroy and recreate the core instance... // Destroy and recreate the core instance...
@ -430,8 +437,8 @@ void NymeaTestBase::createMockDevice()
QVariantList deviceParams; QVariantList deviceParams;
QVariantMap httpPortParam; QVariantMap httpPortParam;
httpPortParam.insert("paramTypeId", mockDeviceHttpportParamTypeId.toString()); httpPortParam.insert("paramTypeId", mockThingHttpportParamTypeId.toString());
httpPortParam.insert("value", m_mockDevice1Port); httpPortParam.insert("value", m_mockThing1Port);
deviceParams.append(httpPortParam); deviceParams.append(httpPortParam);
params.insert("deviceParams", deviceParams); params.insert("deviceParams", deviceParams);

View File

@ -121,6 +121,7 @@ protected:
qDebug() << jsonDoc.toJson(); qDebug() << jsonDoc.toJson();
} }
void waitForDBSync();
void restartServer(); void restartServer();
void clearLoggingDatabase(); void clearLoggingDatabase();
@ -129,14 +130,14 @@ private:
protected: protected:
PluginId mockPluginId = PluginId("727a4a9a-c187-446f-aadf-f1b2220607d1"); 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; MockTcpServer *m_mockTcpServer;
QUuid m_clientId; QUuid m_clientId;
int m_commandId; int m_commandId;
int m_mockDevice1Port; int m_mockThing1Port;
int m_mockDevice2Port; int m_mockThing2Port;
ThingId m_mockThingId; ThingId m_mockThingId;
ThingId m_mockThingAutoId; ThingId m_mockThingAutoId;

View File

@ -244,7 +244,7 @@ void PluginInfoCompiler::writeParams(const ParamTypes &paramTypes, const QString
m_variableNames.append(variableName); m_variableNames.append(variableName);
write(QString("ParamTypeId %1 = ParamTypeId(\"%2\");").arg(variableName).arg(paramType.id().toString())); 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)); 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())); m_translationStrings.insert(thingClass.displayName(), QString("The name of the ThingClass (%1)").arg(thingClass.id().toString()));
writeExtern(QString("extern ThingClassId %1;").arg(variableName)); 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.settingsTypes(), thingClass.name(), "", "settings");
writeParams(thingClass.discoveryParamTypes(), thingClass.name(), "", "discovery"); writeParams(thingClass.discoveryParamTypes(), thingClass.name(), "", "discovery");
@ -291,12 +291,12 @@ void PluginInfoCompiler::writeStateTypes(const StateTypes &stateTypes, const QSt
foreach (const StateType &stateType, stateTypes) { foreach (const StateType &stateType, stateTypes) {
QString variableName = QString("%1%2StateTypeId").arg(thingClassName, stateType.name()[0].toUpper() + stateType.name().right(stateType.name().length() - 1)); QString variableName = QString("%1%2StateTypeId").arg(thingClassName, stateType.name()[0].toUpper() + stateType.name().right(stateType.name().length() - 1));
if (m_variableNames.contains(variableName)) { 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; return;
} }
m_variableNames.append(variableName); m_variableNames.append(variableName);
write(QString("StateTypeId %1 = StateTypeId(\"%2\");").arg(variableName).arg(stateType.id().toString())); 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)); writeExtern(QString("extern StateTypeId %1;").arg(variableName));
} }
} }
@ -306,12 +306,12 @@ void PluginInfoCompiler::writeEventTypes(const EventTypes &eventTypes, const QSt
foreach (const EventType &eventType, eventTypes) { foreach (const EventType &eventType, eventTypes) {
QString variableName = QString("%1%2EventTypeId").arg(thingClassName, eventType.name()[0].toUpper() + eventType.name().right(eventType.name().length() - 1)); QString variableName = QString("%1%2EventTypeId").arg(thingClassName, eventType.name()[0].toUpper() + eventType.name().right(eventType.name().length() - 1));
if (m_variableNames.contains(variableName)) { 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; return;
} }
m_variableNames.append(variableName); m_variableNames.append(variableName);
write(QString("EventTypeId %1 = EventTypeId(\"%2\");").arg(variableName).arg(eventType.id().toString())); 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)); writeExtern(QString("extern EventTypeId %1;").arg(variableName));
writeParams(eventType.paramTypes(), thingClassName, "Event", eventType.name()); writeParams(eventType.paramTypes(), thingClassName, "Event", eventType.name());
@ -323,12 +323,12 @@ void PluginInfoCompiler::writeActionTypes(const ActionTypes &actionTypes, const
foreach (const ActionType &actionType, actionTypes) { foreach (const ActionType &actionType, actionTypes) {
QString variableName = QString("%1%2ActionTypeId").arg(thingClassName, actionType.name()[0].toUpper() + actionType.name().right(actionType.name().length() - 1)); QString variableName = QString("%1%2ActionTypeId").arg(thingClassName, actionType.name()[0].toUpper() + actionType.name().right(actionType.name().length() - 1));
if (m_variableNames.contains(variableName)) { 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; return;
} }
m_variableNames.append(variableName); m_variableNames.append(variableName);
write(QString("ActionTypeId %1 = ActionTypeId(\"%2\");").arg(variableName).arg(actionType.id().toString())); 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)); writeExtern(QString("extern ActionTypeId %1;").arg(variableName));
writeParams(actionType.paramTypes(), thingClassName, "Action", actionType.name()); writeParams(actionType.paramTypes(), thingClassName, "Action", actionType.name());
@ -340,12 +340,12 @@ void PluginInfoCompiler::writeBrowserItemActionTypes(const ActionTypes &actionTy
foreach (const ActionType &actionType, actionTypes) { foreach (const ActionType &actionType, actionTypes) {
QString variableName = QString("%1%2BrowserItemActionTypeId").arg(thingClassName, actionType.name()[0].toUpper() + actionType.name().right(actionType.name().length() - 1)); QString variableName = QString("%1%2BrowserItemActionTypeId").arg(thingClassName, actionType.name()[0].toUpper() + actionType.name().right(actionType.name().length() - 1));
if (m_variableNames.contains(variableName)) { 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; return;
} }
m_variableNames.append(variableName); m_variableNames.append(variableName);
write(QString("ActionTypeId %1 = ActionTypeId(\"%2\");").arg(variableName).arg(actionType.id().toString())); 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)); writeExtern(QString("extern ActionTypeId %1;").arg(variableName));
writeParams(actionType.paramTypes(), thingClassName, "BrowserItemAction", actionType.name()); writeParams(actionType.paramTypes(), thingClassName, "BrowserItemAction", actionType.name());