2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 03:06:37 +00:00

93_DbLog: V2.22.14, create state-events if state has been changed (Forum:#78867)

git-svn-id: https://svn.fhem.de/fhem/trunk@15448 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
nasseeder1 2017-11-18 19:56:40 +00:00
parent 5ef38a204d
commit 667550ecba
2 changed files with 46 additions and 46 deletions

View File

@ -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_DbLog: V2.22.14, create state-events if state has been changed
(Forum:#78867)
- feature: 10_EQ3BT: support remote Bluetooth interface via SSH (thx@Cooltux!) - feature: 10_EQ3BT: support remote Bluetooth interface via SSH (thx@Cooltux!)
- feature: 93_DbRep: V6.0.0, FTP transfer dumpfile after dump (MySQL), delete - feature: 93_DbRep: V6.0.0, FTP transfer dumpfile after dump (MySQL), delete
old dumpfiles within Blockingcall, minor fixes old dumpfiles within Blockingcall, minor fixes

View File

@ -16,6 +16,7 @@
############################################################################################################################################ ############################################################################################################################################
# Versions History done by DS_Starter & DeeSPe: # Versions History done by DS_Starter & DeeSPe:
# #
# 2.22.14 18.11.2017 create state-events if state has been changed (Forum:#78867)
# 2.22.13 20.10.2017 output of reopen command improved # 2.22.13 20.10.2017 output of reopen command improved
# 2.22.12 19.10.2017 avoid illegible messages in "state" # 2.22.12 19.10.2017 avoid illegible messages in "state"
# 2.22.11 13.10.2017 DbLogType expanded by SampleFill, DbLog_sampleDataFn adapted to sort case insensitive, commandref revised # 2.22.11 13.10.2017 DbLogType expanded by SampleFill, DbLog_sampleDataFn adapted to sort case insensitive, commandref revised
@ -157,7 +158,7 @@ use Blocking;
use Time::HiRes qw(gettimeofday tv_interval); use Time::HiRes qw(gettimeofday tv_interval);
use Encode qw(encode_utf8); use Encode qw(encode_utf8);
my $DbLogVersion = "2.22.13"; my $DbLogVersion = "2.22.14";
my %columns = ("DEVICE" => 64, my %columns = ("DEVICE" => 64,
"TYPE" => 64, "TYPE" => 64,
@ -392,6 +393,7 @@ sub DbLog_Attr(@) {
DbLog_execmemcache($hash) if($do == 1); DbLog_execmemcache($hash) if($do == 1);
readingsSingleUpdate($hash, "state", $val, 1); readingsSingleUpdate($hash, "state", $val, 1);
$hash->{HELPER}{OLDSTATE} = $val;
if ($do == 0) { if ($do == 0) {
InternalTimer(gettimeofday()+2, "DbLog_execmemcache", $hash, 0); InternalTimer(gettimeofday()+2, "DbLog_execmemcache", $hash, 0);
@ -1269,11 +1271,12 @@ sub DbLog_Log($$) {
return if($hash->{HELPER}{REOPEN_RUNS}); return if($hash->{HELPER}{REOPEN_RUNS});
my $error = DbLog_Push($hash, $vb4show, @row_array); my $error = DbLog_Push($hash, $vb4show, @row_array);
Log3 $name, 5, "DbLog $name -> DbLog_Push Returncode: $error" if($vb4show); Log3 $name, 5, "DbLog $name -> DbLog_Push Returncode: $error" if($vb4show);
if($error) {
readingsSingleUpdate($hash, "state", $error, 1); my $state = $error?$error:(IsDisabled($name))?"disabled":"connected";
} else { my $evt = ($state && $state eq $hash->{HELPER}{OLDSTATE})?0:1;
readingsSingleUpdate($hash, "state", "connected", 0); readingsSingleUpdate($hash, "state", $state, $evt);
} $hash->{HELPER}{OLDSTATE} = $state;
# Notify-Routine Laufzeit ermitteln # Notify-Routine Laufzeit ermitteln
$net = tv_interval($nst); $net = tv_interval($nst);
} }
@ -1666,16 +1669,10 @@ sub DbLog_execmemcache ($) {
readingsSingleUpdate($hash, "NextSync", $nsdt. " or if CacheUsage ".$clim." reached", 0); readingsSingleUpdate($hash, "NextSync", $nsdt. " or if CacheUsage ".$clim." reached", 0);
} }
if($error) { my $state = $error?$error:$hash->{HELPER}{OLDSTATE};
readingsSingleUpdate($hash, "state", $error, 1); my $evt = ($state && $state eq $hash->{HELPER}{OLDSTATE})?0:1;
$hash->{HELPER}{OLDSTATE} = $error; readingsSingleUpdate($hash, "state", $state, $evt);
} else { $hash->{HELPER}{OLDSTATE} = $state;
if($hash->{HELPER}{OLDSTATE} && $hash->{HELPER}{OLDSTATE} ne "connected") {
readingsSingleUpdate($hash, "state", "connected", 1);
$hash->{HELPER}{OLDSTATE} = "connected";
}
readingsSingleUpdate($hash, "state", "connected", 0);
}
InternalTimer($nextsync, "DbLog_execmemcache", $hash, 0); InternalTimer($nextsync, "DbLog_execmemcache", $hash, 0);
@ -1987,9 +1984,10 @@ sub DbLog_PushAsyncDone ($) {
my $bt = $a[2]; my $bt = $a[2];
my $rowlist = $a[3]; my $rowlist = $a[3];
my $asyncmode = AttrVal($name, "asyncMode", undef); my $asyncmode = AttrVal($name, "asyncMode", undef);
my $state = "connected";
my $memcount; my $memcount;
Log3 ($name, 5, "DbLog $name -> Start DbLog_PushAsyncDone");
if($rowlist) { if($rowlist) {
$rowlist = decode_base64($rowlist); $rowlist = decode_base64($rowlist);
my @row_array = split('§', $rowlist); my @row_array = split('§', $rowlist);
@ -2006,35 +2004,33 @@ sub DbLog_PushAsyncDone ($) {
}; };
} }
Log3 ($name, 5, "DbLog $name -> Start DbLog_PushAsyncDone"); # $state = "disabled" if(IsDisabled($name));
$state = "disabled" if(IsDisabled($name));
$memcount = $hash->{cache}{memcache}?scalar(keys%{$hash->{cache}{memcache}}):0; $memcount = $hash->{cache}{memcache}?scalar(keys%{$hash->{cache}{memcache}}):0;
readingsSingleUpdate($hash, 'CacheUsage', $memcount, 0); readingsSingleUpdate($hash, 'CacheUsage', $memcount, 0);
if(AttrVal($name, "showproctime", undef) && $bt) { if(AttrVal($name, "showproctime", undef) && $bt) {
my ($rt,$brt) = split(",", $bt); my ($rt,$brt) = split(",", $bt);
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "background_processing_time", sprintf("%.4f",$brt)); readingsBulkUpdate($hash, "background_processing_time", sprintf("%.4f",$brt));
readingsBulkUpdate($hash, "sql_processing_time", sprintf("%.4f",$rt)); readingsBulkUpdate($hash, "sql_processing_time", sprintf("%.4f",$rt));
readingsEndUpdate($hash, 1); readingsEndUpdate($hash, 1);
} }
if($error) { my $state = $error?$error:(IsDisabled($name))?"disabled":"connected";
readingsSingleUpdate($hash, "state", $error, 1); my $evt = ($state && $state eq $hash->{HELPER}{OLDSTATE})?0:1;
} else { readingsSingleUpdate($hash, "state", $state, $evt);
readingsSingleUpdate($hash, "state", $state, 0); $hash->{HELPER}{OLDSTATE} = $state;
}
if(!$asyncmode) { if(!$asyncmode) {
delete($defs{$name}{READINGS}{NextSync}); delete($defs{$name}{READINGS}{NextSync});
delete($defs{$name}{READINGS}{background_processing_time}); delete($defs{$name}{READINGS}{background_processing_time});
delete($defs{$name}{READINGS}{sql_processing_time}); delete($defs{$name}{READINGS}{sql_processing_time});
delete($defs{$name}{READINGS}{CacheUsage}); delete($defs{$name}{READINGS}{CacheUsage});
} }
delete $hash->{HELPER}{RUNNING_PID}; delete $hash->{HELPER}{RUNNING_PID};
Log3 ($name, 5, "DbLog $name -> DbLog_PushAsyncDone finished"); Log3 ($name, 5, "DbLog $name -> DbLog_PushAsyncDone finished");
return; return;
@ -3263,12 +3259,13 @@ sub DbLog_AddLog($$$) {
# return wenn "reopen" mit Ablaufzeit gestartet ist # return wenn "reopen" mit Ablaufzeit gestartet ist
return if($hash->{HELPER}{REOPEN_RUNS}); return if($hash->{HELPER}{REOPEN_RUNS});
my $error = DbLog_Push($hash, 1, @row_array); my $error = DbLog_Push($hash, 1, @row_array);
my $state = $error?$error:(IsDisabled($name))?"disabled":"connected";
my $evt = ($state && $state eq $hash->{HELPER}{OLDSTATE})?0:1;
readingsSingleUpdate($hash, "state", $state, $evt);
$hash->{HELPER}{OLDSTATE} = $state;
Log3 $name, 5, "DbLog $name -> DbLog_Push Returncode: $error"; Log3 $name, 5, "DbLog $name -> DbLog_Push Returncode: $error";
if($error) {
readingsSingleUpdate($hash, "state", $error, 1);
} else {
readingsSingleUpdate($hash, "state", "connected", 0);
}
} }
} }
return; return;
@ -4411,6 +4408,7 @@ sub reopen ($){
my $delay = delete $hash->{HELPER}{REOPEN_RUNS}; my $delay = delete $hash->{HELPER}{REOPEN_RUNS};
Log3($name, 2, "DbLog $name: Database connection reopened (it was $delay seconds closed)."); Log3($name, 2, "DbLog $name: Database connection reopened (it was $delay seconds closed).");
readingsSingleUpdate($hash, "state", "reopened", 1); readingsSingleUpdate($hash, "state", "reopened", 1);
$hash->{HELPER}{OLDSTATE} = "reopened";
DbLog_execmemcache($hash) if($async); DbLog_execmemcache($hash) if($async);
} else { } else {
InternalTimer(gettimeofday()+30, "reopen", $hash, 0); InternalTimer(gettimeofday()+30, "reopen", $hash, 0);