mirror of https://github.com/nymea/nymea.git
add actions to mockdevice
parent
59e8233e45
commit
2dc18583ec
|
|
@ -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<DeviceClass> DevicePluginMock::supportedDevices() const
|
|||
QList<StateType> 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<DeviceClass> DevicePluginMock::supportedDevices() const
|
|||
|
||||
QList<EventType> 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<ActionType> 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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -43,6 +43,11 @@ void HttpDaemon::resume()
|
|||
disabled = false;
|
||||
}
|
||||
|
||||
void HttpDaemon::actionExecuted(const QUuid &actionTypeId)
|
||||
{
|
||||
m_actionList.append(qMakePair<QUuid, QDateTime>(actionTypeId, QDateTime::currentDateTime()));
|
||||
}
|
||||
|
||||
void HttpDaemon::readClient()
|
||||
{
|
||||
if (disabled)
|
||||
|
|
@ -105,9 +110,15 @@ QString HttpDaemon::generateWebPage()
|
|||
"<html>"
|
||||
"<body>"
|
||||
"<h1>Mock device Controller</h1>\n"
|
||||
"<hr>"
|
||||
"<h2>Device Information</h2>"
|
||||
"Name: %1<br>"
|
||||
"ID: %2<br>"
|
||||
"DeviceClass ID: %3<br>").arg(m_device->name()).arg(m_device->id().toString()).arg(deviceClass.id().toString());
|
||||
|
||||
body.append("<hr>");
|
||||
body.append("<h2>States</h2>");
|
||||
|
||||
body.append("<table>");
|
||||
for (int i = 0; i < deviceClass.states().count(); ++i) {
|
||||
body.append("<tr>");
|
||||
|
|
@ -121,13 +132,16 @@ QString HttpDaemon::generateWebPage()
|
|||
}
|
||||
body.append("</table>");
|
||||
|
||||
body.append("<hr>");
|
||||
body.append("<h2>Events</h2>");
|
||||
|
||||
body.append("<table>");
|
||||
for (int i = 0; i < deviceClass.events().count(); ++i) {
|
||||
const EventType &eventType = deviceClass.events().at(i);
|
||||
body.append(QString(
|
||||
"<tr>"
|
||||
"<form action=\"/generateevent\" method=\"get\">"
|
||||
"<td>Event %1<input type='hidden' name='eventid' value='%2'/></td>"
|
||||
"<td>%1<input type='hidden' name='eventid' value='%2'/></td>"
|
||||
"<td><input type='submit' value='Generate'/></td>"
|
||||
"</form>"
|
||||
"</tr>"
|
||||
|
|
@ -135,6 +149,32 @@ QString HttpDaemon::generateWebPage()
|
|||
}
|
||||
body.append("</table>");
|
||||
|
||||
body.append("<hr>");
|
||||
body.append("<h2>Actions</h2>");
|
||||
|
||||
body.append("<table border=2px>");
|
||||
body.append("<tr><td>Name</td><td>Type ID</td><td>Timestamp</td></tr>");
|
||||
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(
|
||||
"<tr>"
|
||||
"<td>%1</td>"
|
||||
"<td>%2</td>"
|
||||
"<td>%3</td>"
|
||||
"</tr>"
|
||||
).arg(actionName).arg(actionTypeId.toString()).arg(timestamp.toString()));
|
||||
}
|
||||
body.append("</table>");
|
||||
|
||||
|
||||
body.append("</body></html>\n");
|
||||
|
||||
return contentHeader + body;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
#define HTTPDAEMON_H
|
||||
|
||||
#include <QTcpServer>
|
||||
#include <QUuid>
|
||||
#include <QDateTime>
|
||||
|
||||
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<QPair<QUuid, QDateTime> > m_actionList;
|
||||
};
|
||||
|
||||
#endif // HTTPDAEMON_H
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue