From a4c6a9e52b7e11c9270dff96d6ac6a0038c8ee48 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Thu, 2 Sep 2021 15:15:52 +0200 Subject: [PATCH] Fix params on the shelly i3 --- shelly/integrationpluginshelly.cpp | 31 +++++++++++++++-------------- shelly/integrationpluginshelly.json | 18 +++++------------ 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/shelly/integrationpluginshelly.cpp b/shelly/integrationpluginshelly.cpp index 4a558bd7..379cf187 100644 --- a/shelly/integrationpluginshelly.cpp +++ b/shelly/integrationpluginshelly.cpp @@ -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)); } } diff --git a/shelly/integrationpluginshelly.json b/shelly/integrationpluginshelly.json index f9e97683..34d5cccd 100644 --- a/shelly/integrationpluginshelly.json +++ b/shelly/integrationpluginshelly.json @@ -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"] }