From 64d68e6a2f3258ffdf9deb7ccc35dcb175f84acf Mon Sep 17 00:00:00 2001
From: rudolfkoenig <>
Date: Mon, 15 Apr 2019 10:50:20 +0000
Subject: [PATCH] dummy/ZWave/MQTT2_DEVICE: setExtensionsEvent attr for orig
cmds (Forum #95581)
git-svn-id: https://svn.fhem.de/fhem/trunk@19189 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/CHANGED | 1 +
fhem/FHEM/10_MQTT2_DEVICE.pm | 21 ++++++++++++++++-----
fhem/FHEM/10_ZWave.pm | 9 +++++++++
fhem/FHEM/98_dummy.pm | 27 ++++++++++++++++++++++++---
fhem/FHEM/SetExtensions.pm | 14 +++++++++-----
5 files changed, 59 insertions(+), 13 deletions(-)
diff --git a/fhem/CHANGED b/fhem/CHANGED
index 60f36a641..5c3366f9d 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.
+ - change: dummy/MQTT2_DEVICE/ZWave: setExtensionsEvent attr (Forum #95581)
- change: 93_DbLog: add support for Meta.pm and delayed shutdown, attribute
shutdownWait removed, direct attribute help in FHEMWEB,
!!! NOTE !!! attr shutdownWait will be deleted it set and
diff --git a/fhem/FHEM/10_MQTT2_DEVICE.pm b/fhem/FHEM/10_MQTT2_DEVICE.pm
index f1e4edc65..484d61bc7 100644
--- a/fhem/FHEM/10_MQTT2_DEVICE.pm
+++ b/fhem/FHEM/10_MQTT2_DEVICE.pm
@@ -37,6 +37,7 @@ MQTT2_DEVICE_Initialize($)
jsonMap:textField-long
model
readingList:textField-long
+ setExtensionsEvent:1,0
setList:textField-long
setStateList
);
@@ -338,27 +339,33 @@ MQTT2_DEVICE_Set($@)
{
my ($hash, @a) = @_;
return "Not enough arguments for set" if(!defined($a[1]));
+ my $name = $hash->{NAME};
- my ($sets,$cmdList) = MQTT2_getCmdHash(AttrVal($hash->{NAME}, "setList", ""));
+ my ($sets,$cmdList) = MQTT2_getCmdHash(AttrVal($name, "setList", ""));
my $cmdName = $a[1];
return MQTT2_DEVICE_addPos($hash,@a) if($cmdName eq "addPos"); # hidden cmd
my $cmd = $sets->{$cmdName};
return SetExtensions($hash, $cmdList, @a) if(!$cmd);
- return undef if(IsDisabled($hash->{NAME}));
+ return undef if(IsDisabled($name));
my $a1 = (@a > 1 ? $a[1] : '');
$cmd = MQTT2_buildCmd($hash, \@a, $cmd);
return if(!$cmd);
SetExtensionsCancel($hash) if($a1 eq "on" || $a1 eq "off");
IOWrite($hash, "publish", $cmd);
- my $ssl = AttrVal($hash->{NAME}, "setStateList", "");
+ my $ssl = AttrVal($name, "setStateList", "");
+
+ my $cmdSE = $cmdName;
+ $cmdSE = $hash->{SetExtensionsCommand}
+ if($hash->{SetExtensionsCommand} &&
+ AttrVal($name, "setExtensionsEvent", undef));
if(!$ssl) {
- readingsSingleUpdate($hash, "state", $cmdName, 1);
+ readingsSingleUpdate($hash, "state", $cmdSE, 1);
} else {
if($ssl =~ m/\b$cmdName\b/) {
$hash->{skipStateFormat} = 1;
- readingsSingleUpdate($hash, "state", "set_$cmdName", 1);
+ readingsSingleUpdate($hash, "state", "set_$cmdSE", 1);
delete($hash->{skipStateFormat});
} else {
shift(@a);
@@ -894,6 +901,10 @@ zigbee2mqtt_devStateIcon255($)
+
setExtensionsEvent
+ If set, the event will contain the command implemented by SetExtensions
+ (e.g. on-for-timer 10), else the executed command (e.g. on).
+
setList cmd [topic|perl-Expression] ...
When the FHEM command cmd is issued, publish the topic.
diff --git a/fhem/FHEM/10_ZWave.pm b/fhem/FHEM/10_ZWave.pm
index 226b2d7ff..ddf0644af 100644
--- a/fhem/FHEM/10_ZWave.pm
+++ b/fhem/FHEM/10_ZWave.pm
@@ -728,6 +728,7 @@ ZWave_Initialize($)
noExplorerFrames:noArg
noWakeupForApplicationUpdate:noArg
secure_classes
+ setExtensionsEvent:1,0
showtime:noArg
vclasses
useMultiCmd:noArg
@@ -1128,6 +1129,9 @@ ZWave_Cmd($$@)
$cmd .= " ".join(" ", @a) if(@a);
my $iohash = $hash->{IODev};
my $withSet = ($iohash->{showSetInState} && !$cmdList{$cmd}{ctrlCmd});
+ $cmd = $hash->{SetExtensionsCommand}
+ if($hash->{SetExtensionsCommand} &&
+ AttrVal($name, "setExtensionsEvent", undef));
readingsSingleUpdate($hash, "state", $withSet ? "set_$cmd" : $cmd, 1);
}
@@ -6456,6 +6460,11 @@ s2Hex($)
command. It contains a space seperated list of the the command classes
that are supported with SECURITY.
+
+ setExtensionsEvent
+ If set, the event will contain the command implemented by SetExtensions
+ (e.g. on-for-timer 10), else the executed command (e.g. on).
+
showtime
vclasses
This is the result of the "get DEVICE versionClassAll" command, and
diff --git a/fhem/FHEM/98_dummy.pm b/fhem/FHEM/98_dummy.pm
index 95f64b82d..41fe487c6 100644
--- a/fhem/FHEM/98_dummy.pm
+++ b/fhem/FHEM/98_dummy.pm
@@ -13,9 +13,18 @@ dummy_Initialize($)
$hash->{SetFn} = "dummy_Set";
$hash->{DefFn} = "dummy_Define";
- $hash->{AttrList} = "readingList setList useSetExtensions " .
- "disable disabledForIntervals ".
- $readingFnAttributes;
+ no warnings 'qw';
+ my @attrList = qw(
+ disable
+ disabledForIntervals
+ readingList
+ setExtensionsEvent:1,0
+ setList
+ useSetExtensions
+ $readingFnAttributes;
+ );
+ use warnings 'qw';
+ $hash->{AttrList} = join(" ", @attrList);
}
###################################
@@ -60,6 +69,9 @@ dummy_Set($@)
my $v = join(" ", @a);
Log3 $name, 4, "dummy set $name $v";
+ $v = $hash->{SetExtensionsCommand}
+ if($hash->{SetExtensionsCommand} &&
+ AttrVal($name, "setExtensionsEvent", undef));
readingsSingleUpdate($hash,"state",$v,1);
return undef;
}
@@ -135,6 +147,10 @@ dummy_Define($$)
In this case no arbitrary set commands are accepted, only the setList and
the set exensions commands.
+ setExtensionsEvent
+ If set, the event will contain the command implemented by SetExtensions
+ (e.g. on-for-timer 10), else the executed command (e.g. on).
+
readingFnAttributes
@@ -198,6 +214,11 @@ dummy_Define($$)
diesem Fall werden nur die Befehle aus setList und die set exensions
akzeptiert.
+ setExtensionsEvent
+ Falls gesetzt, enthält das Event den im SetExtensions
+ implementierten Befehl (z.Bsp. on-for-timer 10), sonst den
+ Ausgefürten (z.Bsp. on).
+
readingFnAttributes
diff --git a/fhem/FHEM/SetExtensions.pm b/fhem/FHEM/SetExtensions.pm
index 124c03570..78c4f3ff1 100644
--- a/fhem/FHEM/SetExtensions.pm
+++ b/fhem/FHEM/SetExtensions.pm
@@ -38,6 +38,7 @@ SE_DoSet(@)
$hash->{InSetExtensions} = 1;
AnalyzeCommand($hash->{CL}, "set ".join(" ", @_)); # cmdalias (Forum #63896)
delete $hash->{InSetExtensions};
+ delete $hash->{SetExtensionsCommand};
}
sub
@@ -114,6 +115,7 @@ SetExtensions($$@)
my $param = $a[0];
+ $hash->{SetExtensionsCommand} = $cmd.(@a ? " ".join(" ",@a) : "");
if($cmd eq "on-for-timer" || $cmd eq "off-for-timer") {
return "$cmd requires a number as argument" if($param !~ m/^\d*\.?\d*$/);
@@ -123,7 +125,7 @@ SetExtensions($$@)
CMD=>$cmd, NEXTCMD=>$cmd2
};
SE_DoSet($name, $cmd1);
- InternalTimer(gettimeofday()+$param,"SetExtensionsFn","SE $name $cmd",0);
+ InternalTimer(gettimeofday()+$param,"SetExtensionsFn",$hash, 0);
}
} elsif($cmd =~ m/^(on|off)-till/) {
@@ -153,6 +155,7 @@ SetExtensions($$@)
if($param !~ m/^\d+$/ || $p2 !~ m/^\d*\.?\d*$/);
if($param) {
+ delete($hash->{SetExtensionsCommand}) if($param == 1 && $a[2]);
SE_DoSet($name, $a[2] ? $offCmd : $onCmd);
$param-- if($a[2]);
if($param) {
@@ -160,7 +163,7 @@ SetExtensions($$@)
START=>time(), START_FMT=>TimeNow(), DURATION=>$param,
CMD=>$cmd, NEXTCMD=>"$cmd $param $p2 ".($a[2] ? "0" : "1")
};
- InternalTimer(gettimeofday()+$p2, "SetExtensionsFn","SE $name $cmd",0);
+ InternalTimer(gettimeofday()+$p2, "SetExtensionsFn",$hash,0);
}
}
@@ -175,6 +178,7 @@ SetExtensions($$@)
my @lt = localtime;
my $hms_from = sprintf("%02d:%02d:%02d", $hr, $min, $sec);
my $hms_now = sprintf("%02d:%02d:%02d", $lt[2], $lt[1], $lt[0]);
+ delete($hash->{SetExtensionsCommand}); # Will be set by on-till
if($hms_from le $hms_now) { # By slight delays at will schedule tomorrow.
SetExtensions($hash, $list, $name, "on-till", $till);
@@ -194,6 +198,7 @@ SetExtensions($$@)
}
} elsif($cmd eq "toggle") {
+ delete($hash->{SetExtensionsCommand}); # Need on/off in STATE
my $value = Value($name);
(undef,$value) = ReplaceEventMap($name, [$name, $value], 0) if($eventMap);
@@ -208,13 +213,12 @@ SetExtensions($$@)
sub
SetExtensionsFn($)
{
- my (undef, $name, $cmd) = split(" ", shift, 3);
- my $hash = $defs{$name};
+ my ($hash) = @_;
return if(!$hash || !$hash->{TIMED_OnOff});
my $nextcmd = $hash->{TIMED_OnOff}{NEXTCMD};
delete $hash->{TIMED_OnOff};
- SE_DoSet($name, split(" ",$nextcmd));
+ SE_DoSet($hash->{NAME}, split(" ",$nextcmd));
}
1;