From 498f736ce0e93f793743ceac9661d02940e31591 Mon Sep 17 00:00:00 2001 From: rudolfkoenig Date: Sun, 16 Dec 2018 22:17:56 +0000 Subject: [PATCH] 10_MQTT2_DEVICE.pm: add setStateList attribute (Forum #94434) git-svn-id: https://svn.fhem.de/fhem/trunk@17990 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/10_MQTT2_DEVICE.pm | 86 ++++++++++++++++++++++++------------ fhem/fhem.pl | 7 ++- 2 files changed, 63 insertions(+), 30 deletions(-) diff --git a/fhem/FHEM/10_MQTT2_DEVICE.pm b/fhem/FHEM/10_MQTT2_DEVICE.pm index 5364f168e..79e9a46b1 100644 --- a/fhem/FHEM/10_MQTT2_DEVICE.pm +++ b/fhem/FHEM/10_MQTT2_DEVICE.pm @@ -27,10 +27,11 @@ MQTT2_DEVICE_Initialize($) devicetopic disable:0,1 disabledForIntervals + getList:textField-long model readingList:textField-long setList:textField-long - getList:textField-long + setStateList ); use warnings 'qw'; $hash->{AttrList} = join(" ", @attrList)." ".$readingFnAttributes; @@ -293,7 +294,21 @@ MQTT2_DEVICE_Set($@) $cmd = MQTT2_buildCmd($hash, \@a, $cmd); return if(!$cmd); IOWrite($hash, "publish", $cmd); - readingsSingleUpdate($hash, "state", $cmdName, 1); + my $ssl = AttrVal($hash->{NAME}, "setStateList", ""); + if(!$ssl) { + readingsSingleUpdate($hash, "state", $cmdName, 1); + + } else { + if($ssl =~ m/\b$cmdName\b/) { + $hash->{skipStateFormat} = 1; + readingsSingleUpdate($hash, "state", "set_$cmdName", 1); + delete($hash->{skipStateFormat}); + } else { + shift(@a); + unshift(@a, "set"); + readingsSingleUpdate($hash, $cmdName, join(" ",@a), 1); + } + } return undef; } @@ -532,6 +547,36 @@ zigbee2mqtt_devStateIcon255($)
  • disable
    disabledForIntervals

  • + +
  • getList cmd [topic|perl-Expression] ...
    + When the FHEM command cmd is issued, publish the topic, wait for the + answer (the specified reading), and show it in the user interface. + Multiple triples can be specified, each of them separated by newline, the + newline does not have to be entered in the FHEMWEB frontend.
    + Example:
    + +   attr dev getList\
    +     temp temperature myDev/cmd/getstatus\
    +     hum hum myDev/cmd/getStatus +

    + This example defines 2 get commands (temp and hum), which both publish + the same topic, but wait for different readings to be set.
    + Notes: + +

  • + +
  • readingList <regexp> [readingName|perl-Expression] ...
    @@ -590,33 +635,16 @@ zigbee2mqtt_devStateIcon255($)

  • - -
  • getList cmd [topic|perl-Expression] ...
    - When the FHEM command cmd is issued, publish the topic, wait for the - answer (the specified reading), and show it in the user interface. - Multiple triples can be specified, each of them separated by newline, the - newline does not have to be entered in the FHEMWEB frontend.
    - Example:
    - -   attr dev getList\
    -     temp temperature myDev/cmd/getstatus\
    -     hum hum myDev/cmd/getStatus -

    - This example defines 2 get commands (temp and hum), which both publish - the same topic, but wait for different readings to be set.
    - Notes: - + +
  • setStateList command command ...
    + This attribute is used to get more detailed feedback when switching + devices. I.e. when the command on is contained in the list, state will + be first set to set_on, and after the device reports execution, state + will be set to on (probably with the help of stateFormat). Commands not + in the list will set a reading named after the command, with the word set + and the command parameters as its value.

    + If this attribute is not defined, then a set command will set the state + reading to the name of the command.

  • diff --git a/fhem/fhem.pl b/fhem/fhem.pl index f55b9aa5c..00f130352 100755 --- a/fhem/fhem.pl +++ b/fhem/fhem.pl @@ -4456,8 +4456,13 @@ evalStateFormat($) ########################### # Set STATE - my $sr = AttrVal($name, "stateFormat", undef); my $st = $hash->{READINGS}{state}; + if($hash->{skipStateFormat} && defined($st)) { + $hash->{STATE} = ReplaceEventMap($name, $st->{VAL}, 1); + return; + } + + my $sr = AttrVal($name, "stateFormat", undef); if(!$sr) { $st = $st->{VAL} if(defined($st));