From 4a9cde46e5e798ad9bbae5be4edca05e004114d5 Mon Sep 17 00:00:00 2001 From: Herb Paar Date: Tue, 26 Jan 2021 00:32:30 +0100 Subject: [PATCH] State and Event distribution --- shelly/integrationpluginshelly.cpp | 21 ++++++++++++++++++--- shelly/integrationpluginshelly.json | 18 ++---------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/shelly/integrationpluginshelly.cpp b/shelly/integrationpluginshelly.cpp index c5d2a215..849db51c 100644 --- a/shelly/integrationpluginshelly.cpp +++ b/shelly/integrationpluginshelly.cpp @@ -672,7 +672,22 @@ void IntegrationPluginShelly::onPublishReceived(MqttChannel *channel, const QStr // Emit event button pressed bool on = payload == "1"; if (thing->thingClassId() == shellyI3ThingClassId) { - thing->emitEvent(shellyI3PressEventTypeId, ParamList() << Param(shellyI3PressEventOriginParamTypeId, QString::number(channel +1))); + if (channel == 0) { + if (thing->stateValue(shellyI3Input1StateTypeId).toBool() != on) { + thing->setStateValue(shellyI3Input1StateTypeId, on); + emit emitEvent(Event(shellyI3Input1EventTypeId, thing->id())); + } + } else if (channel == 1) { + if (thing->stateValue(shellyI3Input2StateTypeId).toBool() != on) { + thing->setStateValue(shellyI3Input2StateTypeId, on); + emit emitEvent(Event(shellyI3Input2EventTypeId, thing->id())); + } + } else { + if (thing->stateValue(shellyI3Input3StateTypeId).toBool() != on) { + thing->setStateValue(shellyI3Input3StateTypeId, on); + emit emitEvent(Event(shellyI3Input3EventTypeId, thing->id())); + } + } return; } foreach (Thing *child, myThings().filterByParentId(thing->id())) { @@ -864,7 +879,7 @@ void IntegrationPluginShelly::onPublishReceived(MqttChannel *channel, const QStr QString param = ""; EventTypeId eventTypeId = shellyI3LongPressedEventTypeId;; ParamTypeId paramTypeId = shellyI3LongPressedEventButtonNameParamTypeId; - ParamTypeId param2TypeId = shellyI3LongPressedEventPressOriginParamTypeId; + ParamTypeId param2TypeId = shellyI3LongPressedEventOriginParamTypeId; if (event == "L") { param = "1"; } else if (event == "SL") { @@ -875,7 +890,7 @@ void IntegrationPluginShelly::onPublishReceived(MqttChannel *channel, const QStr param = QString::number(event.length()); eventTypeId = shellyI3PressedEventTypeId; paramTypeId = shellyI3PressedEventButtonNameParamTypeId; - param2TypeId = shellyI3PressedEventPressOriginParamTypeId; + param2TypeId = shellyI3PressedEventOriginParamTypeId; } 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 55149a63..4b92c20c 100644 --- a/shelly/integrationpluginshelly.json +++ b/shelly/integrationpluginshelly.json @@ -1200,20 +1200,6 @@ } ], "eventTypes": [ - { - "id": "724d18ff-693b-4a9c-aa72-66557e0069d6", - "name": "press", - "displayName": "Press", - "paramTypes": [ - { - "id": "ee2e1728-dfb3-4c0b-a131-0b7798415b2c", - "name": "origin", - "displayName": "Switch", - "type": "QString", - "allowedValues": ["1", "2", "3"] - } - ] - }, { "id": "79648810-b2f4-4aa5-902f-2875242e7bf8", "name": "pressed", @@ -1228,7 +1214,7 @@ }, { "id": "0ed31339-7457-443c-b6e3-3b8ce3fc2bd8", - "name": "pressOrigin", + "name": "origin", "displayName": "Switch", "type": "QString", "allowedValues": ["1", "2", "3"] @@ -1249,7 +1235,7 @@ }, { "id": "866d6db6-e989-4b19-93c3-cc4aa7453c9e", - "name": "pressOrigin", + "name": "origin", "displayName": "Switch", "type": "QString", "allowedValues": ["1", "2", "3"]