mirror of https://github.com/nymea/nymea.git
state changes emit events now
parent
bbd05ca7fd
commit
21738b3907
|
|
@ -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
|
||||
|
||||
-- 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
|
||||
|
||||
|
|
|
|||
|
|
@ -241,7 +241,7 @@ QPair<DeviceManager::DeviceError, QString> DeviceManager::addConfiguredDeviceInt
|
|||
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) {
|
||||
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
|
||||
DeviceClass deviceClass = findDeviceClass(device->deviceClassId());
|
||||
bool found = false;
|
||||
foreach (const ActionType &actionType, deviceClass.actions()) {
|
||||
foreach (const ActionType &actionType, deviceClass.actionTypes()) {
|
||||
if (actionType.id() == action.actionTypeId()) {
|
||||
QPair<DeviceError, QString> paramCheck = verifyParams(actionType.parameters(), action.params());
|
||||
if (paramCheck.first != DeviceErrorNoError) {
|
||||
|
|
@ -593,6 +593,10 @@ void DeviceManager::slotDeviceStateValueChanged(const QUuid &stateTypeId, const
|
|||
return;
|
||||
}
|
||||
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)
|
||||
|
|
@ -627,7 +631,7 @@ QPair<DeviceManager::DeviceSetupStatus,QString> DeviceManager::setupDevice(Devic
|
|||
}
|
||||
|
||||
QList<State> states;
|
||||
foreach (const StateType &stateType, deviceClass.states()) {
|
||||
foreach (const StateType &stateType, deviceClass.stateTypes()) {
|
||||
State state(stateType.id(), device->id());
|
||||
state.setValue(stateType.defaultValue());
|
||||
states.append(state);
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@
|
|||
*/
|
||||
|
||||
#include "device.h"
|
||||
#include "types/event.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
|
|
|||
|
|
@ -87,68 +87,86 @@ void DeviceClass::setName(const QString &name)
|
|||
|
||||
/*! Returns the statesTypes of this DeviceClass. \{Device}{Devices} created
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
from this DeviceClass must have their actions matching to this template. */
|
||||
void DeviceClass::setActions(const QList<ActionType> &actionTypes)
|
||||
{
|
||||
m_actions = actionTypes;
|
||||
m_actionTypes = actionTypes;
|
||||
}
|
||||
|
||||
/*! Returns the params description of this DeviceClass. \{Device}{Devices} created
|
||||
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
|
||||
from this DeviceClass must have their actions matching to this template. */
|
||||
void DeviceClass::setParams(const QList<ParamType> ¶ms)
|
||||
void DeviceClass::setParamTypes(const QList<ParamType> ¶ms)
|
||||
{
|
||||
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> ¶ms)
|
||||
void DeviceClass::setDiscoveryParamTypes(const QList<ParamType> ¶ms)
|
||||
{
|
||||
m_discoveryParams = params;
|
||||
m_discoveryParamTypes = params;
|
||||
}
|
||||
|
||||
DeviceClass::CreateMethod DeviceClass::createMethod() const
|
||||
|
|
|
|||
|
|
@ -54,20 +54,20 @@ public:
|
|||
QString name() const;
|
||||
void setName(const QString &name);
|
||||
|
||||
QList<StateType> states() const;
|
||||
void setStates(const QList<StateType> &stateTypes);
|
||||
QList<StateType> stateTypes() const;
|
||||
void setStateTypes(const QList<StateType> &stateTypes);
|
||||
|
||||
QList<EventType> events() const;
|
||||
void setEvents(const QList<EventType> &eventTypes);
|
||||
QList<EventType> eventTypes() const;
|
||||
void setEventTypes(const QList<EventType> &eventTypes);
|
||||
|
||||
QList<ActionType> actions() const;
|
||||
QList<ActionType> actionTypes() const;
|
||||
void setActions(const QList<ActionType> &actionTypes);
|
||||
|
||||
QList<ParamType> params() const;
|
||||
void setParams(const QList<ParamType> ¶ms);
|
||||
QList<ParamType> paramTypes() const;
|
||||
void setParamTypes(const QList<ParamType> ¶mTypes);
|
||||
|
||||
QList<ParamType> discoveryParams() const;
|
||||
void setDiscoveryParams(const QList<ParamType> ¶ms);
|
||||
QList<ParamType> discoveryParamTypes() const;
|
||||
void setDiscoveryParamTypes(const QList<ParamType> ¶mTypes);
|
||||
|
||||
CreateMethod createMethod() const;
|
||||
void setCreateMethod(CreateMethod createMethod);
|
||||
|
|
@ -81,11 +81,12 @@ private:
|
|||
VendorId m_vendorId;
|
||||
PluginId m_pluginId;
|
||||
QString m_name;
|
||||
QList<StateType> m_states;
|
||||
QList<EventType> m_events;
|
||||
QList<ActionType> m_actions;
|
||||
QList<ParamType> m_params;
|
||||
QList<ParamType> m_discoveryParams;
|
||||
QList<StateType> m_stateTypes;
|
||||
QList<EventType> m_eventTypes;
|
||||
QList<EventType> m_allEventTypes;
|
||||
QList<ActionType> m_actionTypes;
|
||||
QList<ParamType> m_paramTypes;
|
||||
QList<ParamType> m_discoveryParamTypes;
|
||||
CreateMethod m_createMethod;
|
||||
SetupMethod m_setupMethod;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -53,19 +53,19 @@ void EventType::setName(const QString &name)
|
|||
}
|
||||
|
||||
/*!
|
||||
Holds a map describing possible parameters for a \l{Event} of this EventType.
|
||||
e.g. QVariantList(QVariantMap(("name", "temperature"), ("type": QVariant::Real)))
|
||||
Holds a List describing possible parameters for a \l{Event} of this EventType.
|
||||
e.g. QList(ParamType("temperature", QVariant::Real))
|
||||
*/
|
||||
QVariantList EventType::parameters() const
|
||||
QList<ParamType> EventType::parameters() const
|
||||
{
|
||||
return m_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 ¶meters)
|
||||
void EventType::setParameters(const QList<ParamType> ¶meters)
|
||||
{
|
||||
m_parameters = parameters;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
#define TRIGGERTYPE_H
|
||||
|
||||
#include "typeutils.h"
|
||||
#include "paramtype.h"
|
||||
|
||||
#include <QVariantMap>
|
||||
|
||||
|
|
@ -33,14 +34,14 @@ public:
|
|||
QString name() const;
|
||||
void setName(const QString &name);
|
||||
|
||||
QVariantList parameters() const;
|
||||
void setParameters(const QVariantList ¶meters);
|
||||
QList<ParamType> parameters() const;
|
||||
void setParameters(const QList<ParamType> ¶meters);
|
||||
|
||||
private:
|
||||
EventTypeId m_id;
|
||||
QString m_name;
|
||||
|
||||
QVariantList m_parameters;
|
||||
QList<ParamType> m_parameters;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ QList<DeviceClass> DevicePluginBoblight::supportedDevices() const
|
|||
colorState.setDefaultValue(QColor(Qt::black));
|
||||
boblightStates.append(colorState);
|
||||
|
||||
deviceClassBoblight.setStates(boblightStates);
|
||||
deviceClassBoblight.setStateTypes(boblightStates);
|
||||
|
||||
QList<ActionType> boblightActons;
|
||||
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@
|
|||
#include "devicemanager.h"
|
||||
#include "plugin/device.h"
|
||||
#include "hardware/radio433.h"
|
||||
#include "types/paramtype.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QStringList>
|
||||
|
|
@ -98,20 +99,14 @@ QList<DeviceClass> DevicePluginConrad::supportedDevices() const
|
|||
// Events
|
||||
QList<EventType> buttonEvents;
|
||||
|
||||
QVariantList paramsRemote;
|
||||
QVariantMap paramButton;
|
||||
paramButton.insert("name", "button");
|
||||
paramButton.insert("type", "int");
|
||||
QList<ParamType> paramsRemote;
|
||||
ParamType paramButton("button", QVariant::Int);
|
||||
paramsRemote.append(paramButton);
|
||||
|
||||
QVariantMap paramGroup;
|
||||
paramGroup.insert("name", "group");
|
||||
paramGroup.insert("type", "int");
|
||||
ParamType paramGroup("group", QVariant::Int);
|
||||
paramsRemote.append(paramGroup);
|
||||
|
||||
QVariantMap paramPower;
|
||||
paramPower.insert("name", "power");
|
||||
paramPower.insert("type", "bool");
|
||||
ParamType paramPower("power", QVariant::Bool);
|
||||
paramsRemote.append(paramPower);
|
||||
|
||||
EventType buttonEvent(conradRemoteButtonEventTypeId);
|
||||
|
|
@ -119,8 +114,8 @@ QList<DeviceClass> DevicePluginConrad::supportedDevices() const
|
|||
buttonEvent.setParameters(paramsRemote);
|
||||
buttonEvents.append(buttonEvent);
|
||||
|
||||
deviceClassConradRemote.setParams(deviceParamsRemote);
|
||||
deviceClassConradRemote.setEvents(buttonEvents);
|
||||
deviceClassConradRemote.setParamTypes(deviceParamsRemote);
|
||||
deviceClassConradRemote.setEventTypes(buttonEvents);
|
||||
ret.append(deviceClassConradRemote);
|
||||
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -105,14 +105,12 @@ QList<DeviceClass> DevicePluginElro::supportedDevices() const
|
|||
channelParam = ParamType("channel5", QVariant::Bool);
|
||||
deviceParamsRemote.append(channelParam);
|
||||
|
||||
deviceClassElroRemote.setParams(deviceParamsRemote);
|
||||
deviceClassElroRemote.setParamTypes(deviceParamsRemote);
|
||||
|
||||
QList<EventType> buttonEvents;
|
||||
|
||||
QVariantList paramsRemote;
|
||||
QVariantMap param;
|
||||
param.insert("name", "power");
|
||||
param.insert("type", "bool");
|
||||
QList<ParamType> paramsRemote;
|
||||
ParamType param("power", QVariant::Bool);
|
||||
paramsRemote.append(param);
|
||||
|
||||
EventType buttonAEvent(EventTypeId("9dd3f862-35f3-4b69-954e-fa3c8bd68e39"));
|
||||
|
|
@ -140,7 +138,7 @@ QList<DeviceClass> DevicePluginElro::supportedDevices() const
|
|||
buttonEEvent.setParameters(paramsRemote);
|
||||
buttonEvents.append(buttonEEvent);
|
||||
|
||||
deviceClassElroRemote.setEvents(buttonEvents);
|
||||
deviceClassElroRemote.setEventTypes(buttonEvents);
|
||||
ret.append(deviceClassElroRemote);
|
||||
|
||||
// =======================================
|
||||
|
|
@ -184,7 +182,7 @@ QList<DeviceClass> DevicePluginElro::supportedDevices() const
|
|||
paramSwitch = ParamType("E", QVariant::Bool);
|
||||
deviceParamsSwitch.append(paramSwitch);
|
||||
|
||||
deviceClassElroSwitch.setParams(deviceParamsSwitch);
|
||||
deviceClassElroSwitch.setParamTypes(deviceParamsSwitch);
|
||||
|
||||
|
||||
QList<ParamType> actionParamsSwitch;
|
||||
|
|
@ -436,7 +434,7 @@ void DevicePluginElro::radioData(QList<int> rawData)
|
|||
|
||||
// FIXME: find a better way to get to the remote DeviceClass
|
||||
DeviceClass deviceClass = supportedDevices().first();
|
||||
foreach (const EventType &eventType, deviceClass.events()) {
|
||||
foreach (const EventType &eventType, deviceClass.eventTypes()) {
|
||||
if (eventType.name() == button) {
|
||||
//qDebug() << "emit event " << pluginName() << group << eventType.name() << power;
|
||||
Event event = Event(eventType.id(), device->id(), params);
|
||||
|
|
|
|||
|
|
@ -194,17 +194,14 @@ QList<DeviceClass> DevicePluginIntertechno::supportedDevices() const
|
|||
ParamType familyParam("familyCode", QVariant::String);
|
||||
remoteParams.append(familyParam);
|
||||
|
||||
deviceClassIntertechnoRemote.setParams(remoteParams);
|
||||
deviceClassIntertechnoRemote.setParamTypes(remoteParams);
|
||||
|
||||
QList<EventType> buttonEvents;
|
||||
|
||||
QVariantList paramsRemote;
|
||||
QVariantMap paramRemote;
|
||||
|
||||
QList<ParamType> paramsRemote;
|
||||
// on = true
|
||||
// off = false
|
||||
paramRemote.insert("name", "power");
|
||||
paramRemote.insert("type", "bool");
|
||||
ParamType paramRemote("power", QVariant::Bool);
|
||||
paramsRemote.append(paramRemote);
|
||||
|
||||
/* 1-16
|
||||
|
|
@ -298,7 +295,7 @@ QList<DeviceClass> DevicePluginIntertechno::supportedDevices() const
|
|||
button16Event.setParameters(paramsRemote);
|
||||
buttonEvents.append(button16Event);
|
||||
|
||||
deviceClassIntertechnoRemote.setEvents(buttonEvents);
|
||||
deviceClassIntertechnoRemote.setEventTypes(buttonEvents);
|
||||
ret.append(deviceClassIntertechnoRemote);
|
||||
|
||||
|
||||
|
|
@ -314,7 +311,7 @@ QList<DeviceClass> DevicePluginIntertechno::supportedDevices() const
|
|||
switchDeviceParams.append(familyParam);
|
||||
switchDeviceParams.append(buttonParam);
|
||||
|
||||
deviceClassIntertechnoSwitch.setParams(switchDeviceParams);
|
||||
deviceClassIntertechnoSwitch.setParamTypes(switchDeviceParams);
|
||||
|
||||
QList<ActionType> switchActions;
|
||||
|
||||
|
|
@ -695,7 +692,7 @@ void DevicePluginIntertechno::radioData(QList<int> rawData)
|
|||
|
||||
// FIXME: find a better way to get to the remote DeviceClass
|
||||
DeviceClass deviceClass = supportedDevices().first();
|
||||
foreach (const EventType &eventType, deviceClass.events()) {
|
||||
foreach (const EventType &eventType, deviceClass.eventTypes()) {
|
||||
if (eventType.name() == buttonCode) {
|
||||
qDebug() << "emit event " << pluginName() << familyCode << eventType.name() << power;
|
||||
Event event = Event(eventType.id(), device->id(), params);
|
||||
|
|
|
|||
|
|
@ -58,15 +58,13 @@ QList<DeviceClass> DevicePluginLircd::supportedDevices() const
|
|||
QList<ParamType> params;
|
||||
ParamType remoteNameParam("remoteName", QVariant::String);
|
||||
params.append(remoteNameParam);
|
||||
deviceClassLircd.setParams(params);
|
||||
deviceClassLircd.setParamTypes(params);
|
||||
|
||||
// TODO: find a way to load this stuff from a json file, really!
|
||||
// Ideally that file can be generated from /usr/share/lirc/remotes/*
|
||||
// Note that the IDs need to be kept static!
|
||||
QVariantList repeatParam;
|
||||
QVariantMap repeatParamMap;
|
||||
repeatParamMap.insert("name", "repeat");
|
||||
repeatParamMap.insert("type", "int");
|
||||
QList<ParamType> repeatParam;
|
||||
ParamType repeatParamMap("repeat", QVariant::Int);
|
||||
repeatParam.append(repeatParamMap);
|
||||
|
||||
QList<EventType> events;
|
||||
|
|
@ -91,7 +89,7 @@ QList<DeviceClass> DevicePluginLircd::supportedDevices() const
|
|||
redButton.setParameters(repeatParam);
|
||||
events.append(redButton);
|
||||
|
||||
deviceClassLircd.setEvents(events);
|
||||
deviceClassLircd.setEventTypes(events);
|
||||
|
||||
ret.append(deviceClassLircd);
|
||||
|
||||
|
|
@ -128,8 +126,8 @@ void DevicePluginLircd::buttonPressed(const QString &remoteName, const QString &
|
|||
return;
|
||||
}
|
||||
|
||||
qDebug() << "found remote" << remoteName << supportedDevices().first().events().count();
|
||||
foreach (const EventType &eventType, supportedDevices().first().events()) {
|
||||
qDebug() << "found remote" << remoteName << supportedDevices().first().eventTypes().count();
|
||||
foreach (const EventType &eventType, supportedDevices().first().eventTypes()) {
|
||||
if (eventType.name() == buttonName) {
|
||||
QList<Param> params;
|
||||
Param param("repeat", repeat);
|
||||
|
|
|
|||
|
|
@ -295,7 +295,7 @@ QList<DeviceClass> DevicePluginMailNotification::supportedDevices() const
|
|||
googleMailParams.append(recipientGoogleParam);
|
||||
|
||||
deviceClassGoogleMail.setActions(mailActions);
|
||||
deviceClassGoogleMail.setParams(googleMailParams);
|
||||
deviceClassGoogleMail.setParamTypes(googleMailParams);
|
||||
|
||||
// Custom Mail
|
||||
// ---------------------------------------------------------------
|
||||
|
|
@ -325,7 +325,7 @@ QList<DeviceClass> DevicePluginMailNotification::supportedDevices() const
|
|||
customMailParams.append(authCustomParam);
|
||||
|
||||
deviceClassCustomMail.setActions(mailActions);
|
||||
deviceClassCustomMail.setParams(customMailParams);
|
||||
deviceClassCustomMail.setParamTypes(customMailParams);
|
||||
|
||||
ret.append(deviceClassGoogleMail);
|
||||
ret.append(deviceClassCustomMail);
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ QList<DeviceClass> DevicePluginMock::supportedDevices() const
|
|||
ParamType portParam("httpport", QVariant::Int);
|
||||
mockParams.append(portParam);
|
||||
|
||||
deviceClassMock.setParams(mockParams);
|
||||
deviceClassMock.setParamTypes(mockParams);
|
||||
|
||||
QList<StateType> mockStates;
|
||||
|
||||
|
|
@ -86,7 +86,7 @@ QList<DeviceClass> DevicePluginMock::supportedDevices() const
|
|||
boolState.setDefaultValue(false);
|
||||
mockStates.append(boolState);
|
||||
|
||||
deviceClassMock.setStates(mockStates);
|
||||
deviceClassMock.setStateTypes(mockStates);
|
||||
|
||||
QList<EventType> mockEvents;
|
||||
|
||||
|
|
@ -98,7 +98,7 @@ QList<DeviceClass> DevicePluginMock::supportedDevices() const
|
|||
event2.setName("Mock Event 2");
|
||||
mockEvents.append(event2);
|
||||
|
||||
deviceClassMock.setEvents(mockEvents);
|
||||
deviceClassMock.setEventTypes(mockEvents);
|
||||
|
||||
QList<ActionType> mockActions;
|
||||
|
||||
|
|
@ -138,9 +138,9 @@ QList<DeviceClass> DevicePluginMock::supportedDevices() const
|
|||
deviceClassMockAuto.setCreateMethod(DeviceClass::CreateMethodAuto);
|
||||
|
||||
mockParams.clear();
|
||||
deviceClassMockAuto.setParams(mockParams);
|
||||
deviceClassMockAuto.setStates(mockStates);
|
||||
deviceClassMockAuto.setEvents(mockEvents);
|
||||
deviceClassMockAuto.setParamTypes(mockParams);
|
||||
deviceClassMockAuto.setStateTypes(mockStates);
|
||||
deviceClassMockAuto.setEventTypes(mockEvents);
|
||||
deviceClassMockAuto.setActions(mockActions);
|
||||
|
||||
ret.append(deviceClassMockAuto);
|
||||
|
|
@ -152,9 +152,9 @@ QList<DeviceClass> DevicePluginMock::supportedDevices() const
|
|||
|
||||
mockParams.clear();
|
||||
mockParams.append(portParam);
|
||||
deviceClassMockDiscovery.setParams(mockParams);
|
||||
deviceClassMockDiscovery.setStates(mockStates);
|
||||
deviceClassMockDiscovery.setEvents(mockEvents);
|
||||
deviceClassMockDiscovery.setParamTypes(mockParams);
|
||||
deviceClassMockDiscovery.setStateTypes(mockStates);
|
||||
deviceClassMockDiscovery.setEventTypes(mockEvents);
|
||||
deviceClassMockDiscovery.setActions(mockActions);
|
||||
|
||||
ret.append(deviceClassMockDiscovery);
|
||||
|
|
@ -164,9 +164,9 @@ QList<DeviceClass> DevicePluginMock::supportedDevices() const
|
|||
deviceClassMockAsync.setName("Mock Device (Async)");
|
||||
deviceClassMockAsync.setCreateMethod(DeviceClass::CreateMethodUser);
|
||||
|
||||
deviceClassMockAsync.setParams(mockParams);
|
||||
deviceClassMockAsync.setStates(mockStates);
|
||||
deviceClassMockAsync.setEvents(mockEvents);
|
||||
deviceClassMockAsync.setParamTypes(mockParams);
|
||||
deviceClassMockAsync.setStateTypes(mockStates);
|
||||
deviceClassMockAsync.setEventTypes(mockEvents);
|
||||
deviceClassMockAsync.setActions(mockActions);
|
||||
|
||||
ret.append(deviceClassMockAsync);
|
||||
|
|
@ -176,9 +176,9 @@ QList<DeviceClass> DevicePluginMock::supportedDevices() const
|
|||
deviceClassMockBroken.setName("Mock Device (Broken setup)");
|
||||
deviceClassMockBroken.setCreateMethod(DeviceClass::CreateMethodUser);
|
||||
|
||||
deviceClassMockBroken.setParams(mockParams);
|
||||
deviceClassMockBroken.setStates(mockStates);
|
||||
deviceClassMockBroken.setEvents(mockEvents);
|
||||
deviceClassMockBroken.setParamTypes(mockParams);
|
||||
deviceClassMockBroken.setStateTypes(mockStates);
|
||||
deviceClassMockBroken.setEventTypes(mockEvents);
|
||||
deviceClassMockBroken.setActions(mockActions);
|
||||
|
||||
ret.append(deviceClassMockBroken);
|
||||
|
|
@ -188,9 +188,9 @@ QList<DeviceClass> DevicePluginMock::supportedDevices() const
|
|||
deviceClassMockBrokenAsyncSetup.setName("Mock Device (Async Broken setup)");
|
||||
deviceClassMockBrokenAsyncSetup.setCreateMethod(DeviceClass::CreateMethodUser);
|
||||
|
||||
deviceClassMockBrokenAsyncSetup.setParams(mockParams);
|
||||
deviceClassMockBrokenAsyncSetup.setStates(mockStates);
|
||||
deviceClassMockBrokenAsyncSetup.setEvents(mockEvents);
|
||||
deviceClassMockBrokenAsyncSetup.setParamTypes(mockParams);
|
||||
deviceClassMockBrokenAsyncSetup.setStateTypes(mockStates);
|
||||
deviceClassMockBrokenAsyncSetup.setEventTypes(mockEvents);
|
||||
deviceClassMockBrokenAsyncSetup.setActions(mockActions);
|
||||
|
||||
ret.append(deviceClassMockBrokenAsyncSetup);
|
||||
|
|
|
|||
|
|
@ -143,10 +143,10 @@ QString HttpDaemon::generateWebPage()
|
|||
body.append("<h2>States</h2>");
|
||||
|
||||
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("<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(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>");
|
||||
|
|
@ -159,16 +159,21 @@ QString HttpDaemon::generateWebPage()
|
|||
body.append("<h2>Events</h2>");
|
||||
|
||||
body.append("<table>");
|
||||
for (int i = 0; i < deviceClass.events().count(); ++i) {
|
||||
const EventType &eventType = deviceClass.events().at(i);
|
||||
for (int i = 0; i < deviceClass.eventTypes().count(); ++i) {
|
||||
qDebug() << "adding eventType" << deviceClass.eventTypes().at(i).name();
|
||||
const EventType &eventType = deviceClass.eventTypes().at(i);
|
||||
body.append(QString(
|
||||
"<tr>"
|
||||
"<form action=\"/generateevent\" method=\"get\">"
|
||||
"<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>"
|
||||
"</tr>"
|
||||
).arg(eventType.name()).arg(eventType.id().toString()));
|
||||
);
|
||||
}
|
||||
body.append("</table>");
|
||||
|
||||
|
|
@ -181,7 +186,7 @@ QString HttpDaemon::generateWebPage()
|
|||
ActionTypeId actionTypeId = ActionTypeId(m_actionList.at(i).first);
|
||||
QDateTime timestamp = m_actionList.at(i).second;
|
||||
QString actionName;
|
||||
foreach (const ActionType &at, deviceClass.actions()) {
|
||||
foreach (const ActionType &at, deviceClass.actionTypes()) {
|
||||
if (at.id() == actionTypeId) {
|
||||
actionName = at.name();
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -326,7 +326,7 @@ QList<DeviceClass> DevicePluginOpenweathermap::supportedDevices() const
|
|||
params.append(locationParam);
|
||||
|
||||
//Location is all we need for discovery.
|
||||
deviceClassOpenweathermap.setDiscoveryParams(params);
|
||||
deviceClassOpenweathermap.setDiscoveryParamTypes(params);
|
||||
|
||||
ParamType countryParam("country", QVariant::String);
|
||||
params.append(countryParam);
|
||||
|
|
@ -334,7 +334,7 @@ QList<DeviceClass> DevicePluginOpenweathermap::supportedDevices() const
|
|||
ParamType idParam("id", QVariant::String);
|
||||
params.append(idParam);
|
||||
|
||||
deviceClassOpenweathermap.setParams(params);
|
||||
deviceClassOpenweathermap.setParamTypes(params);
|
||||
|
||||
// Actions
|
||||
QList<ActionType> weatherActions;
|
||||
|
|
@ -417,7 +417,7 @@ QList<DeviceClass> DevicePluginOpenweathermap::supportedDevices() const
|
|||
weatherStates.append(sunriseState);
|
||||
|
||||
deviceClassOpenweathermap.setActions(weatherActions);
|
||||
deviceClassOpenweathermap.setStates(weatherStates);
|
||||
deviceClassOpenweathermap.setStateTypes(weatherStates);
|
||||
|
||||
ret.append(deviceClassOpenweathermap);
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ QList<DeviceClass> DevicePluginWakeOnLan::supportedDevices() const
|
|||
wolAction.setName("wakeup");
|
||||
wolActions.append(wolAction);
|
||||
|
||||
deviceClassWakeOnLan.setParams(wolParams);
|
||||
deviceClassWakeOnLan.setParamTypes(wolParams);
|
||||
deviceClassWakeOnLan.setActions(wolActions);
|
||||
|
||||
ret.append(deviceClassWakeOnLan);
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ QList<DeviceClass> DevicePluginWifiDetector::supportedDevices() const
|
|||
ParamType macParam("mac", QVariant::String);
|
||||
detectorParams.append(macParam);
|
||||
|
||||
deviceClassWifiDetector.setParams(detectorParams);
|
||||
deviceClassWifiDetector.setParamTypes(detectorParams);
|
||||
|
||||
QList<StateType> detectorStates;
|
||||
|
||||
|
|
@ -62,7 +62,7 @@ QList<DeviceClass> DevicePluginWifiDetector::supportedDevices() const
|
|||
inRangeState.setDefaultValue(false);
|
||||
detectorStates.append(inRangeState);
|
||||
|
||||
deviceClassWifiDetector.setStates(detectorStates);
|
||||
deviceClassWifiDetector.setStateTypes(detectorStates);
|
||||
|
||||
ret.append(deviceClassWifiDetector);
|
||||
|
||||
|
|
|
|||
|
|
@ -101,6 +101,10 @@ GuhCore::GuhCore(QObject *parent) :
|
|||
here will be evaluated by the \l{RuleEngine} and the according \l{Action}{Actions} are executed.*/
|
||||
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)) {
|
||||
qDebug() << "executing action" << action.actionTypeId();
|
||||
QPair<DeviceManager::DeviceError, QString> status = m_deviceManager->executeAction(action);
|
||||
|
|
|
|||
|
|
@ -42,6 +42,9 @@ public:
|
|||
DeviceManager* deviceManager() const;
|
||||
RuleEngine *ruleEngine() const;
|
||||
|
||||
signals:
|
||||
void eventTriggered(const Event &event);
|
||||
|
||||
private:
|
||||
explicit GuhCore(QObject *parent = 0);
|
||||
static GuhCore *s_instance;
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ JsonReply *ActionHandler::GetActionType(const QVariantMap ¶ms) const
|
|||
{
|
||||
ActionTypeId actionTypeId(params.value("actionTypeId").toString());
|
||||
foreach (const DeviceClass &deviceClass, GuhCore::instance()->deviceManager()->supportedDevices()) {
|
||||
foreach (const ActionType &actionType, deviceClass.actions()) {
|
||||
foreach (const ActionType &actionType, deviceClass.actionTypes()) {
|
||||
if (actionType.id() == actionTypeId) {
|
||||
QVariantMap data;
|
||||
data.insert("success", true);
|
||||
|
|
|
|||
|
|
@ -391,7 +391,7 @@ JsonReply* DeviceHandler::GetEventTypes(const QVariantMap ¶ms) const
|
|||
|
||||
QVariantList eventList;
|
||||
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));
|
||||
}
|
||||
returns.insert("eventTypes", eventList);
|
||||
|
|
@ -404,7 +404,7 @@ JsonReply* DeviceHandler::GetActionTypes(const QVariantMap ¶ms) const
|
|||
|
||||
QVariantList actionList;
|
||||
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));
|
||||
}
|
||||
returns.insert("actionTypes", actionList);
|
||||
|
|
@ -417,7 +417,7 @@ JsonReply* DeviceHandler::GetStateTypes(const QVariantMap ¶ms) const
|
|||
|
||||
QVariantList stateList;
|
||||
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));
|
||||
}
|
||||
returns.insert("stateTypes", stateList);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
@ -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 ¶ms);
|
||||
|
||||
private slots:
|
||||
void eventTriggered(const Event &event);
|
||||
};
|
||||
|
||||
#endif // EVENTHANDLER_H
|
||||
|
|
@ -37,6 +37,7 @@
|
|||
#include "devicehandler.h"
|
||||
#include "actionhandler.h"
|
||||
#include "ruleshandler.h"
|
||||
#include "eventhandler.h"
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QStringList>
|
||||
|
|
@ -138,6 +139,7 @@ void JsonRPCServer::setup()
|
|||
registerHandler(new DeviceHandler(this));
|
||||
registerHandler(new ActionHandler(this));
|
||||
registerHandler(new RulesHandler(this));
|
||||
registerHandler(new EventHandler(this));
|
||||
}
|
||||
|
||||
void JsonRPCServer::processData(const QUuid &clientId, const QByteArray &jsonData)
|
||||
|
|
|
|||
|
|
@ -191,7 +191,11 @@ QVariantMap JsonTypes::packEventType(const EventType &eventType)
|
|||
QVariantMap variant;
|
||||
variant.insert("id", eventType.id());
|
||||
variant.insert("name", eventType.name());
|
||||
variant.insert("paramTypes", eventType.parameters());
|
||||
QVariantList paramTypes;
|
||||
foreach (const ParamType ¶mType, eventType.parameters()) {
|
||||
paramTypes.append(packParamType(paramType));
|
||||
}
|
||||
variant.insert("paramTypes", paramTypes);
|
||||
return variant;
|
||||
}
|
||||
|
||||
|
|
@ -305,23 +309,23 @@ QVariantMap JsonTypes::packDeviceClass(const DeviceClass &deviceClass)
|
|||
variant.insert("id", deviceClass.id());
|
||||
variant.insert("vendorId", deviceClass.vendorId());
|
||||
QVariantList stateTypes;
|
||||
foreach (const StateType &stateType, deviceClass.states()) {
|
||||
foreach (const StateType &stateType, deviceClass.stateTypes()) {
|
||||
stateTypes.append(packStateType(stateType));
|
||||
}
|
||||
QVariantList eventTypes;
|
||||
foreach (const EventType &eventType, deviceClass.events()) {
|
||||
foreach (const EventType &eventType, deviceClass.eventTypes()) {
|
||||
eventTypes.append(packEventType(eventType));
|
||||
}
|
||||
QVariantList actionTypes;
|
||||
foreach (const ActionType &actionType, deviceClass.actions()) {
|
||||
foreach (const ActionType &actionType, deviceClass.actionTypes()) {
|
||||
actionTypes.append(packActionType(actionType));
|
||||
}
|
||||
QVariantList paramTypes;
|
||||
foreach (const ParamType ¶mType, deviceClass.params()) {
|
||||
foreach (const ParamType ¶mType, deviceClass.paramTypes()) {
|
||||
paramTypes.append(packParamType(paramType));
|
||||
}
|
||||
QVariantList discoveryParamTypes;
|
||||
foreach (const ParamType ¶mType, deviceClass.discoveryParams()) {
|
||||
foreach (const ParamType ¶mType, deviceClass.discoveryParamTypes()) {
|
||||
discoveryParamTypes.append(packParamType(paramType));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -190,7 +190,7 @@ RuleEngine::RuleError RuleEngine::addRule(const EventDescriptor &eventDescriptor
|
|||
qDebug() << "found deviceClass" << deviceClass.name();
|
||||
|
||||
bool eventTypeFound = false;
|
||||
foreach (const EventType &eventType, deviceClass.events()) {
|
||||
foreach (const EventType &eventType, deviceClass.eventTypes()) {
|
||||
if (eventType.id() == eventDescriptor.eventTypeId()) {
|
||||
eventTypeFound = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@ SOURCES += $$top_srcdir/server/guhcore.cpp \
|
|||
$$top_srcdir/server/jsonrpc/jsontypes.cpp \
|
||||
$$top_srcdir/server/jsonrpc/ruleshandler.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 \
|
||||
$$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/ruleshandler.h \
|
||||
$$top_srcdir/server/jsonrpc/actionhandler.h \
|
||||
$$top_srcdir/server/stateevaluator.h
|
||||
$$top_srcdir/server/jsonrpc/eventhandler.h \
|
||||
$$top_srcdir/server/stateevaluator.h \
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
0.1.5
|
||||
0.1.6
|
||||
{
|
||||
"methods": {
|
||||
"Actions.ExecuteAction": {
|
||||
|
|
@ -253,6 +253,12 @@
|
|||
"stateTypeId": "uuid",
|
||||
"variant": "value"
|
||||
}
|
||||
},
|
||||
"Events.EventTriggered": {
|
||||
"description": "Emitted whenever an Event is triggered.",
|
||||
"params": {
|
||||
"event": "$ref:Event"
|
||||
}
|
||||
}
|
||||
},
|
||||
"types": {
|
||||
|
|
|
|||
|
|
@ -383,7 +383,7 @@ void TestDevices::getEventTypes_data()
|
|||
QTest::addColumn<DeviceClassId>("deviceClassId");
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ void TestJSONRPC::stateChangeEmitsNotifications()
|
|||
|
||||
// Lets wait for the notification
|
||||
clientSpy.wait();
|
||||
QCOMPARE(clientSpy.count(), 1);
|
||||
QCOMPARE(clientSpy.count(), 2);
|
||||
|
||||
// Make sure the notification contains all the stuff we expect
|
||||
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("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
|
||||
params.clear();
|
||||
params.insert("enabled", false);
|
||||
|
|
|
|||
Loading…
Reference in New Issue