From 67255c91703eeef5fb5d329c9d65323ddabcfa32 Mon Sep 17 00:00:00 2001 From: nasseeder1 Date: Fri, 13 Dec 2024 22:10:26 +0000 Subject: [PATCH] 49_SSCam: internal code changed git-svn-id: https://svn.fhem.de/fhem/trunk@29426 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/49_SSCam.pm | 1227 ++++++++++++++++++++++------------------- 2 files changed, 657 insertions(+), 571 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 786188474..a464efc52 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # 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: 49_SSCam: internal code changed - change: 76_SolarForecast: Warning if no create AllPVforecastsToEvent events - change: 76_SolarForecast: consumerXX if mode is device/reading combination - feature: 76_SolarForecast: consumerkey 'mode' can device/reading combination diff --git a/fhem/FHEM/49_SSCam.pm b/fhem/FHEM/49_SSCam.pm index 47fc43adf..1f2ef1413 100644 --- a/fhem/FHEM/49_SSCam.pm +++ b/fhem/FHEM/49_SSCam.pm @@ -49,6 +49,7 @@ use FHEM::SynoModules::ErrCodes qw(:all); use FHEM::SynoModules::SMUtils qw( getClHash delClHash + delHashRefDeep trim moduleVersion sortVersion @@ -192,6 +193,7 @@ BEGIN { # Versions History intern my %vNotesIntern = ( + "9.12.3" => "08.12.2024 rollout delHashRefDeep, edit comref, internal code changed, replace some special data by local owndata ", "9.12.2" => "26.11.2024 Bugfix PATH in hvada & hsimu ", "9.12.1" => "25.11.2024 set COMPATIBILITY to 9.2.1, attr customSVSversion new option 9.2.0 ", "9.12.0" => "27.10.2024 internal code changes, implement new Take camera snapshot API if SVS >= 9.2.1 ". @@ -711,6 +713,7 @@ my %hsimu = ( # Fun ); # Standardvariablen und Forward-Deklaration +my %owndata; my $defSlim = 3; # default Anzahl der abzurufenden Schnappschüsse mit snapGallery my $defColumns = 3; # default Anzahl der Spalten einer snapGallery my $sgnum = '1,2,3,4,5,6,7,8,9,10'; # mögliche Anzahl der abzurufenden Schnappschüsse mit snapGallery @@ -730,23 +733,11 @@ my $todef = 20; # httptimeout default 9.2.0 ); -# use vars qw($FW_ME); # webname (default is fhem), used by 97_GROUP/weblink -# use vars qw($FW_subdir); # Sub-path in URL, used by FLOORPLAN/weblink -# use vars qw($FW_room); # currently selected room -# use vars qw($FW_detail); # currently selected device for detail view -# use vars qw($FW_wname); # Web instance - -# $data{SSCam}{$name}{PARAMS} -# $data{SSCam}{$name}{SENDCOUNT} -# $data{SSCam}{$name}{SENDRECS} -# $data{SSCam}{$name}{SENDSNAPS} -# $data{SSCam}{$name}{LASTSNAP} -# $data{SSCam}{$name}{SNAPHASH} -# $data{SSCam}{$name}{SNAPOLDHASH} -# $data{SSCam}{$name}{TMP} # universelle/temporäre Nutzung -# $data{SSCam}{$name}{TMPDA} # temporärer Speicher dekodierte Daten -# $data{SSCam}{$name}{TMPIDAT} # temporärer Speicher Gallerydaten -# $data{SSCam}{$name}{TMPCDAT} # temporärer Speicher Gallerydaten Cache + use vars qw($FW_ME); # webname (default is fhem), used by 97_GROUP/weblink + use vars qw($FW_subdir); # Sub-path in URL, used by FLOORPLAN/weblink + use vars qw($FW_room); # currently selected room + use vars qw($FW_detail); # currently selected device for detail view + use vars qw($FW_wname); # Web instance ############################################################################################# # Hint Hash EN @@ -877,6 +868,16 @@ my %vHintsExt_de = ( "

