From 521ad6b21319febc48d6604c7ba673538ac04278 Mon Sep 17 00:00:00 2001 From: nasseeder1 Date: Mon, 23 Nov 2020 18:07:13 +0000 Subject: [PATCH] 50_SSChatBot: do once event CHAT_INITIALIZED when users are loaded git-svn-id: https://svn.fhem.de/fhem/trunk@23220 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 2 ++ fhem/FHEM/50_SSChatBot.pm | 29 +++++++++++++++++++++++----- fhem/lib/FHEM/SynoModules/SMUtils.pm | 15 +++++++++----- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 40d77777c..f0602af9d 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,7 @@ # 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: 50_SSChatBot: do once event CHAT_INITIALIZED when users are loaded, + (also update SMUtils.pm) - bugfix: 93_DbRep: fix undefined ARRAY reference in reduceLog, Forum:#116057 - feature: 93_DbRep: values next_day_begin, next_day_end for time attributes - feature: 23_LUXTRONIK2: new set parameter opModeVentilation diff --git a/fhem/FHEM/50_SSChatBot.pm b/fhem/FHEM/50_SSChatBot.pm index 429e0cb2c..8a8bcc622 100644 --- a/fhem/FHEM/50_SSChatBot.pm +++ b/fhem/FHEM/50_SSChatBot.pm @@ -91,6 +91,7 @@ BEGIN { CommandAttr CommandDefine CommandGet + CommandTrigger data defs devspec2array @@ -134,6 +135,8 @@ BEGIN { # Versions History intern my %vNotesIntern = ( + "1.12.0" => "23.11.2020 generate event CHAT_INITIALIZED when users are once loaded, Forum: https://forum.fhem.de/index.php/topic,105714.msg1103700.html#msg1103700 ". + "postpone new operation is one ist still running ", "1.11.7" => "01.11.2020 quotation marks can be used in text tag of received messages (__botCGIcheckData) ", "1.11.6" => "08.10.2020 add urlEncode of character codes like \x{c3}\x{85} to formString ", "1.11.5" => "06.10.2020 use addSendqueue from SMUtils, delete local addSendqueue ", @@ -859,6 +862,11 @@ sub getApiSites { return $ret; } + if($hash->{OPMODE}) { # Überholer vermeiden wenn eine Operation läuft (V. 1.12.0" => "23.11.2020) + Log3($name, 4, qq{$name - Operation "$hash->{OPMODE} (idx: $hash->{OPIDX})" is still running. Next operation start postponed}); + return; + } + # den nächsten Eintrag aus "SendQueue" selektieren und ausführen wenn nicht forbidSend gesetzt ist for my $idx (sort{$a<=>$b} keys %{$data{SSChatBot}{$name}{sendqueue}{entries}}) { if (!$data{SSChatBot}{$name}{sendqueue}{entries}{$idx}{forbidSend} || $hash->{HELPER}{RESENDFORCE}) { @@ -983,7 +991,7 @@ sub getApiSites_parse { Log3 ($name, 4, "$name - API completed:\n".Dumper $hash->{HELPER}{API}); if ($opmode eq "apiInfo") { # API Infos in Popup anzeigen - showAPIinfo ($hash, $hash->{HELPER}{API}); # übergibt Referenz zum instanziierten API-Hash) + showAPIinfo ($hash, $hash->{HELPER}{API}); # übergibt Referenz zum instanziierten API-Hash) checkSendRetry ($name, 0, $queueStartFn); return; } @@ -1178,7 +1186,7 @@ sub _parseUsers { my $name = $hash->{NAME}; my ($un,$ui,$st,$nn,$em,$uids); - my %users = (); + my %users; my $i = 0; my $out = ""; @@ -1207,8 +1215,16 @@ sub _parseUsers { $i++; } - $hash->{HELPER}{USERS} = \%users if(%users); - $hash->{HELPER}{USERFETCHED} = 1; + if(%users) { + $hash->{HELPER}{USERS} = \%users; + my $olduf = $hash->{HELPER}{USERFETCHED}; + $hash->{HELPER}{USERFETCHED} = 1; + + if(!$olduf) { + my $event = "CHAT_INITIALIZED"; + CommandTrigger(undef, "$name $event"); + } + } my @newa; my $list = $modules{$hash->{TYPE}}{AttrList}; @@ -1295,6 +1311,9 @@ sub _parseSendItem { my $postid = ""; my $idx = $hash->{OPIDX}; + + return if(!$idx); + my $uid = $data{SSChatBot}{$name}{sendqueue}{entries}{$idx}{userid}; if($data->{data}{succ}{user_id_post_map}{$uid}) { @@ -1370,7 +1389,7 @@ sub formString { "+" => "%2B", }; - %$replacements = (%$replacements, %$enctourl); + %$replacements = (%$replacements, %$enctourl); } else { $replacements = { diff --git a/fhem/lib/FHEM/SynoModules/SMUtils.pm b/fhem/lib/FHEM/SynoModules/SMUtils.pm index 2f23e7f92..ae4501e43 100644 --- a/fhem/lib/FHEM/SynoModules/SMUtils.pm +++ b/fhem/lib/FHEM/SynoModules/SMUtils.pm @@ -25,6 +25,9 @@ # ######################################################################################################################### +# Version History +# 1.20.6 delete $hash->{OPMODE} in checkSendRetry + package FHEM::SynoModules::SMUtils; use strict; @@ -42,7 +45,7 @@ use FHEM::SynoModules::ErrCodes qw(:all); # Erro use GPUtils qw( GP_Import GP_Export ); use Carp qw(croak carp); -use version; our $VERSION = version->declare('1.20.5'); +use version; our $VERSION = version->declare('1.20.6'); use Exporter ('import'); our @EXPORT_OK = qw( @@ -1601,8 +1604,11 @@ sub checkSendRetry { my $startfn = shift // carp $carpnotfn && return; my $hash = $defs{$name}; my $idx = $hash->{OPIDX}; + my $opmode = $hash->{OPMODE}; my $type = $hash->{TYPE}; + $hash->{OPMODE} = q{}; + my $forbidSend = q{}; my $startfnref = \&{$startfn}; @@ -1620,7 +1626,7 @@ sub checkSendRetry { if(!$retry) { # Befehl erfolgreich, Senden nur neu starten wenn weitere Einträge in SendQueue delete $hash->{OPIDX}; delete $data{$type}{$name}{sendqueue}{entries}{$idx}; - Log3($name, 4, qq{$name - Opmode "$hash->{OPMODE}" finished successfully, Sendqueue index "$idx" deleted.}); + Log3($name, 4, qq{$name - Opmode "$opmode" finished successfully, Sendqueue index "$idx" deleted.}); updQueueLength ($hash); if(keys %{$data{$type}{$name}{sendqueue}{entries}}) { @@ -1642,10 +1648,9 @@ sub checkSendRetry { $forbidSend = expErrors($hash,$errorcode); # Fehlertext zum Errorcode ermitteln $data{$type}{$name}{sendqueue}{entries}{$idx}{forbidSend} = $forbidSend; - Log3($name, 2, qq{$name - ERROR - "$hash->{OPMODE}" SendQueue index "$idx" not executed. It seems to be a permanent error. Exclude it from new send attempt !}); + Log3($name, 2, qq{$name - ERROR - "$opmode" SendQueue index "$idx" not executed. It seems to be a permanent error. Exclude it from new send attempt !}); delete $hash->{OPIDX}; - delete $hash->{OPMODE}; updQueueLength ($hash); # updaten Länge der Sendequeue @@ -1662,7 +1667,7 @@ sub checkSendRetry { : 86400 ; - Log3($name, 2, qq{$name - ERROR - "$hash->{OPMODE}" SendQueue index "$idx" not executed. Restart SendQueue in $rs s (retryCount $rc).}); + Log3($name, 2, qq{$name - ERROR - "$opmode" SendQueue index "$idx" not executed. Restart SendQueue in $rs s (retryCount $rc).}); my $rst = gettimeofday()+$rs; # resend Timer updQueueLength ($hash, $rst); # updaten Länge der Sendequeue mit resend Timer