From 65105fe5ff35bf2893e015149c807496621e3fd4 Mon Sep 17 00:00:00 2001 From: LeonGaultier Date: Mon, 25 Mar 2019 07:09:31 +0000 Subject: [PATCH] 42_AptToDate: fix Can't call method readFromChild on an undefined value git-svn-id: https://svn.fhem.de/fhem/trunk@19024 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 2 ++ fhem/FHEM/42_AptToDate.pm | 52 +++++++++++++++++++++++---------------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 215b7d9d8..0e0fe25d7 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,7 @@ # 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. + - bugfix: 42_AptToDate: fix Can't call method readFromChild + on an undefined value - feature: 93_Log2Syslog: new attribute "exclErrCond" to exclude events from rating as "Error" - changed: 70_BRAVIA: optimized command queue, diff --git a/fhem/FHEM/42_AptToDate.pm b/fhem/FHEM/42_AptToDate.pm index c9b3c88f8..c4fc92466 100644 --- a/fhem/FHEM/42_AptToDate.pm +++ b/fhem/FHEM/42_AptToDate.pm @@ -2,7 +2,7 @@ # # Developed with Kate # -# (c) 2017-2018 Copyright: Marko Oldenburg (leongaultier at gmail dot com) +# (c) 2017-2019 Copyright: Marko Oldenburg (leongaultier at gmail dot com) # All rights reserved # # Special thanks goes to: @@ -35,7 +35,7 @@ package main; use strict; use warnings; -my $version = "1.4.2"; +my $version = "1.4.3"; sub AptToDate_Initialize($) { @@ -499,24 +499,27 @@ sub PollChild($) { my $hash = shift; my $name = $hash->{NAME}; - my $subprocess = $hash->{".fhem"}{subprocess}; - my $json = $subprocess->readFromChild(); + + if ( defined($hash->{".fhem"}{subprocess}) ) { + my $subprocess = $hash->{".fhem"}{subprocess}; + my $json = $subprocess->readFromChild(); - if ( !defined($json) ) { - Log3 $name, 5, "AptToDate ($name) - still waiting (" - . $subprocess->{lasterror} . ")."; - InternalTimer( gettimeofday() + POLLINTERVAL, - "AptToDate::PollChild", $hash, 0 ); - return; - } - else { - Log3 $name, 4, - "AptToDate ($name) - got result from asynchronous parsing."; - $subprocess->wait(); - Log3 $name, 4, "AptToDate ($name) - asynchronous finished."; + if ( !defined($json) ) { + Log3 $name, 5, "AptToDate ($name) - still waiting (" + . $subprocess->{lasterror} . ")."; + InternalTimer( gettimeofday() + POLLINTERVAL, + "AptToDate::PollChild", $hash, 0 ); + return; + } + else { + Log3 $name, 4, + "AptToDate ($name) - got result from asynchronous parsing."; + $subprocess->wait(); + Log3 $name, 4, "AptToDate ($name) - asynchronous finished."; - CleanSubprocess($hash); - PreProcessing( $hash, $json ); + CleanSubprocess($hash); + PreProcessing( $hash, $json ); + } } } @@ -843,9 +846,16 @@ sub WriteReadings($$) { readingsBulkUpdateIfChanged( $hash, 'updatesAvailable', scalar keys %{ $decode_json->{packages} } ) if ( $hash->{".fhem"}{aptget}{cmd} eq 'getUpdateList' ); - readingsBulkUpdateIfChanged( $hash, 'upgradeListAsJSON', - eval { encode_json( $hash->{".fhem"}{aptget}{packages} ) } ) - if ( AttrVal( $name, 'upgradeListReading', 'none' ) ne 'none' ); + + if ( scalar keys%{ $hash->{".fhem"}{aptget}{packages} } > 0 ) { + readingsBulkUpdateIfChanged( $hash, 'upgradeListAsJSON', + eval { encode_json( $hash->{".fhem"}{aptget}{packages} ) } ) + if ( AttrVal( $name, 'upgradeListReading', 'none' ) ne 'none' ); + } + else { readingsBulkUpdateIfChanged( $hash, 'upgradeListAsJSON', '' ) + if ( AttrVal( $name, 'upgradeListReading', 'none' ) ne 'none' ); + } + readingsBulkUpdate( $hash, 'toUpgrade', 'successful' ) if ( $hash->{".fhem"}{aptget}{cmd} eq 'toUpgrade' and not defined( $hash->{".fhem"}{aptget}{'errors'} )