From bd8257371d440c701ad7e44edec6009787fb765e Mon Sep 17 00:00:00 2001
From: eisler
Date: Fri, 23 Feb 2018 20:12:16 +0000
Subject: [PATCH] 10_MQTT_DEVICE: add SetExtensions
git-svn-id: https://svn.fhem.de/fhem/trunk@16249 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/CHANGED | 1 +
fhem/FHEM/10_MQTT_DEVICE.pm | 29 ++++++++++++++++++++++++++++-
2 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/fhem/CHANGED b/fhem/CHANGED
index 53fad4efa..2d2cc7282 100644
--- a/fhem/CHANGED
+++ b/fhem/CHANGED
@@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it.
+ - feature: 10_MQTT_DEVICE: add SetExtensions
- bugfix: 00_MQTT: small bugfix
- feature: 98_DOIFtools: support for multiple holiday files in holiday2we for
next timer calculation
diff --git a/fhem/FHEM/10_MQTT_DEVICE.pm b/fhem/FHEM/10_MQTT_DEVICE.pm
index d9c738a72..17ec9c4f6 100644
--- a/fhem/FHEM/10_MQTT_DEVICE.pm
+++ b/fhem/FHEM/10_MQTT_DEVICE.pm
@@ -52,6 +52,7 @@ sub MQTT_DEVICE_Initialize($) {
"publishSet_.* ".
"subscribeReading_.* ".
"autoSubscribeReadings ".
+ "useSetExtensions:1,0 ".
$main::readingFnAttributes;
main::LoadModule("MQTT");
@@ -64,6 +65,7 @@ use warnings;
use GPUtils qw(:all);
use Net::MQTT::Constants;
+use SetExtensions qw/ :all /;
BEGIN {
MQTT->import(qw(:all));
@@ -73,6 +75,8 @@ BEGIN {
CommandAttr
readingsSingleUpdate
Log3
+ SetExtensions
+ SetExtensionsCancel
fhem
defs
AttrVal
@@ -91,6 +95,14 @@ sub Set($$$@) {
return "Need at least one parameters" unless defined $command;
my $msgid;
my $mark=0;
+
+ if (AttrVal($name,"useSetExtensions",undef)) {
+ if ($command =~ m/^(blink|intervals|(off-|on-)(for-timer|till(-overnight)?))(.+)?|toggle$/) {
+ Log3($hash->{NAME},5,"calling SetExtensions(...) for $command");
+ return SetExtensions($hash, join(" ", map {$hash->{sets}->{$_} eq "" ? $_ : "$_:".$hash->{sets}->{$_}} sort keys %{$hash->{sets}}), $name, $command, @values);
+ }
+ }
+
if($command ne '?') {
if(defined($hash->{publishSets}->{$command})) {
my $value = join " ",@values;
@@ -115,8 +127,13 @@ sub Set($$$@) {
}
}
if(!$mark) {
- return "Unknown argument $command, choose one of " . join(" ", map {$hash->{sets}->{$_} eq "" ? $_ : "$_:".$hash->{sets}->{$_}} sort keys %{$hash->{sets}})
+ if(AttrVal($name,"useSetExtensions",undef)) {
+ return SetExtensions($hash, join(" ", map {$hash->{sets}->{$_} eq "" ? $_ : "$_:".$hash->{sets}->{$_}} sort keys %{$hash->{sets}}), $name, $command, @values);
+ } else {
+ return "Unknown argument $command, choose one of " . join(" ", map {$hash->{sets}->{$_} eq "" ? $_ : "$_:".$hash->{sets}->{$_}} sort keys %{$hash->{sets}})
+ }
}
+ SetExtensionsCancel($hash);
$hash->{message_ids}->{$msgid}++ if defined $msgid;
readingsSingleUpdate($hash,"transmission-state","outgoing publish sent",1);
return undef;
@@ -264,6 +281,12 @@ sub onmessage($$$) {
set <name> <reading> <value>
sets reading <reading> and publishes the command to topic configured via attr publishSet_<reading>
+
+ The set extensions are supported with useSetExtensions attribute.
+ Set eventMap if your publishSet commands are not on/off.
+ example for true/false:
+ attr mqttest eventMap { dev=>{ 'true'=>'on', 'false'=>'off' }, usr=>{ '^on$'=>'true', '^off$'=>'false' }, fw=>{ '^on$'=>'on', '^off$'=>'off' } }
+
Attributes
@@ -314,6 +337,10 @@ sub onmessage($$$) {
defines QOS 0 for all readings/topics except the reading 'test'. Retain for 'test' is 1
+
+ attr <name> useSetExtensions <flags>
+ If set to 1, then the set extensions are supported.
+