Fix creating interface based rules with parameters being taken from the event
This commit is contained in:
parent
43ad05397e
commit
a7f88cbfcd
@ -155,13 +155,15 @@ void DeviceManager::notificationReceived(const QVariantMap &data)
|
||||
{
|
||||
QString notification = data.value("notification").toString();
|
||||
if (notification == "Devices.StateChanged") {
|
||||
// qDebug() << "Device state changed" << data.value("params");
|
||||
Device *dev = m_devices->getDevice(data.value("params").toMap().value("deviceId").toUuid());
|
||||
if (!dev) {
|
||||
qWarning() << "Device state change notification received for an unknown device";
|
||||
return;
|
||||
}
|
||||
dev->setStateValue(data.value("params").toMap().value("stateTypeId").toUuid(), data.value("params").toMap().value("value"));
|
||||
QUuid stateTyoeId = data.value("params").toMap().value("stateTypeId").toUuid();
|
||||
QVariant value = data.value("params").toMap().value("value");
|
||||
// qDebug() << "Device state changed for:" << dev->name() << "State name:" << dev->thingClass()->stateTypes()->getStateType(stateTyoeId) << "value:" << value;
|
||||
dev->setStateValue(stateTyoeId, value);
|
||||
} else if (notification == "Devices.DeviceAdded") {
|
||||
Device *dev = JsonTypes::unpackDevice(this, data.value("params").toMap().value("device").toMap(), m_deviceClasses);
|
||||
if (!dev) {
|
||||
@ -243,6 +245,10 @@ void DeviceManager::notificationReceived(const QVariantMap &data)
|
||||
return;
|
||||
}
|
||||
m_ioConnections->removeIOConnection(connectionId);
|
||||
} else if (notification == "Integrations.EventTriggered") {
|
||||
// Still using Devices.EventTriggered
|
||||
} else if (notification == "Integrations.StateChanged") {
|
||||
// Still using Devies.StateChanged
|
||||
} else {
|
||||
qWarning() << "DeviceManager unhandled device notification received" << notification;
|
||||
}
|
||||
@ -263,7 +269,7 @@ void DeviceManager::getVendorsResponse(const QVariantMap ¶ms)
|
||||
|
||||
void DeviceManager::getSupportedDevicesResponse(const QVariantMap ¶ms)
|
||||
{
|
||||
qDebug() << "DeviceClass received:" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson(QJsonDocument::Indented));
|
||||
// qDebug() << "DeviceClasses received:" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson(QJsonDocument::Indented));
|
||||
if (params.value("params").toMap().keys().contains("deviceClasses")) {
|
||||
QVariantList deviceClassList = params.value("params").toMap().value("deviceClasses").toList();
|
||||
foreach (QVariant deviceClassVariant, deviceClassList) {
|
||||
|
||||
@ -226,12 +226,11 @@ LogEntry *LogsModelNg::get(int index) const
|
||||
|
||||
void LogsModelNg::logsReply(const QVariantMap &data)
|
||||
{
|
||||
qDebug() << "logs reply" << qUtf8Printable(QJsonDocument::fromVariant(data).toJson());
|
||||
|
||||
|
||||
int offset = data.value("params").toMap().value("offset").toInt();
|
||||
int count = data.value("params").toMap().value("count").toInt();
|
||||
|
||||
// qDebug() << qUtf8Printable(QJsonDocument::fromVariant(data).toJson());
|
||||
|
||||
QList<LogEntry*> newBlock;
|
||||
QList<QVariant> logEntries = data.value("params").toMap().value("logEntries").toList();
|
||||
foreach (const QVariant &logEntryVariant, logEntries) {
|
||||
@ -248,6 +247,8 @@ void LogsModelNg::logsReply(const QVariantMap &data)
|
||||
newBlock.append(entry);
|
||||
}
|
||||
|
||||
qDebug() << "Received logs from" << offset << "to" << offset + count << "Actual count:" << newBlock.count();
|
||||
|
||||
if (count < m_blockSize) {
|
||||
m_canFetchMore = false;
|
||||
}
|
||||
@ -350,7 +351,6 @@ void LogsModelNg::logsReply(const QVariantMap &data)
|
||||
void LogsModelNg::fetchMore(const QModelIndex &parent)
|
||||
{
|
||||
Q_UNUSED(parent)
|
||||
// qDebug() << "fetchMore called";
|
||||
|
||||
if (!m_engine) {
|
||||
qWarning() << "Cannot update. Engine not set";
|
||||
@ -393,6 +393,8 @@ void LogsModelNg::fetchMore(const QModelIndex &parent)
|
||||
params.insert("limit", m_blockSize);
|
||||
params.insert("offset", m_list.count());
|
||||
|
||||
qDebug() << "Fetching logs from" << m_startTime.toString() << "to" << m_endTime.toString() << "with offset" << m_list.count() << "and limit" << m_blockSize;
|
||||
|
||||
m_engine->jsonRpcClient()->sendCommand("Logging.GetLogEntries", params, this, "logsReply");
|
||||
// qDebug() << "GetLogEntries called";
|
||||
}
|
||||
|
||||
@ -145,15 +145,15 @@ Interfaces::Interfaces(QObject *parent) : QAbstractListModel(parent)
|
||||
addActionType("mediacontroller", "skipBack", tr("Skip back"), new ParamTypes());
|
||||
addActionType("mediacontroller", "skipNext", tr("Skip next"), new ParamTypes());
|
||||
|
||||
addInterface("extendedmediacontroller", tr("Media controllers"), {"mediacontroller"});
|
||||
addInterface("extendedmediacontroller", tr("Media controllers with seeking"), {"mediacontroller"});
|
||||
addActionType("extendedmediacontroller", "fastForward", tr("Fast forward"), new ParamTypes());
|
||||
addActionType("extendedmediacontroller", "fastRewind", tr("Fast rewind"), new ParamTypes());
|
||||
|
||||
addInterface("navigationpad", tr("Navigation pad"));
|
||||
pts = createParamTypes("to", tr("To"), QVariant::String, QVariant(), {"up", "down", "left", "right", "enter", "back", "menu", "info", "home"});
|
||||
pts = createParamTypes("to", tr("To"), QVariant::String, QVariant(), {"up", "down", "left", "right", "enter", "back"});
|
||||
addActionType("navigationpad", "navigate", tr("Navigate"), pts);
|
||||
|
||||
addInterface("extendednavigationpad", tr("Navigation pad"));
|
||||
addInterface("extendednavigationpad", tr("Navigation pad with menu"));
|
||||
pts = createParamTypes("to", tr("To"), QVariant::String, QVariant(), {"up", "down", "left", "right", "enter", "back", "menu", "info", "home"});
|
||||
addActionType("extendednavigationpad", "navigate", tr("Navigate"), pts);
|
||||
|
||||
@ -268,7 +268,7 @@ Interfaces::Interfaces(QObject *parent) : QAbstractListModel(parent)
|
||||
addInterface("pressuresensor", tr("Pressure sensors"), {"sensor"});
|
||||
addStateType("pressuresensor", "pressure", QVariant::Double, false, tr("Pressure"), tr("Pressure changed"));
|
||||
|
||||
addInterface("shufflerepeat", tr("Media player"));
|
||||
addInterface("shufflerepeat", tr("Shuffle and repeat controllers"));
|
||||
addStateType("shufflerepeat", "shuffle", QVariant::Bool, true, tr("Shuffle"), tr("Shuffle changed"), tr("Set shuffle"));
|
||||
addStateType("shufflerepeat", "repeat", QVariant::Bool, true, tr("Repeat"), tr("Repeat changed"), tr("Set repeat"));
|
||||
|
||||
|
||||
@ -56,8 +56,8 @@ class ParamType : public QObject
|
||||
Q_PROPERTY(bool readOnly READ readOnly CONSTANT)
|
||||
|
||||
public:
|
||||
ParamType(QObject *parent = 0);
|
||||
ParamType(const QString &name, const QVariant::Type type, const QVariant &defaultValue = QVariant(), QObject *parent = 0);
|
||||
ParamType(QObject *parent = nullptr);
|
||||
ParamType(const QString &name, const QVariant::Type type, const QVariant &defaultValue = QVariant(), QObject *parent = nullptr);
|
||||
|
||||
QUuid id() const;
|
||||
void setId(const QUuid &id);
|
||||
|
||||
@ -124,6 +124,22 @@ void RuleActionParams::setRuleActionParamEvent(const QString ¶mTypeId, const
|
||||
addRuleActionParam(rap);
|
||||
}
|
||||
|
||||
void RuleActionParams::setRuleActionParamEventByName(const QString ¶mName, const QString &eventTypeId, const QString &eventParamTypeId)
|
||||
{
|
||||
foreach (RuleActionParam *rap, m_list) {
|
||||
if (rap->paramName() == paramName) {
|
||||
rap->setEventTypeId(eventTypeId);
|
||||
rap->setEventParamTypeId(eventParamTypeId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
RuleActionParam *rap = new RuleActionParam(this);
|
||||
rap->setParamName(paramName);
|
||||
rap->setEventTypeId(eventTypeId);
|
||||
rap->setEventParamTypeId(eventParamTypeId);
|
||||
addRuleActionParam(rap);
|
||||
}
|
||||
|
||||
void RuleActionParams::setRuleActionParamState(const QString ¶mTypeId, const QString &stateDeviceId, const QString &stateTypeId)
|
||||
{
|
||||
foreach (RuleActionParam *rap, m_list) {
|
||||
@ -140,6 +156,22 @@ void RuleActionParams::setRuleActionParamState(const QString ¶mTypeId, const
|
||||
addRuleActionParam(rap);
|
||||
}
|
||||
|
||||
void RuleActionParams::setRuleActionParamStateByName(const QString ¶mName, const QString &stateDeviceId, const QString &stateTypeId)
|
||||
{
|
||||
foreach (RuleActionParam *rap, m_list) {
|
||||
if (rap->paramName() == paramName) {
|
||||
rap->setStateDeviceId(stateDeviceId);
|
||||
rap->setStateTypeId(stateTypeId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
RuleActionParam *rap = new RuleActionParam(this);
|
||||
rap->setParamName(paramName);
|
||||
rap->setStateDeviceId(stateDeviceId);
|
||||
rap->setStateTypeId(stateTypeId);
|
||||
addRuleActionParam(rap);
|
||||
}
|
||||
|
||||
RuleActionParam *RuleActionParams::get(int index) const
|
||||
{
|
||||
return m_list.at(index);
|
||||
|
||||
@ -59,7 +59,9 @@ public:
|
||||
Q_INVOKABLE void setRuleActionParam(const QString ¶mTypeId, const QVariant &value);
|
||||
Q_INVOKABLE void setRuleActionParamByName(const QString ¶mName, const QVariant &value);
|
||||
Q_INVOKABLE void setRuleActionParamEvent(const QString ¶mTypeId, const QString &eventTypeId, const QString &eventParamTypeId);
|
||||
Q_INVOKABLE void setRuleActionParamEventByName(const QString ¶mName, const QString &eventTypeId, const QString &eventParamTypeId);
|
||||
Q_INVOKABLE void setRuleActionParamState(const QString ¶mTypeId, const QString &stateDeviceId, const QString &stateTypeId);
|
||||
Q_INVOKABLE void setRuleActionParamStateByName(const QString ¶mName, const QString &stateDeviceId, const QString &stateTypeId);
|
||||
|
||||
Q_INVOKABLE RuleActionParam* get(int index) const;
|
||||
|
||||
|
||||
@ -232,5 +232,6 @@
|
||||
<file>ui/images/garage/garage-080.svg</file>
|
||||
<file>ui/images/garage/garage-090.svg</file>
|
||||
<file>ui/images/garage/garage-100.svg</file>
|
||||
<file>ui/images/navigationpad.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
@ -209,7 +209,7 @@ ApplicationWindow {
|
||||
}
|
||||
|
||||
function interfacesToIcon(interfaces) {
|
||||
print("finding icon for interfaces:", interfaces)
|
||||
// print("finding icon for interfaces:", interfaces)
|
||||
for (var i = 0; i < interfaces.length; i++) {
|
||||
var icon = interfaceToIcon(interfaces[i]);
|
||||
if (icon !== "") {
|
||||
@ -220,7 +220,7 @@ ApplicationWindow {
|
||||
}
|
||||
|
||||
function interfaceToIcon(name) {
|
||||
print("finding icon for interface:", name)
|
||||
// print("finding icon for interface:", name)
|
||||
switch (name) {
|
||||
case "light":
|
||||
case "colorlight":
|
||||
@ -255,6 +255,7 @@ ApplicationWindow {
|
||||
return Qt.resolvedUrl("images/sensors/windspeed.svg")
|
||||
case "media":
|
||||
case "mediacontroller":
|
||||
case "extendedmediacontroller":
|
||||
case "mediaplayer":
|
||||
return Qt.resolvedUrl("images/mediaplayer-app-symbolic.svg")
|
||||
case "powersocket":
|
||||
@ -324,6 +325,16 @@ ApplicationWindow {
|
||||
return Qt.resolvedUrl("images/account.svg")
|
||||
case "smartlock":
|
||||
return Qt.resolvedUrl("images/smartlock.svg")
|
||||
case "navigationpad":
|
||||
case "extendednavigationpad":
|
||||
return Qt.resolvedUrl("images/navigationpad.svg")
|
||||
case "volumecontroller":
|
||||
case "extendedvolumecontroller":
|
||||
return Qt.resolvedUrl("images/audio-speakers-symbolic.svg")
|
||||
case "shufflerepeat":
|
||||
return Qt.resolvedUrl("images/media-playlist-shuffle.svg")
|
||||
case "alert":
|
||||
return Qt.resolvedUrl("images/notification.svg")
|
||||
default:
|
||||
console.warn("InterfaceToIcon: Unhandled interface", name)
|
||||
}
|
||||
|
||||
164
nymea-app/ui/images/navigationpad.svg
Normal file
164
nymea-app/ui/images/navigationpad.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 20 KiB |
@ -246,6 +246,7 @@ Page {
|
||||
pageStack.pop();
|
||||
})
|
||||
ruleActionPage.onDone.connect(function() {
|
||||
print("Adding rule action", ruleAction)
|
||||
ruleActions.addRuleAction(ruleAction)
|
||||
pageStack.pop(root);
|
||||
})
|
||||
|
||||
@ -40,7 +40,7 @@ Page {
|
||||
// Needs to be set and have rule.ruleActions filled in with deviceId and actionTypeId or interfaceName and interfaceAction
|
||||
property var ruleAction: null
|
||||
|
||||
// optionally a rule which will be used to propose event's params as param values
|
||||
// optionally a rule which will be used to propose events params as param values
|
||||
property var rule: null
|
||||
|
||||
readonly property var device: ruleAction && ruleAction.deviceId ? engine.deviceManager.devices.getDevice(ruleAction.deviceId) : null
|
||||
@ -216,20 +216,32 @@ Page {
|
||||
var params = [];
|
||||
for (var i = 0; i < delegateRepeater.count; i++) {
|
||||
var paramDelegate = delegateRepeater.itemAt(i);
|
||||
print("Working on parameter", paramDelegate.paramType, paramDelegate.paramType.id, paramDelegate.value, paramDelegate.eventType, paramDelegate.eventParamTypeId, paramDelegate.stateDeviceId, paramDelegate.stateTypeId)
|
||||
|
||||
if (paramDelegate.type === "static") {
|
||||
print("Setting static value", paramDelegate.value)
|
||||
if (root.device) {
|
||||
print("setting", paramDelegate.paramType.id)
|
||||
print("Setting static value rule action param", paramDelegate.paramType.id, paramDelegate.value)
|
||||
root.ruleAction.ruleActionParams.setRuleActionParam(paramDelegate.paramType.id, paramDelegate.value)
|
||||
} else if (root.iface) {
|
||||
print("Setting static value rule action param by name", root.actionType.paramTypes.get(i).name, paramDelegate.value)
|
||||
root.ruleAction.ruleActionParams.setRuleActionParamByName(root.actionType.paramTypes.get(i).name, paramDelegate.value)
|
||||
}
|
||||
} else if (paramDelegate.type === "event") {
|
||||
print("adding event based rule action param", paramDelegate.paramType.id, paramDelegate.eventType.id, paramDelegate.eventParamTypeId)
|
||||
root.ruleAction.ruleActionParams.setRuleActionParamEvent(paramDelegate.paramType.id, paramDelegate.eventType.id, paramDelegate.eventParamTypeId)
|
||||
if (root.device) {
|
||||
print("adding event based rule action param", paramDelegate.paramType.id, paramDelegate.eventType.id, paramDelegate.eventParamTypeId)
|
||||
root.ruleAction.ruleActionParams.setRuleActionParamEvent(paramDelegate.paramType.id, paramDelegate.eventType.id, paramDelegate.eventParamTypeId)
|
||||
} else if (root.iface) {
|
||||
print("adding event based rule action param by name", root.actionType.paramTypes.get(i).name, paramDelegate.eventType.id, paramDelegate.eventParamTypeId)
|
||||
root.ruleAction.ruleActionParams.setRuleActionParamEventByName(root.actionType.paramTypes.get(i).name, paramDelegate.eventType.id, paramDelegate.eventParamTypeId)
|
||||
}
|
||||
} else if (paramDelegate.type === "state") {
|
||||
print("adding state value based rule action param", paramDelegate.paramType.id, paramDelegate.stateDeviceId, paramDelegate.stateTypeId)
|
||||
root.ruleAction.ruleActionParams.setRuleActionParamState(paramDelegate.paramType.id, paramDelegate.stateDeviceId, paramDelegate.stateTypeId)
|
||||
if (root.device) {
|
||||
print("adding state value based rule action param", paramDelegate.paramType.id, paramDelegate.stateDeviceId, paramDelegate.stateTypeId)
|
||||
root.ruleAction.ruleActionParams.setRuleActionParamState(paramDelegate.paramType.id, paramDelegate.stateDeviceId, paramDelegate.stateTypeId)
|
||||
} else if (root.iface) {
|
||||
print("adding state value based rule action param by name", root.actionType.paramTypes.get(i).name, paramDelegate.stateDeviceId, paramDelegate.stateTypeId)
|
||||
root.ruleAction.ruleActionParams.setRuleActionParamStateByName(root.actionType.paramTypes.get(i).name, paramDelegate.stateDeviceId, paramDelegate.stateTypeId)
|
||||
}
|
||||
}
|
||||
}
|
||||
root.completed()
|
||||
|
||||
Reference in New Issue
Block a user