mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-19 00:26:03 +00:00
93_DbRep: attr executeBeforeProc, executeAfterProc can execute FHEM commands as well as PERL code
git-svn-id: https://svn.fhem.de/fhem/trunk@27577 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
fcc675f40a
commit
d15574e192
@ -1,5 +1,7 @@
|
|||||||
# 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: 93_DbRep: attr executeBeforeProc, executeAfterProc can execute
|
||||||
|
FHEM commands as well as PERL code
|
||||||
- bugfix: 82_LGTV_WebOS: fix little typos and change version
|
- bugfix: 82_LGTV_WebOS: fix little typos and change version
|
||||||
- change: 93_DBLog: changed default splitting, Forum: #133537
|
- change: 93_DBLog: changed default splitting, Forum: #133537
|
||||||
- feature: AutomowerConnectFamily: set cutting height for user defined zones
|
- feature: AutomowerConnectFamily: set cutting height for user defined zones
|
||||||
|
@ -59,6 +59,7 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch';
|
|||||||
|
|
||||||
# Version History intern
|
# Version History intern
|
||||||
my %DbRep_vNotesIntern = (
|
my %DbRep_vNotesIntern = (
|
||||||
|
"8.52.7" => "16.05.2023 DbRep_afterproc, DbRep_beforeproc can execute FHEM commands as well as PERL code ",
|
||||||
"8.52.6" => "11.04.2023 change diffValue for aggr month ",
|
"8.52.6" => "11.04.2023 change diffValue for aggr month ",
|
||||||
"8.52.5" => "10.04.2023 change diffValue, Forum: https://forum.fhem.de/index.php?msg=1271853 ",
|
"8.52.5" => "10.04.2023 change diffValue, Forum: https://forum.fhem.de/index.php?msg=1271853 ",
|
||||||
"8.52.4" => "10.04.2023 fix perl warning ",
|
"8.52.4" => "10.04.2023 fix perl warning ",
|
||||||
@ -465,8 +466,8 @@ sub DbRep_Initialize {
|
|||||||
"dumpMemlimit ".
|
"dumpMemlimit ".
|
||||||
"dumpSpeed ".
|
"dumpSpeed ".
|
||||||
"dumpFilesKeep:0,1,2,3,4,5,6,7,8,9,10 ".
|
"dumpFilesKeep:0,1,2,3,4,5,6,7,8,9,10 ".
|
||||||
"executeBeforeProc ".
|
"executeBeforeProc:textField-long ".
|
||||||
"executeAfterProc ".
|
"executeAfterProc:textField-long ".
|
||||||
"expimpfile ".
|
"expimpfile ".
|
||||||
"fastStart:0,1 ".
|
"fastStart:0,1 ".
|
||||||
"fetchRoute:ascent,descent ".
|
"fetchRoute:ascent,descent ".
|
||||||
@ -1639,6 +1640,16 @@ sub DbRep_Attr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($aName =~ /executeAfterProc|executeBeforeProc/xs) {
|
||||||
|
if($cmd eq "set") {
|
||||||
|
if ($aVal =~ m/^\s*(\{.*\}|{.*|.*})\s*$/xs) {
|
||||||
|
$aVal = $1;
|
||||||
|
eval $aVal;
|
||||||
|
return $@ if ($@);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($aName eq "role") {
|
if ($aName eq "role") {
|
||||||
if($cmd eq "set") {
|
if($cmd eq "set") {
|
||||||
if ($aVal eq "Agent") {
|
if ($aVal eq "Agent") {
|
||||||
@ -4837,11 +4848,6 @@ sub DbRep_diffvalDone {
|
|||||||
|
|
||||||
my %rh = split("§", $rowlist);
|
my %rh = split("§", $rowlist);
|
||||||
|
|
||||||
#Log3 ($name, 4, "DbRep $name - print result of diffValue calculation after decoding ...");
|
|
||||||
#for my $key (sort(keys(%rh))) {
|
|
||||||
# Log3 ($name, 4, "DbRep $name - runtimestring Key: $key, value: ".$rh{$key});
|
|
||||||
#}
|
|
||||||
|
|
||||||
readingsBeginUpdate($hash);
|
readingsBeginUpdate($hash);
|
||||||
|
|
||||||
for my $key (sort(keys(%rh))) {
|
for my $key (sort(keys(%rh))) {
|
||||||
@ -12402,21 +12408,21 @@ return ($txt);
|
|||||||
###################################################################################
|
###################################################################################
|
||||||
sub DbRep_beforeproc {
|
sub DbRep_beforeproc {
|
||||||
my $hash = shift;
|
my $hash = shift;
|
||||||
my $txt = shift // q{process};
|
my $cmd = shift // q{process};
|
||||||
|
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
my $fn = AttrVal($name, 'executeBeforeProc', '');
|
||||||
|
|
||||||
my $ebd = AttrVal($name, 'executeBeforeProc', '');
|
if($fn) {
|
||||||
|
Log3 ($name, 3, "DbRep $name - execute command before $cmd: '$fn' ");
|
||||||
|
|
||||||
if($ebd) {
|
my $err = _DbRep_procCode ($hash, $fn);
|
||||||
Log3 ($name, 3, "DbRep $name - execute command before $txt: '$ebd' ");
|
|
||||||
my $err = AnalyzeCommandChain(undef, $ebd);
|
|
||||||
|
|
||||||
if ($err) {
|
if ($err) {
|
||||||
Log3 ($name, 2, "DbRep $name - command message before $txt: \"$err\" ");
|
Log3 ($name, 2, "DbRep $name - command message before $cmd: \"$err\" ");
|
||||||
my $erread = "Warning - message from command before $txt appeared";
|
my $erread = "Warning - message from command before $cmd appeared";
|
||||||
|
|
||||||
ReadingsSingleUpdateValue ($hash, "before".$txt."_message", $err, 1);
|
ReadingsSingleUpdateValue ($hash, "before_".$cmd."_message", $err, 1);
|
||||||
ReadingsSingleUpdateValue ($hash, "state", $erread, 1);
|
ReadingsSingleUpdateValue ($hash, "state", $erread, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -12432,20 +12438,20 @@ sub DbRep_afterproc {
|
|||||||
my $cmd = shift // q{process};
|
my $cmd = shift // q{process};
|
||||||
my $bfile = shift // q{};
|
my $bfile = shift // q{};
|
||||||
|
|
||||||
my $erread;
|
my ($err,$erread);
|
||||||
|
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
$cmd = (split " ", $cmd)[0];
|
$cmd = (split " ", $cmd)[0];
|
||||||
my $sval = ReadingsVal ($name, 'state', '');
|
my $sval = ReadingsVal ($name, 'state', '');
|
||||||
my $ead = AttrVal ($name, 'executeAfterProc', '');
|
my $fn = AttrVal ($name, 'executeAfterProc', '');
|
||||||
|
|
||||||
if($ead) {
|
if($fn) {
|
||||||
Log3 ($name, 3, "DbRep $name - execute command after $cmd: '$ead' ");
|
Log3 ($name, 3, "DbRep $name - execute command after $cmd: '$fn' ");
|
||||||
|
|
||||||
my $err = AnalyzeCommandChain(undef, $ead);
|
$err = _DbRep_procCode ($hash, $fn);
|
||||||
|
|
||||||
if ($err) {
|
if ($err) {
|
||||||
Log3 ($name, 2, qq{DbRep $name - command message after $cmd: "$err"});
|
Log3 ($name, 2, qq{DbRep $name - command message after $cmd: >$err<});
|
||||||
|
|
||||||
$erread = $sval eq 'error' ? $sval : qq(WARNING - $cmd finished, but message after command appeared);
|
$erread = $sval eq 'error' ? $sval : qq(WARNING - $cmd finished, but message after command appeared);
|
||||||
|
|
||||||
@ -12470,6 +12476,34 @@ sub DbRep_afterproc {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
###################################################################################
|
||||||
|
# Befehl oder Code prozessieren
|
||||||
|
###################################################################################
|
||||||
|
sub _DbRep_procCode {
|
||||||
|
my $hash = shift;
|
||||||
|
my $fn = shift;
|
||||||
|
|
||||||
|
my $err = q{};
|
||||||
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
|
$fn =~ s/\s*#.*//g; # Kommentare entfernen
|
||||||
|
$fn = join ' ', split /\s+/sx, $fn; # Funktion serialisieren
|
||||||
|
|
||||||
|
if ($fn =~ m/^\s*(\{.*\})\s*$/xs) { # unnamed Funktion direkt mit {...}
|
||||||
|
$fn = $1;
|
||||||
|
|
||||||
|
eval $fn;
|
||||||
|
if ($@) {
|
||||||
|
$err = $@;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$err = AnalyzeCommandChain (undef, $fn);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $err;
|
||||||
|
}
|
||||||
|
|
||||||
##############################################################################################
|
##############################################################################################
|
||||||
# timestamp_begin, timestamp_end bei Einsatz datetime-Picker entsprechend
|
# timestamp_begin, timestamp_end bei Einsatz datetime-Picker entsprechend
|
||||||
# den Anforderungen formatieren
|
# den Anforderungen formatieren
|
||||||
@ -16508,54 +16542,59 @@ sub dbval {
|
|||||||
</li>
|
</li>
|
||||||
|
|
||||||
<a id="DbRep-attr-executeAfterProc"></a>
|
<a id="DbRep-attr-executeAfterProc"></a>
|
||||||
<li><b>executeAfterProc </b> - you can specify a FHEM command or perl function which should be executed
|
<li><b>executeAfterProc </b> <br><br>
|
||||||
<b>after command execution</b>. <br>
|
|
||||||
Perl functions have to be enclosed in {} .<br><br>
|
|
||||||
|
|
||||||
<ul>
|
You can specify a FHEM command or Perl code that should be executed <b>after the command is processed</b>. <br>
|
||||||
<b>Example:</b> <br><br>
|
Perl code is to be enclosed in {...}. The variables $hash (hash of the DbRep device) and $name
|
||||||
attr <name> executeAfterProc set og_gz_westfenster off; <br>
|
(name of the DbRep device) are available. <br><br>
|
||||||
attr <name> executeAfterProc {adump ("<name>")} <br><br>
|
|
||||||
|
|
||||||
# "adump" is a function defined in 99_myUtils.pm e.g.: <br>
|
<ul>
|
||||||
|
<b>Example:</b> <br><br>
|
||||||
|
attr <name> executeAfterProc set og_gz_westfenster off; <br>
|
||||||
|
attr <name> executeAfterProc {adump ($name)} <br><br>
|
||||||
|
|
||||||
|
# "adump" is a function defined in 99_myUtils. <br>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
sub adump {
|
sub adump {
|
||||||
my ($name) = @_;
|
my ($name) = @_;
|
||||||
my $hash = $defs{$name};
|
my $hash = $defs{$name};
|
||||||
# own function, e.g.
|
# the own function, e.g.
|
||||||
Log3($name, 3, "DbRep $name -> Dump finished");
|
Log3($name, 3, "DbRep $name -> Dump is finished");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<a id="DbRep-attr-executeBeforeProc"></a>
|
<a id="DbRep-attr-executeBeforeProc"></a>
|
||||||
<li><b>executeBeforeProc </b> - you can specify a FHEM command or perl function which should be executed
|
<li><b>executeBeforeProc </b> <br><br>
|
||||||
<b>before command execution</b>. <br>
|
|
||||||
Perl functions have to be enclosed in {} .<br><br>
|
|
||||||
|
|
||||||
<ul>
|
A FHEM command or Perl code can be specified which is to be executed <b>before the command is processed</b>. <br>
|
||||||
<b>Example:</b> <br><br>
|
Perl code is to be enclosed in {...}. The variables $hash (hash of the DbRep device) and $name
|
||||||
attr <name> executeBeforeProc set og_gz_westfenster on; <br>
|
(name of the DbRep device) are available. <br><br>
|
||||||
attr <name> executeBeforeProc {bdump ("<name>")} <br><br>
|
|
||||||
|
|
||||||
# "bdump" is a function defined in 99_myUtils.pm e.g.: <br>
|
<ul>
|
||||||
|
<b>Example:</b> <br><br>
|
||||||
|
attr <name> executeBeforeProc set og_gz_westfenster on; <br>
|
||||||
|
attr <name> executeBeforeProc {bdump ($name)} <br><br>
|
||||||
|
|
||||||
|
# "bdump" is a function defined in 99_myUtils. <br>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
sub bdump {
|
sub bdump {
|
||||||
my ($name) = @_;
|
my ($name) = @_;
|
||||||
my $hash = $defs{$name};
|
my $hash = $defs{$name};
|
||||||
# own function, e.g.
|
# the own function, e.g.
|
||||||
Log3($name, 3, "DbRep $name -> Dump starts now");
|
Log3($name, 3, "DbRep $name -> Dump starts");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
|
||||||
<a id="DbRep-attr-expimpfile"></a>
|
<a id="DbRep-attr-expimpfile"></a>
|
||||||
<li><b>expimpfile </path/file> [MAXLINES=<lines>] </b>
|
<li><b>expimpfile </path/file> [MAXLINES=<lines>] </b>
|
||||||
@ -19550,54 +19589,60 @@ sub dbval {
|
|||||||
</li>
|
</li>
|
||||||
|
|
||||||
<a id="DbRep-attr-executeAfterProc"></a>
|
<a id="DbRep-attr-executeAfterProc"></a>
|
||||||
<li><b>executeAfterProc </b> - Es kann ein FHEM-Kommando oder eine Perl-Funktion angegeben werden welche <b>nach der
|
<li><b>executeAfterProc </b> <br><br>
|
||||||
Befehlsabarbeitung</b> ausgeführt werden soll. <br>
|
|
||||||
Funktionen sind in {} einzuschließen.<br><br>
|
|
||||||
|
|
||||||
<ul>
|
Es kann ein FHEM-Kommando oder Perl Code angegeben werden der <b>nach der Befehlsabarbeitung</b> ausgeführt
|
||||||
<b>Beispiel:</b> <br><br>
|
werden soll. <br>
|
||||||
attr <name> executeAfterProc set og_gz_westfenster off; <br>
|
Perl Code ist in {...} einzuschließen. Es stehen die Variablen $hash (Hash des DbRep Devices) und $name
|
||||||
attr <name> executeAfterProc {adump ("<name>")} <br><br>
|
(Name des DbRep-Devices) zur Verfügung. <br><br>
|
||||||
|
|
||||||
# "adump" ist eine in 99_myUtils definierte Funktion. <br>
|
<ul>
|
||||||
|
<b>Beispiel:</b> <br><br>
|
||||||
|
attr <name> executeAfterProc set og_gz_westfenster off; <br>
|
||||||
|
attr <name> executeAfterProc {adump ($name)} <br><br>
|
||||||
|
|
||||||
|
# "adump" ist eine in 99_myUtils definierte Funktion. <br>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
sub adump {
|
sub adump {
|
||||||
my ($name) = @_;
|
my ($name) = @_;
|
||||||
my $hash = $defs{$name};
|
my $hash = $defs{$name};
|
||||||
# die eigene Funktion, z.B.
|
# die eigene Funktion, z.B.
|
||||||
Log3($name, 3, "DbRep $name -> Dump ist beendet");
|
Log3($name, 3, "DbRep $name -> Dump ist beendet");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<a id="DbRep-attr-executeBeforeProc"></a>
|
<a id="DbRep-attr-executeBeforeProc"></a>
|
||||||
<li><b>executeBeforeProc </b> - Es kann ein FHEM-Kommando oder eine Perl-Funktion angegeben werden welche <b>vor der
|
<li><b>executeBeforeProc </b> <br><br>
|
||||||
Befehlsabarbeitung</b> ausgeführt werden soll. <br>
|
|
||||||
Funktionen sind in {} einzuschließen.<br><br>
|
|
||||||
|
|
||||||
<ul>
|
Es kann ein FHEM-Kommando oder Perl Code angegeben werden der <b>vor der Befehlsabarbeitung</b> ausgeführt
|
||||||
<b>Beispiel:</b> <br><br>
|
werden soll. <br>
|
||||||
attr <name> executeBeforeProc set og_gz_westfenster on; <br>
|
Perl Code ist in {...} einzuschließen. Es stehen die Variablen $hash (Hash des DbRep Devices) und $name
|
||||||
attr <name> executeBeforeProc {bdump ("<name>")} <br><br>
|
(Name des DbRep-Devices) zur Verfügung. <br><br>
|
||||||
|
|
||||||
# "bdump" ist eine in 99_myUtils definierte Funktion. <br>
|
<ul>
|
||||||
|
<b>Beispiel:</b> <br><br>
|
||||||
|
attr <name> executeBeforeProc set og_gz_westfenster on; <br>
|
||||||
|
attr <name> executeBeforeProc {bdump ($name)} <br><br>
|
||||||
|
|
||||||
|
# "bdump" ist eine in 99_myUtils definierte Funktion. <br>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
sub bdump {
|
sub bdump {
|
||||||
my ($name) = @_;
|
my ($name) = @_;
|
||||||
my $hash = $defs{$name};
|
my $hash = $defs{$name};
|
||||||
# die eigene Funktion, z.B.
|
# die eigene Funktion, z.B.
|
||||||
Log3($name, 3, "DbRep $name -> Dump startet");
|
Log3($name, 3, "DbRep $name -> Dump startet");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<a id="DbRep-attr-expimpfile"></a>
|
<a id="DbRep-attr-expimpfile"></a>
|
||||||
<li><b>expimpfile </Pfad/Filename> [MAXLINES=<lines>]</b>
|
<li><b>expimpfile </Pfad/Filename> [MAXLINES=<lines>]</b>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user