mirror of https://github.com/nymea/nymea.git
implemented removeconfigureddevice
parent
c8ab8493fe
commit
cf9d460bad
|
|
@ -168,6 +168,30 @@ DeviceManager::DeviceError DeviceManager::addConfiguredDevice(const QUuid &devic
|
|||
return DeviceErrorNoError;
|
||||
}
|
||||
|
||||
DeviceManager::DeviceError DeviceManager::removeConfiguredDevice(const QUuid &deviceId)
|
||||
{
|
||||
Device *device = findConfiguredDevice(deviceId);
|
||||
if (!device) {
|
||||
return DeviceErrorDeviceNotFound;
|
||||
}
|
||||
|
||||
m_configuredDevices.removeAll(device);
|
||||
m_devicePlugins.value(device->pluginId())->deviceRemoved(device);
|
||||
|
||||
m_pluginTimerUsers.removeAll(device);
|
||||
if (m_pluginTimerUsers.isEmpty()) {
|
||||
m_pluginTimer.stop();
|
||||
}
|
||||
|
||||
device->deleteLater();
|
||||
|
||||
QSettings settings;
|
||||
settings.beginGroup(deviceId.toString());
|
||||
settings.remove("");
|
||||
|
||||
return DeviceErrorNoError;
|
||||
}
|
||||
|
||||
/*! Returns the \l{Device} with the given \a id. Null if the id couldn't be found. */
|
||||
Device *DeviceManager::findConfiguredDevice(const QUuid &id) const
|
||||
{
|
||||
|
|
@ -354,6 +378,7 @@ bool DeviceManager::setupDevice(Device *device)
|
|||
// Additionally fire off one event to initialize stuff
|
||||
QTimer::singleShot(0, this, SLOT(timerEvent()));
|
||||
}
|
||||
m_pluginTimerUsers.append(device);
|
||||
}
|
||||
|
||||
if (!plugin->deviceCreated(device)) {
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ public:
|
|||
|
||||
QList<Device*> configuredDevices() const;
|
||||
DeviceError addConfiguredDevice(const QUuid &deviceClassId, const QVariantMap ¶ms, const QUuid id = QUuid::createUuid());
|
||||
DeviceError removeConfiguredDevice(const QUuid &deviceId);
|
||||
|
||||
Device* findConfiguredDevice(const QUuid &id) const;
|
||||
QList<Device*> findConfiguredDevices(const QUuid &deviceClassId) const;
|
||||
|
|
@ -97,6 +98,7 @@ private:
|
|||
// Hardware Resources
|
||||
Radio433* m_radio433;
|
||||
QTimer m_pluginTimer;
|
||||
QList<Device*> m_pluginTimerUsers;
|
||||
|
||||
friend class DevicePlugin;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -109,9 +109,19 @@ DevicePlugin::~DevicePlugin()
|
|||
*/
|
||||
bool DevicePlugin::deviceCreated(Device *device)
|
||||
{
|
||||
Q_UNUSED(device)
|
||||
return true;
|
||||
}
|
||||
|
||||
/*! This will be called when a device removed. The plugin has the chance to do some teardown.
|
||||
The device is still valid during this call, but already removed from the system.
|
||||
The device will be deleted as soon as this method returns.
|
||||
*/
|
||||
void DevicePlugin::deviceRemoved(Device *device)
|
||||
{
|
||||
Q_UNUSED(device)
|
||||
}
|
||||
|
||||
/*! This will be called when the DeviceManager initializes the plugin and set up the things behind the scenes.
|
||||
When implementing a new plugin, use \l{DevicePlugin::init()} instead in order to do initialisation work. */
|
||||
void DevicePlugin::initPlugin(DeviceManager *deviceManager)
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ public:
|
|||
virtual DeviceManager::HardwareResources requiredHardware() const = 0;
|
||||
|
||||
virtual bool deviceCreated(Device *device);
|
||||
virtual void deviceRemoved(Device *device);
|
||||
|
||||
// Hardware input
|
||||
virtual void radioData(QList<int> rawData) {Q_UNUSED(rawData)}
|
||||
|
|
|
|||
|
|
@ -129,6 +129,11 @@ bool DevicePluginMock::deviceCreated(Device *device)
|
|||
return true;
|
||||
}
|
||||
|
||||
void DevicePluginMock::deviceRemoved(Device *device)
|
||||
{
|
||||
m_daemons.take(device)->deleteLater();
|
||||
}
|
||||
|
||||
void DevicePluginMock::executeAction(Device *device, const Action &action)
|
||||
{
|
||||
qDebug() << "Should execute action" << action.actionTypeId();
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ public:
|
|||
QUuid pluginId() const override;
|
||||
|
||||
bool deviceCreated(Device *device) override;
|
||||
void deviceRemoved(Device *device) override;
|
||||
|
||||
public slots:
|
||||
void executeAction(Device *device, const Action &action) override;
|
||||
|
|
|
|||
|
|
@ -35,16 +35,6 @@ void HttpDaemon::incomingConnection(qintptr socket)
|
|||
|
||||
}
|
||||
|
||||
void HttpDaemon::pause()
|
||||
{
|
||||
disabled = true;
|
||||
}
|
||||
|
||||
void HttpDaemon::resume()
|
||||
{
|
||||
disabled = false;
|
||||
}
|
||||
|
||||
void HttpDaemon::actionExecuted(const QUuid &actionTypeId)
|
||||
{
|
||||
m_actionList.append(qMakePair<QUuid, QDateTime>(actionTypeId, QDateTime::currentDateTime()));
|
||||
|
|
|
|||
|
|
@ -16,10 +16,6 @@ public:
|
|||
|
||||
void incomingConnection(qintptr socket) override;
|
||||
|
||||
void pause();
|
||||
|
||||
void resume();
|
||||
|
||||
void actionExecuted(const QUuid&actionTypeId);
|
||||
|
||||
signals:
|
||||
|
|
|
|||
|
|
@ -77,6 +77,14 @@ DeviceHandler::DeviceHandler(QObject *parent) :
|
|||
returns.insert("devices", devices);
|
||||
setReturns("GetConfiguredDevices", returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
setDescription("RemoveConfiguredDevice", "Remove a device from the system.");
|
||||
params.insert("deviceId", "uuid");
|
||||
setParams("RemoveConfiguredDevice", params);
|
||||
returns.insert("success", "bool");
|
||||
returns.insert("errorMessage", "string");
|
||||
setReturns("RemoveConfiguredDevice", returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
setDescription("GetEventTypes", "Get event types for a specified deviceClassId.");
|
||||
params.insert("deviceClassId", "uuid");
|
||||
|
|
@ -209,6 +217,24 @@ QVariantMap DeviceHandler::GetConfiguredDevices(const QVariantMap ¶ms) const
|
|||
return returns;
|
||||
}
|
||||
|
||||
QVariantMap DeviceHandler::RemoveConfiguredDevice(const QVariantMap ¶ms)
|
||||
{
|
||||
QVariantMap returns;
|
||||
switch(GuhCore::instance()->deviceManager()->removeConfiguredDevice(params.value("deviceId").toUuid())) {
|
||||
case DeviceManager::DeviceErrorNoError:
|
||||
returns.insert("success", true);
|
||||
returns.insert("errorMessage", "");
|
||||
return returns;
|
||||
case DeviceManager::DeviceErrorDeviceNotFound:
|
||||
returns.insert("success", false);
|
||||
returns.insert("errorMessage", "No such device.");
|
||||
return returns;
|
||||
}
|
||||
returns.insert("success", false);
|
||||
returns.insert("errorMessage", "Unknown error.");
|
||||
return returns;
|
||||
}
|
||||
|
||||
QVariantMap DeviceHandler::GetEventTypes(const QVariantMap ¶ms) const
|
||||
{
|
||||
QVariantMap returns;
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ public:
|
|||
|
||||
Q_INVOKABLE QVariantMap GetConfiguredDevices(const QVariantMap ¶ms) const;
|
||||
|
||||
Q_INVOKABLE QVariantMap RemoveConfiguredDevice(const QVariantMap ¶ms);
|
||||
|
||||
Q_INVOKABLE QVariantMap GetEventTypes(const QVariantMap ¶ms) const;
|
||||
|
||||
Q_INVOKABLE QVariantMap GetActionTypes(const QVariantMap ¶ms) const;
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ private slots:
|
|||
|
||||
void stateChangeEmitsNotifications();
|
||||
|
||||
void removeDevice();
|
||||
|
||||
private:
|
||||
QVariant injectAndWait(const QString &method, const QVariantMap ¶ms);
|
||||
|
|
@ -239,10 +240,25 @@ void TestJSONRPC::stateChangeEmitsNotifications()
|
|||
params.insert("stateTypeId", stateTypeId);
|
||||
response = injectAndWait("Devices.GetStateValue", params);
|
||||
|
||||
qDebug() << "response" << response;
|
||||
QCOMPARE(response.toMap().value("params").toMap().value("value").toInt(), newVal);
|
||||
|
||||
}
|
||||
|
||||
void TestJSONRPC::removeDevice()
|
||||
{
|
||||
QVERIFY(!m_mockDeviceId.isNull());
|
||||
|
||||
QVariantMap params;
|
||||
params.insert("deviceId", m_mockDeviceId);
|
||||
|
||||
QVariant response = injectAndWait("Devices.RemoveConfiguredDevice", params);
|
||||
|
||||
QCOMPARE(response.toMap().value("params").toMap().value("success").toBool(), true);
|
||||
|
||||
// Make sure the device is gone from settings too
|
||||
QSettings settings;
|
||||
QCOMPARE(settings.allKeys().count(), 0);
|
||||
}
|
||||
|
||||
QTEST_MAIN(TestJSONRPC)
|
||||
#include "testjsonrpc.moc"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [ -z $2 ]; then
|
||||
echo "usage: $0 host deviceId"
|
||||
else
|
||||
(echo '{"id":1, "method":"Devices.RemoveConfiguredDevice", "params":{"deviceId":"'$2'"}}'; sleep 1) | nc $1 1234
|
||||
fi
|
||||
Loading…
Reference in New Issue