From 48f87b9dc2590b9adc1fd245f8051923bc3cada1 Mon Sep 17 00:00:00 2001 From: Beta-User <> Date: Sat, 26 Mar 2022 05:51:21 +0000 Subject: [PATCH] 10_RHASSPY: small fixes to test modes git-svn-id: https://svn.fhem.de/fhem/trunk@25882 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/contrib/RHASSPY/10_RHASSPY.pm | 44 ++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/fhem/contrib/RHASSPY/10_RHASSPY.pm b/fhem/contrib/RHASSPY/10_RHASSPY.pm index 3705e7c2b..452a1abec 100644 --- a/fhem/contrib/RHASSPY/10_RHASSPY.pm +++ b/fhem/contrib/RHASSPY/10_RHASSPY.pm @@ -660,8 +660,8 @@ sub Get { my $start = gettimeofday(); my $tHash = { hash=>$hash, CL=>$hash->{CL}, reading=> 'testResult', start=>$start}; $hash->{asyncGet} = $tHash; - InternalTimer(gettimeofday()+4, sub { - asyncOutput($tHash->{CL}, "Timeout for test sentence - most likely this is no problem, check testResult reading later, but your system seems to be rather slow..."); + InternalTimer(gettimeofday()+4, sub { delete $hash->{testline}; + asyncOutput($tHash->{CL}, "Timeout for test sentence - most likely this is no problem, check testResult reading later, but either intent was not recognized, RHASSPY's siteId is not configured for NLU or your system seems to be rather slow..."); delete($hash->{asyncGet}); }, $tHash, 0); } @@ -2817,10 +2817,17 @@ sub testmode_next { }; my $json = _toCleanJSON($sendData); + resetRegIntTimer( 'testmode_end', time + 10, \&RHASSPY_testmode_timeout, $hash ) if $hash->{helper}->{test}->{filename} ne 'none'; return IOWrite($hash, 'publish', qq{hermes/nlu/query $json}); } + return testmode_end($hash); +} - my $filename = $hash->{helper}->{test}->{filename}; +sub testmode_end { + my $hash = shift // return; + my $fail = shift // 0; + + my $filename = $hash->{helper}->{test}->{filename} // q{none}; $filename =~ s{[.]txt\z}{}i; $filename = "${filename}_result.txt"; @@ -2832,8 +2839,11 @@ sub testmode_next { if ( $filename ne 'none_result.txt' ) { my $duration = ''; $duration = sprintf( " Testing time: %.2f seconds.", (gettimeofday() - $hash->{asyncGet}{start})*1) if $hash->{asyncGet} && $hash->{asyncGet}{reading} eq 'testResult'; - FileWrite({ FileName => $filename, ForceType => 'file' }, @{$hash->{helper}->{test}->{result}} ); - $result .= "$duration See $filename for detailed results." + my $result = $hash->{helper}->{test}->{result}; + push @{$result}, "test ended with timeout! Last request was $hash->{helper}->{test}->{content}->[$hash->{testline}]" if $fail; + FileWrite({ FileName => $filename, ForceType => 'file' }, @{$result} ); + $result .= "$duration See $filename for detailed results." if !$fail; + $result = "Test ended incomplete with timeout. See $filename for results up to failure." if $fail; } else { $result = $fails ? 'Test failed, ' : 'Test ok, '; $result .= "result is: $hash->{helper}->{test}->{result}->[0]" @@ -2842,11 +2852,14 @@ sub testmode_next { if( $hash->{asyncGet} && $hash->{asyncGet}{reading} eq 'testResult' ) { my $duration = sprintf( "%.2f", (gettimeofday() - $hash->{asyncGet}{start})*1); RemoveInternalTimer($hash->{asyncGet}); - asyncOutput($hash->{asyncGet}{CL}, "test(s) passed successfully. Summary: $result, duration: $duration s"); + my $suc = $fail ? 'not completely passed!' : 'passed successfully.'; + asyncOutput($hash->{asyncGet}{CL}, "test(s) $suc Summary: $result duration: $duration s"); delete($hash->{asyncGet}); } delete $hash->{testline}; delete $hash->{helper}->{test}; + deleteSingleRegIntTimer('testmode_end', $hash); + return; } @@ -2860,6 +2873,7 @@ sub testmode_parse { $hash->{helper}->{test}->{passed}++; if ( $intent eq 'intentNotRecognized' ) { $result = $line; + $result .= " => Intent not recognized." if $hash->{helper}->{test}->{filename} eq 'none'; $hash->{helper}->{test}->{notRecogn}++; $hash->{helper}->{test}->{notRecognInDialogue}++ if defined $hash->{helper}->{test}->{isInDialogue}; } else { @@ -2883,6 +2897,17 @@ sub testmode_parse { return testmode_next($hash); } +sub RHASSPY_testmode_timeout { + my $fnHash = shift // return; + my $hash = $fnHash->{HASH} // $fnHash; + return if !defined $hash; + my $identiy = $fnHash->{MODIFIER}; + deleteSingleRegIntTimer($identiy, $hash, 1); + + return testmode_end($hash, 1); +} + + sub _isUnexpectedInTestMode { my $hash = shift // return; my $data = shift // return; @@ -4495,9 +4520,9 @@ sub handleIntentSetNumeric { if ( defined $specials ) { my $vencmd = $specials->{setter} // $cmd; my $vendev = $specials->{device} // $device; - if ( $change ne 'cmdStop' ) { + if ( defined $change && $change ne 'cmdStop' ) { analyzeAndRunCmd($hash, $vendev, defined $specials->{CustomCommand} ? $specials->{CustomCommand} :$vencmd , $newVal) if $device ne $vendev || $cmd ne $vencmd; - } elsif ( defined $specials->{stopCommand} ) { + } elsif ( defined $change && $change eq 'cmdStop' && defined $specials->{stopCommand} ) { analyzeAndRunCmd($hash, $vendev, $specials->{stopCommand}); } } @@ -5819,7 +5844,6 @@ After changing something relevant within FHEM for either the data structure in

Get

-

Note: To get test results, RHASSPY's siteId has to be configured for intent recognition in Rhasspy as well.