Fix params on the shelly i3

This commit is contained in:
Michael Zanetti 2021-09-02 15:15:52 +02:00
parent 02791d1411
commit a4c6a9e52b
2 changed files with 21 additions and 28 deletions

View File

@ -1029,25 +1029,26 @@ void IntegrationPluginShelly::onPublishReceived(MqttChannel *channel, const QStr
qCWarning(dcShelly()) << "Failed to parse JSON from shelly:" << error.errorString() << qUtf8Printable(payload);
return;
}
QString buttonName = QString::number(channel + 1);
QString event = jsonDoc.toVariant().toMap().value("event").toString();
QString param = "";
EventTypeId eventTypeId = shellyI3LongPressedEventTypeId;
ParamTypeId paramTypeId = shellyI3LongPressedEventButtonNameParamTypeId;
ParamTypeId param2TypeId = shellyI3LongPressedEventOriginParamTypeId;
if (event == "L") {
param = "1";
if (event == "S") {
thing->emitEvent(shellyI3PressedEventTypeId, ParamList() << Param(shellyI3PressedEventButtonNameParamTypeId, buttonName) << Param(shellyI3PressedEventCountParamTypeId, 1));
} else if (event == "L") {
thing->emitEvent(shellyI3LongPressedEventTypeId, ParamList() << Param(shellyI3LongPressedEventButtonNameParamTypeId, buttonName));
} else if (event == "SS") {
thing->emitEvent(shellyI3PressedEventTypeId, ParamList() << Param(shellyI3PressedEventButtonNameParamTypeId, buttonName) << Param(shellyI3PressedEventCountParamTypeId, 2));
} else if (event == "SSS") {
thing->emitEvent(shellyI3PressedEventTypeId, ParamList() << Param(shellyI3PressedEventButtonNameParamTypeId, buttonName) << Param(shellyI3PressedEventCountParamTypeId, 3));
} else if (event == "SL") {
param = "2";
thing->emitEvent(shellyI3PressedEventTypeId, ParamList() << Param(shellyI3PressedEventButtonNameParamTypeId, buttonName) << Param(shellyI3PressedEventCountParamTypeId, 1));
thing->emitEvent(shellyI3LongPressedEventTypeId, ParamList() << Param(shellyI3LongPressedEventButtonNameParamTypeId, buttonName));
} else if (event == "LS") {
param = "3";
} else { // short press
param = QString::number(event.length());
eventTypeId = shellyI3PressedEventTypeId;
paramTypeId = shellyI3PressedEventButtonNameParamTypeId;
param2TypeId = shellyI3PressedEventOriginParamTypeId;
thing->emitEvent(shellyI3LongPressedEventTypeId, ParamList() << Param(shellyI3LongPressedEventButtonNameParamTypeId, buttonName));
thing->emitEvent(shellyI3PressedEventTypeId, ParamList() << Param(shellyI3PressedEventButtonNameParamTypeId, buttonName) << Param(shellyI3PressedEventCountParamTypeId, 1));
} else {
qCDebug(dcShelly()) << "Invalid button code from shelly I3:" << event;
}
QString usedSwitch = QString::number(channel + 1);
thing->emitEvent(eventTypeId, ParamList() << Param(paramTypeId, param) << Param(param2TypeId, usedSwitch));
}
}

View File

@ -1268,16 +1268,15 @@
{
"id": "146313a1-cfb6-4732-a1be-86ec575bcbdb",
"name": "buttonName",
"displayName": "Count",
"displayName": "Button name",
"type": "QString",
"allowedValues": ["1", "2", "3"]
},
{
"id": "0ed31339-7457-443c-b6e3-3b8ce3fc2bd8",
"name": "origin",
"displayName": "Switch",
"type": "QString",
"allowedValues": ["1", "2", "3"]
"name": "count",
"displayName": "Press count",
"type": "uint"
}
]
},
@ -1289,14 +1288,7 @@
{
"id": "99683cf9-930e-4f10-94f2-73bb32092639",
"name": "buttonName",
"displayName": "Count",
"type": "QString",
"allowedValues": ["1", "2", "3"]
},
{
"id": "866d6db6-e989-4b19-93c3-cc4aa7453c9e",
"name": "origin",
"displayName": "Switch",
"displayName": "Button name",
"type": "QString",
"allowedValues": ["1", "2", "3"]
}