diff --git a/plugins/deviceplugins/mock/devicepluginmock.cpp b/plugins/deviceplugins/mock/devicepluginmock.cpp index 290d92d2..f8c07020 100644 --- a/plugins/deviceplugins/mock/devicepluginmock.cpp +++ b/plugins/deviceplugins/mock/devicepluginmock.cpp @@ -29,6 +29,8 @@ QUuid mockEvent1Id = QUuid("45bf3752-0fc6-46b9-89fd-ffd878b5b22b"); QUuid mockEvent2Id = QUuid("863d5920-b1cf-4eb9-88bd-8f7b8583b1cf"); QUuid mockIntStateId = QUuid("80baec19-54de-4948-ac46-31eabfaceb83"); QUuid mockBoolStateId = QUuid("9dd6a97c-dfd1-43dc-acbd-367932742310"); +QUuid mockAction1Id = QUuid("dea0f4e1-65e3-4981-8eaa-2701c53a9185"); +QUuid mockAction2Id = QUuid("defd3ed6-1a0d-400b-8879-a0202cf39935"); DevicePluginMock::DevicePluginMock() { @@ -52,13 +54,13 @@ QList DevicePluginMock::supportedDevices() const QList mockStates; StateType intState(mockIntStateId); - intState.setName("intState"); + intState.setName("Dummy int state"); intState.setType(QVariant::Int); intState.setDefaultValue(10); mockStates.append(intState); StateType boolState(mockBoolStateId); - boolState.setName("boolState"); + boolState.setName("Dummy bool state"); boolState.setType(QVariant::Int); boolState.setDefaultValue(false); mockStates.append(boolState); @@ -67,24 +69,28 @@ QList DevicePluginMock::supportedDevices() const QList mockEvents; -// QVariantList detectorEventParams; -// QVariantMap paramInRange; -// paramInRange.insert("name", "inRange"); -// paramInRange.insert("type", "bool"); -// detectorEventParams.append(paramInRange); - EventType event1(mockEvent1Id); - event1.setName("event1"); -// event1.setParameters(detectorEventParams); + event1.setName("Mock Event 1"); mockEvents.append(event1); EventType event2(mockEvent2Id); - event2.setName("event2"); -// event2.setParameters(detectorEventParams); + event2.setName("Mock Event 2"); mockEvents.append(event2); deviceClassMock.setEvents(mockEvents); + QList mockActions; + + ActionType action1(mockAction1Id); + action1.setName("Mock Action 1"); + mockActions.append(action1); + + ActionType action2(mockAction2Id); + action2.setName("Mock Action 2"); + mockActions.append(action2); + + deviceClassMock.setActions(mockActions); + ret.append(deviceClassMock); return ret; @@ -123,6 +129,12 @@ bool DevicePluginMock::deviceCreated(Device *device) return true; } +void DevicePluginMock::executeAction(Device *device, const Action &action) +{ + qDebug() << "Should execute action" << action.actionTypeId(); + m_daemons.value(device)->actionExecuted(action.actionTypeId()); +} + void DevicePluginMock::setState(const QUuid &stateTypeId, const QVariant &value) { qDebug() << "should set state" << stateTypeId << value; diff --git a/plugins/deviceplugins/mock/devicepluginmock.h b/plugins/deviceplugins/mock/devicepluginmock.h index 8d8f291e..c85f3d33 100644 --- a/plugins/deviceplugins/mock/devicepluginmock.h +++ b/plugins/deviceplugins/mock/devicepluginmock.h @@ -43,6 +43,9 @@ public: bool deviceCreated(Device *device) override; +public slots: + void executeAction(Device *device, const Action &action) override; + private slots: void setState(const QUuid &stateTypeId, const QVariant &value); void triggerEvent(const QUuid &id); diff --git a/plugins/deviceplugins/mock/httpdaemon.cpp b/plugins/deviceplugins/mock/httpdaemon.cpp index 802397f2..287486d6 100644 --- a/plugins/deviceplugins/mock/httpdaemon.cpp +++ b/plugins/deviceplugins/mock/httpdaemon.cpp @@ -43,6 +43,11 @@ void HttpDaemon::resume() disabled = false; } +void HttpDaemon::actionExecuted(const QUuid &actionTypeId) +{ + m_actionList.append(qMakePair(actionTypeId, QDateTime::currentDateTime())); +} + void HttpDaemon::readClient() { if (disabled) @@ -105,9 +110,15 @@ QString HttpDaemon::generateWebPage() "" "" "

Mock device Controller

\n" + "
" + "

Device Information

" "Name: %1
" "ID: %2
" "DeviceClass ID: %3
").arg(m_device->name()).arg(m_device->id().toString()).arg(deviceClass.id().toString()); + + body.append("
"); + body.append("

States

"); + body.append(""); for (int i = 0; i < deviceClass.states().count(); ++i) { body.append(""); @@ -121,13 +132,16 @@ QString HttpDaemon::generateWebPage() } body.append("
"); + body.append("
"); + body.append("

Events

"); + body.append(""); for (int i = 0; i < deviceClass.events().count(); ++i) { const EventType &eventType = deviceClass.events().at(i); body.append(QString( "" "" - "" + "" "" "" "" @@ -135,6 +149,32 @@ QString HttpDaemon::generateWebPage() } body.append("
Event %1%1
"); + body.append("
"); + body.append("

Actions

"); + + body.append(""); + body.append(""); + for (int i = 0; i < m_actionList.count(); ++i) { + QUuid actionTypeId = m_actionList.at(i).first; + QDateTime timestamp = m_actionList.at(i).second; + QString actionName; + foreach (const ActionType &at, deviceClass.actions()) { + if (at.id() == actionTypeId) { + actionName = at.name(); + break; + } + } + body.append(QString( + "" + "" + "" + "" + "" + ).arg(actionName).arg(actionTypeId.toString()).arg(timestamp.toString())); + } + body.append("
NameType IDTimestamp
%1%2%3
"); + + body.append("\n"); return contentHeader + body; diff --git a/plugins/deviceplugins/mock/httpdaemon.h b/plugins/deviceplugins/mock/httpdaemon.h index 128475f9..40a5b804 100644 --- a/plugins/deviceplugins/mock/httpdaemon.h +++ b/plugins/deviceplugins/mock/httpdaemon.h @@ -2,6 +2,8 @@ #define HTTPDAEMON_H #include +#include +#include class Device; class DevicePlugin; @@ -18,6 +20,8 @@ public: void resume(); + void actionExecuted(const QUuid&actionTypeId); + signals: void setState(const QUuid &stateTypeId, const QVariant &value); void triggerEvent(const QUuid &eventTypeId); @@ -34,6 +38,8 @@ private: DevicePlugin *m_plugin; Device *m_device; + + QList > m_actionList; }; #endif // HTTPDAEMON_H diff --git a/tests/scripts/addconfigureddevice.sh b/tests/scripts/addconfigureddevice.sh index 23542d4e..edde6441 100755 --- a/tests/scripts/addconfigureddevice.sh +++ b/tests/scripts/addconfigureddevice.sh @@ -26,5 +26,7 @@ else elif [ $2 == "mock" ]; then # Adds a Mock device (echo '{"id":1, "method":"Devices.AddConfiguredDevice", "params":{"deviceClassId": "{753f0d32-0468-4d08-82ed-1964aab03298}","deviceParams":{"httpport":"8081"}}}'; sleep 1) | nc $1 1234 + else + echo "unknown type $2. Possible values are: elroremote, elroswitch, intertechnoremote, meisteranker, wifidetector, mock" fi fi