state changes emit events now

This commit is contained in:
Michael Zanetti 2014-06-08 20:47:07 +02:00
parent bbd05ca7fd
commit 21738b3907
31 changed files with 270 additions and 133 deletions

10
debian/changelog vendored
View File

@ -1,8 +1,14 @@
guh (0.1.5) UNRELEASED; urgency=medium guh (0.1.6) utopic; urgency=medium
* state changes auto generate events now
-- Michael Zanetti <micha@noneyet> Sun, 08 Jun 2014 20:28:17 +0200
guh (0.1.5) utopic; urgency=medium
* align params/paramTypes with the rest of the type system * align params/paramTypes with the rest of the type system
-- Michael Zanetti <micha@noneyet> Sun, 08 Jun 2014 16:36:27 +0200 -- Michael Zanetti <micha@noneyet> Sun, 08 Jun 2014 20:24:25 +0200
guh (0.1.4) trusty; urgency=medium guh (0.1.4) trusty; urgency=medium

View File

@ -241,7 +241,7 @@ QPair<DeviceManager::DeviceError, QString> DeviceManager::addConfiguredDeviceInt
return qMakePair<DeviceError, QString>(DeviceErrorDeviceClassNotFound, deviceClassId.toString()); return qMakePair<DeviceError, QString>(DeviceErrorDeviceClassNotFound, deviceClassId.toString());
} }
QPair<DeviceError, QString> result = verifyParams(deviceClass.params(), params); QPair<DeviceError, QString> result = verifyParams(deviceClass.paramTypes(), params);
if (result.first != DeviceErrorNoError) { if (result.first != DeviceErrorNoError) {
return result; return result;
} }
@ -360,7 +360,7 @@ QPair<DeviceManager::DeviceError, QString> DeviceManager::executeAction(const Ac
// Make sure this device has an action type with this id // Make sure this device has an action type with this id
DeviceClass deviceClass = findDeviceClass(device->deviceClassId()); DeviceClass deviceClass = findDeviceClass(device->deviceClassId());
bool found = false; bool found = false;
foreach (const ActionType &actionType, deviceClass.actions()) { foreach (const ActionType &actionType, deviceClass.actionTypes()) {
if (actionType.id() == action.actionTypeId()) { if (actionType.id() == action.actionTypeId()) {
QPair<DeviceError, QString> paramCheck = verifyParams(actionType.parameters(), action.params()); QPair<DeviceError, QString> paramCheck = verifyParams(actionType.parameters(), action.params());
if (paramCheck.first != DeviceErrorNoError) { if (paramCheck.first != DeviceErrorNoError) {
@ -593,6 +593,10 @@ void DeviceManager::slotDeviceStateValueChanged(const QUuid &stateTypeId, const
return; return;
} }
emit deviceStateChanged(device, stateTypeId, value); emit deviceStateChanged(device, stateTypeId, value);
Param valueParam("value", value);
Event event(EventTypeId(stateTypeId.toString()), device->id(), QList<Param>() << valueParam);
emit eventTriggered(event);
} }
void DeviceManager::radio433SignalReceived(QList<int> rawData) void DeviceManager::radio433SignalReceived(QList<int> rawData)
@ -627,7 +631,7 @@ QPair<DeviceManager::DeviceSetupStatus,QString> DeviceManager::setupDevice(Devic
} }
QList<State> states; QList<State> states;
foreach (const StateType &stateType, deviceClass.states()) { foreach (const StateType &stateType, deviceClass.stateTypes()) {
State state(stateType.id(), device->id()); State state(stateType.id(), device->id());
state.setValue(stateType.defaultValue()); state.setValue(stateType.defaultValue());
states.append(state); states.append(state);

View File

@ -30,6 +30,7 @@
*/ */
#include "device.h" #include "device.h"
#include "types/event.h"
#include <QDebug> #include <QDebug>

View File

@ -87,68 +87,86 @@ void DeviceClass::setName(const QString &name)
/*! Returns the statesTypes of this DeviceClass. \{Device}{Devices} created /*! Returns the statesTypes of this DeviceClass. \{Device}{Devices} created
from this DeviceClass must have their states matching to this template. */ from this DeviceClass must have their states matching to this template. */
QList<StateType> DeviceClass::states() const QList<StateType> DeviceClass::stateTypes() const
{ {
return m_states; return m_stateTypes;
} }
/*! Set the \a stateTypes of this DeviceClass. \{Device}{Devices} created /*! Set the \a stateTypes of this DeviceClass. \{Device}{Devices} created
from this DeviceClass must have their states matching to this template. */ from this DeviceClass must have their states matching to this template. */
void DeviceClass::setStates(const QList<StateType> &stateTypes) void DeviceClass::setStateTypes(const QList<StateType> &stateTypes)
{ {
m_states = stateTypes; m_stateTypes = stateTypes;
m_allEventTypes = m_eventTypes;
foreach (const StateType &stateType, m_stateTypes) {
EventType eventType(EventTypeId(stateType.id().toString()));
eventType.setName(QString("%1 changed").arg(stateType.name()));
ParamType paramType("value", stateType.type());
eventType.setParameters(QList<ParamType>() << paramType);
m_allEventTypes.append(eventType);
}
} }
/*! Returns the eventTypes of this DeviceClass. \{Device}{Devices} created /*! Returns the eventTypes of this DeviceClass. \{Device}{Devices} created
from this DeviceClass must have their events matching to this template. */ from this DeviceClass must have their events matching to this template. */
QList<EventType> DeviceClass::events() const QList<EventType> DeviceClass::eventTypes() const
{ {
return m_events; return m_allEventTypes;
} }
/*! Set the \a eventTypes of this DeviceClass. \{Device}{Devices} created /*! Set the \a eventTypes of this DeviceClass. \{Device}{Devices} created
from this DeviceClass must have their events matching to this template. */ from this DeviceClass must have their events matching to this template. */
void DeviceClass::setEvents(const QList<EventType> &eventTypes) void DeviceClass::setEventTypes(const QList<EventType> &eventTypes)
{ {
m_events = eventTypes; m_eventTypes = eventTypes;
m_allEventTypes = m_eventTypes;
foreach (const StateType &stateType, m_stateTypes) {
EventType eventType(EventTypeId(stateType.id().toString()));
eventType.setName(QString("%1 changed").arg(stateType.name()));
ParamType paramType("value", stateType.type());
eventType.setParameters(QList<ParamType>() << paramType);
m_allEventTypes.append(eventType);
}
} }
/*! Returns the actionTypes of this DeviceClass. \{Device}{Devices} created /*! Returns the actionTypes of this DeviceClass. \{Device}{Devices} created
from this DeviceClass must have their actions matching to this template. */ from this DeviceClass must have their actions matching to this template. */
QList<ActionType> DeviceClass::actions() const QList<ActionType> DeviceClass::actionTypes() const
{ {
return m_actions; return m_actionTypes;
} }
/*! Set the \a actionTypes of this DeviceClass. \{Device}{Devices} created /*! Set the \a actionTypes of this DeviceClass. \{Device}{Devices} created
from this DeviceClass must have their actions matching to this template. */ from this DeviceClass must have their actions matching to this template. */
void DeviceClass::setActions(const QList<ActionType> &actionTypes) void DeviceClass::setActions(const QList<ActionType> &actionTypes)
{ {
m_actions = actionTypes; m_actionTypes = actionTypes;
} }
/*! Returns the params description of this DeviceClass. \{Device}{Devices} created /*! Returns the params description of this DeviceClass. \{Device}{Devices} created
from this DeviceClass must have their params matching to this template. */ from this DeviceClass must have their params matching to this template. */
QList<ParamType> DeviceClass::params() const QList<ParamType> DeviceClass::paramTypes() const
{ {
return m_params; return m_paramTypes;
} }
/*! Set the \a params of this DeviceClass. \{Device}{Devices} created /*! Set the \a params of this DeviceClass. \{Device}{Devices} created
from this DeviceClass must have their actions matching to this template. */ from this DeviceClass must have their actions matching to this template. */
void DeviceClass::setParams(const QList<ParamType> &params) void DeviceClass::setParamTypes(const QList<ParamType> &params)
{ {
m_params = params; m_paramTypes = params;
} }
QList<ParamType> DeviceClass::discoveryParams() const QList<ParamType> DeviceClass::discoveryParamTypes() const
{ {
return m_discoveryParams; return m_discoveryParamTypes;
} }
void DeviceClass::setDiscoveryParams(const QList<ParamType> &params) void DeviceClass::setDiscoveryParamTypes(const QList<ParamType> &params)
{ {
m_discoveryParams = params; m_discoveryParamTypes = params;
} }
DeviceClass::CreateMethod DeviceClass::createMethod() const DeviceClass::CreateMethod DeviceClass::createMethod() const

View File

@ -54,20 +54,20 @@ public:
QString name() const; QString name() const;
void setName(const QString &name); void setName(const QString &name);
QList<StateType> states() const; QList<StateType> stateTypes() const;
void setStates(const QList<StateType> &stateTypes); void setStateTypes(const QList<StateType> &stateTypes);
QList<EventType> events() const; QList<EventType> eventTypes() const;
void setEvents(const QList<EventType> &eventTypes); void setEventTypes(const QList<EventType> &eventTypes);
QList<ActionType> actions() const; QList<ActionType> actionTypes() const;
void setActions(const QList<ActionType> &actionTypes); void setActions(const QList<ActionType> &actionTypes);
QList<ParamType> params() const; QList<ParamType> paramTypes() const;
void setParams(const QList<ParamType> &params); void setParamTypes(const QList<ParamType> &paramTypes);
QList<ParamType> discoveryParams() const; QList<ParamType> discoveryParamTypes() const;
void setDiscoveryParams(const QList<ParamType> &params); void setDiscoveryParamTypes(const QList<ParamType> &paramTypes);
CreateMethod createMethod() const; CreateMethod createMethod() const;
void setCreateMethod(CreateMethod createMethod); void setCreateMethod(CreateMethod createMethod);
@ -81,11 +81,12 @@ private:
VendorId m_vendorId; VendorId m_vendorId;
PluginId m_pluginId; PluginId m_pluginId;
QString m_name; QString m_name;
QList<StateType> m_states; QList<StateType> m_stateTypes;
QList<EventType> m_events; QList<EventType> m_eventTypes;
QList<ActionType> m_actions; QList<EventType> m_allEventTypes;
QList<ParamType> m_params; QList<ActionType> m_actionTypes;
QList<ParamType> m_discoveryParams; QList<ParamType> m_paramTypes;
QList<ParamType> m_discoveryParamTypes;
CreateMethod m_createMethod; CreateMethod m_createMethod;
SetupMethod m_setupMethod; SetupMethod m_setupMethod;
}; };

View File

@ -53,19 +53,19 @@ void EventType::setName(const QString &name)
} }
/*! /*!
Holds a map describing possible parameters for a \l{Event} of this EventType. Holds a List describing possible parameters for a \l{Event} of this EventType.
e.g. QVariantList(QVariantMap(("name", "temperature"), ("type": QVariant::Real))) e.g. QList(ParamType("temperature", QVariant::Real))
*/ */
QVariantList EventType::parameters() const QList<ParamType> EventType::parameters() const
{ {
return m_parameters; return m_parameters;
} }
/*! /*!
Set the parameter description for this EventType to \a parameters, Set the parameter description for this EventType to \a parameters,
e.g. QVariantList(QVariantMap(("name", "temperature"), ("type": QVariant::Real))) e.g. QList<ParamType>() << ParamType("temperature", QVariant::Real))
*/ */
void EventType::setParameters(const QVariantList &parameters) void EventType::setParameters(const QList<ParamType> &parameters)
{ {
m_parameters = parameters; m_parameters = parameters;
} }

View File

@ -20,6 +20,7 @@
#define TRIGGERTYPE_H #define TRIGGERTYPE_H
#include "typeutils.h" #include "typeutils.h"
#include "paramtype.h"
#include <QVariantMap> #include <QVariantMap>
@ -33,14 +34,14 @@ public:
QString name() const; QString name() const;
void setName(const QString &name); void setName(const QString &name);
QVariantList parameters() const; QList<ParamType> parameters() const;
void setParameters(const QVariantList &parameters); void setParameters(const QList<ParamType> &parameters);
private: private:
EventTypeId m_id; EventTypeId m_id;
QString m_name; QString m_name;
QVariantList m_parameters; QList<ParamType> m_parameters;
}; };

