add more sub routine to take low PBP complexity score

This commit is contained in:
Marko Oldenburg 2022-01-04 22:45:57 +01:00
parent ecd35d4526
commit 65b2ef48d1

View File

@ -956,43 +956,30 @@ sub LGTV_WebOS_ResponseProcessing {
return; return;
} }
sub LGTV_WebOS_WriteReadings { sub LGTV_WebOS_WriteServiceReadings {
my ( $hash, $decode_json ) = @_; my $hash = shift;
my $decode_json = shift;
my $name = $hash->{NAME};
my $response;
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 )
{
for my $services ( @{ $decode_json->{payload}{services} } ) { for my $services ( @{ $decode_json->{payload}{services} } ) {
readingsBulkUpdateIfChanged( readingsBulkUpdateIfChanged(
$hash, $hash,
'service_' . $services->{name}, 'service_' . $services->{name},
'v.' . $services->{version} 'v.' . $services->{version}
); );
} }
}
elsif ( ref( $decode_json->{payload}{devices} ) eq "ARRAY" return;
&& scalar( @{ $decode_json->{payload}{devices} } ) > 0 ) }
{
sub LGTV_WebOS_WriteDeviceReadings {
my $hash = shift;
my $decode_json = shift;
for my $devices ( @{ $decode_json->{payload}{devices} } ) { for my $devices ( @{ $decode_json->{payload}{devices} } ) {
if ( if ( !defined( $hash->{helper}{device}{inputs}{ $devices->{label} } )
!defined( || !
$hash->{helper}{device}{inputs}{ $devices->{label} } defined( $hash->{helper}{device}{inputapps}{ $devices->{appId} } ) )
)
|| !defined(
$hash->{helper}{device}{inputapps}{ $devices->{appId} }
)
)
{ {
$hash->{helper}{device}{inputs} $hash->{helper}{device}{inputs}
@ -1007,20 +994,21 @@ sub LGTV_WebOS_WriteReadings {
'connect_' . $devices->{connected} 'connect_' . $devices->{connected}
); );
} }
}
elsif ( ref( $decode_json->{payload}{programList} ) eq "ARRAY" return;
&& scalar( @{ $decode_json->{payload}{programList} } ) > 0 ) }
{
sub LGTV_WebOS_WriteProgramlistReadings {
my $hash = shift;
my $decode_json = shift;
require Date::Parse; require Date::Parse;
my $count = 0; my $count = 0;
for my $programList ( @{ $decode_json->{payload}{programList} } ) { for my $programList ( @{ $decode_json->{payload}{programList} } ) {
if ( if (
str2time( str2time(
LGTV_WebOS_FormartStartEndTime( LGTV_WebOS_FormartStartEndTime( $programList->{localEndTime} )
$programList->{localEndTime}
)
) > time() ) > time()
) )
{ {
@ -1068,11 +1056,13 @@ sub LGTV_WebOS_WriteReadings {
return if ( $count > 1 ); return if ( $count > 1 );
} }
} }
}
elsif (defined( $decode_json->{payload}{'mute'} ) return;
|| defined( $decode_json->{payload}{'muted'} ) ) }
{
sub LGTV_WebOS_WriteMuteReadings {
my $hash = shift;
my $decode_json = shift;
if ( if (
defined( $decode_json->{payload}{'mute'} ) defined( $decode_json->{payload}{'mute'} )
@ -1112,9 +1102,14 @@ sub LGTV_WebOS_WriteReadings {
readingsBulkUpdateIfChanged( $hash, 'mute', 'off' ); readingsBulkUpdateIfChanged( $hash, 'mute', 'off' );
} }
}
elsif ( defined( $decode_json->{payload}{status3D}{status} ) ) { return;
}
sub LGTV_WebOS_Write3dReadings {
my $hash = shift;
my $decode_json = shift;
if ( $decode_json->{payload}{status3D}{status} eq 'false' if ( $decode_json->{payload}{status3D}{status} eq 'false'
|| $decode_json->{payload}{status3D}{status} == 0 ) || $decode_json->{payload}{status3D}{status} == 0 )
{ {
@ -1131,9 +1126,13 @@ sub LGTV_WebOS_WriteReadings {
readingsBulkUpdateIfChanged( $hash, '3DMode', readingsBulkUpdateIfChanged( $hash, '3DMode',
$decode_json->{payload}{status3D}{pattern} ); $decode_json->{payload}{status3D}{pattern} );
}
elsif ( defined( $decode_json->{payload}{appId} ) ) { return;
}
sub LGTV_WebOS_WriteAppIdReadings {
my $hash = shift;
my $decode_json = shift;
if ( if (
( (
@ -1141,22 +1140,19 @@ sub LGTV_WebOS_WriteReadings {
|| $decode_json->{payload}{appId} =~ /com.webos.app.hdmi/x || $decode_json->{payload}{appId} =~ /com.webos.app.hdmi/x
) )
&& defined( && defined(
$hash->{helper}{device}{inputapps} $hash->{helper}{device}{inputapps}{ $decode_json->{payload}{appId} }
{ $decode_json->{payload}{appId} }
) )
&& $hash->{helper}{device}{inputapps} && $hash->{helper}{device}{inputapps}{ $decode_json->{payload}{appId} }
{ $decode_json->{payload}{appId} }
) )
{ {
readingsBulkUpdateIfChanged( $hash, 'input', readingsBulkUpdateIfChanged( $hash, 'input',
$hash->{helper}{device}{inputapps} $hash->{helper}{device}{inputapps}{ $decode_json->{payload}{appId} }
{ $decode_json->{payload}{appId} } ); );
readingsBulkUpdateIfChanged( $hash, 'launchApp', '-' ); readingsBulkUpdateIfChanged( $hash, 'launchApp', '-' );
} }
elsif ( elsif ( defined( $openAppsPackageName{ $decode_json->{payload}{appId} } )
defined( $openAppsPackageName{ $decode_json->{payload}{appId} } )
&& $openAppsPackageName{ $decode_json->{payload}{appId} } ) && $openAppsPackageName{ $decode_json->{payload}{appId} } )
{ {
@ -1165,9 +1161,14 @@ sub LGTV_WebOS_WriteReadings {
readingsBulkUpdateIfChanged( $hash, 'input', '-' ); readingsBulkUpdateIfChanged( $hash, 'input', '-' );
} }
} return;
}
if ( defined( $decode_json->{type} ) ) { sub LGTV_WebOS_WriteTypeReadings {
my $hash = shift;
my $decode_json = shift;
my $response;
if ( $decode_json->{type} eq 'registered' if ( $decode_json->{type} eq 'registered'
&& defined( $decode_json->{payload}{'client-key'} ) ) && defined( $decode_json->{payload}{'client-key'} ) )
@ -1211,6 +1212,50 @@ sub LGTV_WebOS_WriteReadings {
$hash->{helper}{device}{runsetcmd} - 1 $hash->{helper}{device}{runsetcmd} - 1
if ( $hash->{helper}{device}{runsetcmd} > 0 ); if ( $hash->{helper}{device}{runsetcmd} > 0 );
} }
return $response;
}
sub LGTV_WebOS_WriteReadings {
my ( $hash, $decode_json ) = @_;
my $name = $hash->{NAME};
my $response;
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 )
{
LGTV_WebOS_WriteServiceReadings( $hash, $decode_json );
}
elsif ( ref( $decode_json->{payload}{devices} ) eq "ARRAY"
&& scalar( @{ $decode_json->{payload}{devices} } ) > 0 )
{
LGTV_WebOS_WriteDeviceReadings( $hash, $decode_json );
}
elsif ( ref( $decode_json->{payload}{programList} ) eq "ARRAY"
&& scalar( @{ $decode_json->{payload}{programList} } ) > 0 )
{
LGTV_WebOS_WriteProgramlistReadings( $hash, $decode_json );
}
if ( defined( $decode_json->{payload}{'mute'} )
|| defined( $decode_json->{payload}{'muted'} ) )
{
LGTV_WebOS_WriteMuteReadings( $hash, $decode_json );
}
elsif ( defined( $decode_json->{payload}{status3D}{status} ) ) {
LGTV_WebOS_Write3dReadings( $hash, $decode_json );
}
elsif ( defined( $decode_json->{payload}{appId} ) ) {
LGTV_WebOS_WriteAppIdReadings( $hash, $decode_json );
}
if ( defined( $decode_json->{type} ) ) {
$response = LGTV_WebOS_WriteTypeReadings( $hash, $decode_json );
} }
readingsBulkUpdateIfChanged( $hash, 'lgKey', readingsBulkUpdateIfChanged( $hash, 'lgKey',