fix can't read from socket

fix via try catch directive.

[Ticket: #9]
This commit is contained in:
Marko Oldenburg 2022-03-17 11:01:14 +01:00
parent d990354547
commit 4c92240cc5
3 changed files with 19 additions and 36 deletions

View File

@ -368,7 +368,7 @@ __END__
],
"release_status": "stable",
"license": "GPL_2",
"version": "v3.6.2",
"version": "v3.6.3",
"author": [
"Marko Oldenburg <fhemdevelopment@cooltux.net>"
],

View File

@ -1,2 +1,2 @@
UPD 2022-03-13_11:17:13 18968 FHEM/82_LGTV_WebOS.pm
UPD 2022-03-17_08:40:15 54825 lib/FHEM/Devices/LGTV/LGTVWebOS.pm
UPD 2022-03-17_11:00:18 18968 FHEM/82_LGTV_WebOS.pm
UPD 2022-03-17_10:59:44 54628 lib/FHEM/Devices/LGTV/LGTVWebOS.pm

View File

@ -736,8 +736,20 @@ sub Read {
$hash->{helper}->{lastResponse} =
int( ::gettimeofday() ); # Check Socket KeepAlive
$len = sysread( $hash->{CD}, $buf, 10240 )
if exists( $hash->{CD} );
try {
$len = sysread( $hash->{CD}, $buf, 10240 );
}
catch {
if ( $_->isa('autodie::exception') && $_->matches(':io') ) {
Log3( $name, 2, "LGTV_WebOS ($name) - can't read from socket: $_" );
return;
}
else {
Log3( $name, 2, "LGTV_WebOS ($name) - can't read from socket: $_" );
return;
}
};
if ( !defined($len) || !$len ) {
@ -994,8 +1006,6 @@ sub WriteServiceReadings {
my $hash = shift;
my $decode_json = shift;
::readingsBeginUpdate($hash);
for my $services ( @{ $decode_json->{payload}{services} } ) {
::readingsBulkUpdateIfChanged(
$hash,
@ -1004,8 +1014,6 @@ sub WriteServiceReadings {
);
}
::readingsEndUpdate( $hash, 1 );
return;
}
@ -1013,8 +1021,6 @@ sub WriteDeviceReadings {
my $hash = shift;
my $decode_json = shift;
::readingsBeginUpdate($hash);
for my $devices ( @{ $decode_json->{payload}{devices} } ) {
if ( !exists( $hash->{helper}{device}{inputs}{ $devices->{label} } )
@ -1035,8 +1041,6 @@ sub WriteDeviceReadings {
);
}
::readingsEndUpdate( $hash, 1 );
return;
}
@ -1046,9 +1050,6 @@ sub WriteProgramlistReadings {
require Date::Parse;
my $count = 0;
::readingsBeginUpdate($hash);
for my $programList ( @{ $decode_json->{payload}{programList} } ) {
if (
@ -1080,8 +1081,6 @@ sub WriteProgramlistReadings {
}
}
::readingsEndUpdate( $hash, 1 );
return;
}
@ -1089,8 +1088,6 @@ sub WriteMuteReadings {
my $hash = shift;
my $decode_json = shift;
::readingsBeginUpdate($hash);
if (
exists( $decode_json->{payload}{'mute'} )
&& ( $decode_json->{payload}{'mute'} eq 'true'
@ -1130,8 +1127,6 @@ sub WriteMuteReadings {
::readingsBulkUpdateIfChanged( $hash, 'mute', 'off' );
}
::readingsEndUpdate( $hash, 1 );
return;
}
@ -1139,8 +1134,6 @@ sub Write3dReadings {
my $hash = shift;
my $decode_json = shift;
::readingsBeginUpdate($hash);
if ( $decode_json->{payload}{status3D}{status} eq 'false'
|| $decode_json->{payload}{status3D}{status} == 0 )
{
@ -1158,8 +1151,6 @@ sub Write3dReadings {
::readingsBulkUpdateIfChanged( $hash, '3DMode',
$decode_json->{payload}{status3D}{pattern} );
::readingsEndUpdate( $hash, 1 );
return;
}
@ -1167,8 +1158,6 @@ sub WriteAppIdReadings {
my $hash = shift;
my $decode_json = shift;
::readingsBeginUpdate($hash);
if (
(
$decode_json->{payload}{appId} =~ /com.webos.app.externalinput/x
@ -1196,8 +1185,6 @@ sub WriteAppIdReadings {
::readingsBulkUpdateIfChanged( $hash, 'input', '-' );
}
::readingsEndUpdate( $hash, 1 );
return;
}
@ -1207,8 +1194,6 @@ sub WriteTypeReadings {
my $response;
::readingsBeginUpdate($hash);
if ( $decode_json->{type} eq 'registered'
&& exists( $decode_json->{payload}{'client-key'} ) )
{
@ -1252,8 +1237,6 @@ sub WriteTypeReadings {
if ( $hash->{helper}{device}{runsetcmd} > 0 );
}
::readingsEndUpdate( $hash, 1 );
return $response;
}
@ -1265,6 +1248,8 @@ sub WriteReadings {
::Log3( $name, 4, "LGTV_WebOS ($name) - Beginn Readings writing" );
::readingsBeginUpdate($hash);
if ( ref( $decode_json->{payload}{services} ) eq "ARRAY"
&& scalar( @{ $decode_json->{payload}{services} } ) > 0 )
{
@ -1293,8 +1278,6 @@ sub WriteReadings {
WriteAppIdReadings( $hash, $decode_json );
}
::readingsBeginUpdate($hash);
if ( exists( $decode_json->{type} ) ) {
$response = WriteTypeReadings( $hash, $decode_json );
}