2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

93_DbRep: multicmd: add nextHop Keyword

git-svn-id: https://svn.fhem.de/fhem/trunk@28707 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
nasseeder1 2024-03-25 15:29:42 +00:00
parent 71f88a1e41
commit f0e1ae306f
2 changed files with 89 additions and 46 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.
- feature: 93_DbRep: multicmd: add nextHop Keyword
- bugfix: 73_PRESENCE2: Fehlerbereinigungen - bugfix: 73_PRESENCE2: Fehlerbereinigungen
Hochlaufen bei Neustart von Fhem korrigiert Hochlaufen bei Neustart von Fhem korrigiert
Lokale Bluetooth Erkennung korrigiert Lokale Bluetooth Erkennung korrigiert

View File

@ -59,6 +59,7 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch';
# Version History intern # Version History intern
my %DbRep_vNotesIntern = ( my %DbRep_vNotesIntern = (
"8.53.9" => "18.03.2024 multicmd: add nextHop Keyword ",
"8.53.8" => "17.03.2024 sqlCmdBlocking able to use sql Keywords (§timestamp_end§ etc.) ", "8.53.8" => "17.03.2024 sqlCmdBlocking able to use sql Keywords (§timestamp_end§ etc.) ",
"8.53.7" => "16.03.2024 prevent some attribute evaluation as long as init_done is not set ", "8.53.7" => "16.03.2024 prevent some attribute evaluation as long as init_done is not set ",
"8.53.6" => "15.03.2024 change verbose level of DbRep_beforeproc, DbRep_afterproc to 3 ", "8.53.6" => "15.03.2024 change verbose level of DbRep_beforeproc, DbRep_afterproc to 3 ",
@ -376,6 +377,7 @@ my $dbrep_fName = $attr{global}{modpath}."/FHEM/FhemUtils/cacheDbR
my $dbrep_deftonbl = 86400; # default Timeout non-blocking Operationen my $dbrep_deftonbl = 86400; # default Timeout non-blocking Operationen
my $dbrep_deftobl = 10; # default Timeout blocking Operationen my $dbrep_deftobl = 10; # default Timeout blocking Operationen
# $data{DbRep}{$name}{multicmd} # MultiCommand Hash + Steuerung
################################################################################### ###################################################################################
# DbRep_Initialize # DbRep_Initialize
@ -1169,10 +1171,12 @@ sub DbRep_Set {
my $ok = 0; my $ok = 0;
my $arg = join " ", @cmd; my $arg = join " ", @cmd;
my $err = perlSyntaxCheck ($arg); #my $err = perlSyntaxCheck ($arg);
return $err if($err); #return $err if($err);
(undef, $arg) = _DbRep_replaceStrKeywords ( { hash => $hash, string => $arg } ); # Keywords (nextHop) ersetzen
if ($arg =~ m/^\{.*\}$/xs && $arg =~ m/=>/xs) { # ist als Hash geschrieben if ($arg =~ m/^\{.*\}$/xs && $arg =~ m/=>/xs) { # ist als Hash geschrieben?
my $av = eval $arg; my $av = eval $arg;
if (ref $av eq "HASH") { if (ref $av eq "HASH") {
@ -1183,14 +1187,14 @@ sub DbRep_Set {
return "The syntax of 'multiCmd' is wrong. See command reference." if(!$ok); return "The syntax of 'multiCmd' is wrong. See command reference." if(!$ok);
delete $data{DbRep}{$name}{multicmd}; # evtl. alten multiCmd löschen delete $data{DbRep}{$name}{multicmd}; # evtl. alten multiCmd löschen
$data{DbRep}{$name}{multicmd} = $arg; $data{DbRep}{$name}{multicmd}{cmdhash} = $arg;
DbRep_setLastCmd ($name, $opt); DbRep_setLastCmd ($name, $opt);
DbRep_nextMultiCmd ($name); # Multikommandokette starten DbRep_nextMultiCmd ($name); # Multikommandokette starten
} }
else { else {
return "$setlist"; return $setlist;
} }
return; return;
@ -6909,7 +6913,7 @@ sub DbRep_sqlCmd {
my $bst = [gettimeofday]; # Background-Startzeit my $bst = [gettimeofday]; # Background-Startzeit
my ($err,$dbh,$dbmodel) = DbRep_dbConnect($name); my ($err, $dbh, $dbmodel) = DbRep_dbConnect($name);
return "$name|$err" if ($err); return "$name|$err" if ($err);
no warnings 'uninitialized'; no warnings 'uninitialized';
@ -6934,8 +6938,8 @@ sub DbRep_sqlCmd {
return "$name|$err" if ($err); return "$name|$err" if ($err);
# Ersetzung von Schlüsselwörtern für Timing, Gerät, Lesen (unter Verwendung der Attributsyntax) # Ersetzung von Schlüsselwörtern für Timing, Gerät, Lesen (unter Verwendung der Attributsyntax)
($err, $sql) = _DbRep_sqlReplaceKeywords ( { hash => $hash, ($err, $sql) = _DbRep_replaceStrKeywords ( { hash => $hash,
sql => $sql, string => $sql,
device => $device, device => $device,
reading => $reading, reading => $reading,
dbmodel => $dbmodel, dbmodel => $dbmodel,
@ -7071,8 +7075,8 @@ sub DbRep_sqlCmdBlocking {
} }
# Ersetzung von Schlüsselwörtern für Timing, Gerät, Lesen (unter Verwendung der Attributsyntax) # Ersetzung von Schlüsselwörtern für Timing, Gerät, Lesen (unter Verwendung der Attributsyntax)
($err, $sql) = _DbRep_sqlReplaceKeywords ( { hash => $hash, ($err, $sql) = _DbRep_replaceStrKeywords ( { hash => $hash,
sql => $sql, string => $sql,
device => $device, device => $device,
reading => $reading, reading => $reading,
dbmodel => $dbmodel, dbmodel => $dbmodel,
@ -7318,32 +7322,35 @@ return;
#################################################################################################### ####################################################################################################
# Ersetzung von Schlüsselwörtern für Time*, Devices und Readings # Ersetzung von Schlüsselwörtern für Time*, Devices und Readings
# in SQL-Statements (unter Verwendung der Attributsyntax) # in Strings (SQL-Statements etc) unter Verwendung der Attributsyntax
#################################################################################################### ####################################################################################################
sub _DbRep_sqlReplaceKeywords { sub _DbRep_replaceStrKeywords {
my $paref = shift; my $paref = shift;
my $hash = $paref->{hash}; my $hash = $paref->{hash};
my $sql = $paref->{sql}; my $string = $paref->{string};
my $device = $paref->{device}; my $device = $paref->{device};
my $reading = $paref->{reading}; my $reading = $paref->{reading};
my $dbmodel = $paref->{dbmodel}; my $dbmodel = $paref->{dbmodel};
my $rsf = $paref->{rsf}; my $rsf = $paref->{rsf};
my $rsn = $paref->{rsn}; my $rsn = $paref->{rsn};
my $name = $hash->{NAME};
my $err = q{};
$string =~ s/nextHop\s\((.*)\)/DbRep_nextHop (q|$name|, q|$1|)/g;
return ($err, $string) if(!$dbmodel); # Rückgabe String wenn kein SQL-Statement -> dbmodel fehlt in dem Fall
my $err = q{}; $string =~ s/§timestamp_begin§/'$rsf'/g;
my $name = $hash->{NAME}; $string =~ s/§timestamp_end§/'$rsn'/g;
my $rdspec;
my $sfx = AttrVal("global", "language", "EN"); my $sfx = AttrVal("global", "language", "EN");
$sfx = $sfx eq 'EN' ? '' : "_$sfx"; $sfx = $sfx eq 'EN' ? '' : "_$sfx";
$sql =~ s/§timestamp_begin§/'$rsf'/g;
$sql =~ s/§timestamp_end§/'$rsn'/g;
my $rdspec;
my @keywords = qw(device reading); my @keywords = qw(device reading);
for my $kw (@keywords) { for my $kw (@keywords) {
next if ($sql !~ /§${kw}§/xs); next if ($string !~ /§${kw}§/xs);
my $vna = $kw eq "device" ? $device : my $vna = $kw eq "device" ? $device :
$kw eq "reading" ? $reading : $kw eq "reading" ? $reading :
@ -7356,16 +7363,16 @@ sub _DbRep_sqlReplaceKeywords {
$err = qq{<html> $err </html>}; $err = qq{<html> $err </html>};
$err =~ s/"${kw}"/<a href='https:\/\/fhem.de\/commandref${sfx}.html#${kw}' target='_blank'>${kw}<\/a>/xs; $err =~ s/"${kw}"/<a href='https:\/\/fhem.de\/commandref${sfx}.html#${kw}' target='_blank'>${kw}<\/a>/xs;
$err = encode_base64($err,""); $err = encode_base64 ($err,"");
return $err; return $err;
} }
$rdspec = DbRep_createCommonSql( {hash => $hash, ${kw} => $vna, dbmodel => $dbmodel} ); $rdspec = DbRep_createCommonSql ( {hash => $hash, ${kw} => $vna, dbmodel => $dbmodel} );
$rdspec = (split /AND\s(?:1|true)/xis, $rdspec)[0]; $rdspec = (split /AND\s(?:1|true)/xis, $rdspec)[0];
$sql =~ s/§${kw}§/$rdspec/xg; $string =~ s/§${kw}§/$rdspec/xg;
} }
return ($err, $sql); return ($err, $string);
} }
#################################################################################################### ####################################################################################################
@ -12744,10 +12751,10 @@ sub _DbRep_procCode {
my $err = q{}; my $err = q{};
my $name = $hash->{NAME}; my $name = $hash->{NAME};
$fn =~ s/\s*#.*//g; # Kommentare entfernen $fn =~ s/\s*#.*//g; # Kommentare entfernen
$fn = join ' ', split /\s+/sx, $fn; # Funktion serialisieren $fn = join ' ', split /\s+/sx, $fn; # Funktion serialisieren
if ($fn =~ m/^\s*(\{.*\})\s*$/xs) { # unnamed Funktion direkt mit {...} if ($fn =~ m/^\s*(\{.*\})\s*$/xs) { # unnamed Funktion direkt mit {...}
$fn = $1; $fn = $1;
my $fdv = __DbRep_fhemDefVars (); my $fdv = __DbRep_fhemDefVars ();
@ -13020,7 +13027,7 @@ return ($success);
sub DbRep_nextMultiCmd { sub DbRep_nextMultiCmd {
my $name = shift; my $name = shift;
return if(!defined $data{DbRep}{$name}{multicmd} || !scalar keys %{$data{DbRep}{$name}{multicmd}}); return if(!defined $data{DbRep}{$name}{multicmd}{cmdhash} || !scalar keys %{$data{DbRep}{$name}{multicmd}{cmdhash}});
my @mattr = qw(aggregation my @mattr = qw(aggregation
autoForward autoForward
@ -13035,6 +13042,7 @@ sub DbRep_nextMultiCmd {
device device
reading reading
readingNameMap readingNameMap
userExitFn
optimizeTablesBeforeDump optimizeTablesBeforeDump
); );
@ -13042,15 +13050,29 @@ sub DbRep_nextMultiCmd {
CommandDeleteAttr (undef, "-silent $name $da") if(defined AttrVal($name, $da, undef)); CommandDeleteAttr (undef, "-silent $name $da") if(defined AttrVal($name, $da, undef));
} }
pop (@mattr); # optimizeTablesBeforeDump aus Liste entfernen -> Attr darf nicht gesetzt werden! pop @mattr; # optimizeTablesBeforeDump aus Liste entfernen -> Attr darf nicht gesetzt werden!
my $ok = 0; my $ok = 0;
my $verb = 4; my $verb = 4;
my $cmd = ''; my $cmd = '';
my $la = ''; my $la = '';
my $nexthop;
$nexthop = delete $data{DbRep}{$name}{multicmd}{nexthop} if(defined $data{DbRep}{$name}{multicmd}{nexthop});
for my $k (sort{$a<=>$b} keys %{$data{DbRep}{$name}{multicmd}}) { for my $k (sort{$a<=>$b} keys %{$data{DbRep}{$name}{multicmd}{cmdhash}}) {
my $mcmd = delete $data{DbRep}{$name}{multicmd}{$k}; my $mcmd = delete $data{DbRep}{$name}{multicmd}{cmdhash}{$k};
if ($nexthop && $nexthop ne $k) {
if ($nexthop eq 'quit') {
Log3 ($name, $verb, "DbRep $name - nextHop is set to >$nexthop< -> Exit multiCmd");
delete $data{DbRep}{$name}{multicmd};
return;
}
Log3 ($name, $verb, "DbRep $name - nextHop is set to >$nexthop< -> multiCmd index >$k< skipped");
next;
}
for my $sa (@mattr) { for my $sa (@mattr) {
next if(!defined $mcmd->{$sa}); next if(!defined $mcmd->{$sa});
@ -13070,6 +13092,8 @@ sub DbRep_nextMultiCmd {
$la = "don't contain a valid command -> skip '$cmd'"; $la = "don't contain a valid command -> skip '$cmd'";
} }
delete $data{DbRep}{$name}{multicmd}{nexthop}; # vor MC Ausführung {nexthop} löschen (wurde evtl. durch Attribut setzen definiert!)
Log3 ($name, $verb, "DbRep $name - multiCmd index >$k< $la"); Log3 ($name, $verb, "DbRep $name - multiCmd index >$k< $la");
last; # immer nur den ersten verbliebenen Eintrag abarbeiten last; # immer nur den ersten verbliebenen Eintrag abarbeiten
@ -13085,6 +13109,20 @@ sub DbRep_nextMultiCmd {
return; return;
} }
###################################################################################
# nextHop für multiCmd speichern
###################################################################################
sub DbRep_nextHop {
my $name = shift;
my $hop = shift // return;
$data{DbRep}{$name}{multicmd}{nexthop} = $hop;
Log3 ($name, 4, "DbRep $name - multiCmd nextHop was set by previous function: ".$data{DbRep}{$name}{multicmd}{nexthop});
return;
}
###################################################################################### ######################################################################################
# Username / Paßwort abrufen # Username / Paßwort abrufen
# $cre = "adminCredentials" -> Credentials für Datenbank root-Zugriff # $cre = "adminCredentials" -> Credentials für Datenbank root-Zugriff
@ -15899,7 +15937,7 @@ return;
hash. <br> hash. <br>
The commands to be executed (key <b>cmd</b>) and the attributes to be set for them are defined via keys in the The commands to be executed (key <b>cmd</b>) and the attributes to be set for them are defined via keys in the
transferred hash. The order in which the commands are processed is determined via the command index in the transferred hash. The order in which the commands are processed is determined via the command index in the
hash. hash which must not be '0'.
<br><br> <br><br>
Attribute keys that can be defined in the hash are: <br> Attribute keys that can be defined in the hash are: <br>
@ -15907,14 +15945,17 @@ return;
<ul> <ul>
<a href="#DbRep-attr-autoForward">autoForward</a>, <a href="#DbRep-attr-autoForward">autoForward</a>,
<a href="#DbRep-attr-averageCalcForm">averageCalcForm</a>, <a href="#DbRep-attr-averageCalcForm">averageCalcForm</a>,
<a href="#DbRep-attr-device">device</a>,
<a href="#DbRep-attr-executeBeforeProc">executeBeforeProc</a>,
<a href="#DbRep-attr-executeAfterProc">executeAfterProc</a>,
<a href="#DbRep-attr-reading">reading</a>,
<a href="#DbRep-attr-reading">readingNameMap</a>,
<a href="#DbRep-attr-timestamp_begin">timestamp_begin</a>, <a href="#DbRep-attr-timestamp_begin">timestamp_begin</a>,
<a href="#DbRep-attr-timestamp_end">timestamp_end</a>, <a href="#DbRep-attr-timestamp_end">timestamp_end</a>,
<a href="#DbRep-attr-timeDiffToNow">timeDiffToNow</a>, <a href="#DbRep-attr-timeDiffToNow">timeDiffToNow</a>,
<a href="#DbRep-attr-timeOlderThan">timeOlderThan</a>, <a href="#DbRep-attr-timeOlderThan">timeOlderThan</a>,
<a href="#DbRep-attr-timeYearPeriod">timeYearPeriod</a>, <a href="#DbRep-attr-timeYearPeriod">timeYearPeriod</a>,
<a href="#DbRep-attr-device">device</a>, <a href="#DbRep-attr-userExitFn">userExitFn</a>,
<a href="#DbRep-attr-reading">reading</a>,
<a href="#DbRep-attr-reading">readingNameMap</a>,
</ul> </ul>
<br> <br>
@ -19015,7 +19056,7 @@ return;
Hash enthält. <br> Hash enthält. <br>
Die auszuführenden Befehle (Schlüssel <b>cmd</b>) und die dafür zu setzenden Attribute werden über Schlüssel im Die auszuführenden Befehle (Schlüssel <b>cmd</b>) und die dafür zu setzenden Attribute werden über Schlüssel im
übergebenen Hash definiert. Die Festlegung der Abarbeitungsreihenfolge der Befehle erfolgt über den Befehl-Index im übergebenen Hash definiert. Die Festlegung der Abarbeitungsreihenfolge der Befehle erfolgt über den Befehl-Index im
Hash. Hash der nicht '0' sein darf.
<br><br> <br><br>
Im Hash definierbare Attributschlüssel sind: <br> Im Hash definierbare Attributschlüssel sind: <br>
@ -19023,16 +19064,17 @@ return;
<ul> <ul>
<a href="#DbRep-attr-autoForward">autoForward</a>, <a href="#DbRep-attr-autoForward">autoForward</a>,
<a href="#DbRep-attr-averageCalcForm">averageCalcForm</a>, <a href="#DbRep-attr-averageCalcForm">averageCalcForm</a>,
<a href="#DbRep-attr-device">device</a>,
<a href="#DbRep-attr-executeBeforeProc">executeBeforeProc</a>, <a href="#DbRep-attr-executeBeforeProc">executeBeforeProc</a>,
<a href="#DbRep-attr-executeAfterProc">executeAfterProc</a>, <a href="#DbRep-attr-executeAfterProc">executeAfterProc</a>,
<a href="#DbRep-attr-reading">reading</a>,
<a href="#DbRep-attr-reading">readingNameMap</a>,
<a href="#DbRep-attr-timestamp_begin">timestamp_begin</a>, <a href="#DbRep-attr-timestamp_begin">timestamp_begin</a>,
<a href="#DbRep-attr-timestamp_end">timestamp_end</a>, <a href="#DbRep-attr-timestamp_end">timestamp_end</a>,
<a href="#DbRep-attr-timeDiffToNow">timeDiffToNow</a>, <a href="#DbRep-attr-timeDiffToNow">timeDiffToNow</a>,
<a href="#DbRep-attr-timeOlderThan">timeOlderThan</a>, <a href="#DbRep-attr-timeOlderThan">timeOlderThan</a>,
<a href="#DbRep-attr-timeYearPeriod">timeYearPeriod</a>, <a href="#DbRep-attr-timeYearPeriod">timeYearPeriod</a>,
<a href="#DbRep-attr-device">device</a>, <a href="#DbRep-attr-userExitFn">userExitFn</a>,
<a href="#DbRep-attr-reading">reading</a>,
<a href="#DbRep-attr-reading">readingNameMap</a>,
</ul> </ul>
<br> <br>