add some debug helpers
This commit is contained in:
parent
98dc4f3808
commit
2cdefcb1f2
@ -193,6 +193,42 @@ DeviceManager *DevicePlugin::deviceManager() const
|
||||
return m_deviceManager;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns a list of all configured devices belonging to this plugin.
|
||||
*/
|
||||
QList<Device *> DevicePlugin::myDevices() const
|
||||
{
|
||||
QList<DeviceClassId> myDeviceClassIds;
|
||||
foreach (const DeviceClass &deviceClass, supportedDevices()) {
|
||||
myDeviceClassIds.append(deviceClass.id());
|
||||
}
|
||||
|
||||
QList<Device*> ret;
|
||||
foreach (Device *device, deviceManager()->configuredDevices()) {
|
||||
if (myDeviceClassIds.contains(device->deviceClassId())) {
|
||||
ret.append(device);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*!
|
||||
Find a certain device from myDevices() by its params. All parameters must
|
||||
match or the device will not be found. Be prepared for nullptrs.
|
||||
*/
|
||||
Device *DevicePlugin::findDeviceByParams(const QVariantMap ¶ms) const
|
||||
{
|
||||
foreach (Device *device, myDevices()) {
|
||||
bool matching = true;
|
||||
foreach (const QString ¶mName, device->params().keys()) {
|
||||
if (device->params().value(paramName) == params.value(paramName)) {
|
||||
return device;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*!
|
||||
Transmits data contained in \a rawData on the Radio433 or Radio868
|
||||
devices, depending on the hardware requested by this plugin.
|
||||
|
||||
@ -73,6 +73,8 @@ signals:
|
||||
|
||||
protected:
|
||||
DeviceManager *deviceManager() const;
|
||||
QList<Device*> myDevices() const;
|
||||
Device* findDeviceByParams(const QVariantMap ¶ms) const;
|
||||
|
||||
void transmitData(QList<int> rawData);
|
||||
|
||||
|
||||
@ -75,3 +75,20 @@ bool Event::operator ==(const Event &other) const
|
||||
&& m_deviceId == other.deviceId()
|
||||
&& m_params == other.params();
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const Event &event)
|
||||
{
|
||||
dbg.nospace() << "Event(EventTypeId: " << event.eventTypeId().toString() << ", DeviceId" << event.deviceId() << ")";
|
||||
|
||||
return dbg.space();
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const QList<Event> &events)
|
||||
{
|
||||
dbg.nospace() << "EventList (count:" << events.count() << ")";
|
||||
for (int i = 0; i < events.count(); i++ ) {
|
||||
dbg.nospace() << " " << i << ": " << events.at(i);
|
||||
}
|
||||
|
||||
return dbg.space();
|
||||
}
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
|
||||
#include <QString>
|
||||
#include <QVariantList>
|
||||
#include <QDebug>
|
||||
|
||||
class Event
|
||||
{
|
||||
@ -42,5 +43,7 @@ private:
|
||||
DeviceId m_deviceId;
|
||||
QVariantMap m_params;
|
||||
};
|
||||
QDebug operator<<(QDebug dbg, const Event &event);
|
||||
QDebug operator<<(QDebug dbg, const QList<Event> &events);
|
||||
|
||||
#endif // EVENT_H
|
||||
|
||||
@ -62,3 +62,19 @@ void State::setValue(const QVariant &value)
|
||||
{
|
||||
m_value = value;
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const State &state)
|
||||
{
|
||||
dbg.nospace() << "State(StateTypeId: " << state.stateTypeId().toString() << ", DeviceId:" << state.deviceId() << ", value:" << state.value() << ")";
|
||||
return dbg.space();
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug dbg, const QList<State> &states)
|
||||
{
|
||||
dbg.nospace() << "StateList (count:" << states.count() << ")";
|
||||
for (int i = 0; i < states.count(); i++ ) {
|
||||
dbg.nospace() << " " << i << ": " << states.at(i);
|
||||
}
|
||||
|
||||
return dbg.space();
|
||||
}
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
#include "typeutils.h"
|
||||
|
||||
#include <QVariant>
|
||||
#include <QDebug>
|
||||
|
||||
class State
|
||||
{
|
||||
@ -31,6 +32,7 @@ public:
|
||||
StateTypeId stateTypeId() const;
|
||||
DeviceId deviceId() const;
|
||||
|
||||
QStringList stateNames() const;
|
||||
QVariant value() const;
|
||||
void setValue(const QVariant &value);
|
||||
|
||||
@ -40,4 +42,8 @@ private:
|
||||
QVariant m_value;
|
||||
};
|
||||
|
||||
QDebug operator<<(QDebug dbg, const State &event);
|
||||
QDebug operator<<(QDebug dbg, const QList<State> &events);
|
||||
|
||||
|
||||
#endif // STATE_H
|
||||
|
||||
@ -119,11 +119,13 @@ RuleEngine::RuleEngine(QObject *parent) :
|
||||
list of all \l{Action}{Actions} that should be executed. */
|
||||
QList<Action> RuleEngine::evaluateEvent(const Event &event)
|
||||
{
|
||||
qDebug() << "got event:" << event;
|
||||
QList<Action> actions;
|
||||
for (int i = 0; i < m_rules.count(); ++i) {
|
||||
qDebug() << "evaluating rule" << i << m_rules.at(i).events();
|
||||
if (m_rules.at(i).events().contains(event)) {
|
||||
bool statesMatching = true;
|
||||
qDebug() << "checking states";
|
||||
qDebug() << "checking states:" << m_rules.at(i).states();
|
||||
foreach (const State &state, m_rules.at(i).states()) {
|
||||
Device *device = GuhCore::instance()->deviceManager()->findConfiguredDevice(state.deviceId());
|
||||
if (!device) {
|
||||
@ -131,6 +133,7 @@ QList<Action> RuleEngine::evaluateEvent(const Event &event)
|
||||
break;
|
||||
}
|
||||
if (state.value() != device->stateValue(state.stateTypeId())) {
|
||||
qDebug() << "State value not matching:" << state.value() << device->stateValue(state.stateTypeId());
|
||||
statesMatching = false;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user