From df5f411873a473a421bf3b66d18915913724b2bc Mon Sep 17 00:00:00 2001 From: delmar <> Date: Tue, 20 Aug 2019 09:54:08 +0000 Subject: [PATCH] 70_ZoneMinder: added cause and notes to alerts. Credits to Obi git-svn-id: https://svn.fhem.de/fhem/trunk@20028 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/70_ZoneMinder.pm | 29 ++++++++++++----------------- fhem/FHEM/71_ZM_Monitor.pm | 17 +++++++++++++++-- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 1fc3c72c1..e43dd1af2 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. + - feature: 70_ZoneMinder: added cause and notes to alerts. Credits to Obi - bugfix: 73_NUKIBridge: fix "Can't use stringas a HASH ref while strict refs in use" - change: 88_HMCCU: New features and bug fixes diff --git a/fhem/FHEM/70_ZoneMinder.pm b/fhem/FHEM/70_ZoneMinder.pm index d4699f12b..1067a15d9 100755 --- a/fhem/FHEM/70_ZoneMinder.pm +++ b/fhem/FHEM/70_ZoneMinder.pm @@ -329,15 +329,13 @@ sub ZoneMinder_GetConfigValueByKey { sub ZoneMinder_GetConfigArrayByKey { my ($hash, $config, $key) = @_; -# my $searchString = '"'.$key.'":['; -my $searchString = qr/"$key":\s*\[/; + my $searchString = qr/"$key":\s*\[/; return ZoneMinder_GetFromJson($hash, $config, $searchString, ']'); } sub ZoneMinder_GetConfigValueByName { my ($hash, $config, $key) = @_; -# my $searchString = '"Name":"'.$key.'","Value":"'; -my $searchString = qr/"Name":"$key","Value":"/; + my $searchString = qr/"Name":"$key","Value":"/; return ZoneMinder_GetFromJson($hash, $config, $searchString, '"'); } @@ -345,18 +343,14 @@ sub ZoneMinder_GetFromJson { my ($hash, $config, $searchString, $endChar) = @_; my $name = $hash->{NAME}; -# Log3 $name, 5, "json: $config"; -# my $searchLength = length($searchString); my $searchLength; my $prema; -# my $startIdx = index($config, $searchString); my $startIdx; - if (my ($match) = $config =~ $searchString) { + if ( my ($match) = $config =~ $searchString ) { $prema = $'; my $ma = $&; my $poma = $`; -# Log3 $name, 1, "ZM_TEST prematch: $prema match: $ma postmatch: $poma startIdx: $startIdx"; $searchLength = length($ma); } else { Log3 $name, 1, "ZoneMinder ($name) - $searchString NOT found. Please report, this is a problem."; @@ -368,8 +362,6 @@ sub ZoneMinder_GetFromJson { my $searchResult = substr $prema, 0; my $endIdx = index($searchResult, $endChar); $searchResult = substr $searchResult, 0, $endIdx; - -# Log3 $name, 5, "ZoneMinder ($name) - looking for $searchString - length: $searchLength. start: $startIdx. end: $endIdx. result: $searchResult"; return $searchResult; } @@ -463,8 +455,11 @@ sub ZoneMinder_Write { my $zmMonitorId = $arguments->{zmMonitorId}; my $zmAlarm = $arguments->{zmAlarm}; - Log3 $name, 4, "ZoneMinder ($name) method: $method, monitorId:$zmMonitorId, Alarm:$zmAlarm"; - return ZoneMinder_Trigger_ChangeAlarmState($hash, $zmMonitorId, $zmAlarm); + my $zmCause = $arguments->{zmCause}; + my $zmNotes = $arguments->{zmNotes}; + + Log3 $name, 4, "ZoneMinder ($name) method: $method, monitorId:$zmMonitorId, Alarm:$zmAlarm , Cause:$zmCause, Notes:$zmNotes"; + return ZoneMinder_Trigger_ChangeAlarmState($hash, $zmMonitorId, $zmAlarm, $zmCause, $zmNotes); } elsif ($method eq 'changeMonitorText') { @@ -580,17 +575,17 @@ sub ZoneMinder_API_QueryEventDetails_Callback { sub ZoneMinder_Trigger_ChangeAlarmState { - my ( $hash, $zmMonitorId, $zmAlarm ) = @_; + my ( $hash, $zmMonitorId, $zmAlarm, $zmCause, $zmNotes ) = @_; my $name = $hash->{NAME}; my $msg = "$zmMonitorId|"; if ( 'on' eq $zmAlarm ) { - DevIo_SimpleWrite( $hash, $msg.'on|1|fhem', 2 ); + DevIo_SimpleWrite( $hash, $msg.'on|1|'.$zmCause.'|'.$zmNotes, 2 ); } elsif ( 'off' eq $zmAlarm ) { - DevIo_SimpleWrite( $hash, $msg.'off|1|fhem', 2); + DevIo_SimpleWrite( $hash, $msg.'off|1|'.$zmCause.'|'.$zmNotes, 2); } elsif ( $zmAlarm =~ /^on\-for\-timer/ ) { my $duration = $zmAlarm =~ s/on\-for\-timer\ /on\ /r; - DevIo_SimpleWrite( $hash, $msg.$duration.'|1|fhem', 2); + DevIo_SimpleWrite( $hash, $msg.$duration.'|1|'.$zmCause.'|'.$zmNotes, 2); } return undef; diff --git a/fhem/FHEM/71_ZM_Monitor.pm b/fhem/FHEM/71_ZM_Monitor.pm index 25299c16f..3012e3bd6 100755 --- a/fhem/FHEM/71_ZM_Monitor.pm +++ b/fhem/FHEM/71_ZM_Monitor.pm @@ -220,10 +220,23 @@ sub ZM_Monitor_Set { if (grep { $_ eq $arg } @ZM_Alarms) { $arg .= ' '.$args[1] if ( 'on-for-timer' eq $arg ); + + my ( $unnamedParams, $namedParams ) = parseParams(join(' ', @args)); + my $cause = 'fhem'; + my $notes = ''; + if( defined($namedParams->{'cause'}) ) { + $cause = $namedParams->{'cause'}; + } + if( defined($namedParams->{'notes'}) ) { + $notes = $namedParams->{'notes'}; + } + my $arguments = { method => 'changeMonitorAlarm', zmMonitorId => $hash->{helper}{ZM_MONITOR_ID}, - zmAlarm => $arg + zmAlarm => $arg, + zmCause => $cause, + zmNotes => $notes }; my $result = IOWrite($hash, $arguments); return $result; @@ -502,7 +515,7 @@ sub ZM_Monitor_Notify { Set