fix 'Can't call method readFromChild on an undefined value'

This commit is contained in:
Marko Oldenburg 2019-03-24 10:24:00 +01:00
parent bc8f2ac22f
commit 380cea01ed

View File

@ -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,6 +499,8 @@ sub PollChild($) {
my $hash = shift;
my $name = $hash->{NAME};
if ( defined($hash->{".fhem"}{subprocess}) ) {
my $subprocess = $hash->{".fhem"}{subprocess};
my $json = $subprocess->readFromChild();
@ -519,6 +521,7 @@ sub PollChild($) {
PreProcessing( $hash, $json );
}
}
}
######################################
# Begin Childprozess
@ -843,9 +846,16 @@ sub WriteReadings($$) {
readingsBulkUpdateIfChanged( $hash, 'updatesAvailable',
scalar keys %{ $decode_json->{packages} } )
if ( $hash->{".fhem"}{aptget}{cmd} eq 'getUpdateList' );
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'} )