Implement autodevice reconfigure in mock plugin and prepare tests

This commit is contained in:
Simon Stürz 2019-04-03 19:56:25 +02:00 committed by Michael Zanetti
parent 13b0f38693
commit beb00aa0f1
7 changed files with 50 additions and 0 deletions

View File

@ -260,3 +260,11 @@ Device *Devices::findById(const DeviceId &id)
}
return nullptr;
}
QDebug operator<<(QDebug dbg, Device *device)
{
dbg.nospace() << "Device(" << device->name();
dbg.nospace() << ", id" << device->id();
dbg.nospace() << ", deviceClassId" << device->deviceClassId() << ")";
return dbg.space();
}

View File

@ -94,6 +94,8 @@ private:
bool m_autoCreated = false;
};
QDebug operator<<(QDebug dbg, Device *device);
class Devices: public QList<Device*>
{
public:

View File

@ -383,6 +383,24 @@ void DevicePluginMock::onDisappear()
emit autoDeviceDisappeared(device->id());
}
void DevicePluginMock::onReconfigureAutoDevice()
{
HttpDaemon *daemon = qobject_cast<HttpDaemon*>(sender());
if (!daemon) {
return;
}
Device *device = m_daemons.key(daemon);
qCDebug(dcMockDevice) << "Reconfigure auto device for" << device;
DeviceDescriptor deviceDescriptor;
deviceDescriptor.setTitle(device->name() + " (reconfigured)");
deviceDescriptor.setDescription("This auto device was reconfigured");
deviceDescriptor.setDeviceId(device->id());
deviceDescriptor.setParams(device->params());
emit autoDevicesAppeared(mockDeviceAutoDeviceClassId, { deviceDescriptor });
}
void DevicePluginMock::emitDevicesDiscovered()
{
QList<DeviceDescriptor> deviceDescriptors;

View File

@ -59,6 +59,7 @@ private slots:
void setState(const StateTypeId &stateTypeId, const QVariant &value);
void triggerEvent(const EventTypeId &id);
void onDisappear();
void onReconfigureAutoDevice();
void emitDevicesDiscovered();
void emitPushButtonDevicesDiscovered();
void emitDisplayPinDevicesDiscovered();

View File

@ -114,6 +114,9 @@ void HttpDaemon::readClient()
} else if (url.path() == "/disappear") {
qCDebug(dcMockDevice) << "Should disappear";
emit disappear();
} else if (url.path() == "/reconfigureautodevice") {
qCDebug(dcMockDevice) << "Reconfigure auto device";
emit reconfigureAutodevice();
}
if (tokens[0] == "GET") {

View File

@ -47,6 +47,7 @@ signals:
void setState(const StateTypeId &stateTypeId, const QVariant &value);
void triggerEvent(const EventTypeId &eventTypeId);
void disappear();
void reconfigureAutodevice();
private slots:
void readClient();

View File

@ -91,6 +91,7 @@ private slots:
void reconfigureByDiscovery();
void reconfigureByDiscoveryAndPair();
void reconfigureAutodevice();
void removeDevice_data();
void removeDevice();
@ -1275,6 +1276,22 @@ void TestDevices::reconfigureByDiscoveryAndPair()
}
void TestDevices::reconfigureAutodevice()
{
// Get the current autodevice
QVariant response = injectAndWait("Devices.GetConfiguredDevices");
QVariantList devices = response.toMap().value("params").toMap().value("devices").toList();
QVariantMap autoDevice;
foreach (const QVariant &deviceVariant, devices) {
QVariantMap deviceMap = deviceVariant.toMap();
qDebug() << deviceMap;
}
}
void TestDevices::removeDevice_data()
{