2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-22 14:16:42 +00:00

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
This commit is contained in:
rudolfkoenig 2019-04-15 10:50:20 +00:00
parent 1bf7167dd8
commit 64d68e6a2f
5 changed files with 59 additions and 13 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # 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. # 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 - change: 93_DbLog: add support for Meta.pm and delayed shutdown, attribute
shutdownWait removed, direct attribute help in FHEMWEB, shutdownWait removed, direct attribute help in FHEMWEB,
!!! NOTE !!! attr shutdownWait will be deleted it set and !!! NOTE !!! attr shutdownWait will be deleted it set and

View File

@ -37,6 +37,7 @@ MQTT2_DEVICE_Initialize($)
jsonMap:textField-long jsonMap:textField-long
model model
readingList:textField-long readingList:textField-long
setExtensionsEvent:1,0
setList:textField-long setList:textField-long
setStateList setStateList
); );
@ -338,27 +339,33 @@ MQTT2_DEVICE_Set($@)
{ {
my ($hash, @a) = @_; my ($hash, @a) = @_;
return "Not enough arguments for set" if(!defined($a[1])); 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]; my $cmdName = $a[1];
return MQTT2_DEVICE_addPos($hash,@a) if($cmdName eq "addPos"); # hidden cmd return MQTT2_DEVICE_addPos($hash,@a) if($cmdName eq "addPos"); # hidden cmd
my $cmd = $sets->{$cmdName}; my $cmd = $sets->{$cmdName};
return SetExtensions($hash, $cmdList, @a) if(!$cmd); return SetExtensions($hash, $cmdList, @a) if(!$cmd);
return undef if(IsDisabled($hash->{NAME})); return undef if(IsDisabled($name));
my $a1 = (@a > 1 ? $a[1] : ''); my $a1 = (@a > 1 ? $a[1] : '');
$cmd = MQTT2_buildCmd($hash, \@a, $cmd); $cmd = MQTT2_buildCmd($hash, \@a, $cmd);
return if(!$cmd); return if(!$cmd);
SetExtensionsCancel($hash) if($a1 eq "on" || $a1 eq "off"); SetExtensionsCancel($hash) if($a1 eq "on" || $a1 eq "off");
IOWrite($hash, "publish", $cmd); 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) { if(!$ssl) {
readingsSingleUpdate($hash, "state", $cmdName, 1); readingsSingleUpdate($hash, "state", $cmdSE, 1);
} else { } else {
if($ssl =~ m/\b$cmdName\b/) { if($ssl =~ m/\b$cmdName\b/) {
$hash->{skipStateFormat} = 1; $hash->{skipStateFormat} = 1;
readingsSingleUpdate($hash, "state", "set_$cmdName", 1); readingsSingleUpdate($hash, "state", "set_$cmdSE", 1);
delete($hash->{skipStateFormat}); delete($hash->{skipStateFormat});
} else { } else {
shift(@a); shift(@a);
@ -894,6 +901,10 @@ zigbee2mqtt_devStateIcon255($)
</ul> </ul>
</li><br> </li><br>
<li><a name="setExtensionsEvent">setExtensionsEvent</a><br>
If set, the event will contain the command implemented by SetExtensions
(e.g. on-for-timer 10), else the executed command (e.g. on).</li><br>
<a name="setList"></a> <a name="setList"></a>
<li>setList cmd [topic|perl-Expression] ...<br> <li>setList cmd [topic|perl-Expression] ...<br>
When the FHEM command cmd is issued, publish the topic. When the FHEM command cmd is issued, publish the topic.

View File

@ -728,6 +728,7 @@ ZWave_Initialize($)
noExplorerFrames:noArg noExplorerFrames:noArg
noWakeupForApplicationUpdate:noArg noWakeupForApplicationUpdate:noArg
secure_classes secure_classes
setExtensionsEvent:1,0
showtime:noArg showtime:noArg
vclasses vclasses
useMultiCmd:noArg useMultiCmd:noArg
@ -1128,6 +1129,9 @@ ZWave_Cmd($$@)
$cmd .= " ".join(" ", @a) if(@a); $cmd .= " ".join(" ", @a) if(@a);
my $iohash = $hash->{IODev}; my $iohash = $hash->{IODev};
my $withSet = ($iohash->{showSetInState} && !$cmdList{$cmd}{ctrlCmd}); 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); 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 command. It contains a space seperated list of the the command classes
that are supported with SECURITY. that are supported with SECURITY.
</li> </li>
<li><a name="setExtensionsEvent">setExtensionsEvent</a><br>
If set, the event will contain the command implemented by SetExtensions
(e.g. on-for-timer 10), else the executed command (e.g. on).</li><br>
<li><a href="#showtime">showtime</a></li> <li><a href="#showtime">showtime</a></li>
<li><a name="vclasses">vclasses</a><br> <li><a name="vclasses">vclasses</a><br>
This is the result of the "get DEVICE versionClassAll" command, and This is the result of the "get DEVICE versionClassAll" command, and

View File

@ -13,9 +13,18 @@ dummy_Initialize($)
$hash->{SetFn} = "dummy_Set"; $hash->{SetFn} = "dummy_Set";
$hash->{DefFn} = "dummy_Define"; $hash->{DefFn} = "dummy_Define";
$hash->{AttrList} = "readingList setList useSetExtensions " . no warnings 'qw';
"disable disabledForIntervals ". my @attrList = qw(
$readingFnAttributes; 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); my $v = join(" ", @a);
Log3 $name, 4, "dummy set $name $v"; Log3 $name, 4, "dummy set $name $v";
$v = $hash->{SetExtensionsCommand}
if($hash->{SetExtensionsCommand} &&
AttrVal($name, "setExtensionsEvent", undef));
readingsSingleUpdate($hash,"state",$v,1); readingsSingleUpdate($hash,"state",$v,1);
return undef; return undef;
} }
@ -135,6 +147,10 @@ dummy_Define($$)
In this case no arbitrary set commands are accepted, only the setList and In this case no arbitrary set commands are accepted, only the setList and
the set exensions commands.</li> the set exensions commands.</li>
<li><a name="setExtensionsEvent">setExtensionsEvent</a><br>
If set, the event will contain the command implemented by SetExtensions
(e.g. on-for-timer 10), else the executed command (e.g. on).</li>
<li><a href="#readingFnAttributes">readingFnAttributes</a></li> <li><a href="#readingFnAttributes">readingFnAttributes</a></li>
</ul> </ul>
<br> <br>
@ -198,6 +214,11 @@ dummy_Define($$)
diesem Fall werden nur die Befehle aus setList und die set exensions diesem Fall werden nur die Befehle aus setList und die set exensions
akzeptiert.</li> akzeptiert.</li>
<li><a name="setExtensionsEvent">setExtensionsEvent</a><br>
Falls gesetzt, enth&auml;lt das Event den im SetExtensions
implementierten Befehl (z.Bsp. on-for-timer 10), sonst den
Ausgef&uuml;rten (z.Bsp. on).</li>
<li><a href="#readingFnAttributes">readingFnAttributes</a></li> <li><a href="#readingFnAttributes">readingFnAttributes</a></li>
</ul> </ul>
<br> <br>

View File

@ -38,6 +38,7 @@ SE_DoSet(@)
$hash->{InSetExtensions} = 1; $hash->{InSetExtensions} = 1;
AnalyzeCommand($hash->{CL}, "set ".join(" ", @_)); # cmdalias (Forum #63896) AnalyzeCommand($hash->{CL}, "set ".join(" ", @_)); # cmdalias (Forum #63896)
delete $hash->{InSetExtensions}; delete $hash->{InSetExtensions};
delete $hash->{SetExtensionsCommand};
} }
sub sub
@ -114,6 +115,7 @@ SetExtensions($$@)
my $param = $a[0]; my $param = $a[0];
$hash->{SetExtensionsCommand} = $cmd.(@a ? " ".join(" ",@a) : "");
if($cmd eq "on-for-timer" || $cmd eq "off-for-timer") { if($cmd eq "on-for-timer" || $cmd eq "off-for-timer") {
return "$cmd requires a number as argument" if($param !~ m/^\d*\.?\d*$/); return "$cmd requires a number as argument" if($param !~ m/^\d*\.?\d*$/);
@ -123,7 +125,7 @@ SetExtensions($$@)
CMD=>$cmd, NEXTCMD=>$cmd2 CMD=>$cmd, NEXTCMD=>$cmd2
}; };
SE_DoSet($name, $cmd1); SE_DoSet($name, $cmd1);
InternalTimer(gettimeofday()+$param,"SetExtensionsFn","SE $name $cmd",0); InternalTimer(gettimeofday()+$param,"SetExtensionsFn",$hash, 0);
} }
} elsif($cmd =~ m/^(on|off)-till/) { } elsif($cmd =~ m/^(on|off)-till/) {
@ -153,6 +155,7 @@ SetExtensions($$@)
if($param !~ m/^\d+$/ || $p2 !~ m/^\d*\.?\d*$/); if($param !~ m/^\d+$/ || $p2 !~ m/^\d*\.?\d*$/);
if($param) { if($param) {
delete($hash->{SetExtensionsCommand}) if($param == 1 && $a[2]);
SE_DoSet($name, $a[2] ? $offCmd : $onCmd); SE_DoSet($name, $a[2] ? $offCmd : $onCmd);
$param-- if($a[2]); $param-- if($a[2]);
if($param) { if($param) {
@ -160,7 +163,7 @@ SetExtensions($$@)
START=>time(), START_FMT=>TimeNow(), DURATION=>$param, START=>time(), START_FMT=>TimeNow(), DURATION=>$param,
CMD=>$cmd, NEXTCMD=>"$cmd $param $p2 ".($a[2] ? "0" : "1") 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 @lt = localtime;
my $hms_from = sprintf("%02d:%02d:%02d", $hr, $min, $sec); my $hms_from = sprintf("%02d:%02d:%02d", $hr, $min, $sec);
my $hms_now = sprintf("%02d:%02d:%02d", $lt[2], $lt[1], $lt[0]); 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. if($hms_from le $hms_now) { # By slight delays at will schedule tomorrow.
SetExtensions($hash, $list, $name, "on-till", $till); SetExtensions($hash, $list, $name, "on-till", $till);
@ -194,6 +198,7 @@ SetExtensions($$@)
} }
} elsif($cmd eq "toggle") { } elsif($cmd eq "toggle") {
delete($hash->{SetExtensionsCommand}); # Need on/off in STATE
my $value = Value($name); my $value = Value($name);
(undef,$value) = ReplaceEventMap($name, [$name, $value], 0) if($eventMap); (undef,$value) = ReplaceEventMap($name, [$name, $value], 0) if($eventMap);
@ -208,13 +213,12 @@ SetExtensions($$@)
sub sub
SetExtensionsFn($) SetExtensionsFn($)
{ {
my (undef, $name, $cmd) = split(" ", shift, 3); my ($hash) = @_;
my $hash = $defs{$name};
return if(!$hash || !$hash->{TIMED_OnOff}); return if(!$hash || !$hash->{TIMED_OnOff});
my $nextcmd = $hash->{TIMED_OnOff}{NEXTCMD}; my $nextcmd = $hash->{TIMED_OnOff}{NEXTCMD};
delete $hash->{TIMED_OnOff}; delete $hash->{TIMED_OnOff};
SE_DoSet($name, split(" ",$nextcmd)); SE_DoSet($hash->{NAME}, split(" ",$nextcmd));
} }
1; 1;