", ); +# $owndata{PARAMS} # temporärer Parameter-Speicher +# $owndata{SENDCOUNT} # temporärer Sende-Zähler +# $owndata{RS} +# $owndata{SENDRECS} # temporärer Sendehash Aufnahmen +# $owndata{SENDSNAPS} # temporärer Sendehash Schnappschüsse +# $owndata{TMPDA} # temporärer Speicher dekodierte Daten + +# $data{SSCam}{$name}{LASTSNAP} # Anzeigehash letzter Schnappschuß (nicht auf owndata umstellen - reload Problem) +# $data{SSCam}{$name}{SNAPHASH} # Anzeigehash Galerie (nicht auf owndata umstellen - reload Problem) + ################################################################ sub Initialize { my $hash = shift; @@ -1063,13 +1064,13 @@ sub delayedShutdown { $shutdownInProcess = 1; # Statusbit shutdown setzen -> asynchrone Funktionen nicht mehr ausgeführen - Log3($name, 2, "$name - Quit session due to shutdown ..."); + cache ($name, 'c_clear'); + cache ($name, 'c_destroy'); + + Log3 ($name, 1, "$name - Data of CHI-Cache removed") if(AttrVal ($name, 'debugactivetoken', 0)); + Log3 ($name, 2, "$name - Quit session due to shutdown ..."); - __sessionOff($hash); - - if($hash->{HELPER}{CACHEKEY}) { - cache($name, "c_destroy"); - } + __sessionOff ($hash); # CancelDelayedShutdown in SMUtils -> _logoutReturn return 1; } @@ -1097,6 +1098,7 @@ sub Delete { CommandDelete($hash->{CL},"TYPE=SSCamSTRM:FILTER=PARENT=$name"); # alle zugeordneten Streaming-Devices löschen falls vorhanden + delHashRefDeep ($data{SSCam}{$name}); delete $data{SSCam}{$name}; # internen Cache löschen return; @@ -1427,8 +1429,9 @@ sub Attr { readingsSingleUpdate($hash, "Availability", "???", 1) if($do == 1 && IsModelCam($hash)); } - if($aName =~ m/cacheType/) { + if ($aName =~ m/cacheType/) { my $type = AttrVal($name,"cacheType","internal"); + if ($cmd eq "set") { if ($aVal ne "internal") { if ($SScamMMCHI) { @@ -1450,9 +1453,10 @@ sub Attr { } if ($aVal ne $type) { if ($hash->{HELPER}{CACHEKEY}) { - cache($name, "c_destroy"); # CHI-Cache löschen/entfernen + cache ($name, "c_destroy"); # CHI-Cache löschen/entfernen } else { + delHashRefDeep ($data{SSCam}{$name}); delete $data{SSCam}{$name}; # internen Cache löschen } } @@ -1516,8 +1520,8 @@ sub Attr { if(!AttrVal ($name, 'pollcaminfoall', 0)); $hash->{HELPER}{GETSNAPGALLERY} = 1; - my $slim = AttrVal($name, "snapGalleryNumber", $defSlim); # Anzahl der abzurufenden Snaps - my $sg = AttrVal($name, "snapGallerySize", "Icon" ); # Auflösung Image + my $slim = AttrVal ($name, 'snapGalleryNumber', $defSlim); # Anzahl der abzurufenden Snaps + my $sg = AttrVal ($name, 'snapGallerySize', 'Icon'); # Auflösung Image my $ssize = ($sg eq "Icon") ? 1 : 2; RemoveInternalTimer ($hash, "FHEM::SSCam::__getSnapInfo" ); @@ -1525,7 +1529,7 @@ sub Attr { } } - if ($aName eq "snapGalleryNumber" && AttrVal($name, 'snapGalleryBoost', $sgbdef)) { + if ($aName eq 'snapGalleryNumber' && AttrVal ($name, 'snapGalleryBoost', $sgbdef)) { my ($slim,$ssize); if ($cmd eq 'set') { $do = $aVal != 0 ? 1 : 0; @@ -1543,7 +1547,7 @@ sub Attr { if ($init_done) { delete($hash->{HELPER}{".SNAPHASH"}); # bestehenden Snaphash löschen $hash->{HELPER}{GETSNAPGALLERY} = 1; - my $sg = AttrVal($name,"snapGallerySize","Icon"); # Auflösung Image + my $sg = AttrVal ($name, 'snapGallerySize', 'Icon'); # Auflösung Image $ssize = $sg eq "Icon" ? 1 : 2; RemoveInternalTimer ($hash, "FHEM::SSCam::__getSnapInfo" ); @@ -1558,6 +1562,7 @@ sub Attr { $do = 0 if($cmd eq 'del'); if (!$do) {$aVal = 0} + for my $i (1..10) { if ($i>$aVal) { readingsDelete($hash, "LastSnapFilename$i" ); @@ -1599,7 +1604,7 @@ sub Attr { if ($aName =~ m/cacheServerParam/x) { return "Please provide the Redis server parameters in form: : or unix:" if($aVal !~ /:\d+$|unix:.+$/x); my $type = AttrVal($name, 'cacheType', 'internal'); - if($hash->{HELPER}{CACHEKEY} && $type eq 'redis') { + if ($hash->{HELPER}{CACHEKEY} && $type eq 'redis') { cache($name, "c_destroy"); } } @@ -1847,7 +1852,7 @@ sub _setoff { ## no critic "not used" return if(!IsModelCam($hash)); - my $spec = join(" ",@$aref); + my $spec = join " ", @$aref; my ($inf) = $spec =~ m/STRM:(.*)/ix; # Aufnahmestop durch SSCamSTRM-Device $hash->{HELPER}{INFORM} = $inf if($inf); @@ -1873,12 +1878,12 @@ sub _setsnap { ## no critic "not used" my ($num,$lag,$ncount) = (1,2,1); - if($prop =~ /^\d+$/x) { # Anzahl der Schnappschüsse zu triggern (default: 1) + if ($prop =~ /^\d+$/x) { # Anzahl der Schnappschüsse zu triggern (default: 1) $num = $prop; $ncount = $prop; } - if($prop1 =~ /^\d+$/x) { # Zeit zwischen zwei Schnappschüssen (default: 2 Sekunden) + if ($prop1 =~ /^\d+$/x) { # Zeit zwischen zwei Schnappschüssen (default: 2 Sekunden) $lag = $prop1; } @@ -1890,7 +1895,7 @@ sub _setsnap { ## no critic "not used" } my $emtxt = AttrVal ($name, "snapEmailTxt", ""); - if($spec =~ /snapEmailTxt:/x) { + if ($spec =~ /snapEmailTxt:/x) { ($emtxt) = $spec =~ m/snapEmailTxt:"(.*)"/xi; } @@ -2088,13 +2093,13 @@ sub _setsnapGallery { ## no critic "not used" if (!AttrVal($name, 'snapGalleryBoost', $sgbdef)) { # Snaphash ist nicht vorhanden und wird neu abgerufen und ausgegeben $hash->{HELPER}{GETSNAPGALLERY} = 1; - my $slim = $prop // AttrVal($name,"snapGalleryNumber",$defSlim); # Anzahl der abzurufenden Snapshots - my $ssize = AttrVal($name,"snapGallerySize","Icon") eq "Icon" ? 1 : 2; # Image Size 1-Icon, 2-Full + my $slim = $prop // AttrVal ($name, 'snapGalleryNumber', $defSlim); # Anzahl der abzurufenden Snapshots + my $ssize = AttrVal ($name, 'snapGallerySize', 'Icon') eq 'Icon' ? 1 : 2; # Image Size 1-Icon, 2-Full __getSnapInfo ("$name:$slim:$ssize"); } else { # Snaphash ist vorhanden und wird zur Ausgabe aufbereitet (Polling ist aktiv) - $hash->{HELPER}{SNAPLIMIT} = AttrVal($name,"snapGalleryNumber",$defSlim); + $hash->{HELPER}{SNAPLIMIT} = AttrVal ($name, 'snapGalleryNumber', $defSlim); my %pars = ( linkparent => $name, linkname => '', @@ -2105,7 +2110,7 @@ sub _setsnapGallery { ## no critic "not used" for (my $k=1; (defined($hash->{HELPER}{CL}{$k})); $k++ ) { if ($hash->{HELPER}{CL}{$k}->{COMP}) { # CL zusammengestellt (Auslösung durch Notify) - asyncOutput ($hash->{HELPER}{CL}{$k}, "$htmlCode"); + asyncOutput ($hash->{HELPER}{CL}{$k}, $htmlCode); } else { # Output wurde über FHEMWEB ausgelöst return $htmlCode; @@ -4449,19 +4454,19 @@ sub _getsaveLastSnap { ## no critic 'not used' return if(!IsModelCam($hash)); - my $err; + my ($err, $tmpda); my $cache = cache ($name, "c_init"); # Cache initialisieren Log3 ($name, 1, "$name - Fall back to internal Cache due to preceding failure") if(!$cache); if (!$cache || $cache eq "internal" ) { - $data{SSCam}{$name}{TMPDA} = $data{SSCam}{$name}{LASTSNAP}; + $tmpda = $data{SSCam}{$name}{LASTSNAP}; } else { - $data{SSCam}{$name}{TMPDA} = cache ($name, "c_read", "{LASTSNAP}"); + $tmpda = cache ($name, "c_read", "{LASTSNAP}"); } - if (!$data{SSCam}{$name}{TMPDA}) { + if (!$tmpda) { Log3 ($name, 2, "$name - No image data available to save locally") } @@ -4475,7 +4480,7 @@ sub _getsaveLastSnap { ## no critic 'not used' if (!$err) { $err = "none"; binmode $fh; - print $fh MIME::Base64::decode_base64 ($data{SSCam}{$name}{TMPDA}); + print $fh MIME::Base64::decode_base64 ($tmpda); close($fh); Log3 ($name, 3, qq{$name - Last Snapshot was saved to local file "$file"}); } @@ -4531,24 +4536,24 @@ sub _getsnapGallery { ## no critic "not used" if (!AttrVal($name, 'snapGalleryBoost', $sgbdef)) { # Snaphash ist nicht vorhanden und wird abgerufen $hash->{HELPER}{GETSNAPGALLERY} = 1; - my $slim = $arg // AttrVal($name,"snapGalleryNumber",$defSlim); # Anzahl der abzurufenden Snapshots - my $ssize = (AttrVal($name,"snapGallerySize","Icon") eq "Icon") ? 1 : 2; # Image Size 1-Icon, 2-Full + my $slim = $arg // AttrVal ($name, 'snapGalleryNumber', $defSlim); # Anzahl der abzurufenden Snapshots + my $ssize = AttrVal ($name, 'snapGallerySize', 'Icon') eq 'Icon' ? 1 : 2; # Image Size 1-Icon, 2-Full - __getSnapInfo("$name:$slim:$ssize"); + __getSnapInfo ("$name:$slim:$ssize"); } else { # Snaphash ist vorhanden und wird zur Ausgabe aufbereitet - $hash->{HELPER}{SNAPLIMIT} = AttrVal($name,"snapGalleryNumber",$defSlim); + $hash->{HELPER}{SNAPLIMIT} = AttrVal ($name, 'snapGalleryNumber', $defSlim); - my %pars = ( linkparent => $name, + my $pars = { linkparent => $name, linkname => '', ftui => 0 - ); + }; - my $htmlCode = composeGallery(\%pars); + my $htmlCode = composeGallery ($pars); for (my $k=1; (defined($hash->{HELPER}{CL}{$k})); $k++ ) { if ($hash->{HELPER}{CL}{$k}->{COMP}) { # CL zusammengestellt (Auslösung durch Notify) - asyncOutput($hash->{HELPER}{CL}{$k}, "$htmlCode"); + asyncOutput ($hash->{HELPER}{CL}{$k}, $htmlCode); } else { # Output wurde über FHEMWEB ausgelöst return $htmlCode; @@ -5338,7 +5343,7 @@ sub __sessionOff { my $caller = (caller(0))[3]; - RemoveInternalTimer($hash, $caller); + RemoveInternalTimer ($hash, $caller); return if(IsDisabled($name)); if ($hash->{HELPER}{ACTIVE} eq "off") { @@ -5443,7 +5448,7 @@ sub getApiSites_Parse { my $hash = $defs{$name}; my $opmode = $hash->{OPMODE}; - my ($error,$errorcode,$success); + my ($error, $errorcode, $success, $tmpda); if ($err ne "") { # wenn ein Fehler bei der HTTP Abfrage aufgetreten ist Log3 ($name, 2, "$name - error while requesting ".$paref->{url}." - $err"); @@ -5460,13 +5465,13 @@ sub getApiSites_Parse { return; } - $data{SSCam}{$name}{TMPDA} = decode_json ($jdata); - $success = $data{SSCam}{$name}{TMPDA}->{success}; + $tmpda = decode_json ($jdata); + $success = $tmpda->{success}; if ($success) { - Log3 ($name, 5, "$name - JSON returned: ". Dumper $data{SSCam}{$name}{TMPDA}); # Logausgabe decodierte JSON Daten + Log3 ($name, 5, "$name - JSON returned: ". Dumper $tmpda); # Logausgabe decodierte JSON Daten - my $completed = completeAPI ($data{SSCam}{$name}{TMPDA}, $hash->{HELPER}{API}); # übergibt Referenz zum instanziierten API-Hash + my $completed = completeAPI ($tmpda, $hash->{HELPER}{API}); # übergibt Referenz zum instanziierten API-Hash if (!$completed) { $errorcode = "9001"; @@ -5612,7 +5617,7 @@ sub getCamId { callback => \&getCamId_Parse }; - HttpUtils_NonblockingGet($param); + HttpUtils_NonblockingGet ($param); return; } @@ -5631,7 +5636,7 @@ sub getCamId_Parse { my $apicamver = $hash->{HELPER}{API}{CAM}{VER}; my $OpMode = $hash->{OPMODE}; - my ($success,$error,$errorcode,$camid); + my ($success, $error, $errorcode, $camid, $tmpda); my ($i,$n,$id,$errstate,$camdef,$nrcreated); my $cdall = ""; my %allcams; @@ -5652,24 +5657,24 @@ sub getCamId_Parse { return; } - $data{SSCam}{$name}{TMPDA} = decode_json ($jdata); - $success = $data{SSCam}{$name}{TMPDA}->{'success'}; + $tmpda = decode_json ($jdata); + $success = $tmpda->{'success'}; - Log3 ($name, 5, "$name - JSON returned: ". Dumper $data{SSCam}{$name}{TMPDA}); + Log3 ($name, 5, "$name - JSON returned: ". Dumper $tmpda); if ($success) { # die Liste aller Kameras konnte ausgelesen werden ($i,$nrcreated) = (0,0); %allcams = (); # Namen aller installierten Kameras mit Id's in Hash einlesen - while ($data{SSCam}{$name}{TMPDA}->{'data'}{'cameras'}[$i]) { + while ($tmpda->{'data'}{'cameras'}[$i]) { if ($apicamver <= 8) { - $n = $data{SSCam}{$name}{TMPDA}->{'data'}{'cameras'}[$i]{'name'}; + $n = $tmpda->{'data'}{'cameras'}[$i]{'name'}; } else { - $n = $data{SSCam}{$name}{TMPDA}->{'data'}{'cameras'}[$i]{'newName'}; # Änderung ab SVS 8.0.0 + $n = $tmpda->{'data'}{'cameras'}[$i]{'newName'}; # Änderung ab SVS 8.0.0 } - $id = $data{SSCam}{$name}{TMPDA}->{'data'}{'cameras'}[$i]{'id'}; + $id = $tmpda->{'data'}{'cameras'}[$i]{'id'}; $allcams{"$n"} = $id; $i += 1; @@ -5722,7 +5727,7 @@ sub getCamId_Parse { } } else { - $errorcode = $data{SSCam}{$name}{TMPDA}->{'error'}{'code'}; # Errorcode aus JSON ermitteln + $errorcode = $tmpda->{'error'}{'code'}; # Errorcode aus JSON ermitteln $error = expErrors ($hash,$errorcode); # Fehlertext zum Errorcode ermitteln readingsBeginUpdate ($hash); @@ -5903,7 +5908,7 @@ sub camOp_Parse { # Einstellung für Logausgabe Pollinginfos # wenn "pollnologging" = 1 -> logging nur bei Verbose=4, sonst 3 my $verbose = 3; - if (AttrVal($name, "pollnologging", 0)) { + if (AttrVal ($name, 'pollnologging', 0)) { $verbose = 4; } @@ -5915,7 +5920,7 @@ sub camOp_Parse { return; } - elsif ($jdata ne "") { # wenn die Abfrage erfolgreich war + elsif ($jdata ne "") { # wenn die Abfrage erfolgreich war if ($OpMode !~ /SaveRec|GetRec/x) { # "SaveRec/GetRec" liefern MP4-Daten und kein JSON ($success) = evaljson ($hash, $jdata); @@ -5925,10 +5930,10 @@ sub camOp_Parse { return; } - $data{SSCam}{$name}{TMPDA} = decode_json ($jdata); - $success = $data{SSCam}{$name}{TMPDA}->{'success'}; + $owndata{TMPDA} = decode_json ($jdata); + $success = $owndata{TMPDA}->{'success'}; - Log3 ($name, 5, "$name - JSON returned: ". Dumper $data{SSCam}{$name}{TMPDA}); # Logausgabe decodierte JSON Daten + Log3 ($name, 5, "$name - JSON returned: ". Dumper $owndata{TMPDA}); # Logausgabe decodierte JSON Daten } else { $success = 1; @@ -5949,30 +5954,32 @@ sub camOp_Parse { my $ret = q{}; $ret = &{$hparse{$OpMode}{fn}} ($params); - delete $data{SSCam}{$name}{TMPDA}; + delHashRefDeep ($owndata{TMPDA}); + delete $owndata{TMPDA}; + return if($ret); } use strict "refs"; if ($OpMode eq "ExpMode") { - Log3 ($name, 3, qq{$name - Camera $camname exposure mode is set to "$hash->{HELPER}{EXPMODE}"} ); + Log3 ($name, 3, qq{$name - Camera $camname exposure mode is set to "$hash->{HELPER}{EXPMODE}"} ); setReadingErrorNone($hash, 1 ); __getCamInfo ($hash); } elsif ($OpMode eq "setZoom") { - Log3 ($name, 3, qq{$name - Zoom operation "$hash->{HELPER}{ZOOM}{DIR}:$hash->{HELPER}{ZOOM}{MOVETYPE}" of Camera $camname successfully done} ); + Log3 ($name, 3, qq{$name - Zoom operation "$hash->{HELPER}{ZOOM}{DIR}:$hash->{HELPER}{ZOOM}{MOVETYPE}" of Camera $camname successfully done} ); setReadingErrorNone($hash, 1 ); } elsif ($OpMode eq "extevent") { - Log3 ($name, 3, qq{$name - External Event "$hash->{HELPER}{EVENTID}" successfully triggered} ); + Log3 ($name, 3, qq{$name - External Event "$hash->{HELPER}{EVENTID}" successfully triggered} ); setReadingErrorNone($hash, 1 ); } elsif ($OpMode eq "sethomemode") { - Log3 ($name, 3, qq{$name - HomeMode was set to "$hash->{HELPER}{HOMEMODE}"} ); + Log3 ($name, 3, qq{$name - HomeMode was set to "$hash->{HELPER}{HOMEMODE}"} ); + setReadingErrorNone($hash, 1 ); - delActiveToken ($hash); # Token freigeben vor nächstem Kommando __getHomeModeState ($hash); # neuen HomeModeState abrufen } @@ -5983,6 +5990,7 @@ sub camOp_Parse { $pspeed = $pspeed ? $pspeed : "not set"; Log3 ($name, 3, "$name - Camera $camname preset \"$pname\" was saved to number $pnumber with speed $pspeed"); + setReadingErrorNone ($hash, 1); __getPtzPresetList ($hash); } @@ -5991,6 +5999,7 @@ sub camOp_Parse { delete $hash->{HELPER}{ALLPRESETS}{$dp}; Log3 ($name, 3, "$name - Preset \"$dp\" of camera \"$camname\" has been deleted"); + setReadingErrorNone ($hash, 1); __getPtzPresetList ($hash); } @@ -5998,17 +6007,19 @@ sub camOp_Parse { my $piract = $hash->{HELPER}{PIRACT} == 0 ? "activated" : "deactivated"; Log3 ($name, 3, "$name - PIR sensor $piract"); + setReadingErrorNone ($hash, 1); } elsif ($OpMode eq "setHome") { my $sh = $hash->{HELPER}{SETHOME}; Log3 ($name, 3, "$name - Preset \"$sh\" of camera \"$camname\" was set as Home position"); + setReadingErrorNone ($hash, 1); __getPtzPresetList ($hash); } elsif ($OpMode eq "setoptpar") { - my $rid = $data{SSCam}{$name}{TMPDA}->{'data'}{'id'}; # Cam ID return wenn i.O. + my $rid = $owndata{TMPDA}->{'data'}{'id'}; # Cam ID return wenn i.O. my $ropt = $rid == $hash->{CAMID} ? "none" : "error in operation"; delete $hash->{HELPER}{NTPSERV}; @@ -6033,7 +6044,10 @@ sub camOp_Parse { elsif ($OpMode eq "reactivate_hls") { # HLS Streaming wurde deaktiviert, Aktivitätsstatus speichern $hash->{HELPER}{HLSSTREAM} = "inactive"; Log3($name, 3, "$name - HLS Streaming of camera \"$name\" deactivated for reactivation"); - delete $data{SSCam}{$name}{TMPDA}; + + delHashRefDeep ($owndata{TMPDA}); + delete $owndata{TMPDA}; + delActiveToken ($hash); # Token freigeben vor hlsactivate __activateHls ($hash); return; @@ -6049,18 +6063,21 @@ sub camOp_Parse { if (!$snapid) { Log3 ($name, 2, "$name - Snap-ID \"LastSnapId\" isn't set. Filename can't be retrieved"); delActiveToken ($hash); # Token freigeben vor hlsactivate - delete $data{SSCam}{$name}{TMPDA}; + + delHashRefDeep ($owndata{TMPDA}); + delete $owndata{TMPDA}; + return; } - Log3 ($name, 4, qq{$name - Filename of Snap-ID $snapid is "$data{SSCam}{$name}{TMPDA}->{'data'}{'data'}[0]{'fileName'}"}) - if($data{SSCam}{$name}{TMPDA}->{'data'}{'data'}[0]{'fileName'}); + Log3 ($name, 4, qq{$name - Filename of Snap-ID $snapid is "$owndata{TMPDA}->{'data'}{'data'}[0]{'fileName'}"}) + if($owndata{TMPDA}->{'data'}{'data'}[0]{'fileName'}); - readingsSingleUpdate ($hash, 'LastSnapFilename', $data{SSCam}{$name}{TMPDA}->{'data'}{'data'}[0]{'fileName'}, 1); + readingsSingleUpdate ($hash, 'LastSnapFilename', $owndata{TMPDA}->{'data'}{'data'}[0]{'fileName'}, 1); setReadingErrorNone ($hash, 1); } elsif ($OpMode eq "getstreamformat") { # aktuelles Streamformat abgefragt - my $sformat = jboolmap ($data{SSCam}{$name}{TMPDA}->{'data'}->{'format'}); + my $sformat = jboolmap ($owndata{TMPDA}->{'data'}->{'format'}); $sformat = $sformat ? uc($sformat) : "no API"; readingsSingleUpdate ($hash, "CamStreamFormat", $sformat, 1); @@ -6079,6 +6096,7 @@ sub camOp_Parse { DoTrigger($name,"move stop"); Log3 ($name, 3, qq{$name - Camera $camname has been moved to absolute position "posX=$hash->{HELPER}{GOPTZPOSX}" and "posY=$hash->{HELPER}{GOPTZPOSY}"} ); + readingsSingleUpdate ($hash,"state", $st, 0); setReadingErrorNone ($hash, 1); } @@ -6092,6 +6110,7 @@ sub camOp_Parse { } elsif ($OpMode eq "movestart") { # ein "Move" in eine bestimmte Richtung wird durchgeführt Log3 ($name, 3, qq{$name - Camera $camname started move to direction "$hash->{HELPER}{GOMOVEDIR}" with duration of $hash->{HELPER}{GOMOVETIME} s} ); + setReadingErrorNone ($hash, 1); RemoveInternalTimer ($hash, "FHEM::SSCam::__moveStop" ); InternalTimer (gettimeofday()+($hash->{HELPER}{GOMOVETIME}), "FHEM::SSCam::__moveStop", $hash ); @@ -6101,6 +6120,7 @@ sub camOp_Parse { DoTrigger($name,"move stop"); Log3 ($name, 3, qq{$name - Camera $camname stopped move to direction "$hash->{HELPER}{GOMOVEDIR}"} ); + readingsSingleUpdate ($hash,"state", $st, 0); setReadingErrorNone ($hash, 1); } @@ -6126,7 +6146,7 @@ sub camOp_Parse { } } else { # die API-Operation war fehlerhaft - my $errorcode = $data{SSCam}{$name}{TMPDA}->{'error'}->{'code'}; # Errorcode aus JSON ermitteln + my $errorcode = $owndata{TMPDA}->{'error'}->{'code'}; # Errorcode aus JSON ermitteln my $error = expErrors ($hash,$errorcode); # Fehlertext zum Errorcode ermitteln readingsBeginUpdate ($hash); @@ -6136,14 +6156,18 @@ sub camOp_Parse { if ($errorcode =~ /105/x) { Log3 ($name, 2, "$name - ERROR - $errorcode - $error in operation $OpMode -> try new login"); - delete $data{SSCam}{$name}{TMPDA}; + + delHashRefDeep ($owndata{TMPDA}); + delete $owndata{TMPDA}; + return login ($hash, $hash->{HELPER}{API}, \&camOp); } Log3 ($name, 2, "$name - ERROR - Operation $OpMode not successful. Cause: $errorcode - $error"); } - delete $data{SSCam}{$name}{TMPDA}; + delHashRefDeep ($owndata{TMPDA}); + delete $owndata{TMPDA}; } delActiveToken ($hash); # Token freigeben @@ -6256,11 +6280,11 @@ sub _parseGetRec { ## no critic "not used" Log3 ($name, 1, "$name - Fall back to internal Cache due to preceding failure.") if(!$cache); if (!$cache || $cache eq "internal" ) { - $data{SSCam}{$name}{SENDRECS}{$tac}{$sn}{recid} = $recid; - $data{SSCam}{$name}{SENDRECS}{$tac}{$sn}{createdTm} = $createdTm; - $data{SSCam}{$name}{SENDRECS}{$tac}{$sn}{fileName} = $fileName; - $data{SSCam}{$name}{SENDRECS}{$tac}{$sn}{tdir} = $tdir; - $data{SSCam}{$name}{SENDRECS}{$tac}{$sn}{imageData} = $$jdataref; # dereferenzieren! + $owndata{SENDRECS}{$tac}{$sn}{recid} = $recid; + $owndata{SENDRECS}{$tac}{$sn}{createdTm} = $createdTm; + $owndata{SENDRECS}{$tac}{$sn}{fileName} = $fileName; + $owndata{SENDRECS}{$tac}{$sn}{tdir} = $tdir; + $owndata{SENDRECS}{$tac}{$sn}{imageData} = $$jdataref; # dereferenzieren! } else { cache ($name, "c_write", "{SENDRECS}{$tac}{$sn}{recid}", $recid); @@ -6276,7 +6300,7 @@ sub _parseGetRec { ## no critic "not used" # Recording als Email / Telegram / Chat versenden ################################################## if (!$cache || $cache eq "internal" ) { - prepareSendData ($hash, $OpMode, $data{SSCam}{$name}{SENDRECS}{$tac}); + prepareSendData ($hash, $OpMode, $owndata{SENDRECS}{$tac}); } else { prepareSendData ($hash, $OpMode, "{SENDRECS}{$tac}"); @@ -6331,19 +6355,19 @@ sub _parsegetsvslog { ## no critic "not used" my $name = $paref->{name}; my $hash = $defs{$name}; - my $lec = $data{SSCam}{$name}{TMPDA}->{'data'}{'total'}; # abgerufene Anzahl von Log-Einträgen + my $lec = $owndata{TMPDA}->{'data'}{'total'}; # abgerufene Anzahl von Log-Einträgen my $log = q{}; my $log0 = q{}; my $i = 0; - while ($data{SSCam}{$name}{TMPDA}->{'data'}{'log'}[$i]) { - my $id = $data{SSCam}{$name}{TMPDA}->{'data'}{'log'}[$i]{'id'}; - my $un = $data{SSCam}{$name}{TMPDA}->{'data'}{'log'}[$i]{'user_name'}; - my $desc = $data{SSCam}{$name}{TMPDA}->{'data'}{'log'}[$i]{'desc'}; - my $level = $data{SSCam}{$name}{TMPDA}->{'data'}{'log'}[$i]{'type'}; + while ($owndata{TMPDA}->{'data'}{'log'}[$i]) { + my $id = $owndata{TMPDA}->{'data'}{'log'}[$i]{'id'}; + my $un = $owndata{TMPDA}->{'data'}{'log'}[$i]{'user_name'}; + my $desc = $owndata{TMPDA}->{'data'}{'log'}[$i]{'desc'}; + my $level = $owndata{TMPDA}->{'data'}{'log'}[$i]{'type'}; $level = ($level == 3) ? "Error" : ($level == 2) ? "Warning" : "Information"; - my $time = FmtDateTime ($data{SSCam}{$name}{TMPDA}->{'data'}{'log'}[$i]{'time'}); + my $time = FmtDateTime ($owndata{TMPDA}->{'data'}{'log'}[$i]{'time'}); $log0 = $time." - ".$level." - ".$desc if($i == 0); $log .= "$time - $level - $desc
"; @@ -6415,7 +6439,7 @@ sub _parsegethomemodestate { ## no critic "not used" my $name = $paref->{name}; my $hash = $defs{$name}; - my $hmst = $data{SSCam}{$name}{TMPDA}->{'data'}{'on'}; + my $hmst = $owndata{TMPDA}->{'data'}{'on'}; my $hmststr = $hmst == 1 ? 'on' : 'off'; my ($date, $time) = timestampToDateTime (); @@ -6441,12 +6465,12 @@ sub _parsegetPresets { ## no critic "not used" my %ap = (); my $i = 0; - while ($data{SSCam}{$name}{TMPDA}->{'data'}{'preset'}[$i]) { - my $pname = $data{SSCam}{$name}{TMPDA}->{'data'}{'preset'}[$i]{'name'}; - my $ptype = $data{SSCam}{$name}{TMPDA}->{'data'}{'preset'}[$i]{'type'}; - my $ppos = $data{SSCam}{$name}{TMPDA}->{'data'}{'preset'}[$i]{'position'}; - my $pspeed = $data{SSCam}{$name}{TMPDA}->{'data'}{'preset'}[$i]{'speed'}; - my $pextra = $data{SSCam}{$name}{TMPDA}->{'data'}{'preset'}[$i]{'extra'}; + while ($owndata{TMPDA}->{'data'}{'preset'}[$i]) { + my $pname = $owndata{TMPDA}->{'data'}{'preset'}[$i]{'name'}; + my $ptype = $owndata{TMPDA}->{'data'}{'preset'}[$i]{'type'}; + my $ppos = $owndata{TMPDA}->{'data'}{'preset'}[$i]{'position'}; + my $pspeed = $owndata{TMPDA}->{'data'}{'preset'}[$i]{'speed'}; + my $pextra = $owndata{TMPDA}->{'data'}{'preset'}[$i]{'extra'}; $ptype = ($ptype == 1)?"Home":"Normal"; $ap{$ppos} = "Name: $pname, Speed: $pspeed, Type: $ptype"; $i++; @@ -6491,8 +6515,8 @@ sub _parseSnap { ## no critic "not used" $tac = openOrgetTrans($hash); # Transaktion starten oder vorhandenen Code holen } - my $snapid = $data{SSCam}{$name}{TMPDA}->{data}{'id'}; - $snapid = $data{SSCam}{$name}{TMPDA}->{data}{'snapshotId'} if($hash->{HELPER}{CALL}{VKEY} eq 'SNAPWEBAPI'); + my $snapid = $owndata{TMPDA}->{data}{'id'}; + $snapid = $owndata{TMPDA}->{data}{'snapshotId'} if($hash->{HELPER}{CALL}{VKEY} eq 'SNAPWEBAPI'); setReadingErrorNone ($hash, 1); @@ -6521,6 +6545,7 @@ sub _parseSnap { ## no critic "not used" if ($ncount > 0) { InternalTimer (gettimeofday()+$lag, "FHEM::SSCam::__camSnap", "$name!_!$num!_!$lag!_!$ncount!_!$emtxt!_!$teletxt!_!$chattxt!_!$tac", 0); + if (!$tac) { delActiveToken ($hash); # Token freigeben wenn keine Transaktion läuft } @@ -6552,19 +6577,19 @@ sub _parsegetsvsinfo { ## no critic "not used" my $verbose = $paref->{verbose}; my $hash = $defs{$name}; - my $userPriv = $data{SSCam}{$name}{TMPDA}{'data'}{'userPriv'}; + my $userPriv = $owndata{TMPDA}{'data'}{'userPriv'}; if (defined $userPriv) { $userPriv = $hrkeys{userPriv}{$userPriv}; } - $hash->{HELPER}{SVSVERSION}{MAJOR} = $data{SSCam}{$name}{TMPDA}{'data'}{'version'}{'major'}; # Werte in $hash zur späteren Auswertung einfügen - $hash->{HELPER}{SVSVERSION}{MINOR} = $data{SSCam}{$name}{TMPDA}{'data'}{'version'}{'minor'}; - $hash->{HELPER}{SVSVERSION}{SMALL} = $data{SSCam}{$name}{TMPDA}{'data'}{'version'}{'small'}; - $hash->{HELPER}{SVSVERSION}{BUILD} = $data{SSCam}{$name}{TMPDA}{'data'}{'version'}{'build'}; + $hash->{HELPER}{SVSVERSION}{MAJOR} = $owndata{TMPDA}{'data'}{'version'}{'major'}; # Werte in $hash zur späteren Auswertung einfügen + $hash->{HELPER}{SVSVERSION}{MINOR} = $owndata{TMPDA}{'data'}{'version'}{'minor'}; + $hash->{HELPER}{SVSVERSION}{SMALL} = $owndata{TMPDA}{'data'}{'version'}{'small'}; + $hash->{HELPER}{SVSVERSION}{BUILD} = $owndata{TMPDA}{'data'}{'version'}{'build'}; - readingsDelete ($hash, 'SVScustomPortHttp') if(!exists($data{SSCam}{$name}{TMPDA}{'data'}{'customizedPortHttp'})); - readingsDelete ($hash, 'SVScustomPortHttps') if(!exists($data{SSCam}{$name}{TMPDA}{'data'}{'customizedPortHttps'})); + readingsDelete ($hash, 'SVScustomPortHttp') if(!exists($owndata{TMPDA}{'data'}{'customizedPortHttp'})); + readingsDelete ($hash, 'SVScustomPortHttps') if(!exists($owndata{TMPDA}{'data'}{'customizedPortHttps'})); my $major = $hash->{HELPER}{SVSVERSION}{MAJOR} // ''; my $minor = $hash->{HELPER}{SVSVERSION}{MINOR} // ''; @@ -6604,9 +6629,9 @@ sub _parsegetsvsinfo { ## no critic "not used" readingsBeginUpdate ($hash); - readingsBulkUpdate ($hash, 'SVScustomPortHttp', $data{SSCam}{$name}{TMPDA}{'data'}{'customizedPortHttp'}); - readingsBulkUpdate ($hash, 'SVScustomPortHttps', $data{SSCam}{$name}{TMPDA}{'data'}{'customizedPortHttps'}); - readingsBulkUpdate ($hash, 'SVSlicenseNumber', $data{SSCam}{$name}{TMPDA}{'data'}{'liscenseNumber'}); + readingsBulkUpdate ($hash, 'SVScustomPortHttp', $owndata{TMPDA}{'data'}{'customizedPortHttp'}); + readingsBulkUpdate ($hash, 'SVScustomPortHttps', $owndata{TMPDA}{'data'}{'customizedPortHttps'}); + readingsBulkUpdate ($hash, 'SVSlicenseNumber', $owndata{TMPDA}{'data'}{'liscenseNumber'}); readingsBulkUpdate ($hash, 'SVSuserPriv', $userPriv); readingsBulkUpdate ($hash, 'compstate', $compstate); readingsBulkUpdate ($hash, 'SVSversion', $major.".".$minor.".".$small."-".$build); @@ -6698,9 +6723,9 @@ sub __parserunliveviewSNAP { ## no critic "not used" Log3 ($name, $verbose, "$name - Snapinfos of camera $camname retrieved"); - if (exists($data{SSCam}{$name}{TMPDA}->{'data'}{'data'}[0]{imageData})) { + if (exists($owndata{TMPDA}->{'data'}{'data'}[0]{imageData})) { delete $hash->{HELPER}{RUNVIEW}; - $hash->{HELPER}{LINK} = delete $data{SSCam}{$name}{TMPDA}->{data}{data}[0]{imageData}; + $hash->{HELPER}{LINK} = delete $owndata{TMPDA}->{data}{data}[0]{imageData}; } else { Log3($name, 3, "$name - There is no snapshot of camera $camname to display. Take one snapshot before."); @@ -6730,20 +6755,20 @@ sub _parsegetStmUrlPath { ## no critic "not used" my($camforcemcast,$mjpegHttp,$multicst,$mxpegHttp,$unicastOverHttp,$unicastPath); if ($apicamver < 9) { - $camforcemcast = jboolmap ($data{SSCam}{$name}{TMPDA}->{'data'}{'pathInfos'}[0]{'forceEnableMulticast'}); - $mjpegHttp = $data{SSCam}{$name}{TMPDA}->{'data'}{'pathInfos'}[0]{'mjpegHttpPath'}; - $multicst = $data{SSCam}{$name}{TMPDA}->{'data'}{'pathInfos'}[0]{'multicstPath'}; - $mxpegHttp = $data{SSCam}{$name}{TMPDA}->{'data'}{'pathInfos'}[0]{'mxpegHttpPath'}; - $unicastOverHttp = $data{SSCam}{$name}{TMPDA}->{'data'}{'pathInfos'}[0]{'unicastOverHttpPath'}; - $unicastPath = $data{SSCam}{$name}{TMPDA}->{'data'}{'pathInfos'}[0]{'unicastPath'}; + $camforcemcast = jboolmap ($owndata{TMPDA}->{'data'}{'pathInfos'}[0]{'forceEnableMulticast'}); + $mjpegHttp = $owndata{TMPDA}->{'data'}{'pathInfos'}[0]{'mjpegHttpPath'}; + $multicst = $owndata{TMPDA}->{'data'}{'pathInfos'}[0]{'multicstPath'}; + $mxpegHttp = $owndata{TMPDA}->{'data'}{'pathInfos'}[0]{'mxpegHttpPath'}; + $unicastOverHttp = $owndata{TMPDA}->{'data'}{'pathInfos'}[0]{'unicastOverHttpPath'}; + $unicastPath = $owndata{TMPDA}->{'data'}{'pathInfos'}[0]{'unicastPath'}; } if ($apicamver >= 9) { - $mjpegHttp = $data{SSCam}{$name}{TMPDA}->{'data'}[0]{'mjpegHttpPath'}; - $multicst = $data{SSCam}{$name}{TMPDA}->{'data'}[0]{'multicstPath'}; - $mxpegHttp = $data{SSCam}{$name}{TMPDA}->{'data'}[0]{'mxpegHttpPath'}; - $unicastOverHttp = $data{SSCam}{$name}{TMPDA}->{'data'}[0]{'rtspOverHttpPath'}; - $unicastPath = $data{SSCam}{$name}{TMPDA}->{'data'}[0]{'rtspPath'}; + $mjpegHttp = $owndata{TMPDA}->{'data'}[0]{'mjpegHttpPath'}; + $multicst = $owndata{TMPDA}->{'data'}[0]{'multicstPath'}; + $mxpegHttp = $owndata{TMPDA}->{'data'}[0]{'mxpegHttpPath'}; + $unicastOverHttp = $owndata{TMPDA}->{'data'}[0]{'rtspOverHttpPath'}; + $unicastPath = $owndata{TMPDA}->{'data'}[0]{'rtspPath'}; } if (AttrVal($name, "livestreamprefix", undef)) { # Rewrite Url's falls livestreamprefix ist gesetzt @@ -6810,13 +6835,13 @@ sub _parseGetcaminfo { ## no critic "not used" my $hash = $defs{$name}; my ($date, $time) = timestampToDateTime (); - my $camLiveMode = $data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'camLiveMode'}; + my $camLiveMode = $owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'camLiveMode'}; $camLiveMode = $hrkeys{camLiveMode}{$camLiveMode}; - my $deviceType = $data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'deviceType'}; + my $deviceType = $owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'deviceType'}; $deviceType = $hrkeys{deviceType}{$deviceType}; - my $camStatus = jboolmap ($data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'camStatus'}); + my $camStatus = jboolmap ($owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'camStatus'}); $camStatus = $hrkeys{camStatus}{$camStatus}; if ($camStatus eq "enabled") { @@ -6828,22 +6853,22 @@ sub _parseGetcaminfo { ## no critic "not used" } } - my $recStatus = $data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'recStatus'}; + my $recStatus = $owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'recStatus'}; $recStatus = $recStatus ne "0" ? "Start" : "Stop"; - my $rotate = $data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'video_rotation'}; + my $rotate = $owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'video_rotation'}; $rotate = $rotate == 1 ? "true" : "false"; - my $exposuremode = jboolmap ($data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'exposure_mode'}); + my $exposuremode = jboolmap ($owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'exposure_mode'}); $exposuremode = $hrkeys{exposure_mode}{$exposuremode}; - my $exposurecontrol = jboolmap ($data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'exposure_control'}); + my $exposurecontrol = jboolmap ($owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'exposure_control'}); $exposurecontrol = $hrkeys{exposure_control}{$exposurecontrol}; - my $camaudiotype = jboolmap ($data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camAudioType'}); + my $camaudiotype = jboolmap ($owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camAudioType'}); $camaudiotype = $hrkeys{camAudioType}{$camaudiotype}; - my $pdcap = jboolmap ($data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'PDCap'}); + my $pdcap = jboolmap ($owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'PDCap'}); if (!$pdcap || $pdcap == 0) { $pdcap = "false"; @@ -6852,46 +6877,46 @@ sub _parseGetcaminfo { ## no critic "not used" $pdcap = "true"; } - $data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'video_flip'} = jboolmap ($data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'video_flip'}); - $data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'video_mirror'} = jboolmap ($data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'video_mirror'}); - $data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'blPresetSpeed'} = jboolmap ($data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'blPresetSpeed'}); + $owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'video_flip'} = jboolmap ($owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'video_flip'}); + $owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'video_mirror'} = jboolmap ($owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'video_mirror'}); + $owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'blPresetSpeed'} = jboolmap ($owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'blPresetSpeed'}); - my $clstrmno = $data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camLiveStreamNo'}; + my $clstrmno = $owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camLiveStreamNo'}; $clstrmno++ if($clstrmno == 0); - my $fw = $data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camFirmware'}; + my $fw = $owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camFirmware'}; readingsBeginUpdate($hash); readingsBulkUpdate($hash, "CamAudioType", $camaudiotype); readingsBulkUpdate($hash, "CamFirmware", $fw) if($fw); readingsBulkUpdate($hash, "CamLiveMode", $camLiveMode); - readingsBulkUpdate($hash, "CamLiveFps", $data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camLiveFps'}); - readingsBulkUpdate($hash, "CamLiveResolution", $data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camLiveResolution'}); - readingsBulkUpdate($hash, "CamLiveQuality", $data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camLiveQuality'}); + readingsBulkUpdate($hash, "CamLiveFps", $owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camLiveFps'}); + readingsBulkUpdate($hash, "CamLiveResolution", $owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camLiveResolution'}); + readingsBulkUpdate($hash, "CamLiveQuality", $owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camLiveQuality'}); readingsBulkUpdate($hash, "CamLiveStreamNo", $clstrmno); readingsBulkUpdate($hash, "CamExposureMode", $exposuremode); readingsBulkUpdate($hash, "CamExposureControl", $exposurecontrol); - readingsBulkUpdate($hash, "CamModel", $data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camModel'}); - readingsBulkUpdate($hash, "CamRecShare", $data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'camRecShare'}); - readingsBulkUpdate($hash, "CamRecVolume", $data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'camRecVolume'}); - readingsBulkUpdate($hash, "CamIP", $data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'host'}); - readingsBulkUpdate($hash, "CamNTPServer", $data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'time_server'}); - readingsBulkUpdate($hash, "CamVendor", $data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camVendor'}); - readingsBulkUpdate($hash, "CamVideoType", $data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'camVideoType'}); - readingsBulkUpdate($hash, "CamPreRecTime", $data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camPreRecTime'}); - readingsBulkUpdate($hash, "CamPort", $data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'port'}); - readingsBulkUpdate($hash, "CamPtSpeed", $data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'ptSpeed'}) if($deviceType =~ /PTZ/x); - readingsBulkUpdate($hash, "CamblPresetSpeed", $data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'blPresetSpeed'}); - readingsBulkUpdate($hash, "CamVideoMirror", $data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'video_mirror'}); - readingsBulkUpdate($hash, "CamVideoFlip", $data{SSCam}{$name}{TMPDA}->{'data'}->{'cameras'}->[0]->{'video_flip'}); + readingsBulkUpdate($hash, "CamModel", $owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camModel'}); + readingsBulkUpdate($hash, "CamRecShare", $owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'camRecShare'}); + readingsBulkUpdate($hash, "CamRecVolume", $owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'camRecVolume'}); + readingsBulkUpdate($hash, "CamIP", $owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'host'}); + readingsBulkUpdate($hash, "CamNTPServer", $owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'time_server'}); + readingsBulkUpdate($hash, "CamVendor", $owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camVendor'}); + readingsBulkUpdate($hash, "CamVideoType", $owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'camVideoType'}); + readingsBulkUpdate($hash, "CamPreRecTime", $owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camPreRecTime'}); + readingsBulkUpdate($hash, "CamPort", $owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'port'}); + readingsBulkUpdate($hash, "CamPtSpeed", $owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'ptSpeed'}) if($deviceType =~ /PTZ/x); + readingsBulkUpdate($hash, "CamblPresetSpeed", $owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'blPresetSpeed'}); + readingsBulkUpdate($hash, "CamVideoMirror", $owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'video_mirror'}); + readingsBulkUpdate($hash, "CamVideoFlip", $owndata{TMPDA}->{'data'}->{'cameras'}->[0]->{'video_flip'}); readingsBulkUpdate($hash, "CamVideoRotate", $rotate); readingsBulkUpdate($hash, "CapPIR", $pdcap); readingsBulkUpdate($hash, "Availability", $camStatus); readingsBulkUpdate($hash, "DeviceType", $deviceType); readingsBulkUpdate($hash, "LastUpdateTime", $date.' / '.$time); readingsBulkUpdate($hash, "Record", $recStatus); - readingsBulkUpdate($hash, "UsedSpaceMB", $data{SSCam}{$name}{TMPDA}->{'data'}{'cameras'}[0]{'volume_space'}); - readingsBulkUpdate($hash, "VideoFolder", AttrVal($name, "videofolderMap", $data{SSCam}{$name}{TMPDA}->{'data'}{'cameras'}[0]{'folder'})); + readingsBulkUpdate($hash, "UsedSpaceMB", $owndata{TMPDA}->{'data'}{'cameras'}[0]{'volume_space'}); + readingsBulkUpdate($hash, "VideoFolder", AttrVal($name, "videofolderMap", $owndata{TMPDA}->{'data'}{'cameras'}[0]{'folder'})); readingsBulkUpdate($hash, "Errorcode", "none"); readingsBulkUpdate($hash, "Error", "none"); readingsEndUpdate($hash, 1); @@ -6916,15 +6941,15 @@ sub _parseGetptzlistpatrol { ## no critic "not used" my $camname = $paref->{camname}; my $hash = $defs{$name}; - my $patrolcnt = $data{SSCam}{$name}{TMPDA}->{'data'}->{'total'}; + my $patrolcnt = $owndata{TMPDA}->{'data'}->{'total'}; my $cnt = 0; delete $hash->{HELPER}{ALLPATROLS}; - while ($cnt < $patrolcnt) { # alle Patrols der Kamera mit Id's in Hash einlesen - my $patrolid = $data{SSCam}{$name}{TMPDA}->{'data'}->{'patrols'}->[$cnt]->{'id'}; - my $patrolname = $data{SSCam}{$name}{TMPDA}->{'data'}->{'patrols'}->[$cnt]->{'name'}; - $patrolname =~ s/\s+/_/gx; # Leerzeichen im Namen ersetzen falls vorhanden + while ($cnt < $patrolcnt) { # alle Patrols der Kamera mit Id's in Hash einlesen + my $patrolid = $owndata{TMPDA}->{'data'}->{'patrols'}->[$cnt]->{'id'}; + my $patrolname = $owndata{TMPDA}->{'data'}->{'patrols'}->[$cnt]->{'name'}; + $patrolname =~ s/\s+/_/gx; # Leerzeichen im Namen ersetzen falls vorhanden $hash->{HELPER}{ALLPATROLS}{$patrolname} = $patrolid; $cnt += 1; @@ -6939,9 +6964,9 @@ sub _parseGetptzlistpatrol { ## no critic "not used" readingsBulkUpdate ($hash, "Error", "none" ); readingsEndUpdate ($hash, 1); - $hash->{".ptzhtml"} = ""; # ptzPanel wird neu eingelesen in FWdetailFn + $hash->{".ptzhtml"} = ""; # ptzPanel wird neu eingelesen in FWdetailFn - Log3($name, $verbose, "$name - PTZ Patrols of camera $camname retrieved"); + Log3 ($name, $verbose, "$name - PTZ Patrols of camera $camname retrieved"); return; } @@ -6957,7 +6982,7 @@ sub _parseGetptzlistpreset { ## no critic "not used" my $camname = $paref->{camname}; my $hash = $defs{$name}; - my $presetcnt = $data{SSCam}{$name}{TMPDA}->{'data'}->{'total'}; + my $presetcnt = $owndata{TMPDA}->{'data'}->{'total'}; my $cnt = 0; # alle Presets der Kamera mit Id's in Assoziatives Array einlesen @@ -6965,9 +6990,9 @@ sub _parseGetptzlistpreset { ## no critic "not used" my $home = "not set"; while ($cnt < $presetcnt) { - my $presid = $data{SSCam}{$name}{TMPDA}->{'data'}->{'presets'}->[$cnt]->{'position'}; - my $presname = $data{SSCam}{$name}{TMPDA}->{'data'}->{'presets'}->[$cnt]->{'name'}; - my $ptype = $data{SSCam}{$name}{TMPDA}->{'data'}->{'presets'}->[$cnt]->{'type'}; + my $presid = $owndata{TMPDA}->{'data'}->{'presets'}->[$cnt]->{'position'}; + my $presname = $owndata{TMPDA}->{'data'}->{'presets'}->[$cnt]->{'name'}; + my $ptype = $owndata{TMPDA}->{'data'}->{'presets'}->[$cnt]->{'type'}; $presname =~ s/\s+/_/gx; # Leerzeichen im Namen ersetzen falls vorhanden $hash->{HELPER}{ALLPRESETS}{$presname} = "$presid"; @@ -7005,40 +7030,40 @@ sub _parseGetcapabilities { ## no critic "not used" my $camname = $paref->{camname}; my $hash = $defs{$name}; - my $ptzfocus = $data{SSCam}{$name}{TMPDA}->{'data'}{'ptzFocus'}; + my $ptzfocus = $owndata{TMPDA}->{'data'}{'ptzFocus'}; $ptzfocus = $hrkeys{ptzFocus}{$ptzfocus}; - my $ptztilt = $data{SSCam}{$name}{TMPDA}->{'data'}{'ptzTilt'}; + my $ptztilt = $owndata{TMPDA}->{'data'}{'ptzTilt'}; $ptztilt = $hrkeys{ptzTilt}{$ptztilt}; - my $ptzzoom = $data{SSCam}{$name}{TMPDA}->{'data'}{'ptzZoom'}; + my $ptzzoom = $owndata{TMPDA}->{'data'}{'ptzZoom'}; $ptzzoom = $hrkeys{ptzZoom}{$ptzzoom}; - my $ptzpan = $data{SSCam}{$name}{TMPDA}->{'data'}{'ptzPan'}; + my $ptzpan = $owndata{TMPDA}->{'data'}{'ptzPan'}; $ptzpan = $hrkeys{ptzPan}{$ptzpan}; - my $ptziris = $data{SSCam}{$name}{TMPDA}->{'data'}{'ptzIris'}; + my $ptziris = $owndata{TMPDA}->{'data'}{'ptzIris'}; $ptziris = $hrkeys{ptzIris}{$ptziris}; - $data{SSCam}{$name}{TMPDA}->{'data'}{'ptzHasObjTracking'} = jboolmap ($data{SSCam}{$name}{TMPDA}->{'data'}{'ptzHasObjTracking'}); - $data{SSCam}{$name}{TMPDA}->{'data'}{'audioOut'} = jboolmap ($data{SSCam}{$name}{TMPDA}->{'data'}{'audioOut'}); - $data{SSCam}{$name}{TMPDA}->{'data'}{'ptzSpeed'} = jboolmap ($data{SSCam}{$name}{TMPDA}->{'data'}{'ptzSpeed'}); - $data{SSCam}{$name}{TMPDA}->{'data'}{'ptzAbs'} = jboolmap ($data{SSCam}{$name}{TMPDA}->{'data'}{'ptzAbs'}); - $data{SSCam}{$name}{TMPDA}->{'data'}{'ptzAutoFocus'} = jboolmap ($data{SSCam}{$name}{TMPDA}->{'data'}{'ptzAutoFocus'}); - $data{SSCam}{$name}{TMPDA}->{'data'}{'ptzHome'} = jboolmap ($data{SSCam}{$name}{TMPDA}->{'data'}{'ptzHome'}); + $owndata{TMPDA}->{'data'}{'ptzHasObjTracking'} = jboolmap ($owndata{TMPDA}->{'data'}{'ptzHasObjTracking'}); + $owndata{TMPDA}->{'data'}{'audioOut'} = jboolmap ($owndata{TMPDA}->{'data'}{'audioOut'}); + $owndata{TMPDA}->{'data'}{'ptzSpeed'} = jboolmap ($owndata{TMPDA}->{'data'}{'ptzSpeed'}); + $owndata{TMPDA}->{'data'}{'ptzAbs'} = jboolmap ($owndata{TMPDA}->{'data'}{'ptzAbs'}); + $owndata{TMPDA}->{'data'}{'ptzAutoFocus'} = jboolmap ($owndata{TMPDA}->{'data'}{'ptzAutoFocus'}); + $owndata{TMPDA}->{'data'}{'ptzHome'} = jboolmap ($owndata{TMPDA}->{'data'}{'ptzHome'}); readingsBeginUpdate($hash); - readingsBulkUpdate ($hash,"CapPTZAutoFocus", $data{SSCam}{$name}{TMPDA}->{'data'}{'ptzAutoFocus'} ); - readingsBulkUpdate ($hash,"CapAudioOut", $data{SSCam}{$name}{TMPDA}->{'data'}{'audioOut'} ); - readingsBulkUpdate ($hash,"CapChangeSpeed", $data{SSCam}{$name}{TMPDA}->{'data'}{'ptzSpeed'} ); - readingsBulkUpdate ($hash,"CapPTZHome", $data{SSCam}{$name}{TMPDA}->{'data'}{'ptzHome'} ); - readingsBulkUpdate ($hash,"CapPTZAbs", $data{SSCam}{$name}{TMPDA}->{'data'}{'ptzAbs'} ); - readingsBulkUpdate ($hash,"CapPTZDirections", $data{SSCam}{$name}{TMPDA}->{'data'}{'ptzDirection'} ); + readingsBulkUpdate ($hash,"CapPTZAutoFocus", $owndata{TMPDA}->{'data'}{'ptzAutoFocus'} ); + readingsBulkUpdate ($hash,"CapAudioOut", $owndata{TMPDA}->{'data'}{'audioOut'} ); + readingsBulkUpdate ($hash,"CapChangeSpeed", $owndata{TMPDA}->{'data'}{'ptzSpeed'} ); + readingsBulkUpdate ($hash,"CapPTZHome", $owndata{TMPDA}->{'data'}{'ptzHome'} ); + readingsBulkUpdate ($hash,"CapPTZAbs", $owndata{TMPDA}->{'data'}{'ptzAbs'} ); + readingsBulkUpdate ($hash,"CapPTZDirections", $owndata{TMPDA}->{'data'}{'ptzDirection'} ); readingsBulkUpdate ($hash,"CapPTZFocus", $ptzfocus ); readingsBulkUpdate ($hash,"CapPTZIris", $ptziris ); - readingsBulkUpdate ($hash,"CapPTZObjTracking", $data{SSCam}{$name}{TMPDA}->{'data'}{'ptzHasObjTracking'} ); + readingsBulkUpdate ($hash,"CapPTZObjTracking", $owndata{TMPDA}->{'data'}{'ptzHasObjTracking'} ); readingsBulkUpdate ($hash,"CapPTZPan", $ptzpan ); - readingsBulkUpdate ($hash,"CapPTZPresetNumber", $data{SSCam}{$name}{TMPDA}->{'data'}{'ptzPresetNumber'} ); + readingsBulkUpdate ($hash,"CapPTZPresetNumber", $owndata{TMPDA}->{'data'}{'ptzPresetNumber'} ); readingsBulkUpdate ($hash,"CapPTZTilt", $ptztilt ); readingsBulkUpdate ($hash,"CapPTZZoom", $ptzzoom ); readingsBulkUpdate ($hash,"Errorcode", "none" ); @@ -7060,24 +7085,24 @@ sub _parsegetmotionenum { ## no critic "not used" my $camname = $paref->{camname}; my $hash = $defs{$name}; - my $motdetsc = $data{SSCam}{$name}{TMPDA}->{'data'}{'MDParam'}{'source'}; + my $motdetsc = $owndata{TMPDA}->{'data'}{'MDParam'}{'source'}; $motdetsc = $hrkeys{source}{$motdetsc}; - my $sensitivity_camCap = jboolmap ($data{SSCam}{$name}{TMPDA}->{'data'}{'MDParam'}{'sensitivity'}{'camCap'}); - my $sensitivity_value = $data{SSCam}{$name}{TMPDA}->{'data'}{'MDParam'}{'sensitivity'}{'value'}; - my $sensitivity_ssCap = jboolmap ($data{SSCam}{$name}{TMPDA}->{'data'}{'MDParam'}{'sensitivity'}{'ssCap'}); + my $sensitivity_camCap = jboolmap ($owndata{TMPDA}->{'data'}{'MDParam'}{'sensitivity'}{'camCap'}); + my $sensitivity_value = $owndata{TMPDA}->{'data'}{'MDParam'}{'sensitivity'}{'value'}; + my $sensitivity_ssCap = jboolmap ($owndata{TMPDA}->{'data'}{'MDParam'}{'sensitivity'}{'ssCap'}); - my $threshold_camCap = jboolmap ($data{SSCam}{$name}{TMPDA}->{'data'}{'MDParam'}{'threshold'}{'camCap'}); - my $threshold_value = $data{SSCam}{$name}{TMPDA}->{'data'}{'MDParam'}{'threshold'}{'value'}; - my $threshold_ssCap = jboolmap ($data{SSCam}{$name}{TMPDA}->{'data'}{'MDParam'}{'threshold'}{'ssCap'}); + my $threshold_camCap = jboolmap ($owndata{TMPDA}->{'data'}{'MDParam'}{'threshold'}{'camCap'}); + my $threshold_value = $owndata{TMPDA}->{'data'}{'MDParam'}{'threshold'}{'value'}; + my $threshold_ssCap = jboolmap ($owndata{TMPDA}->{'data'}{'MDParam'}{'threshold'}{'ssCap'}); - my $percentage_camCap = jboolmap ($data{SSCam}{$name}{TMPDA}->{'data'}{'MDParam'}{'percentage'}{'camCap'}); - my $percentage_value = $data{SSCam}{$name}{TMPDA}->{'data'}{'MDParam'}{'percentage'}{'value'}; - my $percentage_ssCap = jboolmap ($data{SSCam}{$name}{TMPDA}->{'data'}{'MDParam'}{'percentage'}{'ssCap'}); + my $percentage_camCap = jboolmap ($owndata{TMPDA}->{'data'}{'MDParam'}{'percentage'}{'camCap'}); + my $percentage_value = $owndata{TMPDA}->{'data'}{'MDParam'}{'percentage'}{'value'}; + my $percentage_ssCap = jboolmap ($owndata{TMPDA}->{'data'}{'MDParam'}{'percentage'}{'ssCap'}); - my $objectSize_camCap = jboolmap ($data{SSCam}{$name}{TMPDA}->{'data'}{'MDParam'}{'objectSize'}{'camCap'}); - my $objectSize_value = $data{SSCam}{$name}{TMPDA}->{'data'}{'MDParam'}{'objectSize'}{'value'}; - my $objectSize_ssCap = jboolmap ($data{SSCam}{$name}{TMPDA}->{'data'}{'MDParam'}{'objectSize'}{'ssCap'}); + my $objectSize_camCap = jboolmap ($owndata{TMPDA}->{'data'}{'MDParam'}{'objectSize'}{'camCap'}); + my $objectSize_value = $owndata{TMPDA}->{'data'}{'MDParam'}{'objectSize'}{'value'}; + my $objectSize_ssCap = jboolmap ($owndata{TMPDA}->{'data'}{'MDParam'}{'objectSize'}{'ssCap'}); if ($motdetsc eq "Camera") { if ($sensitivity_camCap) { @@ -7124,18 +7149,18 @@ sub _parsegeteventlist { ## no critic "not used" my $camname = $paref->{camname}; my $hash = $defs{$name}; - my $eventnum = $data{SSCam}{$name}{TMPDA}->{'data'}{'total'}; - my $lrec = $data{SSCam}{$name}{TMPDA}->{'data'}{'events'}[0]{name}; - my $lrecid = $data{SSCam}{$name}{TMPDA}->{'data'}{'events'}[0]{'eventId'}; + my $eventnum = $owndata{TMPDA}->{'data'}{'total'}; + my $lrec = $owndata{TMPDA}->{'data'}{'events'}[0]{name}; + my $lrecid = $owndata{TMPDA}->{'data'}{'events'}[0]{'eventId'}; my ($lastrecstarttime,$lastrecstoptime); if ($eventnum > 0) { - $lastrecstarttime = $data{SSCam}{$name}{TMPDA}->{'data'}{'events'}[0]{startTime}; + $lastrecstarttime = $owndata{TMPDA}->{'data'}{'events'}[0]{startTime}; my ($date, $time) = timestampToDateTime ($lastrecstarttime); $lastrecstarttime = $date.' / '.$time; - $lastrecstoptime = $data{SSCam}{$name}{TMPDA}->{'data'}{'events'}[0]{stopTime}; + $lastrecstoptime = $owndata{TMPDA}->{'data'}{'events'}[0]{stopTime}; ($date, $time) = timestampToDateTime ($lastrecstoptime); $lastrecstoptime = $time; } @@ -7188,12 +7213,13 @@ sub _parsegetsnapinfo { ## no critic "not used" my $camname = $paref->{camname}; my $hash = $defs{$name}; - my $lang = AttrVal('global', 'language', 'EN'); - my ($cache,@as); + my $lang = AttrVal ('global', 'language', 'EN'); + + my ($cache, @as); $paref->{aref} = \@as; - Log3($name, $verbose, "$name - Snapinfos of camera $camname retrieved"); + Log3 ($name, $verbose, "$name - Snapinfos of camera $camname retrieved"); __saveLastSnapToCache ($paref); # aktuellsten Snap in Cache zur Anzeige durch streamDev "lastsnap" speichern __doSnapRotation ($paref); # Rotationsfeature @@ -7216,12 +7242,14 @@ sub _parsegetsnapgallery { ## no critic "not used" my $camname = $paref->{camname}; my $hash = $defs{$name}; - my $lang = AttrVal("global", "language", "EN"); - my @as; + my $lang = AttrVal ('global', 'language', 'EN'); + + my (@as, %snapoldhash); - $paref->{aref} = \@as; + $paref->{aref} = \@as; + $paref->{snapoldhash} = \%snapoldhash; - Log3($name, $verbose, "$name - Snapinfos of camera $camname retrieved"); + Log3 ($name, $verbose, "$name - Snapinfos of camera $camname retrieved"); __saveLastSnapToCache ($paref); # aktuellsten Snap in Cache zur Anzeige durch streamDev "lastsnap" speichern __doSnapRotation ($paref); # Rotationsfeature @@ -7230,7 +7258,7 @@ sub _parsegetsnapgallery { ## no critic "not used" ##### transaktionaler Versand der erzeugten Schnappschüsse ##### ################################################################## if (canEmailSnap($hash) || canTeleSnap($hash) || canChatSnap($hash)) { # es soll die Anzahl "$hash->{HELPER}{SNAPNUM}" Schnappschüsse versendet werden - my $tac = openOrgetTrans($hash); # Transaktion vorhandenen Code holen + my $tac = openOrgetTrans ($hash); # Transaktion vorhandenen Code holen $paref->{tac} = $tac; my $sn = __insertSnapsToCache ($paref); # neu erzeugte Snaps in SNAPHASH eintragen @@ -7240,9 +7268,10 @@ sub _parsegetsnapgallery { ## no critic "not used" # Schnappschüsse als Email / Telegram / SSChatBot versenden ########################################################### - my $cache = cache($name, "c_init"); # Cache initialisieren + my $cache = cache ($name, "c_init"); # Cache initialisieren + if (!$cache || $cache eq "internal" ) { - prepareSendData ($hash, "getsnapgallery", $data{SSCam}{$name}{SENDSNAPS}{$tac}); + prepareSendData ($hash, "getsnapgallery", $owndata{SENDSNAPS}{$tac}); } else { prepareSendData ($hash, "getsnapgallery", "{SENDSNAPS}{$tac}"); @@ -7252,28 +7281,26 @@ sub _parsegetsnapgallery { ## no critic "not used" # Schnappschußgalerie wird bereitgestellt (Attr snapGalleryBoost=1) bzw. gleich angezeigt # (Attr snapGalleryBoost=0) !! kein Versand !! ######################################################################################### - $hash->{HELPER}{TOTALCNT} = $data{SSCam}{$name}{TMPDA}->{data}{total}; # total Anzahl Schnappschüsse + $hash->{HELPER}{TOTALCNT} = $owndata{TMPDA}->{data}{total}; # total Anzahl Schnappschüsse my $sn = __insertSnapsToCache ($paref); # neu erzeugte Snaps in SNAPHASH eintragen $paref->{sn} = $sn; __copySnapsBackFromOld ($paref); # gesicherte Schnappschußdaten aus SNAPOLDHASH an SNAPHASH anhängen - # Direktausgabe Snaphash wenn nicht gepollt wird - if (!AttrVal($name, 'snapGalleryBoost', $sgbdef)) { - my %pars = ( + if (!AttrVal($name, 'snapGalleryBoost', $sgbdef)) { # Direktausgabe Snaphash wenn nicht gepollt wird + my $pars = { linkparent => $name, linkname => '', ftui => 0 - ); + }; - my $htmlCode = composeGallery(\%pars); + my $htmlCode = composeGallery($pars); for (my $c=1; (defined($hash->{HELPER}{CL}{$c})); $c++ ) { - asyncOutput($hash->{HELPER}{CL}{$c},"$htmlCode"); + asyncOutput ($hash->{HELPER}{CL}{$c}, $htmlCode); } - - delete $data{SSCam}{$name}{SNAPHASH}; # Snaphash Referenz löschen + delClHash ($name); } } @@ -7281,7 +7308,6 @@ sub _parsegetsnapgallery { ## no critic "not used" setReadingErrorNone( $hash, 1 ); delete $hash->{HELPER}{GETSNAPGALLERY}; # Steuerbit getsnapgallery - delete $data{SSCam}{$name}{SNAPOLDHASH}; closeTrans ($hash); # Transaktion beenden __refreshAfterSnap ($hash); # fallabhängige Eventgenerierung @@ -7296,17 +7322,20 @@ sub __saveLastSnapToCache { my $paref = shift; my $name = $paref->{name}; - return if(!exists $data{SSCam}{$name}{TMPDA}->{data}{data}[0]{imageData}); # kein Snap vorhanden + delHashRefDeep ($data{SSCam}{$name}{LASTSNAP}); + delete $data{SSCam}{$name}{LASTSNAP}; + + return if(!exists $owndata{TMPDA}->{data}{data}[0]{imageData}); # kein Snap vorhanden my $cache = cache($name, "c_init"); # Cache initialisieren Log3 ($name, 1, "$name - Fall back to internal Cache due to preceding failure.") if(!$cache); if (!$cache || $cache eq "internal" ) { - $data{SSCam}{$name}{LASTSNAP} = $data{SSCam}{$name}{TMPDA}->{data}{data}[0]{imageData}; + $data{SSCam}{$name}{LASTSNAP} = $owndata{TMPDA}->{data}{data}[0]{imageData}; } else { - cache ($name, "c_write", "{LASTSNAP}", $data{SSCam}{$name}{TMPDA}->{data}{data}[0]{imageData}); + cache ($name, "c_write", "{LASTSNAP}", $owndata{TMPDA}->{data}{data}[0]{imageData}); } return; @@ -7326,16 +7355,16 @@ sub __doSnapRotation { my %snaps = ( 0 => {'createdTm' => 'n.a.', 'fileName' => 'n.a.','snapid' => 'n.a.'} ); # Hilfshash my ($k,$l) = (0,0); - if ($data{SSCam}{$name}{TMPDA}->{'data'}{'data'}[0]{'createdTm'}) { - while ($data{SSCam}{$name}{TMPDA}->{'data'}{'data'}[$k]) { + if ($owndata{TMPDA}->{'data'}{'data'}[0]{'createdTm'}) { + while ($owndata{TMPDA}->{'data'}{'data'}[$k]) { - if (!$data{SSCam}{$name}{TMPDA}->{'data'}{'data'}[$k]{'camName'} || - $data{SSCam}{$name}{TMPDA}->{'data'}{'data'}[$k]{'camName'} ne $camname) { # Forum:#97706 + if (!$owndata{TMPDA}->{'data'}{'data'}[$k]{'camName'} || + $owndata{TMPDA}->{'data'}{'data'}[$k]{'camName'} ne $camname) { # Forum:#97706 $k += 1; next; } - my @t = split " ", FmtDateTime ($data{SSCam}{$name}{TMPDA}->{data}{data}[$k]{createdTm}); + my @t = split " ", FmtDateTime ($owndata{TMPDA}->{data}{data}[$k]{createdTm}); my @d = split "-", $t[0]; my $createdTm; @@ -7347,10 +7376,10 @@ sub __doSnapRotation { } $snaps{$l}{createdTm} = $createdTm; - $snaps{$l}{fileName} = $data{SSCam}{$name}{TMPDA}->{data}{data}[$k]{fileName}; - $snaps{$l}{snapid} = $data{SSCam}{$name}{TMPDA}->{data}{data}[$k]{id}; + $snaps{$l}{fileName} = $owndata{TMPDA}->{data}{data}[$k]{fileName}; + $snaps{$l}{snapid} = $owndata{TMPDA}->{data}{data}[$k]{id}; - Log3 ($name,4, "$name - Snap [$l]: ID => $data{SSCam}{$name}{TMPDA}->{data}{data}[$k]{id}, File => $data{SSCam}{$name}{TMPDA}->{data}{data}[$k]{fileName}, Created => $createdTm"); + Log3 ($name,4, "$name - Snap [$l]: ID => $owndata{TMPDA}->{data}{data}[$k]{id}, File => $owndata{TMPDA}->{data}{data}[$k]{fileName}, Created => $createdTm"); $l += 1; $k += 1; @@ -7363,7 +7392,8 @@ sub __doSnapRotation { my $o = ReadingsVal ($name, "LastSnapId", "n.a."); if ($rotnum && "$o" ne "$snaps{0}{snapid}") { - @$aref = sort{$b<=>$a}keys %snaps; + @$aref = sort {$b<=>$a} keys %snaps; + for my $key (@$aref) { rotateReading ($hash, "LastSnapId", $snaps{$key}{snapid}, $rotnum, 1); rotateReading ($hash, "LastSnapFilename", $snaps{$key}{fileName}, $rotnum, 1); @@ -7371,7 +7401,8 @@ sub __doSnapRotation { } } else { - @$aref = sort{$a<=>$b}keys %snaps; + @$aref = sort {$a<=>$b} keys %snaps; + rotateReading ($hash, "LastSnapId", $snaps{$$aref[0]}{snapid}, $rotnum, 1); rotateReading ($hash, "LastSnapFilename", $snaps{$$aref[0]}{fileName}, $rotnum, 1); rotateReading ($hash, "LastSnapTime" , $snaps{$$aref[0]}{createdTm}, $rotnum, 1); @@ -7385,18 +7416,19 @@ return; # und in SNAPHASH löschen ############################################################################### sub __moveSnapCacheToOld { - my $paref = shift; - my $name = $paref->{name}; - my $aref = $paref->{aref}; + my $paref = shift; + my $name = $paref->{name}; + my $aref = $paref->{aref}; + my $snapoldhash = $paref->{snapoldhash}; - my $cache = cache($name, "c_init"); # Cache initialisieren + my $cache = cache ($name, "c_init"); # Cache initialisieren Log3 ($name, 1, "$name - Fall back to internal Cache due to preceding failure.") if(!$cache); if (!$cache || $cache eq "internal" ) { - if ($data{SSCam}{$name}{SNAPHASH}) { - for my $key (sort(keys%{$data{SSCam}{$name}{SNAPHASH}})) { - $data{SSCam}{$name}{SNAPOLDHASH}{$key} = delete $data{SSCam}{$name}{SNAPHASH}{$key}; + if (exists $data{SSCam}{$name}{SNAPHASH}) { + for my $key (sort keys %{$data{SSCam}{$name}{SNAPHASH}}) { + $snapoldhash->{$key} = delete $data{SSCam}{$name}{SNAPHASH}{$key}; } } } @@ -7409,28 +7441,26 @@ sub __moveSnapCacheToOld { } ); - my %seen; - my @unique = sort{$a<=>$b} grep { !$seen{$_}++ } @$aref; + my (%seen, $tmp); + my @unique = sort {$a<=>$b} grep { !$seen{$_}++ } @$aref; for my $key (@unique) { - $data{SSCam}{$name}{TMP} = cache($name, "c_read", "{SNAPHASH}{$key}{snapid}"); - cache ($name, "c_write", "{SNAPOLDHASH}{$key}{snapid}", $data{SSCam}{$name}{TMP}) if($data{SSCam}{$name}{TMP}); + $tmp = cache ($name, "c_read", "{SNAPHASH}{$key}{snapid}"); + cache ($name, "c_write", "{SNAPOLDHASH}{$key}{snapid}", $tmp) if($tmp); cache ($name, "c_remove", "{SNAPHASH}{$key}{snapid}"); - $data{SSCam}{$name}{TMP} = cache($name, "c_read", "{SNAPHASH}{$key}{createdTm}"); - cache ($name, "c_write", "{SNAPOLDHASH}{$key}{createdTm}", $data{SSCam}{$name}{TMP}) if($data{SSCam}{$name}{TMP}); + $tmp = cache ($name, "c_read", "{SNAPHASH}{$key}{createdTm}"); + cache ($name, "c_write", "{SNAPOLDHASH}{$key}{createdTm}", $tmp) if($tmp); cache ($name, "c_remove", "{SNAPHASH}{$key}{createdTm}"); - $data{SSCam}{$name}{TMP} = cache($name, "c_read", "{SNAPHASH}{$key}{fileName}"); - cache ($name, "c_write", "{SNAPOLDHASH}{$key}{fileName}", $data{SSCam}{$name}{TMP}) if($data{SSCam}{$name}{TMP}); + $tmp = cache ($name, "c_read", "{SNAPHASH}{$key}{fileName}"); + cache ($name, "c_write", "{SNAPOLDHASH}{$key}{fileName}", $tmp) if($tmp); cache ($name, "c_remove", "{SNAPHASH}{$key}{fileName}"); - $data{SSCam}{$name}{TMP} = cache($name, "c_read", "{SNAPHASH}{$key}{imageData}"); - cache ($name, "c_write", "{SNAPOLDHASH}{$key}{imageData}", $data{SSCam}{$name}{TMP}) if($data{SSCam}{$name}{TMP}); + $tmp = cache ($name, "c_read", "{SNAPHASH}{$key}{imageData}"); + cache ($name, "c_write", "{SNAPOLDHASH}{$key}{imageData}", $tmp) if($tmp); cache ($name, "c_remove", "{SNAPHASH}{$key}{imageData}"); } - - delete $data{SSCam}{$name}{TMP}; } return; @@ -7452,24 +7482,26 @@ sub __insertSnapsToCache { my $i = 0; my $sn = 0; - my $cache; + my ($cache, $createdTm); + + delHashRefDeep ($data{SSCam}{$name}{SNAPHASH}); + delete $data{SSCam}{$name}{SNAPHASH}; # vorhandenen Snaphash löschen - while ($data{SSCam}{$name}{TMPDA}->{'data'}{'data'}[$i]) { - if (!$data{SSCam}{$name}{TMPDA}->{'data'}{'data'}[$i]{'camName'} || - $data{SSCam}{$name}{TMPDA}->{'data'}{'data'}[$i]{'camName'} ne $camname) { # Forum:#97706 + while ($owndata{TMPDA}{'data'}{'data'}[$i]) { + if (!$owndata{TMPDA}{'data'}{'data'}[$i]{'camName'} || + $owndata{TMPDA}{'data'}{'data'}[$i]{'camName'} ne $camname) { # Forum:#97706 $i += 1; next; } - my $snapid = delete $data{SSCam}{$name}{TMPDA}->{data}{data}[$i]{id}; - my $fileName = delete $data{SSCam}{$name}{TMPDA}->{data}{data}[$i]{fileName}; - $data{SSCam}{$name}{TMP} = delete $data{SSCam}{$name}{TMPDA}->{data}{data}[$i]{imageData}; # Image data of snapshot in base64 format + my $snapid = delete $owndata{TMPDA}{data}{data}[$i]{id}; + my $fileName = delete $owndata{TMPDA}{data}{data}[$i]{fileName}; + my $imgdat = delete $owndata{TMPDA}{data}{data}[$i]{imageData}; # Image data of snapshot in base64 format - my @t = split(" ", FmtDateTime ($data{SSCam}{$name}{TMPDA}->{data}{data}[$i]{createdTm})); - my @d = split("-", $t[0]); - - my $createdTm; - if ($lang eq "DE") { + my @t = split " ", FmtDateTime ($owndata{TMPDA}{data}{data}[$i]{createdTm}); + my @d = split "-", $t[0]; + + if ($lang eq 'DE') { $createdTm = "$d[2].$d[1].$d[0] / $t[1]"; } else { @@ -7480,21 +7512,21 @@ sub __insertSnapsToCache { ############################################## if (canEmailSnap($hash) || canTeleSnap($hash) || canChatSnap($hash)) { if ($tac) { - $cache = cache($name, "c_init"); # Cache initialisieren + $cache = cache($name, "c_init"); # Cache initialisieren Log3 ($name, 1, "$name - Fall back to internal Cache due to preceding failure.") if(!$cache); if (!$cache || $cache eq "internal" ) { - $data{SSCam}{$name}{SENDSNAPS}{$tac}{$sn}{snapid} = $snapid; - $data{SSCam}{$name}{SENDSNAPS}{$tac}{$sn}{createdTm} = $createdTm; - $data{SSCam}{$name}{SENDSNAPS}{$tac}{$sn}{fileName} = $fileName; - $data{SSCam}{$name}{SENDSNAPS}{$tac}{$sn}{imageData} = $data{SSCam}{$name}{TMP}; + $owndata{SENDSNAPS}{$tac}{$sn}{snapid} = $snapid; + $owndata{SENDSNAPS}{$tac}{$sn}{createdTm} = $createdTm; + $owndata{SENDSNAPS}{$tac}{$sn}{fileName} = $fileName; + $owndata{SENDSNAPS}{$tac}{$sn}{imageData} = $imgdat; } else { cache ($name, "c_write", "{SENDSNAPS}{$tac}{$sn}{snapid}", $snapid); cache ($name, "c_write", "{SENDSNAPS}{$tac}{$sn}{createdTm}", $createdTm); cache ($name, "c_write", "{SENDSNAPS}{$tac}{$sn}{fileName}", $fileName); - cache ($name, "c_write", "{SENDSNAPS}{$tac}{$sn}{imageData}", $data{SSCam}{$name}{TMP}); + cache ($name, "c_write", "{SENDSNAPS}{$tac}{$sn}{imageData}", $imgdat); } Log3 ($name,4, "$name - Snap '$sn' (tac: $tac) added to send gallery hash: ID => $snapid, File => $fileName, Created => $createdTm"); @@ -7509,26 +7541,24 @@ sub __insertSnapsToCache { $cache = cache ($name, "c_init"); # Cache initialisieren Log3 ($name, 1, "$name - Fall back to internal Cache due to preceding failure.") if(!$cache); - + if (!$cache || $cache eq "internal" ) { $data{SSCam}{$name}{SNAPHASH}{$sn}{snapid} = $snapid; $data{SSCam}{$name}{SNAPHASH}{$sn}{createdTm} = $createdTm; $data{SSCam}{$name}{SNAPHASH}{$sn}{fileName} = $fileName; - $data{SSCam}{$name}{SNAPHASH}{$sn}{imageData} = $data{SSCam}{$name}{TMP}; + $data{SSCam}{$name}{SNAPHASH}{$sn}{imageData} = $imgdat; } else { - cache($name, "c_write", "{SNAPHASH}{$sn}{snapid}", $snapid ); - cache($name, "c_write", "{SNAPHASH}{$sn}{createdTm}", $createdTm); - cache($name, "c_write", "{SNAPHASH}{$sn}{fileName}", $fileName ); - cache($name, "c_write", "{SNAPHASH}{$sn}{imageData}", $data{SSCam}{$name}{TMP}); + cache ($name, "c_write", "{SNAPHASH}{$sn}{snapid}", $snapid ); + cache ($name, "c_write", "{SNAPHASH}{$sn}{createdTm}", $createdTm); + cache ($name, "c_write", "{SNAPHASH}{$sn}{fileName}", $fileName ); + cache ($name, "c_write", "{SNAPHASH}{$sn}{imageData}", $imgdat); } Log3 ($name, 4, "$name - Snap '$sn' added to gallery view hash: SN => $sn, ID => $snapid, File => $fileName, Created => $createdTm"); $sn += 1; $i += 1; - - delete $data{SSCam}{$name}{TMP}; } return $sn; @@ -7539,9 +7569,10 @@ return $sn; # Cache SNAPHASH anhängen ############################################################################### sub __copySnapsBackFromOld { - my $paref = shift; - my $name = $paref->{name}; - my $sn = $paref->{sn}; # letzte lfd. Nummer aktueller Snaphash + my $paref = shift; + my $name = $paref->{name}; + my $sn = $paref->{sn}; # letzte lfd. Nummer aktueller Snaphash + my $snapoldhash = $paref->{snapoldhash}; my $hash = $defs{$name}; my $snapnum = $hash->{HELPER}{SNAPLIMIT} // $defSlim; @@ -7549,44 +7580,44 @@ sub __copySnapsBackFromOld { my $ss = $sn; $sn = 0; - my $cache = cache($name, "c_init"); # Cache initialisieren + my $cache = cache ($name, 'c_init'); # Cache initialisieren Log3 ($name, 1, "$name - Fall back to internal Cache due to preceding failure.") if(!$cache); - if (!$cache || $cache eq "internal" ) { - if ($data{SSCam}{$name}{SNAPOLDHASH} && $sgn > $ss) { + if (!$cache || $cache eq 'internal' ) { + if ($snapoldhash && $sgn > $ss) { for my $kn ($ss..($sgn-1)) { - $data{SSCam}{$name}{SNAPHASH}{$kn}{snapid} = delete $data{SSCam}{$name}{SNAPOLDHASH}{$sn}{snapid}; - $data{SSCam}{$name}{SNAPHASH}{$kn}{createdTm} = delete $data{SSCam}{$name}{SNAPOLDHASH}{$sn}{createdTm}; - $data{SSCam}{$name}{SNAPHASH}{$kn}{fileName} = delete $data{SSCam}{$name}{SNAPOLDHASH}{$sn}{fileName}; - $data{SSCam}{$name}{SNAPHASH}{$kn}{imageData} = delete $data{SSCam}{$name}{SNAPOLDHASH}{$sn}{imageData}; - + $data{SSCam}{$name}{SNAPHASH}{$kn}{snapid} = delete $snapoldhash->{$sn}{snapid}; + $data{SSCam}{$name}{SNAPHASH}{$kn}{createdTm} = delete $snapoldhash->{$sn}{createdTm}; + $data{SSCam}{$name}{SNAPHASH}{$kn}{fileName} = delete $snapoldhash->{$sn}{fileName}; + $data{SSCam}{$name}{SNAPHASH}{$kn}{imageData} = delete $snapoldhash->{$sn}{imageData}; + $sn += 1; } } } else { + my $tmp; + for my $kn ($ss..($sgn-1)) { - $data{SSCam}{$name}{TMP} = cache($name, "c_read", "{SNAPOLDHASH}{$sn}{snapid}"); - cache ($name, "c_write", "{SNAPHASH}{$kn}{snapid}", $data{SSCam}{$name}{TMP}) if($data{SSCam}{$name}{TMP}); + $tmp = cache ($name, "c_read", "{SNAPOLDHASH}{$sn}{snapid}"); + cache ($name, "c_write", "{SNAPHASH}{$kn}{snapid}", $tmp) if($tmp); cache ($name, "c_remove", "{SNAPOLDHASH}{$sn}{snapid}"); - $data{SSCam}{$name}{TMP} = cache($name, "c_read", "{SNAPOLDHASH}{$sn}{createdTm}"); - cache ($name, "c_write", "{SNAPHASH}{$kn}{createdTm}", $data{SSCam}{$name}{TMP}) if($data{SSCam}{$name}{TMP}); + $tmp = cache ($name, "c_read", "{SNAPOLDHASH}{$sn}{createdTm}"); + cache ($name, "c_write", "{SNAPHASH}{$kn}{createdTm}", $tmp) if($tmp); cache ($name, "c_remove", "{SNAPOLDHASH}{$sn}{createdTm}"); - $data{SSCam}{$name}{TMP} = cache($name, "c_read", "{SNAPOLDHASH}{$sn}{fileName}"); - cache ($name, "c_write", "{SNAPHASH}{$kn}{fileName}", $data{SSCam}{$name}{TMP}) if($data{SSCam}{$name}{TMP}); + $tmp = cache ($name, "c_read", "{SNAPOLDHASH}{$sn}{fileName}"); + cache ($name, "c_write", "{SNAPHASH}{$kn}{fileName}", $tmp) if($tmp); cache ($name, "c_remove", "{SNAPOLDHASH}{$sn}{fileName}" ); - $data{SSCam}{$name}{TMP} = cache($name, "c_read", "{SNAPOLDHASH}{$sn}{imageData}"); - cache ($name, "c_write", "{SNAPHASH}{$kn}{imageData}", $data{SSCam}{$name}{TMP}) if($data{SSCam}{$name}{TMP}); + $tmp = cache ($name, "c_read", "{SNAPOLDHASH}{$sn}{imageData}"); + cache ($name, "c_write", "{SNAPHASH}{$kn}{imageData}", $tmp) if($tmp); cache ($name, "c_remove", "{SNAPOLDHASH}{$sn}{imageData}"); $sn += 1; } - - delete $data{SSCam}{$name}{TMP}; } return; @@ -8044,7 +8075,7 @@ sub streamDev { ## no critic 'comp my ($ttmjpegrun, $tthlsrun, $ttlrrun, $tth264run, $ttlmjpegrun, $ttlsnaprun); # Hinweis Popups - if(AttrVal("global","language","EN") =~ /EN/x) { + if (AttrVal("global","language","EN") =~ /EN/x) { $ttrefresh = $ttips_en{"ttrefresh"}; $ttrefresh =~ s/§NAME§/$calias/gx; $ttrecstart = $ttips_en{"ttrecstart"}; $ttrecstart =~ s/§NAME§/$calias/gx; $ttrecstop = $ttips_en{"ttrecstop"}; $ttrecstop =~ s/§NAME§/$calias/gx; @@ -8166,7 +8197,7 @@ sub streamDev { ## no critic 'comp my $ismm = IsModelMaster($omodel); # prüfen ob Streaming Dev ist MODEL = master - if(!$ismm && (!$StmKey || ReadingsVal($camname, "Availability", "") ne "enabled" || IsDisabled($camname))) { + if (!$ismm && (!$StmKey || ReadingsVal($camname, "Availability", "") ne "enabled" || IsDisabled($camname))) { # Ausgabe bei Fehler my $cam = AttrVal($camname, "alias", $camname); # Linktext als Aliasname oder Devicename setzen $cause = !$StmKey ? "Camera $cam has no Reading \"StmKey\" set !" : "Cam \"$cam\" is disabled"; @@ -8181,7 +8212,7 @@ sub streamDev { ## no critic 'comp # Streaming ausführen no strict "refs"; ## no critic 'NoStrict' - if($sdfn{$fmt}) { + if ($sdfn{$fmt}) { $ret .= &{$sdfn{$fmt}{fn}} (\%params) if(defined &{$sdfn{$fmt}{fn}}); } else { @@ -8367,6 +8398,7 @@ sub _streamDevLASTSNAP { ## no critic 'not $ret .= "
$cause

"; } + delHashRefDeep ($data{SSCam}{$camname}{TMPLSN}); delete $data{SSCam}{$camname}{TMPLSN}; return $ret; @@ -9173,9 +9205,9 @@ sub composeGallery { my $hash = $defs{$name}; my $camname = $hash->{CAMNAME}; - my $sgc = AttrVal ($name, "snapGalleryColumns", $defColumns); # Anzahl der Images in einer Tabellenzeile - my $lss = ReadingsVal ($name, "LastSnapTime", "" ); # Zeitpunkt neueste Aufnahme - my $lang = AttrVal ("global", "language", "EN" ); # Systemsprache + my $sgc = AttrVal ($name, 'snapGalleryColumns', $defColumns); # Anzahl der Images in einer Tabellenzeile + my $lss = ReadingsVal ($name, 'LastSnapTime', ''); # Zeitpunkt neueste Aufnahme + my $lang = AttrVal ('global', 'language', 'EN'); # Systemsprache my $uuid = ""; my $hdrAlign = "center"; @@ -9185,7 +9217,7 @@ sub composeGallery { $lupt =~ s{ }{ / }; my $totalcnt = $hash->{HELPER}{TOTALCNT}; # totale in SVS vorhandene Anzahl Snaps - my $limit = AttrVal ($name, "snapGalleryNumber", $hash->{HELPER}{SNAPLIMIT}) // $defSlim; # maximale Anzahl anzuzeigende Schnappschüsse + my $limit = AttrVal ($name, 'snapGalleryNumber', $hash->{HELPER}{SNAPLIMIT}) // $defSlim; # maximale Anzahl anzuzeigende Schnappschüsse $limit = $totalcnt < $limit ? $totalcnt : $limit; my ($alias,$dlink,$hb) = ("","",""); @@ -9194,10 +9226,11 @@ sub composeGallery { if ($strmdev) { my $streamHash = $defs{$strmdev}; # Hash des SSCamSTRM-Devices $uuid = $streamHash->{FUUID}; # eindeutige UUID des Streamingdevices + $alias = AttrVal ($strmdev, 'alias', $strmdev); # Linktext als Aliasname oder Devicename setzen + delete $streamHash->{HELPER}{STREAM}; - $alias = AttrVal($strmdev, "alias", $strmdev); # Linktext als Aliasname oder Devicename setzen - - if (AttrVal($strmdev, "noLink", 0)) { + + if (AttrVal ($strmdev, 'noLink', 0)) { $dlink = $alias; # keine Links im Stream-Dev generieren } else { @@ -9208,28 +9241,29 @@ sub composeGallery { my $cmddosnap = "FW_cmd('$FW_ME$FW_subdir?XHR=1&cmd=set $name snap 1 2 STRM:$uuid')"; # Snapshot auslösen mit Kennzeichnung "by STRM-Device" my $imgdosnap = ""; - # bei Aufruf durch FTUI Kommandosyntax anpassen - if ($ftui) { + if ($ftui) { # bei Aufruf durch FTUI Kommandosyntax anpassen $cmddosnap = "ftui.setFhemStatus('set $name snap 1 2 STRM:$uuid')"; } my $ha = AttrVal ($name, "snapGalleryHtmlAttr", AttrVal ($name, "htmlattr", 'width="500" height="325"')); - # falls "composeGallery" durch ein SSCamSTRM-Device aufgerufen wird - my $pws = ""; + # falls durch ein SSCamSTRM-Device aufgerufen + ############################################### + my $pws = ""; + if ($strmdev) { - $pws = AttrVal ($strmdev, "popupWindowSize", ""); # Größe eines Popups (umgelegt: Forum:https://forum.fhem.de/index.php/topic,45671.msg927912.html#msg927912) + $pws = AttrVal ($strmdev, 'popupWindowSize', ''); # Größe eines Popups (umgelegt: Forum:https://forum.fhem.de/index.php/topic,45671.msg927912.html#msg927912) $pws =~ s/"//xg if($pws); - $ha = AttrVal ($strmdev, "htmlattr", $ha); # htmlattr vom SSCamSTRM-Device übernehmen falls von SSCamSTRM-Device aufgerufen und gesetzt - $hb = AttrVal ($strmdev, "hideButtons", 0); # Drucktasten im unteren Bereich ausblenden ? + $ha = AttrVal ($strmdev, 'htmlattr', $ha); # htmlattr vom SSCamSTRM-Device übernehmen falls von SSCamSTRM-Device aufgerufen und gesetzt + $hb = AttrVal ($strmdev, 'hideButtons', 0); # Drucktasten im unteren Bereich ausblenden ? if ($ftui) { $ha = AttrVal ($strmdev, "htmlattrFTUI", $ha); # wenn aus FTUI aufgerufen divers setzen } } - # wenn SSCamSTRM-device genutzt wird und attr "snapGalleryBoost" nicht gesetzt ist -> Warnung in Gallerie ausgeben - my $sgbnote = " "; + my $sgbnote = ' '; # wenn SSCamSTRM-device genutzt wird und attr "snapGalleryBoost" nicht gesetzt ist -> Warnung in Gallerie ausgeben + if ($strmdev && !AttrVal($name, 'snapGalleryBoost', $sgbdef)) { $sgbnote = "CAUTION - The gallery is not updated automatically. Please set the attribute \"snapGalleryBoost=1\" in device $name"; $sgbnote = "ACHTUNG - Die Galerie wird nicht automatisch aktualisiert. Dazu bitte das Attribut \"snapGalleryBoost=1\" im Device $name setzen." if($lang eq "DE"); @@ -9241,14 +9275,14 @@ sub composeGallery { $ttsnap = $ttips_de{"ttsnap"}; $ttsnap =~ s/§NAME§/$camname/xg; } - # Header Generierung - my $header; + my $header; # Header Generierung + if ($strmdev) { # Forum: https://forum.fhem.de/index.php/topic,45671.msg975610.html#msg975610 if ($ftui) { - $header .= "$dlink
" if(!AttrVal ($strmdev,"hideDisplayNameFTUI",0)); + $header .= "$dlink
" if(!AttrVal ($strmdev, 'hideDisplayNameFTUI', 0)); } else { - $header .= "$dlink
" if(!AttrVal ($strmdev,"hideDisplayName",0)); + $header .= "$dlink
" if(!AttrVal ($strmdev, 'hideDisplayName', 0)); } } @@ -9275,12 +9309,12 @@ sub composeGallery { $htmlCode .= ""; my $cell = 1; - # my $idata = ""; # Bildaten aus Cache abrufen ############################ - my $count; - $cache = cache($name, "c_init"); # Cache initialisieren + my ($count, $tmp, $tmpcdat); + + $cache = cache ($name, "c_init"); # Cache initialisieren Log3 ($name, 1, "$name - Fall back to internal Cache due to preceding failure.") if(!$cache); @@ -9289,30 +9323,32 @@ sub composeGallery { $htmlCode =~ s{_LIMIT_}{$count}xms; # Platzhalter Snapanzahl im Header mit realem Wert ersetzen my $i = 1; - for my $key (sort{$a<=>$b}keys %{$data{SSCam}{$name}{SNAPHASH}}) { + for my $key (sort {$a<=>$b} keys %{$data{SSCam}{$name}{SNAPHASH}}) { + my $cttm = $data{SSCam}{$name}{SNAPHASH}{$key}{createdTm} // ''; + my $imgd = $data{SSCam}{$name}{SNAPHASH}{$key}{imageData} // ''; + if ($i > $limit) { $count = $limit; last; } if (!$ftui) { - $data{SSCam}{$name}{TMPIDAT} = "onClick=\"FW_okDialog('')\"" if(AttrVal($name, 'snapGalleryBoost', $sgbdef)); + $tmp = "onClick=\"FW_okDialog('')\"" if(AttrVal($name, 'snapGalleryBoost', $sgbdef)); } - $data{SSCam}{$name}{TMPIDAT} = '' if(!defined $data{SSCam}{$name}{TMPIDAT}); + $tmp = '' if(!defined $tmp); $cell++; if ($cell == $sgc + 1) { - $htmlCode .= sprintf("$data{SSCam}{$name}{SNAPHASH}{$key}{createdTm}
" ); + $htmlCode .= sprintf("$cttm
" ); $htmlCode .= ""; $htmlCode .= ""; $cell = 1; } else { - $htmlCode .= sprintf("$data{SSCam}{$name}{SNAPHASH}{$key}{createdTm}
" ); + $htmlCode .= sprintf("$cttm
" ); } - - delete $data{SSCam}{$name}{TMPIDAT}; + $i++; } } @@ -9336,27 +9372,26 @@ sub composeGallery { last; } - $data{SSCam}{$name}{TMPCDAT} = cache ($name, "c_read", "{SNAPHASH}{$key}{imageData}"); - $imgTm = cache ($name, "c_read", "{SNAPHASH}{$key}{createdTm}"); + $tmpcdat = cache ($name, "c_read", "{SNAPHASH}{$key}{imageData}"); + $imgTm = cache ($name, "c_read", "{SNAPHASH}{$key}{createdTm}"); if (!$ftui) { - $data{SSCam}{$name}{TMPIDAT} = "onClick=\"FW_okDialog('')\"" if(AttrVal ($name, 'snapGalleryBoost', $sgbdef)); + $tmp = "onClick=\"FW_okDialog('')\"" if(AttrVal ($name, 'snapGalleryBoost', $sgbdef)); } - $data{SSCam}{$name}{TMPIDAT} = '' if(!defined $data{SSCam}{$name}{TMPIDAT}); + $tmp = '' if(!defined $tmp); $cell++; if ($cell == $sgc + 1) { - $htmlCode .= sprintf ("$imgTm
" ); + $htmlCode .= sprintf ("$imgTm
" ); $htmlCode .= ""; $htmlCode .= ""; $cell = 1; } else { - $htmlCode .= sprintf ("$imgTm
" ); + $htmlCode .= sprintf ("$imgTm
" ); } - - delete $data{SSCam}{$name}{TMPIDAT}; + $i++; } } @@ -9380,9 +9415,6 @@ sub composeGallery { $htmlCode .= ""; $htmlCode .= ""; - delete $data{SSCam}{$name}{TMPCDAT}; - delete $data{SSCam}{$name}{TMPIDAT}; - return $htmlCode; } @@ -9562,7 +9594,7 @@ sub ptzPanel { else { # $FW_ME = URL-Pfad unter dem der FHEMWEB-Server via HTTP erreichbar ist, z.B. /fhem my $iPath = FW_iconPath($img); # automatisches Suchen der Icons im FHEMWEB iconPath - if($iPath) { + if ($iPath) { $iPath = "$FW_ME/$FW_icondir/$iPath"; } else { @@ -9782,7 +9814,7 @@ sub prepareSendData { # Bilddaten werden erst zum Versand weitergeleitet wenn Schnappshußhash komplett gefüllt ist my $asref; - my @allsvs = devspec2array("TYPE=SSCam:FILTER=MODEL=SVS"); + my @allsvs = devspec2array ("TYPE=SSCam:FILTER=MODEL=SVS"); for my $svs (@allsvs) { my $svshash; @@ -9848,24 +9880,25 @@ sub prepareSendData { my $cache = cache($name, "c_init"); # Cache initialisieren (im SVS Device) if (!$cache || $cache eq "internal" ) { - delete $data{SSCam}{RS}; + delHashRefDeep ($owndata{RS}); + delete $owndata{RS}; - for my $key (keys%{$asref}) { # Referenz zum summarischen Hash einsetzen - $data{SSCam}{RS}{$key} = delete $asref->{$key}; + for my $key (keys %{$asref}) { # Referenz zum summarischen Hash einsetzen + $owndata{RS}{$key} = delete $asref->{$key}; } - $dat = $data{SSCam}{RS}; # Referenz zum summarischen Hash einsetzen + $dat = $owndata{RS}; # Referenz zum summarischen Hash einsetzen } else { cache ($name, 'c_clear'); for my $key (keys%{$asref}) { - cache($name, "c_write", "{RS}{multiple_snapsend}{$key}{createdTm}", delete $asref->{$key}{createdTm}); - cache($name, "c_write", "{RS}{multiple_snapsend}{$key}{imageData}", delete $asref->{$key}{imageData}); - cache($name, "c_write", "{RS}{multiple_snapsend}{$key}{fileName}", delete $asref->{$key}{fileName}); + cache ($name, "c_write", "{RS}{multiple_snapsend}{$key}{createdTm}", delete $asref->{$key}{createdTm}); + cache ($name, "c_write", "{RS}{multiple_snapsend}{$key}{imageData}", delete $asref->{$key}{imageData}); + cache ($name, "c_write", "{RS}{multiple_snapsend}{$key}{fileName}", delete $asref->{$key}{fileName}); } - $dat = "{RS}{multiple_snapsend}"; # Referenz zum summarischen Hash einsetzen + $dat = "{RS}{multiple_snapsend}"; # Identifier des summarischen Hash einsetzen } $calias = AttrVal ($name, 'alias', $hash->{NAME}); # Alias des SVS-Devices @@ -9884,18 +9917,18 @@ sub prepareSendData { $smtpsslport = AttrVal($name,"smtpSSLPort",0); } - $tac = $hash->{HELPER}{TRANSACTION}; # Code der laufenden Transaktion - $data{SSCam}{$name}{SENDCOUNT}{$tac} = 0; # Hilfszähler Senden, init -> +1 , done -> -1, keine Daten - # d. Transaktion werden gelöscht bis Zähler wieder 0 !! (siehe closeTrans) + $tac = $hash->{HELPER}{TRANSACTION}; # Code der laufenden Transaktion + $owndata{SENDCOUNT}{$tac} = 0; # Hilfszähler Senden, init -> +1 , done -> -1, keine Daten + # d. Transaktion werden gelöscht bis Zähler wieder 0 !! (siehe closeTrans) - Log3 ($name, 1, "$name - Send Counter transaction \"$tac\": ".$data{SSCam}{$name}{SENDCOUNT}{$tac}.' (initialized)') if(AttrVal($name, 'debugactivetoken', 0)); + Log3 ($name, 1, "$name - Send Counter transaction \"$tac\": ".$owndata{SENDCOUNT}{$tac}.' (initialized)') if(AttrVal($name, 'debugactivetoken', 0)); ### Schnappschüsse als Email versenden ######################################## if ($OpMode =~ /^getsnap/x && canEmailSnap($hash)) { - $data{SSCam}{$name}{SENDCOUNT}{$tac}++; + $owndata{SENDCOUNT}{$tac}++; - Log3 ($name, 1, "$name - Send Counter transaction \"$tac\": ".$data{SSCam}{$name}{SENDCOUNT}{$tac}." (start eMail)") if(AttrVal($name, "debugactivetoken", 0)); + Log3 ($name, 1, "$name - Send Counter transaction \"$tac\": ".$owndata{SENDCOUNT}{$tac}." (start eMail)") if(AttrVal($name, "debugactivetoken", 0)); my $mt = delete $hash->{HELPER}{SMTPMSG}; @@ -9928,9 +9961,9 @@ sub prepareSendData { ### Aufnahmen als Email versenden ################################### if ($OpMode =~ /^GetRec/x && canEmailRec($hash)) { - $data{SSCam}{$name}{SENDCOUNT}{$tac}++; + $owndata{SENDCOUNT}{$tac}++; - Log3 ($name, 1, "$name - Send Counter transaction \"$tac\": ".$data{SSCam}{$name}{SENDCOUNT}{$tac}." (start eMail)") if(AttrVal($name, 'debugactivetoken', 0)); + Log3 ($name, 1, "$name - Send Counter transaction \"$tac\": ".$owndata{SENDCOUNT}{$tac}." (start eMail)") if(AttrVal($name, 'debugactivetoken', 0)); my $mt = delete $hash->{HELPER}{SMTPRECMSG}; @@ -9967,9 +10000,9 @@ sub prepareSendData { # tbot => , peers => , subject => ################################################################################################ if ($OpMode =~ /^getsnap/x && canTeleSnap($hash)) { - $data{SSCam}{$name}{SENDCOUNT}{$tac}++; + $owndata{SENDCOUNT}{$tac}++; - Log3 ($name, 1, "$name - Send Counter transaction \"$tac\": ".$data{SSCam}{$name}{SENDCOUNT}{$tac}." (start Telegram)") if(AttrVal($name,"debugactivetoken",0)); + Log3 ($name, 1, "$name - Send Counter transaction \"$tac\": ".$owndata{SENDCOUNT}{$tac}." (start Telegram)") if(AttrVal($name,"debugactivetoken",0)); my $mt = delete $hash->{HELPER}{TELEMSG}; @@ -9982,18 +10015,18 @@ sub prepareSendData { }; my $telemsg = _prepSendTelegram ($param); - $ret = _sendTelegram($hash, { - 'subject' => $telemsg->{subject}, - 'part2type' => 'image/jpeg', - 'sdat' => $dat, - 'opmode' => $OpMode, - 'tac' => $tac, - 'telebot' => $telemsg->{tbot}, - 'peers' => $telemsg->{peers}, - 'option' => $telemsg->{option}, # Versandoptionen - 'MediaStream' => '-1', # Code für MediaStream im TelegramBot (png/jpg = -1) - } - ); + $ret = _sendTelegram ($hash, { + 'subject' => $telemsg->{subject}, + 'part2type' => 'image/jpeg', + 'sdat' => $dat, + 'opmode' => $OpMode, + 'tac' => $tac, + 'telebot' => $telemsg->{tbot}, + 'peers' => $telemsg->{peers}, + 'option' => $telemsg->{option}, # Versandoptionen + 'MediaStream' => '-1', # Code für MediaStream im TelegramBot (png/jpg = -1) + } + ); readingsSingleUpdate ($hash, "sendTeleState", $ret, 1) if ($ret); } @@ -10005,9 +10038,9 @@ sub prepareSendData { # tbot => , peers => , subject => ################################################################################################# if ($OpMode =~ /^GetRec/x && canTeleRec($hash)) { - $data{SSCam}{$name}{SENDCOUNT}{$tac}++; + $owndata{SENDCOUNT}{$tac}++; - Log3 ($name, 1, "$name - Send Counter transaction \"$tac\": ".$data{SSCam}{$name}{SENDCOUNT}{$tac}." (start Telegram)") if(AttrVal($name,"debugactivetoken",0)); + Log3 ($name, 1, "$name - Send Counter transaction \"$tac\": ".$owndata{SENDCOUNT}{$tac}." (start Telegram)") if(AttrVal($name,"debugactivetoken",0)); my $mt = delete $hash->{HELPER}{TELERECMSG}; @@ -10021,17 +10054,17 @@ sub prepareSendData { my $telemsg = _prepSendTelegram ($param); $vdat = $dat; - $ret = _sendTelegram($hash, { - 'subject' => $telemsg->{subject}, - 'vdat' => $vdat, - 'opmode' => $OpMode, - 'telebot' => $telemsg->{tbot}, - 'peers' => $telemsg->{peers}, - 'option' => $telemsg->{option}, # Versandoptionen - 'tac' => $tac, - 'MediaStream' => '-30', # Code für MediaStream im TelegramBot (png/jpg = -1) - } - ); + $ret = _sendTelegram ($hash, { + 'subject' => $telemsg->{subject}, + 'vdat' => $vdat, + 'opmode' => $OpMode, + 'telebot' => $telemsg->{tbot}, + 'peers' => $telemsg->{peers}, + 'option' => $telemsg->{option}, # Versandoptionen + 'tac' => $tac, + 'MediaStream' => '-30', # Code für MediaStream im TelegramBot (png/jpg = -1) + } + ); readingsSingleUpdate ($hash, "sendTeleState", $ret, 1) if ($ret); } @@ -10042,9 +10075,9 @@ sub prepareSendData { # peers => , subject => " ############################################################################################# if ($OpMode =~ /^getsnap/x && canChatSnap($hash)) { - $data{SSCam}{$name}{SENDCOUNT}{$tac}++; + $owndata{SENDCOUNT}{$tac}++; - Log3 ($name, 1, "$name - Send Counter transaction \"$tac\": ".$data{SSCam}{$name}{SENDCOUNT}{$tac}." (start Chat)") if(AttrVal($name, 'debugactivetoken', 0)); + Log3 ($name, 1, "$name - Send Counter transaction \"$tac\": ".$owndata{SENDCOUNT}{$tac}." (start Chat)") if(AttrVal($name, 'debugactivetoken', 0)); my $mt = delete $hash->{HELPER}{CHATMSG}; @@ -10057,15 +10090,15 @@ sub prepareSendData { }; my $chatmsg = _prepSendChat ($param); - $ret = _sendChat($hash, { - 'subject' => $chatmsg->{subject}, - 'opmode' => $OpMode, - 'tac' => $tac, - 'sdat' => $dat, - 'chatbot' => $chatmsg->{chatbot}, - 'peers' => $chatmsg->{peers}, - } - ); + $ret = _sendChat ($hash, { + 'subject' => $chatmsg->{subject}, + 'opmode' => $OpMode, + 'tac' => $tac, + 'sdat' => $dat, + 'chatbot' => $chatmsg->{chatbot}, + 'peers' => $chatmsg->{peers}, + } + ); readingsSingleUpdate ($hash, "sendChatState", $ret, 1) if ($ret); } @@ -10076,9 +10109,9 @@ sub prepareSendData { # peers => , subject => ################################################################################### if ($OpMode =~ /^GetRec/x && canChatRec($hash)) { - $data{SSCam}{$name}{SENDCOUNT}{$tac}++; + $owndata{SENDCOUNT}{$tac}++; - Log3 ($name, 1, "$name - Send Counter transaction \"$tac\": ".$data{SSCam}{$name}{SENDCOUNT}{$tac}." (start Chat)") if(AttrVal($name,"debugactivetoken",0)); + Log3 ($name, 1, "$name - Send Counter transaction \"$tac\": ".$owndata{SENDCOUNT}{$tac}." (start Chat)") if(AttrVal($name,"debugactivetoken",0)); my $mt = delete $hash->{HELPER}{CHATRECMSG}; @@ -10091,17 +10124,17 @@ sub prepareSendData { }; my $chatmsg = _prepSendChat ($param); - $ret = _sendChat($hash, { - 'subject' => $chatmsg->{subject}, - 'opmode' => $OpMode, - 'tac' => $tac, - 'vdat' => $dat, - 'chatbot' => $chatmsg->{chatbot}, - 'peers' => $chatmsg->{peers}, - } - ); + $ret = _sendChat ($hash, { + 'subject' => $chatmsg->{subject}, + 'opmode' => $OpMode, + 'tac' => $tac, + 'vdat' => $dat, + 'chatbot' => $chatmsg->{chatbot}, + 'peers' => $chatmsg->{peers}, + } + ); - readingsSingleUpdate ($hash, 'sendChatState', $ret, 1) if ($ret); + readingsSingleUpdate ($hash, 'sendChatState', $ret, 1) if($ret); } closeTrans ($hash) if($hash->{HELPER}{TRANSACTION} eq "multiple_snapsend"); # Transaction Sammelversand (SVS) schließen, Daten bereinigen @@ -10155,8 +10188,9 @@ return \%chatmsg; sub _sendChat { my ($hash, $extparamref) = @_; my $name = $hash->{NAME}; - my $type = AttrVal($name,"cacheType","internal"); + my $type = AttrVal ($name, 'cacheType', 'internal'); my $mtype = ""; + my ($params,$ret,$cache); Log3($name, 4, "$name - ####################################################"); @@ -10177,24 +10211,24 @@ sub _sendChat { my $tac = $extparamref->{tac}; for my $key (keys %chatparams) { - $data{SSCam}{$name}{PARAMS}{$tac}{$key} = AttrVal($name, $chatparams{$key}->{attr}, $chatparams{$key}->{default}) - if(exists $chatparams{$key}->{attr}); + $owndata{PARAMS}{$tac}{$key} = AttrVal ($name, $chatparams{$key}->{attr}, $chatparams{$key}->{default}) + if(exists $chatparams{$key}->{attr}); if ($chatparams{$key}->{set}) { - $data{SSCam}{$name}{PARAMS}{$tac}{$key} = $chatparams{$key}->{default} if(!$extparamref->{$key} && !$chatparams{$key}->{attr}); - $data{SSCam}{$name}{PARAMS}{$tac}{$key} = delete $extparamref->{$key} if(exists $extparamref->{$key}); + $owndata{PARAMS}{$tac}{$key} = $chatparams{$key}->{default} if(!$extparamref->{$key} && !$chatparams{$key}->{attr}); + $owndata{PARAMS}{$tac}{$key} = delete $extparamref->{$key} if(exists $extparamref->{$key}); } Log3 ($name, 4, "$name - param $key is set to >". - ($data{SSCam}{$name}{PARAMS}{$tac}{$key} // "")."< ") if($key !~ /[sv]dat/x); - Log3 ($name, 4, "$name - param $key is set") if($key =~ /[sv]dat/x && $data{SSCam}{$name}{PARAMS}{$tac}{$key} ne ''); + ($owndata{PARAMS}{$tac}{$key} // "")."< ") if($key !~ /[sv]dat/x); + Log3 ($name, 4, "$name - param $key is set") if($key =~ /[sv]dat/x && $owndata{PARAMS}{$tac}{$key} ne ''); } - $data{SSCam}{$name}{PARAMS}{$tac}{name} = $name; + $owndata{PARAMS}{$tac}{name} = $name; my @err = (); - for my $key (keys(%chatparams)) { - push (@err, $key) if($chatparams{$key}->{required} && !$data{SSCam}{$name}{PARAMS}{$tac}{$key}); + for my $key (keys %chatparams) { + push (@err, $key) if($chatparams{$key}->{required} && !exists $owndata{PARAMS}{$tac}{$key}); } if ($#err >= 0) { @@ -10205,13 +10239,13 @@ sub _sendChat { readingsBulkUpdate ($hash,'sendChatState', $ret); readingsEndUpdate ($hash, 1); - $data{SSCam}{$name}{SENDCOUNT}{$tac} -= 1; + $owndata{SENDCOUNT}{$tac} -= 1; return $ret; } - my $chatbot = $data{SSCam}{$name}{PARAMS}{$tac}{chatbot}; - my $peers = $data{SSCam}{$name}{PARAMS}{$tac}{peers}; - my $rootUrl = $data{SSCam}{$name}{PARAMS}{$tac}{videofolderMap}; + my $chatbot = $owndata{PARAMS}{$tac}{chatbot}; + my $peers = $owndata{PARAMS}{$tac}{peers}; + my $rootUrl = $owndata{PARAMS}{$tac}{videofolderMap}; if (!$defs{$chatbot}) { $ret = qq{No SSChatBot device "$chatbot" available}; @@ -10219,7 +10253,7 @@ sub _sendChat { Log3 ($name, 2, "$name - $ret"); - $data{SSCam}{$name}{SENDCOUNT}{$tac} -= 1; + $owndata{SENDCOUNT}{$tac} -= 1; return; } @@ -10229,7 +10263,7 @@ sub _sendChat { Log3 ($name, 3, "$name - $ret"); - $data{SSCam}{$name}{SENDCOUNT}{$tac} -= 1; + $owndata{SENDCOUNT}{$tac} -= 1; return; } @@ -10242,7 +10276,7 @@ sub _sendChat { Log3 ($name, 2, "$name - $ret"); - $data{SSCam}{$name}{SENDCOUNT}{$tac} -= 1; + $owndata{SENDCOUNT}{$tac} -= 1; return; } } @@ -10250,13 +10284,13 @@ sub _sendChat { $peers = join ",", split (" ", $peers); } - if (!$data{SSCam}{$name}{PARAMS}{$tac}{sdat} && !$data{SSCam}{$name}{PARAMS}{$tac}{vdat}) { + if (!exists $owndata{PARAMS}{$tac}{sdat} && !exists $owndata{PARAMS}{$tac}{vdat}) { $ret = "no video or image data existing for send process by SSChatBot \"$chatbot\" "; readingsSingleUpdate ($hash, "sendChatState", $ret, 1); Log3 ($name, 2, "$name - $ret"); - $data{SSCam}{$name}{SENDCOUNT}{$tac} -= 1; + $owndata{SENDCOUNT}{$tac} -= 1; return; } @@ -10266,17 +10300,17 @@ sub _sendChat { Log3 ($name, 1, "$name - Fall back to internal Cache due to preceding failure.") if(!$cache); if (!$cache || $cache eq "internal" ) { - if ($data{SSCam}{$name}{PARAMS}{$tac}{sdat}) { # Images liegen in einem Hash (Ref in $sdat) base64-codiert vor - @as = sort{$b<=>$a} keys%{$data{SSCam}{$name}{PARAMS}{$tac}{sdat}}; + if ($owndata{PARAMS}{$tac}{sdat}) { # Images liegen in einem Hash (Ref in $sdat) base64-codiert vor + @as = sort {$b<=>$a} keys %{$owndata{PARAMS}{$tac}{sdat}}; $mtype = "\@Snapshot"; } - elsif ($data{SSCam}{$name}{PARAMS}{$tac}{vdat}) { # Aufnahmen liegen in einem Hash-Ref in $vdat vor - @as = sort{$b<=>$a} keys%{$data{SSCam}{$name}{PARAMS}{$tac}{vdat}}; + elsif ($owndata{PARAMS}{$tac}{vdat}) { # Aufnahmen liegen in einem Hash-Ref in $vdat vor + @as = sort {$b<=>$a} keys %{$owndata{PARAMS}{$tac}{vdat}}; $mtype = $hash->{CAMNAME}; } for my $key (@as) { - ($subject,$fname) = __extractForChat($name,$key,$data{SSCam}{$name}{PARAMS}{$tac}); + ($subject,$fname) = __extractForChat ($name, $key, $owndata{PARAMS}{$tac}); my @ua = split(",", $peers); # User aufsplitten und zu jedem die ID ermitteln for (@ua) { @@ -10289,7 +10323,7 @@ sub _sendChat { Log3 ($name, 2, "$name - $ret"); - $data{SSCam}{$name}{SENDCOUNT}{$tac} -= 1; + $owndata{SENDCOUNT}{$tac} -= 1; return; } @@ -10323,12 +10357,12 @@ sub _sendChat { } } - $data{SSCam}{$name}{SENDCOUNT}{$tac} -= 1; - Log3 ($name, 1, "$name - Send Counter transaction \"$tac\": ".$data{SSCam}{$name}{SENDCOUNT}{$tac}." (Chat done)") if(AttrVal($name,"debugactivetoken",0)); + $owndata{SENDCOUNT}{$tac} -= 1; + Log3 ($name, 1, "$name - Send Counter transaction \"$tac\": ".$owndata{SENDCOUNT}{$tac}." (Chat done)") if(AttrVal($name,"debugactivetoken",0)); } else { # alle Serial Numbers "{$sn}" der Transaktion ermitteln - if ($data{SSCam}{$name}{PARAMS}{$tac}{sdat}) { # Images liegen in einem Hash (Ref in $sdat) base64-codiert vor + if (exists $owndata{PARAMS}{$tac}{sdat}) { # Images liegen in einem Hash (Ref in $sdat) base64-codiert vor extractTIDfromCache ( { name => $name, tac => $tac, media => "SENDSNAPS", @@ -10338,7 +10372,7 @@ sub _sendChat { ); $mtype = "\@Snapshot"; } - elsif ($data{SSCam}{$name}{PARAMS}{$tac}{vdat}) { # Aufnahmen liegen in einem Hash-Ref in $vdat vor + elsif (exists $owndata{PARAMS}{$tac}{vdat}) { # Aufnahmen liegen in einem Hash-Ref in $vdat vor extractTIDfromCache ( { name => $name, tac => $tac, media => "SENDRECS", @@ -10352,17 +10386,19 @@ sub _sendChat { @unique = sort{$b<=>$a} grep { !$seen{$_}++ } @as; # distinct / unique the keys for my $key (@unique) { - ($subject,$fname) = __extractForChat($name,$key,$data{SSCam}{$name}{PARAMS}{$tac}); + ($subject,$fname) = __extractForChat ($name, $key, $owndata{PARAMS}{$tac}); my @ua = split (/,/x, $peers); # User aufsplitten und zu jedem die ID ermitteln + for (@ua) { next if(!$_); $uid = $defs{$chatbot}{HELPER}{USERS}{$_}{id}; + if (!$uid) { $ret = "The receptor \"$_\" seems to be unknown because its ID coulnd't be found."; readingsSingleUpdate ($hash, "sendChatState", $ret, 1); Log3 ($name, 2, "$name - $ret"); - $data{SSCam}{$name}{SENDCOUNT}{$tac} -= 1; + $owndata{SENDCOUNT}{$tac} -= 1; return; } @@ -10395,8 +10431,8 @@ sub _sendChat { } } - $data{SSCam}{$name}{SENDCOUNT}{$tac} -= 1; - Log3 ($name, 1, "$name - Send Counter transaction \"$tac\": ".$data{SSCam}{$name}{SENDCOUNT}{$tac}." (Chat done)") if(AttrVal($name,"debugactivetoken",0)); + $owndata{SENDCOUNT}{$tac} -= 1; + Log3 ($name, 1, "$name - Send Counter transaction \"$tac\": ".$owndata{SENDCOUNT}{$tac}." (Chat done)") if(AttrVal($name,"debugactivetoken",0)); } FHEM::SSChatBot::getApiSites ($chatbot); # Übertragung Sendqueue starten @@ -10500,7 +10536,8 @@ return \%telemsg; sub _sendTelegram { my ($hash, $extparamref) = @_; my $name = $hash->{NAME}; - my $type = AttrVal($name,"cacheType","internal"); + my $type = AttrVal ($name, 'cacheType', 'internal'); + my ($ret,$cache); Log3($name, 4, "$name - ####################################################"); @@ -10528,23 +10565,23 @@ sub _sendTelegram { my $tac = $extparamref->{tac}; for my $key (keys %teleparams) { - $data{SSCam}{$name}{PARAMS}{$tac}{$key} = AttrVal ($name, $teleparams{$key}->{attr}, $teleparams{$key}->{default}) + $owndata{PARAMS}{$tac}{$key} = AttrVal ($name, $teleparams{$key}->{attr}, $teleparams{$key}->{default}) if($teleparams{$key}->{attr}); if($teleparams{$key}->{set}) { - $data{SSCam}{$name}{PARAMS}{$tac}{$key} = $teleparams{$key}->{default} if(!$extparamref->{$key} && !$teleparams{$key}->{attr}); - $data{SSCam}{$name}{PARAMS}{$tac}{$key} = delete $extparamref->{$key} if($extparamref->{$key}); + $owndata{PARAMS}{$tac}{$key} = $teleparams{$key}->{default} if(!$extparamref->{$key} && !$teleparams{$key}->{attr}); + $owndata{PARAMS}{$tac}{$key} = delete $extparamref->{$key} if($extparamref->{$key}); } Log3 ($name, 4, "$name - param $key is set to >". - ($data{SSCam}{$name}{PARAMS}{$tac}{$key} // '')."< ") if($key !~ /[sv]dat/x); - Log3 ($name, 4, "$name - param $key is set") if($key =~ /[sv]dat/x && $data{SSCam}{$name}{PARAMS}{$tac}{$key} ne ''); + ($owndata{PARAMS}{$tac}{$key} // '')."< ") if($key !~ /[sv]dat/x); + Log3 ($name, 4, "$name - param $key is set") if($key =~ /[sv]dat/x && $owndata{PARAMS}{$tac}{$key} ne ''); } - $data{SSCam}{$name}{PARAMS}{$tac}{name} = $name; + $owndata{PARAMS}{$tac}{name} = $name; my @err = (); for my $key (keys(%teleparams)) { - push (@err, $key) if($teleparams{$key}->{required} && !$data{SSCam}{$name}{PARAMS}{$tac}{$key}); + push (@err, $key) if($teleparams{$key}->{required} && !exists $owndata{PARAMS}{$tac}{$key}); } if ($#err >= 0) { @@ -10556,11 +10593,11 @@ sub _sendTelegram { readingsBulkUpdate ($hash, 'sendTeleState', $ret); readingsEndUpdate ($hash, 1); - $data{SSCam}{$name}{SENDCOUNT}{$tac} -= 1; + $owndata{SENDCOUNT}{$tac} -= 1; return $ret; } - my $telebot = $data{SSCam}{$name}{PARAMS}{$tac}{telebot}; + my $telebot = $owndata{PARAMS}{$tac}{telebot}; if (!$defs{$telebot}) { $ret = qq{No TelegramBot device "$telebot" available}; @@ -10569,7 +10606,7 @@ sub _sendTelegram { Log3 ($name, 2, "$name - $ret"); - $data{SSCam}{$name}{SENDCOUNT}{$tac} -= 1; + $owndata{SENDCOUNT}{$tac} -= 1; return; } @@ -10579,11 +10616,11 @@ sub _sendTelegram { Log3 ($name, 2, "$name - $ret"); - $data{SSCam}{$name}{SENDCOUNT}{$tac} -= 1; + $owndata{SENDCOUNT}{$tac} -= 1; return; } - my $peers = $data{SSCam}{$name}{PARAMS}{$tac}{peers}; + my $peers = $owndata{PARAMS}{$tac}{peers}; if ($peers =~ /^r:/xs) { # Reading mit Empfängern ist hinterlegt my $pr = (split ':', $peers)[1]; @@ -10602,24 +10639,24 @@ sub _sendTelegram { Log3 ($name, 2, "$name - $ret"); - $data{SSCam}{$name}{SENDCOUNT}{$tac} -= 1; + $owndata{SENDCOUNT}{$tac} -= 1; return; } } - if (!$data{SSCam}{$name}{PARAMS}{$tac}{sdat} && !$data{SSCam}{$name}{PARAMS}{$tac}{vdat}) { + if (!exists $owndata{PARAMS}{$tac}{sdat} && !exists $owndata{PARAMS}{$tac}{vdat}) { $ret = "no video or image data existing for send process by TelegramBot \"$telebot\" "; readingsSingleUpdate ($hash, 'sendTeleState', $ret, 1); Log3 ($name, 2, "$name - $ret"); - $data{SSCam}{$name}{SENDCOUNT}{$tac} -= 1; + $owndata{SENDCOUNT}{$tac} -= 1; return; } my $options = ''; - my @opta = split ' ', $data{SSCam}{$name}{PARAMS}{$tac}{option}; + my @opta = split ' ', $owndata{PARAMS}{$tac}{option}; if (@opta) { for my $o (@opta) { @@ -10629,22 +10666,22 @@ sub _sendTelegram { $options .= ' '; } - my ($msg,$subject,$MediaStream,$fname,@as,%seen,@unique); + my ($msg, $subject, $MediaStream, $fname, @as, %seen, @unique); $cache = cache ($name, "c_init"); # Cache initialisieren Log3 ($name, 1, "$name - Fall back to internal Cache due to preceding failure.") if(!$cache); if (!$cache || $cache eq "internal" ) { - if ($data{SSCam}{$name}{PARAMS}{$tac}{sdat}) { # Images liegen in einem Hash (Ref in $sdat) base64-codiert vor - @as = sort{$b<=>$a}keys%{$data{SSCam}{$name}{PARAMS}{$tac}{sdat}}; + if ($owndata{PARAMS}{$tac}{sdat}) { # Images liegen in einem Hash (Ref in $sdat) base64-codiert vor + @as = sort {$b<=>$a} keys %{$owndata{PARAMS}{$tac}{sdat}}; } - elsif($data{SSCam}{$name}{PARAMS}{$tac}{vdat}) { # Aufnahmen liegen in einem Hash-Ref in $vdat vor - @as = sort{$b<=>$a}keys%{$data{SSCam}{$name}{PARAMS}{$tac}{vdat}}; + elsif ($owndata{PARAMS}{$tac}{vdat}) { # Aufnahmen liegen in einem Hash-Ref in $vdat vor + @as = sort {$b<=>$a} keys %{$owndata{PARAMS}{$tac}{vdat}}; } for my $key (@as) { - ($msg,$subject,$MediaStream,$fname) = __extractForTelegram($name,$key,$data{SSCam}{$name}{PARAMS}{$tac}); + ($msg,$subject,$MediaStream,$fname) = __extractForTelegram ($name, $key, $owndata{PARAMS}{$tac}); $ret = __TBotSendIt ($defs{$telebot}, $name, $fname, $peers, $msg, $subject, $MediaStream, undef, $options); if ($ret) { @@ -10660,13 +10697,13 @@ sub _sendTelegram { } } - $data{SSCam}{$name}{SENDCOUNT}{$tac} -= 1; + $owndata{SENDCOUNT}{$tac} -= 1; - Log3 ($name, 1, "$name - Send Counter transaction \"$tac\": ".$data{SSCam}{$name}{SENDCOUNT}{$tac}." (Telegram done)") if(AttrVal($name,"debugactivetoken",0)); + Log3 ($name, 1, "$name - Send Counter transaction \"$tac\": ".$owndata{SENDCOUNT}{$tac}." (Telegram done)") if(AttrVal($name,"debugactivetoken",0)); } else { # alle Serial Numbers "{$sn}" der Transaktion ermitteln - if ($data{SSCam}{$name}{PARAMS}{$tac}{sdat}) { # Images liegen in einem Hash (Ref in $sdat) base64-codiert vor + if (exists $owndata{PARAMS}{$tac}{sdat}) { # Images liegen in einem Hash (Ref in $sdat) base64-codiert vor extractTIDfromCache ( { name => $name, tac => $tac, media => "SENDSNAPS", @@ -10675,7 +10712,7 @@ sub _sendTelegram { } ); } - elsif ($data{SSCam}{$name}{PARAMS}{$tac}{vdat}) { # Aufnahmen liegen in einem Hash-Ref in $vdat vor + elsif (exists $owndata{PARAMS}{$tac}{vdat}) { # Aufnahmen liegen in einem Hash-Ref in $vdat vor extractTIDfromCache ( { name => $name, tac => $tac, media => "SENDRECS", @@ -10688,7 +10725,7 @@ sub _sendTelegram { @unique = sort{$b<=>$a} grep { !$seen{$_}++ } @as; # distinct / unique the keys for my $key (@unique) { - ($msg,$subject,$MediaStream,$fname) = __extractForTelegram($name,$key,$data{SSCam}{$name}{PARAMS}{$tac}); + ($msg,$subject,$MediaStream,$fname) = __extractForTelegram ($name, $key, $owndata{PARAMS}{$tac}); $ret = __TBotSendIt($defs{$telebot}, $name, $fname, $peers, $msg, $subject, $MediaStream, undef, $options); if ($ret) { @@ -10705,9 +10742,9 @@ sub _sendTelegram { } } - $data{SSCam}{$name}{SENDCOUNT}{$tac} -= 1; + $owndata{SENDCOUNT}{$tac} -= 1; - Log3 ($name, 1, "$name - Send Counter transaction \"$tac\": ".$data{SSCam}{$name}{SENDCOUNT}{$tac}." (Telegram done)") if(AttrVal($name,"debugactivetoken",0)); + Log3 ($name, 1, "$name - Send Counter transaction \"$tac\": ".$owndata{SENDCOUNT}{$tac}." (Telegram done)") if(AttrVal($name,"debugactivetoken",0)); } return; @@ -11193,23 +11230,23 @@ sub _sendEmail { my $tac = $extparamref->{tac}; for my $key (keys %mailparams) { - $data{SSCam}{$name}{PARAMS}{$tac}{$key} = AttrVal($name, $mailparams{$key}->{attr}, $mailparams{$key}->{default}) + $owndata{PARAMS}{$tac}{$key} = AttrVal($name, $mailparams{$key}->{attr}, $mailparams{$key}->{default}) if(exists $mailparams{$key}->{attr}); if ($mailparams{$key}->{set}) { - $data{SSCam}{$name}{PARAMS}{$tac}{$key} = $mailparams{$key}->{default} if(!$extparamref->{$key} && !$mailparams{$key}->{attr}); - $data{SSCam}{$name}{PARAMS}{$tac}{$key} = delete $extparamref->{$key} if(exists $extparamref->{$key}); + $owndata{PARAMS}{$tac}{$key} = $mailparams{$key}->{default} if(!$extparamref->{$key} && !$mailparams{$key}->{attr}); + $owndata{PARAMS}{$tac}{$key} = delete $extparamref->{$key} if(exists $extparamref->{$key}); } Log3 ($name, 4, "$name - param $key is now >". - $data{SSCam}{$name}{PARAMS}{$tac}{$key}."< ") if($key !~ /sdat/x); - Log3 ($name, 4, "$name - param $key is set") if($key =~ /sdat/x && $data{SSCam}{$name}{PARAMS}{$tac}{$key} ne ''); + $owndata{PARAMS}{$tac}{$key}."< ") if($key !~ /sdat/x); + Log3 ($name, 4, "$name - param $key is set") if($key =~ /sdat/x && $owndata{PARAMS}{$tac}{$key} ne ''); } - $data{SSCam}{$name}{PARAMS}{$tac}{name} = $name; + $owndata{PARAMS}{$tac}{name} = $name; my @err = (); for my $key (keys(%mailparams)) { - push(@err, $key) if ($mailparams{$key}->{required} && !$data{SSCam}{$name}{PARAMS}{$tac}{$key}); + push(@err, $key) if ($mailparams{$key}->{required} && !exists $owndata{PARAMS}{$tac}{$key}); } if ($#err >= 0) { @@ -11223,7 +11260,7 @@ sub _sendEmail { return $ret; } - $hash->{HELPER}{RUNNING_PID} = BlockingCall("FHEM::SSCam::__sendEmailblocking", $data{SSCam}{$name}{PARAMS}{$tac}, "FHEM::SSCam::__sendEmaildone", $timeout, "FHEM::SSCam::__sendEmailto", $hash); + $hash->{HELPER}{RUNNING_PID} = BlockingCall ("FHEM::SSCam::__sendEmailblocking", $owndata{PARAMS}{$tac}, "FHEM::SSCam::__sendEmaildone", $timeout, "FHEM::SSCam::__sendEmailto", $hash); $hash->{HELPER}{RUNNING_PID}{loglevel} = 5 if($hash->{HELPER}{RUNNING_PID}); # Forum #77057 return; @@ -11233,7 +11270,7 @@ return; # nichtblockierendes Send EMail #################################################################################################### sub __sendEmailblocking { ## no critic 'not used' - my ($paref) = @_; # der Referent wird in cleanData gelöscht + my $paref = shift; # der Referent wird in cleanData gelöscht my $name = delete $paref->{name}; my $cc = delete $paref->{smtpCc}; my $from = delete $paref->{smtpFrom}; @@ -11589,9 +11626,9 @@ sub __sendEmaildone { ## my $name = $hash->{NAME}; - $data{SSCam}{$name}{SENDCOUNT}{$tac}--; + $owndata{SENDCOUNT}{$tac}--; - Log3 ($name, 1, "$name - Send Counter transaction \"$tac\": ".$data{SSCam}{$name}{SENDCOUNT}{$tac}." (eMail done)") if(AttrVal($name, 'debugactivetoken', 0)); + Log3 ($name, 1, "$name - Send Counter transaction \"$tac\": ".$owndata{SENDCOUNT}{$tac}." (eMail done)") if(AttrVal($name, 'debugactivetoken', 0)); if ($err) { readingsBeginUpdate ($hash); @@ -11667,7 +11704,7 @@ sub extractTIDfromCache { my ($k1) = $ck =~ /\{$media\}\{(\d+?)\}\{.*?\}/x; push @$aref, $k1 if($k1 =~ /^\d+$/x); - } + } } return; @@ -11703,9 +11740,8 @@ sub closeTrans { my $hash = shift; my $name = $hash->{NAME}; - my $tac = $hash->{HELPER}{TRANSACTION}; # diese Transaktion beenden + my $tac = $hash->{HELPER}{TRANSACTION} // ''; # diese Transaktion beenden - return if(!$tac); cleanData ("$name:$tac"); # %data Hash & Cache bereinigen return; @@ -11722,57 +11758,70 @@ sub cleanData { RemoveInternalTimer ($hash, "FHEM::SSCam::cleanData"); - if ($data{SSCam}{$name}{SENDCOUNT}{$tac} && $data{SSCam}{$name}{SENDCOUNT}{$tac} > 0) { # Cacheinhalt erst löschen wenn Sendezähler 0 + if ($tac && exists $owndata{SENDCOUNT}{$tac} && $owndata{SENDCOUNT}{$tac} > 0) { # Cacheinhalt erst löschen wenn Sendezähler 0 InternalTimer (gettimeofday()+1, "FHEM::SSCam::cleanData", "$name:$tac", 0); return; } - if (AttrVal($name, "cacheType", "internal") eq "internal") { # internes Caching + if (AttrVal ($name, 'cacheType', 'internal') eq 'internal') { # internes Caching if ($tac) { - if ($data{SSCam}{RS}{$tac}) { - delete $data{SSCam}{RS}{$tac}; + if (exists $owndata{RS}{$tac}) { + delHashRefDeep ($owndata{RS}{$tac}); + delete $owndata{RS}{$tac}; $del = 1; } - if ($data{SSCam}{$name}{SENDRECS}{$tac}) { - delete $data{SSCam}{$name}{SENDRECS}{$tac}; + if (exists $owndata{SENDRECS}{$tac}) { + delHashRefDeep ($owndata{SENDRECS}{$tac}); + delete $owndata{SENDRECS}{$tac}; $del = 1; } - if ($data{SSCam}{$name}{SENDSNAPS}{$tac}) { - delete $data{SSCam}{$name}{SENDSNAPS}{$tac}; + if (exists $owndata{SENDSNAPS}{$tac}) { + delHashRefDeep ($owndata{SENDSNAPS}{$tac}); + delete $owndata{SENDSNAPS}{$tac}; $del = 1; } - if ($data{SSCam}{$name}{PARAMS}{$tac}) { - delete $data{SSCam}{$name}{PARAMS}{$tac}; + if (exists $owndata{PARAMS}{$tac}) { + delHashRefDeep ($owndata{PARAMS}{$tac}); + delete $owndata{PARAMS}{$tac}; $del = 1; } if ($del) { - delete $hash->{HELPER}{TRANSACTION}; # diese Transaktion ist beendet + delete $hash->{HELPER}{TRANSACTION}; # diese Transaktion ist beendet - if (AttrVal($name, 'debugactivetoken', 0)) { + if (AttrVal ($name, 'debugactivetoken', 0)) { Log3 ($name, 1, qq/$name - Data of Transaction "$tac" removed/); Log3 ($name, 1, qq/$name - Transaction "$tac" closed/); } } + + delHashRefDeep ($owndata{SENDCOUNT}{$tac}); + delete $owndata{SENDCOUNT}{$tac}; } else { - delete $data{SSCam}{RS}; - delete $data{SSCam}{$name}{SENDRECS}; - delete $data{SSCam}{$name}{SENDSNAPS}; - delete $data{SSCam}{$name}{PARAMS}; + delHashRefDeep ($owndata{RS}); + delHashRefDeep ($owndata{SENDRECS}); + delHashRefDeep ($owndata{SENDSNAPS}); + delHashRefDeep ($owndata{PARAMS}); + + delete $owndata{RS}; + delete $owndata{SENDRECS}; + delete $owndata{SENDSNAPS}; + delete $owndata{PARAMS}; - Log3 ($name, 1, "$name - Data of internal Cache removed") if(AttrVal($name, 'debugactivetoken', 0)); + Log3 ($name, 1, "$name - Data of internal Cache removed") if(AttrVal ($name, 'debugactivetoken', 0)); } } else { # Caching mit CHI - my @as = cache($name, "c_getkeys"); + my @as = cache ($name, "c_getkeys"); + if ($tac) { for my $k (@as) { if ($k =~ /$tac/x) { - cache($name, "c_remove", $k); + cache ($name, "c_remove", $k); $del = 1; } } @@ -11780,17 +11829,12 @@ sub cleanData { if ($del) { delete $hash->{HELPER}{TRANSACTION}; # diese Transaktion ist beendet - if (AttrVal($name, 'debugactivetoken', 0)) { + if (AttrVal ($name, 'debugactivetoken', 0)) { Log3 ($name, 1, qq/$name - Data of Transaction "$tac" removed/); Log3 ($name, 1, qq/$name - Transaction "$tac" closed/); } } } - else { - cache($name, "c_clear"); - - Log3 ($name, 1, "$name - Data of CHI-Cache removed") if(AttrVal($name,"debugactivetoken",0)); - } } return; @@ -11805,14 +11849,14 @@ sub subaddFromBlocking { my $hash = $defs{$name}; if ($op eq "-") { - $data{SSCam}{$name}{SENDCOUNT}{$tac}--; + $owndata{SENDCOUNT}{$tac}--; } if ($op eq "+") { - $data{SSCam}{$name}{SENDCOUNT}{$tac}++; + $owndata{SENDCOUNT}{$tac}++; } - Log3 ($name, 1, "$name - Send Counter transaction \"$tac\": ".$data{SSCam}{$name}{SENDCOUNT}{$tac}." (eMail done)") if(AttrVal($name,"debugactivetoken",0)); + Log3 ($name, 1, "$name - Send Counter transaction \"$tac\": ".$owndata{SENDCOUNT}{$tac}." (eMail done)") if(AttrVal($name,"debugactivetoken",0)); return; } @@ -11844,10 +11888,11 @@ sub cache { my $dat = shift; my $hash = $defs{$name}; - my $type = AttrVal($name,"cacheType","internal"); + my $ctype = AttrVal ($name, 'cacheType', 'internal'); my ($server,$port) = split ":", AttrVal ($name, 'cacheServerParam', ''); my $path = $attr{global}{modpath}."/FHEM/FhemUtils/cacheSSCam"; # Dir für FileCache my $fuuid = $hash->{FUUID}; + my ($cache,$r,$bst,$brt); $bst = [gettimeofday]; @@ -11855,9 +11900,9 @@ sub cache { ### Cache Initialisierung ### ############################# if ($op eq "c_init") { - if ($type eq "internal") { + if ($ctype eq "internal") { Log3 ($name, 4, "$name - internal Cache mechanism is used "); - return $type; + return $ctype; } if ($SScamMMCHI) { @@ -11865,22 +11910,23 @@ sub cache { return 0; } - if ($type eq "redis" && $SScamMMCHIRedis) { + if ($ctype eq "redis" && $SScamMMCHIRedis) { Log3 ($name, 1, "$name - Perl cache module ".$SScamMMCHIRedis." is missing. You need to install it with the FHEM Installer for example."); return 0; } - if ($type eq "filecache" && $SScamMMCacheCache) { + if ($ctype eq "filecache" && $SScamMMCacheCache) { Log3 ($name, 1, "$name - Perl cache module ".$SScamMMCacheCache." is missing. You need to install it with the FHEM Installer for example."); return 0; } if ($hash->{HELPER}{CACHEKEY}) { - Log3 ($name, 4, "$name - Cache \"$type\" is already initialized "); - return $type; + Log3 ($name, 4, "$name - Cache \"$ctype\" is already initialized "); + + return $ctype; } - if ($type eq "mem") { + if ($ctype eq "mem") { # This cache driver stores data on a per-process basis. This is the fastest of the cache implementations, # but data can not be shared between processes. Data will remain in the cache until cleared, expired, # or the process dies. @@ -11893,7 +11939,7 @@ sub cache { ); } - if ($type eq "rawmem") { + if ($ctype eq "rawmem") { # This is a subclass of CHI::Driver::Memory that stores references to data structures directly instead # of serializing / deserializing. This makes the cache faster at getting and setting complex data structures, # but unlike most drivers, modifications to the original data structure will affect the data structure stored @@ -11907,7 +11953,7 @@ sub cache { ); } - if ($type eq "redis") { + if ($ctype eq "redis") { # A CHI driver that uses Redis to store the data. Care has been taken to not have this module fail in fiery # ways if the cache is unavailable. It is my hope that if it is failing and the cache is not required for your work, # you can ignore its warnings. @@ -11953,14 +11999,15 @@ sub cache { ); } - if ($type eq "file") { + if ($ctype eq "file") { # This is a filecache using Cache::Cache. # https://metacpan.org/pod/Cache::Cache my $pr = (split('/',reverse($path),2))[1]; $pr = reverse($pr); if (!(-R $pr) || !(-W $pr)) { # root-erzeichnis testen - Log3 ($name, 1, "$name - ERROR - cannot create \"$type\" Cache in dir \"$pr\": ".$!); + Log3 ($name, 1, "$name - ERROR - cannot create \"$ctype\" Cache in dir \"$pr\": ".$!); + delete $hash->{HELPER}{CACHEKEY}; return 0; } @@ -11968,7 +12015,8 @@ sub cache { if (!(-d $path)) { # Zielverzeichnis anlegen wenn nicht vorhanden my $success = mkdir($path,0775); if (!$success) { - Log3 ($name, 1, "$name - ERROR - cannot create \"$type\" Cache path \"$path\": ".$!); + Log3 ($name, 1, "$name - ERROR - cannot create \"$ctype\" Cache path \"$path\": ".$!); + delete $hash->{HELPER}{CACHEKEY}; return 0; } @@ -11985,14 +12033,17 @@ sub cache { } if ($cache && $cache =~ /CHI::Driver::Role::Universal/x) { - Log3 ($name, 3, "$name - Cache \"$type\" namespace \"$fuuid\" initialized"); + Log3 ($name, 3, "$name - Cache \"$ctype\" namespace \"$fuuid\" initialized"); + $hash->{HELPER}{CACHEKEY} = $cache; $brt = tv_interval($bst); - Log3($name, 1, "$name - Cache time to create \"$type\": ".$brt) if(AttrVal($name,"debugCachetime",0)); - return $type; + + Log3($name, 1, "$name - Cache time to create \"$ctype\": ".$brt) if(AttrVal($name, 'debugCachetime', 0)); + + return $ctype; } else { - Log3 ($name, 3, "$name - no cache \"$type\" available."); + Log3 ($name, 3, "$name - no cache \"$ctype\" available."); } return 0; } @@ -12006,26 +12057,27 @@ sub cache { return 0; } - if ($type eq "redis") { - # Test ob Redis Serververbindung möglich + if ($ctype eq "redis") { # Test ob Redis Serververbindung möglich my $rc = $hash->{HELPER}{REDISKEY}; + if ($rc) { eval { $r = $rc->ping }; ## no critic 'eval not tested' if (!$r || $r ne "PONG") { # Verbindungskeys löschen -> Neugenerierung mit "c_init" Log3 ($name, 1, "$name - ERROR - connection to Redis server not possible. May be no route to host or port is wrong."); + delete $hash->{HELPER}{REDISKEY}; delete $hash->{HELPER}{CACHEKEY}; return 0; } } else { - Log3($name, 1, "$name - ERROR - no constructor for Redis server is created"); + Log3 ($name, 1, "$name - ERROR - no constructor for Redis server is created"); return 0; } } - if ($type eq "file" && (!(-R $path) || !(-W $path))) { - Log3($name, 1, "$name - ERROR - cannot handle \"$type\" Cache: ".$!); + if ($ctype eq "file" && (!(-R $path) || !(-W $path))) { + Log3($name, 1, "$name - ERROR - cannot handle \"$ctype\" Cache: ".$!); delete $hash->{HELPER}{CACHEKEY}; return 0; } @@ -12042,11 +12094,13 @@ sub cache { if ($key) { $cache->set($key, $dat); $brt = tv_interval($bst); - Log3 ($name, 1, "$name - Cache time write key \"$key\": ".$brt) if(AttrVal($name, "debugCachetime", 0)); + + Log3 ($name, 1, "$name - Cache time write key \"$key\": ".$brt) if(AttrVal($name, 'debugCachetime', 0)); + return 1; } else { - Log3 ($name, 1, "$name - ERROR - no key for \"$type\" cache !"); + Log3 ($name, 1, "$name - ERROR - no key for \"$ctype\" cache !"); } } @@ -12054,7 +12108,8 @@ sub cache { if ($op eq "c_read") { my $g = $cache->get($key); $brt = tv_interval($bst); - Log3 ($name, 1, "$name - Cache time read key \"$key\": ".$brt) if(AttrVal($name, "debugCachetime", 0)); + + Log3 ($name, 1, "$name - Cache time read key \"$key\": ".$brt) if(AttrVal($name, 'debugCachetime', 0)); if (!$g) { return; @@ -12068,15 +12123,19 @@ sub cache { if ($op eq "c_remove") { $cache->remove($key); $brt = tv_interval($bst); - Log3 ($name, 1, "$name - Cache time remove key \"$key\": ".$brt) if(AttrVal($name, "debugCachetime", 0)); + + Log3 ($name, 1, "$name - Cache time remove key \"$key\": ".$brt) if(AttrVal($name, 'debugCachetime', 0)); Log3 ($name, 4, "$name - Cache key \"$key\" removed "); + return 1; } # alle Einträge aus Cache (Namespace) entfernen if ($op eq "c_clear") { $cache->clear(); - Log3 ($name, 4, "$name - All entries removed from \"$type\" cache "); + + Log3 ($name, 4, "$name - All entries removed from \"$ctype\" cache "); + return 1; } @@ -12094,7 +12153,9 @@ sub cache { if ($op eq "c_destroy") { $cache->clear(); delete $hash->{HELPER}{CACHEKEY}; - Log3($name, 3, "$name - Cache \"$type\" destroyed "); + + Log3 ($name, 3, "$name - Cache \"$ctype\" destroyed "); + return 1; } @@ -12173,7 +12234,7 @@ sub startOrShut { my $hash = $defs{$name}; if ($shutdownInProcess) { # shutdown in Proces -> keine weiteren Aktionen - Log3($name, 3, "$name - Shutdown in process. No more activities allowed."); + Log3 ($name, 4, "$name - Shutdown in process. No more activities allowed."); return 1; } @@ -12239,10 +12300,10 @@ sub schedule { Debug (qq{$pack - no delta time found for function "$sub", use default of $dt seconds instead}) } - InternalTimer(gettimeofday()+$dt, $caller, $arg, 0); + InternalTimer (gettimeofday()+$dt, $caller, $arg, 0); - if (AttrVal ($name,"debugactivetoken",0)) { - Log3 ($name, 1, "$name - Function $caller scheduled again with delta time $dt seconds"); + if (AttrVal ($name, 'debugactivetoken', 0)) { + Log3 ($name, 1, "$name - Function $caller new scheduled with $dt seconds delta time"); } return; @@ -14026,11 +14087,23 @@ attr <name> genericStrmHtmlTag <img $HTMLATTR extended
-
  • session
    - selection of login-Session. Not set or set to "DSM" -> session will be established to DSM (Sdefault). - "SurveillanceStation" -> session will be established to SVS.
    - For establish a sesion with Surveillance Station you have to create a user with suitable privilege profile in SVS. - If you need more infomations please execute "get <name> versionNotes 5". +
  • session
    + Selection of the login session. +

    + +
      + + + + + + + +
      DSM the session is established to the Synology DSM (default)
      The credentials of a DSM user with administrative rights must be used.
      SurveillanceStation the session is set up with the SurveillanceStation (SVS).
      The credentials of a user defined in the SVS must be used.
      The user must be assigned a corresponding privilege profile in the SVS.
      +
    +
    + + For more information, please execute “get <name> versionNotes 5”.

  • @@ -16111,11 +16184,23 @@ attr <name> genericStrmHtmlTag <img $HTMLATTR
    -
  • session
    - Auswahl der Login-Session. Nicht gesetzt oder "DSM" -> session wird mit DSM aufgebaut - (Standard). "SurveillanceStation" -> Session-Aufbau erfolgt mit SVS.
    - Um eine Session mit der Surveillance Station aufzubauen muss ein Nutzer mit passenden Privilegien Profil in der SVS - angelegt werden. Für weitere Informationen bitte "get <name> versionNotes 5" ausführen. +
  • session
    + Auswahl der Login-Session. +

    + +
      + + + + + + + +
      DSM die Session wird dem Synology DSM aufgebaut (default)
      Es sind die Credentials eines DSM Nutzers mit administrativen Rechten zu verwenden.
      SurveillanceStation die Session wird mit der SurveillanceStation (SVS aufgebaut).
      Es sind die Credentials eines in der SVS definierten Nutzers zu verwenden.
      Dem Nutzer muß in der SVS ein ensprechendes Privilegien Profil zugeordnet sein.
      +
    +
    + + Für weitere Informationen bitte "get <name> versionNotes 5" ausführen.