From 6211ea93f11e20bacd4a5751603459209b8a1e40 Mon Sep 17 00:00:00 2001 From: justme-1968 Date: Mon, 14 Jan 2019 08:41:43 +0000 Subject: [PATCH] 39_alexa.pm: listen to *** status messages from alexa-fhem git-svn-id: https://svn.fhem.de/fhem/trunk@18248 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/39_alexa.pm | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/fhem/FHEM/39_alexa.pm b/fhem/FHEM/39_alexa.pm index 8a3666a7a..a6604db78 100644 --- a/fhem/FHEM/39_alexa.pm +++ b/fhem/FHEM/39_alexa.pm @@ -283,6 +283,21 @@ alexa_Read($) Log3 $name, 3, "$name: $buf"; } + if( $buf =~ m/^\*\*\* ([^\s]+) (.+)/ ) { + my $service = $1; + my $message = $2; + + if( $service eq 'FHEM:' ) { + if( $message =~ m/^connection failed(: (.*))?/ ) { + my $code = $2; + + $hash->{reason} = 'failed to connect to fhem'; + $hash->{reason} .= ": $code" if( $code ); + alexa_stopAlexaFHEM($hash); + } + } + } + return undef; } @@ -470,6 +485,8 @@ alexa_startAlexaFHEM($) my ($hash) = @_; my $name = $hash->{NAME}; + return undef if( !$init_done ); + my $key = ReadingsVal($name, 'alexaFHEM.skillRegKey', undef); if( !$key ) { my $key = getKeyValue('alexaFHEM.skillRegKey'); @@ -668,7 +685,13 @@ alexa_stoppedAlexaFHEM($) Log3 $name, 3, "$name: alexaFHEM stopped"; $hash->{LAST_STOP} = FmtDateTime( gettimeofday() ); - readingsSingleUpdate($hash, 'alexaFHEM', 'stopped', 1 ); + + if( $hash->{reason} ) { + readingsSingleUpdate($hash, 'alexaFHEM', "stopped: $hash->{reason}", 1 ); + delete $hash->{reason}; + } else { + readingsSingleUpdate($hash, 'alexaFHEM', 'stopped', 1 ); + } if( $hash->{undefine} ) { delete $hash->{undefine};