View File

@ -63,7 +63,7 @@ QList<DeviceClass> DevicePluginBoblight::supportedDevices() const
colorState.setDefaultValue(QColor(Qt::black)); colorState.setDefaultValue(QColor(Qt::black));
boblightStates.append(colorState); boblightStates.append(colorState);
deviceClassBoblight.setStates(boblightStates); deviceClassBoblight.setStateTypes(boblightStates);
QList<ActionType> boblightActons; QList<ActionType> boblightActons;

View File

@ -55,6 +55,7 @@
#include "devicemanager.h" #include "devicemanager.h"
#include "plugin/device.h" #include "plugin/device.h"
#include "hardware/radio433.h" #include "hardware/radio433.h"
#include "types/paramtype.h"
#include <QDebug> #include <QDebug>
#include <QStringList> #include <QStringList>
@ -98,20 +99,14 @@ QList<DeviceClass> DevicePluginConrad::supportedDevices() const
// Events // Events
QList<EventType> buttonEvents; QList<EventType> buttonEvents;
QVariantList paramsRemote; QList<ParamType> paramsRemote;
QVariantMap paramButton; ParamType paramButton("button", QVariant::Int);
paramButton.insert("name", "button");
paramButton.insert("type", "int");
paramsRemote.append(paramButton); paramsRemote.append(paramButton);
QVariantMap paramGroup; ParamType paramGroup("group", QVariant::Int);
paramGroup.insert("name", "group");
paramGroup.insert("type", "int");
paramsRemote.append(paramGroup); paramsRemote.append(paramGroup);
QVariantMap paramPower; ParamType paramPower("power", QVariant::Bool);
paramPower.insert("name", "power");
paramPower.insert("type", "bool");
paramsRemote.append(paramPower); paramsRemote.append(paramPower);
EventType buttonEvent(conradRemoteButtonEventTypeId); EventType buttonEvent(conradRemoteButtonEventTypeId);
@ -119,8 +114,8 @@ QList<DeviceClass> DevicePluginConrad::supportedDevices() const
buttonEvent.setParameters(paramsRemote); buttonEvent.setParameters(paramsRemote);
buttonEvents.append(buttonEvent); buttonEvents.append(buttonEvent);
deviceClassConradRemote.setParams(deviceParamsRemote); deviceClassConradRemote.setParamTypes(deviceParamsRemote);
deviceClassConradRemote.setEvents(buttonEvents); deviceClassConradRemote.setEventTypes(buttonEvents);
ret.append(deviceClassConradRemote); ret.append(deviceClassConradRemote);
return ret; return ret;

View File

@ -105,14 +105,12 @@ QList<DeviceClass> DevicePluginElro::supportedDevices() const
channelParam = ParamType("channel5", QVariant::Bool); channelParam = ParamType("channel5", QVariant::Bool);
deviceParamsRemote.append(channelParam); deviceParamsRemote.append(channelParam);
deviceClassElroRemote.setParams(deviceParamsRemote); deviceClassElroRemote.setParamTypes(deviceParamsRemote);
QList<EventType> buttonEvents; QList<EventType> buttonEvents;
QVariantList paramsRemote; QList<ParamType> paramsRemote;
QVariantMap param; ParamType param("power", QVariant::Bool);
param.insert("name", "power");
param.insert("type", "bool");
paramsRemote.append(param); paramsRemote.append(param);
EventType buttonAEvent(EventTypeId("9dd3f862-35f3-4b69-954e-fa3c8bd68e39")); EventType buttonAEvent(EventTypeId("9dd3f862-35f3-4b69-954e-fa3c8bd68e39"));
@ -140,7 +138,7 @@ QList<DeviceClass> DevicePluginElro::supportedDevices() const
buttonEEvent.setParameters(paramsRemote); buttonEEvent.setParameters(paramsRemote);
buttonEvents.append(buttonEEvent); buttonEvents.append(buttonEEvent);
deviceClassElroRemote.setEvents(buttonEvents); deviceClassElroRemote.setEventTypes(buttonEvents);
ret.append(deviceClassElroRemote); ret.append(deviceClassElroRemote);
// ======================================= // =======================================
@ -184,7 +182,7 @@ QList<DeviceClass> DevicePluginElro::supportedDevices() const
paramSwitch = ParamType("E", QVariant::Bool); paramSwitch = ParamType("E", QVariant::Bool);
deviceParamsSwitch.append(paramSwitch); deviceParamsSwitch.append(paramSwitch);
deviceClassElroSwitch.setParams(deviceParamsSwitch); deviceClassElroSwitch.setParamTypes(deviceParamsSwitch);
QList<ParamType> actionParamsSwitch; QList<ParamType> actionParamsSwitch;
@ -436,7 +434,7 @@ void DevicePluginElro::radioData(QList<int> rawData)
// FIXME: find a better way to get to the remote DeviceClass // FIXME: find a better way to get to the remote DeviceClass
DeviceClass deviceClass = supportedDevices().first(); DeviceClass deviceClass = supportedDevices().first();
foreach (const EventType &eventType, deviceClass.events()) { foreach (const EventType &eventType, deviceClass.eventTypes()) {
if (eventType.name() == button) { if (eventType.name() == button) {
//qDebug() << "emit event " << pluginName() << group << eventType.name() << power; //qDebug() << "emit event " << pluginName() << group << eventType.name() << power;
Event event = Event(eventType.id(), device->id(), params); Event event = Event(eventType.id(), device->id(), params);

View File

@ -194,17 +194,14 @@ QList<DeviceClass> DevicePluginIntertechno::supportedDevices() const
ParamType familyParam("familyCode", QVariant::String); ParamType familyParam("familyCode", QVariant::String);
remoteParams.append(familyParam); remoteParams.append(familyParam);
deviceClassIntertechnoRemote.setParams(remoteParams); deviceClassIntertechnoRemote.setParamTypes(remoteParams);
QList<EventType> buttonEvents; QList<EventType> buttonEvents;
QVariantList paramsRemote; QList<ParamType> paramsRemote;
QVariantMap paramRemote;
// on = true // on = true
// off = false // off = false
paramRemote.insert("name", "power"); ParamType paramRemote("power", QVariant::Bool);
paramRemote.insert("type", "bool");
paramsRemote.append(paramRemote); paramsRemote.append(paramRemote);
/* 1-16 /* 1-16
@ -298,7 +295,7 @@ QList<DeviceClass> DevicePluginIntertechno::supportedDevices() const
button16Event.setParameters(paramsRemote); button16Event.setParameters(paramsRemote);
buttonEvents.append(button16Event); buttonEvents.append(button16Event);
deviceClassIntertechnoRemote.setEvents(buttonEvents); deviceClassIntertechnoRemote.setEventTypes(buttonEvents);
ret.append(deviceClassIntertechnoRemote); ret.append(deviceClassIntertechnoRemote);
@ -314,7 +311,7 @@ QList<DeviceClass> DevicePluginIntertechno::supportedDevices() const
switchDeviceParams.append(familyParam); switchDeviceParams.append(familyParam);
switchDeviceParams.append(buttonParam); switchDeviceParams.append(buttonParam);
deviceClassIntertechnoSwitch.setParams(switchDeviceParams); deviceClassIntertechnoSwitch.setParamTypes(switchDeviceParams);
QList<ActionType> switchActions; QList<ActionType> switchActions;
@ -695,7 +692,7 @@ void DevicePluginIntertechno::radioData(QList<int> rawData)
// FIXME: find a better way to get to the remote DeviceClass // FIXME: find a better way to get to the remote DeviceClass
DeviceClass deviceClass = supportedDevices().first(); DeviceClass deviceClass = supportedDevices().first();
foreach (const EventType &eventType, deviceClass.events()) { foreach (const EventType &eventType, deviceClass.eventTypes()) {
if (eventType.name() == buttonCode) { if (eventType.name() == buttonCode) {
qDebug() << "emit event " << pluginName() << familyCode << eventType.name() << power; qDebug() << "emit event " << pluginName() << familyCode << eventType.name() << power;
Event event = Event(eventType.id(), device->id(), params); Event event = Event(eventType.id(), device->id(), params);

View File

@ -58,15 +58,13 @@ QList<DeviceClass> DevicePluginLircd::supportedDevices() const
QList<ParamType> params; QList<ParamType> params;
ParamType remoteNameParam("remoteName", QVariant::String); ParamType remoteNameParam("remoteName", QVariant::String);
params.append(remoteNameParam); params.append(remoteNameParam);
deviceClassLircd.setParams(params); deviceClassLircd.setParamTypes(params);
// TODO: find a way to load this stuff from a json file, really! // TODO: find a way to load this stuff from a json file, really!
// Ideally that file can be generated from /usr/share/lirc/remotes/* // Ideally that file can be generated from /usr/share/lirc/remotes/*
// Note that the IDs need to be kept static! // Note that the IDs need to be kept static!
QVariantList repeatParam; QList<ParamType> repeatParam;
QVariantMap repeatParamMap; ParamType repeatParamMap("repeat", QVariant::Int);
repeatParamMap.insert("name", "repeat");
repeatParamMap.insert("type", "int");
repeatParam.append(repeatParamMap); repeatParam.append(repeatParamMap);
QList<EventType> events; QList<EventType> events;
@ -91,7 +89,7 @@ QList<DeviceClass> DevicePluginLircd::supportedDevices() const
redButton.setParameters(repeatParam); redButton.setParameters(repeatParam);
events.append(redButton); events.append(redButton);
deviceClassLircd.setEvents(events); deviceClassLircd.setEventTypes(events);
ret.append(deviceClassLircd); ret.append(deviceClassLircd);
@ -128,8 +126,8 @@ void DevicePluginLircd::buttonPressed(const QString &remoteName, const QString &
return; return;
} }
qDebug() << "found remote" << remoteName << supportedDevices().first().events().count(); qDebug() << "found remote" << remoteName << supportedDevices().first().eventTypes().count();
foreach (const EventType &eventType, supportedDevices().first().events()) { foreach (const EventType &eventType, supportedDevices().first().eventTypes()) {
if (eventType.name() == buttonName) { if (eventType.name() == buttonName) {
QList<Param> params; QList<Param> params;
Param param("repeat", repeat); Param param("repeat", repeat);

View File

@ -295,7 +295,7 @@ QList<DeviceClass> DevicePluginMailNotification::supportedDevices() const
googleMailParams.append(recipientGoogleParam); googleMailParams.append(recipientGoogleParam);
deviceClassGoogleMail.setActions(mailActions); deviceClassGoogleMail.setActions(mailActions);
deviceClassGoogleMail.setParams(googleMailParams); deviceClassGoogleMail.setParamTypes(googleMailParams);
// Custom Mail // Custom Mail
// --------------------------------------------------------------- // ---------------------------------------------------------------
@ -325,7 +325,7 @@ QList<DeviceClass> DevicePluginMailNotification::supportedDevices() const
customMailParams.append(authCustomParam); customMailParams.append(authCustomParam);
deviceClassCustomMail.setActions(mailActions); deviceClassCustomMail.setActions(mailActions);
deviceClassCustomMail.setParams(customMailParams); deviceClassCustomMail.setParamTypes(customMailParams);
ret.append(deviceClassGoogleMail); ret.append(deviceClassGoogleMail);
ret.append(deviceClassCustomMail); ret.append(deviceClassCustomMail);

View File

@ -70,7 +70,7 @@ QList<DeviceClass> DevicePluginMock::supportedDevices() const
ParamType portParam("httpport", QVariant::Int); ParamType portParam("httpport", QVariant::Int);
mockParams.append(portParam); mockParams.append(portParam);
deviceClassMock.setParams(mockParams); deviceClassMock.setParamTypes(mockParams);
QList<StateType> mockStates; QList<StateType> mockStates;
@ -86,7 +86,7 @@ QList<DeviceClass> DevicePluginMock::supportedDevices() const
boolState.setDefaultValue(false); boolState.setDefaultValue(false);
mockStates.append(boolState); mockStates.append(boolState);
deviceClassMock.setStates(mockStates); deviceClassMock.setStateTypes(mockStates);
QList<EventType> mockEvents; QList<EventType> mockEvents;
@ -98,7 +98,7 @@ QList<DeviceClass> DevicePluginMock::supportedDevices() const
event2.setName("Mock Event 2"); event2.setName("Mock Event 2");
mockEvents.append(event2); mockEvents.append(event2);
deviceClassMock.setEvents(mockEvents); deviceClassMock.setEventTypes(mockEvents);
QList<ActionType> mockActions; QList<ActionType> mockActions;
@ -138,9 +138,9 @@ QList<DeviceClass> DevicePluginMock::supportedDevices() const
deviceClassMockAuto.setCreateMethod(DeviceClass::CreateMethodAuto); deviceClassMockAuto.setCreateMethod(DeviceClass::CreateMethodAuto);
mockParams.clear(); mockParams.clear();
deviceClassMockAuto.setParams(mockParams); deviceClassMockAuto.setParamTypes(mockParams);
deviceClassMockAuto.setStates(mockStates); deviceClassMockAuto.setStateTypes(mockStates);
deviceClassMockAuto.setEvents(mockEvents); deviceClassMockAuto.setEventTypes(mockEvents);
deviceClassMockAuto.setActions(mockActions); deviceClassMockAuto.setActions(mockActions);
ret.append(deviceClassMockAuto); ret.append(deviceClassMockAuto);
@ -152,9 +152,9 @@ QList<DeviceClass> DevicePluginMock::supportedDevices() const
mockParams.clear(); mockParams.clear();
mockParams.append(portParam); mockParams.append(portParam);
deviceClassMockDiscovery.setParams(mockParams); deviceClassMockDiscovery.setParamTypes(mockParams);
deviceClassMockDiscovery.setStates(mockStates); deviceClassMockDiscovery.setStateTypes(mockStates);
deviceClassMockDiscovery.setEvents(mockEvents); deviceClassMockDiscovery.setEventTypes(mockEvents);
deviceClassMockDiscovery.setActions(mockActions); deviceClassMockDiscovery.setActions(mockActions);
ret.append(deviceClassMockDiscovery); ret.append(deviceClassMockDiscovery);
@ -164,9 +164,9 @@ QList<DeviceClass> DevicePluginMock::supportedDevices() const
deviceClassMockAsync.setName("Mock Device (Async)"); deviceClassMockAsync.setName("Mock Device (Async)");
deviceClassMockAsync.setCreateMethod(DeviceClass::CreateMethodUser); deviceClassMockAsync.setCreateMethod(DeviceClass::CreateMethodUser);
deviceClassMockAsync.setParams(mockParams); deviceClassMockAsync.setParamTypes(mockParams);
deviceClassMockAsync.setStates(mockStates); deviceClassMockAsync.setStateTypes(mockStates);
deviceClassMockAsync.setEvents(mockEvents); deviceClassMockAsync.setEventTypes(mockEvents);
deviceClassMockAsync.setActions(mockActions); deviceClassMockAsync.setActions(mockActions);
ret.append(deviceClassMockAsync); ret.append(deviceClassMockAsync);
@ -176,9 +176,9 @@ QList<DeviceClass> DevicePluginMock::supportedDevices() const
deviceClassMockBroken.setName("Mock Device (Broken setup)"); deviceClassMockBroken.setName("Mock Device (Broken setup)");
deviceClassMockBroken.setCreateMethod(DeviceClass::CreateMethodUser); deviceClassMockBroken.setCreateMethod(DeviceClass::CreateMethodUser);
deviceClassMockBroken.setParams(mockParams); deviceClassMockBroken.setParamTypes(mockParams);
deviceClassMockBroken.setStates(mockStates); deviceClassMockBroken.setStateTypes(mockStates);
deviceClassMockBroken.setEvents(mockEvents); deviceClassMockBroken.setEventTypes(mockEvents);
deviceClassMockBroken.setActions(mockActions); deviceClassMockBroken.setActions(mockActions);
ret.append(deviceClassMockBroken); ret.append(deviceClassMockBroken);
@ -188,9 +188,9 @@ QList<DeviceClass> DevicePluginMock::supportedDevices() const
deviceClassMockBrokenAsyncSetup.setName("Mock Device (Async Broken setup)"); deviceClassMockBrokenAsyncSetup.setName("Mock Device (Async Broken setup)");
deviceClassMockBrokenAsyncSetup.setCreateMethod(DeviceClass::CreateMethodUser); deviceClassMockBrokenAsyncSetup.setCreateMethod(DeviceClass::CreateMethodUser);
deviceClassMockBrokenAsyncSetup.setParams(mockParams); deviceClassMockBrokenAsyncSetup.setParamTypes(mockParams);
deviceClassMockBrokenAsyncSetup.setStates(mockStates); deviceClassMockBrokenAsyncSetup.setStateTypes(mockStates);
deviceClassMockBrokenAsyncSetup.setEvents(mockEvents); deviceClassMockBrokenAsyncSetup.setEventTypes(mockEvents);
deviceClassMockBrokenAsyncSetup.setActions(mockActions); deviceClassMockBrokenAsyncSetup.setActions(mockActions);
ret.append(deviceClassMockBrokenAsyncSetup); ret.append(deviceClassMockBrokenAsyncSetup);

View File

@ -143,10 +143,10 @@ QString HttpDaemon::generateWebPage()
body.append("<h2>States</h2>"); body.append("<h2>States</h2>");
body.append("<table>"); body.append("<table>");
for (int i = 0; i < deviceClass.states().count(); ++i) { for (int i = 0; i < deviceClass.stateTypes().count(); ++i) {
body.append("<tr>"); body.append("<tr>");
body.append("<form action=\"/setstate\" method=\"get\">"); body.append("<form action=\"/setstate\" method=\"get\">");
const StateType &stateType = deviceClass.states().at(i); const StateType &stateType = deviceClass.stateTypes().at(i);
body.append("<td>" + stateType.name() + "</td>"); body.append("<td>" + stateType.name() + "</td>");
body.append(QString("<td><input type='input'' name='%1' value='%2'></td>").arg(stateType.id().toString()).arg(m_device->states().at(i).value().toString())); body.append(QString("<td><input type='input'' name='%1' value='%2'></td>").arg(stateType.id().toString()).arg(m_device->states().at(i).value().toString()));
body.append("<td><input type=submit value='Set State'/></td>"); body.append("<td><input type=submit value='Set State'/></td>");
@ -159,16 +159,21 @@ QString HttpDaemon::generateWebPage()
body.append("<h2>Events</h2>"); body.append("<h2>Events</h2>");
body.append("<table>"); body.append("<table>");
for (int i = 0; i < deviceClass.events().count(); ++i) { for (int i = 0; i < deviceClass.eventTypes().count(); ++i) {
const EventType &eventType = deviceClass.events().at(i); qDebug() << "adding eventType" << deviceClass.eventTypes().at(i).name();
const EventType &eventType = deviceClass.eventTypes().at(i);
body.append(QString( body.append(QString(
"<tr>" "<tr>"
"<form action=\"/generateevent\" method=\"get\">" "<form action=\"/generateevent\" method=\"get\">"
"<td>%1<input type='hidden' name='eventtypeid' value='%2'/></td>" "<td>%1<input type='hidden' name='eventtypeid' value='%2'/></td>"
"<td><input type='submit' value='Generate'/></td>" "<td>").arg(eventType.name()).arg(eventType.id().toString()));
if (!eventType.name().endsWith(" changed")) {
body.append("<input type='submit' value='Generate'/>");
}
body.append("</td>"
"</form>" "</form>"
"</tr>" "</tr>"
).arg(eventType.name()).arg(eventType.id().toString())); );
} }
body.append("</table>"); body.append("</table>");
@ -181,7 +186,7 @@ QString HttpDaemon::generateWebPage()
ActionTypeId actionTypeId = ActionTypeId(m_actionList.at(i).first); ActionTypeId actionTypeId = ActionTypeId(m_actionList.at(i).first);
QDateTime timestamp = m_actionList.at(i).second; QDateTime timestamp = m_actionList.at(i).second;
QString actionName; QString actionName;
foreach (const ActionType &at, deviceClass.actions()) { foreach (const ActionType &at, deviceClass.actionTypes()) {
if (at.id() == actionTypeId) { if (at.id() == actionTypeId) {
actionName = at.name(); actionName = at.name();
break; break;

View File

@ -326,7 +326,7 @@ QList<DeviceClass> DevicePluginOpenweathermap::supportedDevices() const
params.append(locationParam); params.append(locationParam);
//Location is all we need for discovery. //Location is all we need for discovery.
deviceClassOpenweathermap.setDiscoveryParams(params); deviceClassOpenweathermap.setDiscoveryParamTypes(params);
ParamType countryParam("country", QVariant::String); ParamType countryParam("country", QVariant::String);
params.append(countryParam); params.append(countryParam);
@ -334,7 +334,7 @@ QList<DeviceClass> DevicePluginOpenweathermap::supportedDevices() const
ParamType idParam("id", QVariant::String); ParamType idParam("id", QVariant::String);
params.append(idParam); params.append(idParam);
deviceClassOpenweathermap.setParams(params); deviceClassOpenweathermap.setParamTypes(params);
// Actions // Actions
QList<ActionType> weatherActions; QList<ActionType> weatherActions;
@ -417,7 +417,7 @@ QList<DeviceClass> DevicePluginOpenweathermap::supportedDevices() const
weatherStates.append(sunriseState); weatherStates.append(sunriseState);
deviceClassOpenweathermap.setActions(weatherActions); deviceClassOpenweathermap.setActions(weatherActions);
deviceClassOpenweathermap.setStates(weatherStates); deviceClassOpenweathermap.setStateTypes(weatherStates);
ret.append(deviceClassOpenweathermap); ret.append(deviceClassOpenweathermap);
return ret; return ret;

View File

@ -158,7 +158,7 @@ QList<DeviceClass> DevicePluginWakeOnLan::supportedDevices() const
wolAction.setName("wakeup"); wolAction.setName("wakeup");
wolActions.append(wolAction); wolActions.append(wolAction);
deviceClassWakeOnLan.setParams(wolParams); deviceClassWakeOnLan.setParamTypes(wolParams);
deviceClassWakeOnLan.setActions(wolActions); deviceClassWakeOnLan.setActions(wolActions);
ret.append(deviceClassWakeOnLan); ret.append(deviceClassWakeOnLan);

View File

@ -52,7 +52,7 @@ QList<DeviceClass> DevicePluginWifiDetector::supportedDevices() const
ParamType macParam("mac", QVariant::String); ParamType macParam("mac", QVariant::String);
detectorParams.append(macParam); detectorParams.append(macParam);
deviceClassWifiDetector.setParams(detectorParams); deviceClassWifiDetector.setParamTypes(detectorParams);
QList<StateType> detectorStates; QList<StateType> detectorStates;
@ -62,7 +62,7 @@ QList<DeviceClass> DevicePluginWifiDetector::supportedDevices() const
inRangeState.setDefaultValue(false); inRangeState.setDefaultValue(false);
detectorStates.append(inRangeState); detectorStates.append(inRangeState);
deviceClassWifiDetector.setStates(detectorStates); deviceClassWifiDetector.setStateTypes(detectorStates);
ret.append(deviceClassWifiDetector); ret.append(deviceClassWifiDetector);

View File

@ -101,6 +101,10 @@ GuhCore::GuhCore(QObject *parent) :
here will be evaluated by the \l{RuleEngine} and the according \l{Action}{Actions} are executed.*/ here will be evaluated by the \l{RuleEngine} and the according \l{Action}{Actions} are executed.*/
void GuhCore::gotEvent(const Event &event) void GuhCore::gotEvent(const Event &event)
{ {
// first inform other things about it.
emit eventTriggered(event);
// Now execute all the associated rules
foreach (const Action &action, m_ruleEngine->evaluateEvent(event)) { foreach (const Action &action, m_ruleEngine->evaluateEvent(event)) {
qDebug() << "executing action" << action.actionTypeId(); qDebug() << "executing action" << action.actionTypeId();
QPair<DeviceManager::DeviceError, QString> status = m_deviceManager->executeAction(action); QPair<DeviceManager::DeviceError, QString> status = m_deviceManager->executeAction(action);

View File

@ -42,6 +42,9 @@ public:
DeviceManager* deviceManager() const; DeviceManager* deviceManager() const;
RuleEngine *ruleEngine() const; RuleEngine *ruleEngine() const;
signals:
void eventTriggered(const Event &event);
private: private:
explicit GuhCore(QObject *parent = 0); explicit GuhCore(QObject *parent = 0);
static GuhCore *s_instance; static GuhCore *s_instance;

View File

@ -82,7 +82,7 @@ JsonReply *ActionHandler::GetActionType(const QVariantMap &params) const
{ {
ActionTypeId actionTypeId(params.value("actionTypeId").toString()); ActionTypeId actionTypeId(params.value("actionTypeId").toString());
foreach (const DeviceClass &deviceClass, GuhCore::instance()->deviceManager()->supportedDevices()) { foreach (const DeviceClass &deviceClass, GuhCore::instance()->deviceManager()->supportedDevices()) {
foreach (const ActionType &actionType, deviceClass.actions()) { foreach (const ActionType &actionType, deviceClass.actionTypes()) {
if (actionType.id() == actionTypeId) { if (actionType.id() == actionTypeId) {
QVariantMap data; QVariantMap data;
data.insert("success", true); data.insert("success", true);

View File

@ -391,7 +391,7 @@ JsonReply* DeviceHandler::GetEventTypes(const QVariantMap &params) const
QVariantList eventList; QVariantList eventList;
DeviceClass deviceClass = GuhCore::instance()->deviceManager()->findDeviceClass(DeviceClassId(params.value("deviceClassId").toString())); DeviceClass deviceClass = GuhCore::instance()->deviceManager()->findDeviceClass(DeviceClassId(params.value("deviceClassId").toString()));
foreach (const EventType &eventType, deviceClass.events()) { foreach (const EventType &eventType, deviceClass.eventTypes()) {
eventList.append(JsonTypes::packEventType(eventType)); eventList.append(JsonTypes::packEventType(eventType));
} }
returns.insert("eventTypes", eventList); returns.insert("eventTypes", eventList);
@ -404,7 +404,7 @@ JsonReply* DeviceHandler::GetActionTypes(const QVariantMap &params) const
QVariantList actionList; QVariantList actionList;
DeviceClass deviceClass = GuhCore::instance()->deviceManager()->findDeviceClass(DeviceClassId(params.value("deviceClassId").toString())); DeviceClass deviceClass = GuhCore::instance()->deviceManager()->findDeviceClass(DeviceClassId(params.value("deviceClassId").toString()));
foreach (const ActionType &actionType, deviceClass.actions()) { foreach (const ActionType &actionType, deviceClass.actionTypes()) {
actionList.append(JsonTypes::packActionType(actionType)); actionList.append(JsonTypes::packActionType(actionType));
} }
returns.insert("actionTypes", actionList); returns.insert("actionTypes", actionList);
@ -417,7 +417,7 @@ JsonReply* DeviceHandler::GetStateTypes(const QVariantMap &params) const
QVariantList stateList; QVariantList stateList;
DeviceClass deviceClass = GuhCore::instance()->deviceManager()->findDeviceClass(DeviceClassId(params.value("deviceClassId").toString())); DeviceClass deviceClass = GuhCore::instance()->deviceManager()->findDeviceClass(DeviceClassId(params.value("deviceClassId").toString()));
foreach (const StateType &stateType, deviceClass.states()) { foreach (const StateType &stateType, deviceClass.stateTypes()) {
stateList.append(JsonTypes::packStateType(stateType)); stateList.append(JsonTypes::packStateType(stateType));
} }
returns.insert("stateTypes", stateList); returns.insert("stateTypes", stateList);

View File

@ -0,0 +1,48 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* This file is part of guh. *
* *
* Guh is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 2 of the License. *
* *
* Guh is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "eventhandler.h"
#include "guhcore.h"
EventHandler::EventHandler(QObject *parent) :
JsonHandler(parent)
{
QVariantMap params;
QVariantMap returns;
// Notifications
params.clear(); returns.clear();
setDescription("EventTriggered", "Emitted whenever an Event is triggered.");
params.insert("event", JsonTypes::eventRef());
setParams("EventTriggered", params);
connect(GuhCore::instance(), &GuhCore::eventTriggered, this, &EventHandler::eventTriggered);
}
QString EventHandler::name() const
{
return "Events";
}
void EventHandler::eventTriggered(const Event &event)
{
QVariantMap params;
params.insert("event", JsonTypes::packEvent(event));
emit EventTriggered(params);
}

View File

@ -0,0 +1,38 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* This file is part of guh. *
* *
* Guh is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 2 of the License. *
* *
* Guh is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef EVENTHANDLER_H
#define EVENTHANDLER_H
#include "jsonhandler.h"
class EventHandler : public JsonHandler
{
Q_OBJECT
public:
explicit EventHandler(QObject *parent = 0);
QString name() const override;
signals:
void EventTriggered(const QVariantMap &params);
private slots:
void eventTriggered(const Event &event);
};
#endif // EVENTHANDLER_H

View File

@ -37,6 +37,7 @@
#include "devicehandler.h" #include "devicehandler.h"
#include "actionhandler.h" #include "actionhandler.h"
#include "ruleshandler.h" #include "ruleshandler.h"
#include "eventhandler.h"
#include <QJsonDocument> #include <QJsonDocument>
#include <QStringList> #include <QStringList>
@ -138,6 +139,7 @@ void JsonRPCServer::setup()
registerHandler(new DeviceHandler(this)); registerHandler(new DeviceHandler(this));
registerHandler(new ActionHandler(this)); registerHandler(new ActionHandler(this));
registerHandler(new RulesHandler(this)); registerHandler(new RulesHandler(this));
registerHandler(new EventHandler(this));
} }
void JsonRPCServer::processData(const QUuid &clientId, const QByteArray &jsonData) void JsonRPCServer::processData(const QUuid &clientId, const QByteArray &jsonData)

View File

@ -191,7 +191,11 @@ QVariantMap JsonTypes::packEventType(const EventType &eventType)
QVariantMap variant; QVariantMap variant;
variant.insert("id", eventType.id()); variant.insert("id", eventType.id());
variant.insert("name", eventType.name()); variant.insert("name", eventType.name());
variant.insert("paramTypes", eventType.parameters()); QVariantList paramTypes;
foreach (const ParamType &paramType, eventType.parameters()) {
paramTypes.append(packParamType(paramType));
}
variant.insert("paramTypes", paramTypes);
return variant; return variant;
} }
@ -305,23 +309,23 @@ QVariantMap JsonTypes::packDeviceClass(const DeviceClass &deviceClass)
variant.insert("id", deviceClass.id()); variant.insert("id", deviceClass.id());
variant.insert("vendorId", deviceClass.vendorId()); variant.insert("vendorId", deviceClass.vendorId());
QVariantList stateTypes; QVariantList stateTypes;
foreach (const StateType &stateType, deviceClass.states()) { foreach (const StateType &stateType, deviceClass.stateTypes()) {
stateTypes.append(packStateType(stateType)); stateTypes.append(packStateType(stateType));
} }
QVariantList eventTypes; QVariantList eventTypes;
foreach (const EventType &eventType, deviceClass.events()) { foreach (const EventType &eventType, deviceClass.eventTypes()) {
eventTypes.append(packEventType(eventType)); eventTypes.append(packEventType(eventType));
} }
QVariantList actionTypes; QVariantList actionTypes;
foreach (const ActionType &actionType, deviceClass.actions()) { foreach (const ActionType &actionType, deviceClass.actionTypes()) {
actionTypes.append(packActionType(actionType)); actionTypes.append(packActionType(actionType));
} }
QVariantList paramTypes; QVariantList paramTypes;
foreach (const ParamType &paramType, deviceClass.params()) { foreach (const ParamType &paramType, deviceClass.paramTypes()) {
paramTypes.append(packParamType(paramType)); paramTypes.append(packParamType(paramType));
} }
QVariantList discoveryParamTypes; QVariantList discoveryParamTypes;
foreach (const ParamType &paramType, deviceClass.discoveryParams()) { foreach (const ParamType &paramType, deviceClass.discoveryParamTypes()) {
discoveryParamTypes.append(packParamType(paramType)); discoveryParamTypes.append(packParamType(paramType));
} }

View File

@ -190,7 +190,7 @@ RuleEngine::RuleError RuleEngine::addRule(const EventDescriptor &eventDescriptor
qDebug() << "found deviceClass" << deviceClass.name(); qDebug() << "found deviceClass" << deviceClass.name();
bool eventTypeFound = false; bool eventTypeFound = false;
foreach (const EventType &eventType, deviceClass.events()) { foreach (const EventType &eventType, deviceClass.eventTypes()) {
if (eventType.id() == eventDescriptor.eventTypeId()) { if (eventType.id() == eventDescriptor.eventTypeId()) {
eventTypeFound = true; eventTypeFound = true;
} }

View File

@ -8,7 +8,8 @@ SOURCES += $$top_srcdir/server/guhcore.cpp \
$$top_srcdir/server/jsonrpc/jsontypes.cpp \ $$top_srcdir/server/jsonrpc/jsontypes.cpp \
$$top_srcdir/server/jsonrpc/ruleshandler.cpp \ $$top_srcdir/server/jsonrpc/ruleshandler.cpp \
$$top_srcdir/server/jsonrpc/actionhandler.cpp \ $$top_srcdir/server/jsonrpc/actionhandler.cpp \
$$top_srcdir/server/stateevaluator.cpp $$top_srcdir/server/jsonrpc/eventhandler.cpp \
$$top_srcdir/server/stateevaluator.cpp \
HEADERS += $$top_srcdir/server/guhcore.h \ HEADERS += $$top_srcdir/server/guhcore.h \
$$top_srcdir/server/tcpserver.h \ $$top_srcdir/server/tcpserver.h \
@ -20,4 +21,5 @@ HEADERS += $$top_srcdir/server/guhcore.h \
$$top_srcdir/server/jsonrpc/jsontypes.h \ $$top_srcdir/server/jsonrpc/jsontypes.h \
$$top_srcdir/server/jsonrpc/ruleshandler.h \ $$top_srcdir/server/jsonrpc/ruleshandler.h \
$$top_srcdir/server/jsonrpc/actionhandler.h \ $$top_srcdir/server/jsonrpc/actionhandler.h \
$$top_srcdir/server/stateevaluator.h $$top_srcdir/server/jsonrpc/eventhandler.h \
$$top_srcdir/server/stateevaluator.h \

View File

@ -1,4 +1,4 @@
0.1.5 0.1.6
{ {
"methods": { "methods": {
"Actions.ExecuteAction": { "Actions.ExecuteAction": {
@ -253,6 +253,12 @@
"stateTypeId": "uuid", "stateTypeId": "uuid",
"variant": "value" "variant": "value"
} }
},
"Events.EventTriggered": {
"description": "Emitted whenever an Event is triggered.",
"params": {
"event": "$ref:Event"
}
} }
}, },
"types": { "types": {

View File

@ -383,7 +383,7 @@ void TestDevices::getEventTypes_data()
QTest::addColumn<DeviceClassId>("deviceClassId"); QTest::addColumn<DeviceClassId>("deviceClassId");
QTest::addColumn<int>("resultCount"); QTest::addColumn<int>("resultCount");
QTest::newRow("valid deviceclass") << mockDeviceClassId << 2; QTest::newRow("valid deviceclass") << mockDeviceClassId << 4;
QTest::newRow("invalid deviceclass") << DeviceClassId("094f8024-5caa-48c1-ab6a-de486a92088f") << 0; QTest::newRow("invalid deviceclass") << DeviceClassId("094f8024-5caa-48c1-ab6a-de486a92088f") << 0;
} }

View File

@ -210,7 +210,7 @@ void TestJSONRPC::stateChangeEmitsNotifications()
// Lets wait for the notification // Lets wait for the notification
clientSpy.wait(); clientSpy.wait();
QCOMPARE(clientSpy.count(), 1); QCOMPARE(clientSpy.count(), 2);
// Make sure the notification contains all the stuff we expect // Make sure the notification contains all the stuff we expect
QJsonDocument jsonDoc = QJsonDocument::fromJson(clientSpy.at(0).at(1).toByteArray()); QJsonDocument jsonDoc = QJsonDocument::fromJson(clientSpy.at(0).at(1).toByteArray());
@ -218,6 +218,12 @@ void TestJSONRPC::stateChangeEmitsNotifications()
QCOMPARE(jsonDoc.toVariant().toMap().value("params").toMap().value("stateTypeId").toUuid(), stateTypeId); QCOMPARE(jsonDoc.toVariant().toMap().value("params").toMap().value("stateTypeId").toUuid(), stateTypeId);
QCOMPARE(jsonDoc.toVariant().toMap().value("params").toMap().value("value").toInt(), newVal); QCOMPARE(jsonDoc.toVariant().toMap().value("params").toMap().value("value").toInt(), newVal);
// Make sure the notification contains all the stuff we expect
jsonDoc = QJsonDocument::fromJson(clientSpy.at(1).at(1).toByteArray());
QCOMPARE(jsonDoc.toVariant().toMap().value("notification").toString(), QString("Events.EventTriggered"));
QCOMPARE(jsonDoc.toVariant().toMap().value("params").toMap().value("event").toMap().value("eventTypeId").toUuid(), stateTypeId);
QCOMPARE(jsonDoc.toVariant().toMap().value("params").toMap().value("event").toMap().value("params").toList().first().toMap().value("value").toInt(), newVal);
// Now turn off notifications // Now turn off notifications
params.clear(); params.clear();
params.insert("enabled", false); params.insert("enabled", false);