insert older version and check keep alive socket
This commit is contained in:
parent
c9120325b0
commit
47b20c4d3e
262
82_LGTV_WebOS.pm
262
82_LGTV_WebOS.pm
@ -25,7 +25,7 @@
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
#
|
||||
# $Id$
|
||||
# $Id: 82_LGTV_WebOS.pm 25389 2021-12-30 15:48:41Z CoolTux $
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
@ -57,11 +57,12 @@ use strict;
|
||||
use warnings;
|
||||
use FHEM::Meta;
|
||||
|
||||
eval "use MIME::Base64;1" or $missingModul .= "MIME::Base64 ";
|
||||
eval "use IO::Socket::INET;1" or $missingModul .= "IO::Socket::INET ";
|
||||
eval "use Digest::SHA qw(sha1_hex);1" or $missingModul .= "Digest::SHA ";
|
||||
eval "use Encode qw(encode_utf8 decode_utf8);1" or $missingModul .= "Encode ";
|
||||
eval "use Blocking;1" or $missingModul .= "Blocking ";
|
||||
eval { use MIME::Base64; 1 } or $missingModul .= "MIME::Base64 ";
|
||||
eval { use IO::Socket::INET; 1 } or $missingModul .= "IO::Socket::INET ";
|
||||
eval { use Digest::SHA qw(sha1_hex); 1 } or $missingModul .= "Digest::SHA ";
|
||||
eval { use Encode qw(encode_utf8 decode_utf8); 1 }
|
||||
or $missingModul .= "Encode ";
|
||||
eval { use Blocking; 1 } or $missingModul .= "Blocking ";
|
||||
|
||||
# try to use JSON::MaybeXS wrapper
|
||||
# for chance of better performance + open code
|
||||
@ -69,15 +70,11 @@ eval {
|
||||
require JSON::MaybeXS;
|
||||
import JSON::MaybeXS qw( decode_json encode_json );
|
||||
1;
|
||||
};
|
||||
|
||||
if ($@) {
|
||||
$@ = undef;
|
||||
} or do {
|
||||
|
||||
# try to use JSON wrapper
|
||||
# for chance of better performance
|
||||
eval {
|
||||
|
||||
# JSON preference order
|
||||
local $ENV{PERL_JSON_BACKEND} =
|
||||
'Cpanel::JSON::XS,JSON::XS,JSON::PP,JSON::backportPP'
|
||||
@ -86,10 +83,7 @@ if ($@) {
|
||||
require JSON;
|
||||
import JSON qw( decode_json encode_json );
|
||||
1;
|
||||
};
|
||||
|
||||
if ($@) {
|
||||
$@ = undef;
|
||||
} or do {
|
||||
|
||||
# In rare cases, Cpanel::JSON::XS may
|
||||
# be installed but JSON|JSON::MaybeXS not ...
|
||||
@ -97,10 +91,7 @@ if ($@) {
|
||||
require Cpanel::JSON::XS;
|
||||
import Cpanel::JSON::XS qw(decode_json encode_json);
|
||||
1;
|
||||
};
|
||||
|
||||
if ($@) {
|
||||
$@ = undef;
|
||||
} or do {
|
||||
|
||||
# In rare cases, JSON::XS may
|
||||
# be installed but JSON not ...
|
||||
@ -108,10 +99,7 @@ if ($@) {
|
||||
require JSON::XS;
|
||||
import JSON::XS qw(decode_json encode_json);
|
||||
1;
|
||||
};
|
||||
|
||||
if ($@) {
|
||||
$@ = undef;
|
||||
} or do {
|
||||
|
||||
# Fallback to built-in JSON which SHOULD
|
||||
# be available since 5.014 ...
|
||||
@ -119,20 +107,17 @@ if ($@) {
|
||||
require JSON::PP;
|
||||
import JSON::PP qw(decode_json encode_json);
|
||||
1;
|
||||
};
|
||||
|
||||
if ($@) {
|
||||
$@ = undef;
|
||||
} or do {
|
||||
|
||||
# Fallback to JSON::backportPP in really rare cases
|
||||
require JSON::backportPP;
|
||||
import JSON::backportPP qw(decode_json encode_json);
|
||||
1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
my %lgCommands = (
|
||||
|
||||
@ -206,13 +191,11 @@ my %openApps = (
|
||||
'DAZN' => 'dazn',
|
||||
'SkyQ' => 'com.skygo.app.de.q',
|
||||
'WaipuTv' => 'tv.waipu.app.waipu-lg',
|
||||
|
||||
);
|
||||
|
||||
my %openAppsPackageName = reverse %openApps;
|
||||
|
||||
sub LGTV_WebOS_Initialize {
|
||||
|
||||
my ($hash) = @_;
|
||||
|
||||
# Provider
|
||||
@ -237,7 +220,6 @@ sub LGTV_WebOS_Initialize {
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_Define {
|
||||
|
||||
my ( $hash, $def ) = @_;
|
||||
|
||||
my @a = split( "[ \t][ \t]*", $def );
|
||||
@ -278,35 +260,33 @@ sub LGTV_WebOS_Define {
|
||||
"LGTV_WebOS_TimerStatusRequest", $hash );
|
||||
}
|
||||
|
||||
$hash->{helper}->{lastResponse} =
|
||||
int( gettimeofday() ); # Check Socket KeepAlive
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_Undef {
|
||||
|
||||
my ( $hash, $arg ) = @_;
|
||||
|
||||
my $host = $hash->{HOST};
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
RemoveInternalTimer($hash);
|
||||
|
||||
LGTV_WebOS_Close($hash);
|
||||
delete $modules{LGTV_WebOS}{defptr}{ $hash->{HOST} };
|
||||
|
||||
Log3 $name, 3, "LGTV_WebOS ($name) - device $name deleted";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_Attr {
|
||||
|
||||
my ( $cmd, $name, $attrName, $attrVal ) = @_;
|
||||
my $hash = $defs{$name};
|
||||
|
||||
my $orig = $attrVal;
|
||||
|
||||
if ( $attrName eq "disable" ) {
|
||||
if ( $cmd eq "set" and $attrVal eq "1" ) {
|
||||
if ( $cmd eq "set" && $attrVal eq "1" ) {
|
||||
RemoveInternalTimer($hash);
|
||||
readingsSingleUpdate( $hash, "state", "disabled", 1 );
|
||||
$hash->{PARTIAL} = '';
|
||||
@ -336,7 +316,6 @@ sub LGTV_WebOS_Attr {
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_TimerStatusRequest {
|
||||
|
||||
my $hash = shift;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
@ -344,9 +323,9 @@ sub LGTV_WebOS_TimerStatusRequest {
|
||||
|
||||
readingsBeginUpdate($hash);
|
||||
|
||||
if ( !IsDisabled($name)
|
||||
and $hash->{CD}
|
||||
and $hash->{helper}{device}{registered} == 1 )
|
||||
if ( !IsDisabled($name)
|
||||
&& $hash->{CD}
|
||||
&& $hash->{helper}{device}{registered} == 1 )
|
||||
{
|
||||
|
||||
Log3 $name, 4, "LGTV_WebOS ($name) - run get functions";
|
||||
@ -354,9 +333,9 @@ sub LGTV_WebOS_TimerStatusRequest {
|
||||
LGTV_WebOS_Presence($hash)
|
||||
if ( AttrVal( $name, 'pingPresence', 0 ) == 1 );
|
||||
|
||||
if ( $hash->{helper}{device}{channelguide}{counter} > 2
|
||||
and AttrVal( $name, 'channelGuide', 0 ) == 1
|
||||
and ReadingsVal( $name, 'launchApp', 'TV' ) eq 'TV' )
|
||||
if ( $hash->{helper}{device}{channelguide}{counter} > 2
|
||||
&& AttrVal( $name, 'channelGuide', 0 ) == 1
|
||||
&& ReadingsVal( $name, 'launchApp', 'TV' ) eq 'TV' )
|
||||
{
|
||||
|
||||
LGTV_WebOS_GetChannelProgramInfo($hash);
|
||||
@ -407,18 +386,19 @@ sub LGTV_WebOS_TimerStatusRequest {
|
||||
|
||||
readingsEndUpdate( $hash, 1 );
|
||||
|
||||
LGTV_WebOS_Open($hash) if ( !IsDisabled($name) and not $hash->{CD} );
|
||||
LGTV_WebOS_Open($hash) if ( !IsDisabled($name) && !$hash->{CD} );
|
||||
|
||||
$hash->{helper}{device}{channelguide}{counter} =
|
||||
$hash->{helper}{device}{channelguide}{counter} + 1;
|
||||
InternalTimer( gettimeofday() + 10, "LGTV_WebOS_TimerStatusRequest",
|
||||
$hash );
|
||||
|
||||
LGTV_WebOS_SocketKeepAlive($hash); # Check Socket KeepAlive
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_Set {
|
||||
|
||||
my ( $hash, $name, $cmd, @args ) = @_;
|
||||
my ( $arg, @params ) = @args;
|
||||
|
||||
@ -432,7 +412,7 @@ sub LGTV_WebOS_Set {
|
||||
|
||||
LGTV_WebOS_Open($hash);
|
||||
|
||||
return undef;
|
||||
return;
|
||||
|
||||
}
|
||||
elsif ( $cmd eq 'clearInputList' ) {
|
||||
@ -441,7 +421,7 @@ sub LGTV_WebOS_Set {
|
||||
delete $hash->{helper}{device}{inputs};
|
||||
delete $hash->{helper}{device}{inputapps};
|
||||
|
||||
return undef;
|
||||
return;
|
||||
|
||||
}
|
||||
elsif ( $cmd eq 'pairing' ) {
|
||||
@ -449,7 +429,7 @@ sub LGTV_WebOS_Set {
|
||||
|
||||
LGTV_WebOS_Pairing($hash);
|
||||
|
||||
return undef;
|
||||
return;
|
||||
|
||||
}
|
||||
elsif ( $cmd eq 'screenMsg' ) {
|
||||
@ -460,7 +440,7 @@ sub LGTV_WebOS_Set {
|
||||
$uri = $lgCommands{$cmd}->[0];
|
||||
|
||||
}
|
||||
elsif ( $cmd eq 'on' or $cmd eq 'off' ) {
|
||||
elsif ( $cmd eq 'on' || $cmd eq 'off' ) {
|
||||
return "usage: on/off" if ( @args != 0 );
|
||||
|
||||
if ( $cmd eq 'off' ) {
|
||||
@ -641,19 +621,16 @@ sub LGTV_WebOS_Set {
|
||||
. join( ',',
|
||||
=> map qq{$_} => keys %{ $hash->{helper}{device}{inputs} } )
|
||||
if ( defined( $hash->{helper}{device}{inputs} )
|
||||
and ref( $hash->{helper}{device}{inputs} ) eq "HASH" );
|
||||
&& ref( $hash->{helper}{device}{inputs} ) eq "HASH" );
|
||||
|
||||
return "Unknown argument $cmd, choose one of $list";
|
||||
}
|
||||
|
||||
$hash->{helper}{device}{runsetcmd} = $hash->{helper}{device}{runsetcmd} + 1;
|
||||
LGTV_WebOS_CreateSendCommand( $hash, $uri, \%payload );
|
||||
|
||||
return;
|
||||
return LGTV_WebOS_CreateSendCommand( $hash, $uri, \%payload );
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_Open {
|
||||
|
||||
my $hash = shift;
|
||||
my $name = $hash->{NAME};
|
||||
my $host = $hash->{HOST};
|
||||
@ -663,10 +640,11 @@ sub LGTV_WebOS_Open {
|
||||
Log3 $name, 4, "LGTV_WebOS ($name) - Baue Socket Verbindung auf";
|
||||
|
||||
my $socket = new IO::Socket::INET(
|
||||
PeerHost => $host,
|
||||
PeerPort => $port,
|
||||
Proto => 'tcp',
|
||||
Timeout => $timeout
|
||||
PeerHost => $host,
|
||||
PeerPort => $port,
|
||||
Proto => 'tcp',
|
||||
KeepAlive => 1,
|
||||
Timeout => $timeout
|
||||
)
|
||||
or return Log3 $name, 4,
|
||||
"LGTV_WebOS ($name) Couldn't connect to $host:$port"; # open Socket
|
||||
@ -675,6 +653,9 @@ sub LGTV_WebOS_Open {
|
||||
$hash->{CD} = $socket; # sysread / close won't work on fileno
|
||||
$selectlist{$name} = $hash;
|
||||
|
||||
$hash->{helper}->{lastResponse} =
|
||||
int( gettimeofday() ); # Check Socket KeepAlive
|
||||
|
||||
Log3 $name, 4, "LGTV_WebOS ($name) - Socket Connected";
|
||||
|
||||
LGTV_WebOS_Handshake($hash);
|
||||
@ -684,16 +665,18 @@ sub LGTV_WebOS_Open {
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_Close {
|
||||
|
||||
my $hash = shift;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
return if ( !$hash->{CD} );
|
||||
|
||||
delete( $hash->{PARTIAL} );
|
||||
|
||||
close( $hash->{CD} ) if ( $hash->{CD} );
|
||||
delete( $hash->{FD} );
|
||||
delete( $hash->{CD} );
|
||||
|
||||
delete( $selectlist{$name} );
|
||||
delete( $hash->{FD} );
|
||||
|
||||
readingsSingleUpdate( $hash, 'state', 'off', 1 );
|
||||
|
||||
@ -714,12 +697,23 @@ sub LGTV_WebOS_Write {
|
||||
|
||||
Log3 $name, 4, "LGTV_WebOS ($name) - $string";
|
||||
syswrite( $hash->{CD}, $string );
|
||||
return;
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_SocketKeepAlive {
|
||||
my $hash = shift;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
if ( int( gettimeofday() ) - int( $hash->{helper}->{lastResponse} ) > 2 ) {
|
||||
LGTV_WebOS_SocketClosePresenceAbsent( $hash, 'absent' );
|
||||
Log3 $name, 3,
|
||||
"LGTV_WebOS ($name) - KeepAlive It looks like there no Data more response";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_Read {
|
||||
|
||||
my $hash = shift;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
@ -728,9 +722,11 @@ sub LGTV_WebOS_Read {
|
||||
|
||||
Log3 $name, 4, "LGTV_WebOS ($name) - ReadFn started";
|
||||
|
||||
$hash->{helper}->{lastResponse} =
|
||||
int( gettimeofday() ); # Check Socket KeepAlive
|
||||
$len = sysread( $hash->{CD}, $buf, 10240 );
|
||||
|
||||
if ( !defined($len) or !$len ) {
|
||||
if ( !defined($len) || !$len ) {
|
||||
|
||||
LGTV_WebOS_Close($hash);
|
||||
|
||||
@ -770,7 +766,6 @@ sub LGTV_WebOS_Read {
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_ProcessRead {
|
||||
|
||||
my ( $hash, $data ) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
@ -778,7 +773,7 @@ sub LGTV_WebOS_ProcessRead {
|
||||
|
||||
Log3 $name, 4, "LGTV_WebOS ($name) - process read";
|
||||
|
||||
if ( defined( $hash->{PARTIAL} ) and $hash->{PARTIAL} ) {
|
||||
if ( defined( $hash->{PARTIAL} ) && $hash->{PARTIAL} ) {
|
||||
|
||||
Log3 $name, 5, "LGTV_WebOS ($name) - PARTIAL: " . $hash->{PARTIAL};
|
||||
$buffer = $hash->{PARTIAL};
|
||||
@ -816,7 +811,7 @@ sub LGTV_WebOS_ProcessRead {
|
||||
. $tail;
|
||||
|
||||
LGTV_WebOS_ResponseProcessing( $hash, $json )
|
||||
unless ( not defined($tail) and not($tail) );
|
||||
unless ( !defined($tail) && not($tail) );
|
||||
|
||||
( $json, $tail ) = LGTV_WebOS_ParseMsg( $hash, $tail );
|
||||
|
||||
@ -841,7 +836,6 @@ sub LGTV_WebOS_ProcessRead {
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_Handshake {
|
||||
|
||||
my $hash = shift;
|
||||
my $name = $hash->{NAME};
|
||||
my $host = $hash->{HOST};
|
||||
@ -872,7 +866,6 @@ sub LGTV_WebOS_Handshake {
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_ResponseProcessing {
|
||||
|
||||
my ( $hash, $response ) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
@ -917,7 +910,7 @@ sub LGTV_WebOS_ResponseProcessing {
|
||||
}
|
||||
}
|
||||
|
||||
return undef;
|
||||
return;
|
||||
}
|
||||
|
||||
elsif ( $response =~ m/^{"type":".+}}$/ ) {
|
||||
@ -933,7 +926,7 @@ sub LGTV_WebOS_ResponseProcessing {
|
||||
Log3 $name, 4, "LGTV_WebOS ($name) - Corrected JSON String: $json"
|
||||
if ($json);
|
||||
|
||||
if ( not defined($json) or not($json) ) {
|
||||
if ( !defined($json) || not($json) ) {
|
||||
|
||||
Log3 $name, 4, "LGTV_WebOS ($name) - Corrected JSON String empty";
|
||||
return;
|
||||
@ -947,7 +940,7 @@ sub LGTV_WebOS_ResponseProcessing {
|
||||
|
||||
LGTV_WebOS_WriteReadings( $hash, $decode_json );
|
||||
|
||||
return undef;
|
||||
return;
|
||||
}
|
||||
|
||||
Log3 $name, 4, "LGTV_WebOS ($name) - no Match found";
|
||||
@ -956,7 +949,6 @@ sub LGTV_WebOS_ResponseProcessing {
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_WriteReadings {
|
||||
|
||||
my ( $hash, $decode_json ) = @_;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
@ -969,9 +961,9 @@ sub LGTV_WebOS_WriteReadings {
|
||||
readingsBeginUpdate($hash);
|
||||
|
||||
if ( ref( $decode_json->{payload}{services} ) eq "ARRAY"
|
||||
and scalar( @{ $decode_json->{payload}{services} } ) > 0 )
|
||||
&& scalar( @{ $decode_json->{payload}{services} } ) > 0 )
|
||||
{
|
||||
foreach my $services ( @{ $decode_json->{payload}{services} } ) {
|
||||
for my $services ( @{ $decode_json->{payload}{services} } ) {
|
||||
|
||||
readingsBulkUpdateIfChanged(
|
||||
$hash,
|
||||
@ -982,15 +974,15 @@ sub LGTV_WebOS_WriteReadings {
|
||||
}
|
||||
|
||||
elsif ( ref( $decode_json->{payload}{devices} ) eq "ARRAY"
|
||||
and scalar( @{ $decode_json->{payload}{devices} } ) > 0 )
|
||||
&& scalar( @{ $decode_json->{payload}{devices} } ) > 0 )
|
||||
{
|
||||
|
||||
foreach my $devices ( @{ $decode_json->{payload}{devices} } ) {
|
||||
for my $devices ( @{ $decode_json->{payload}{devices} } ) {
|
||||
|
||||
if (
|
||||
not
|
||||
defined( $hash->{helper}{device}{inputs}{ $devices->{label} } )
|
||||
or not defined(
|
||||
|| !defined(
|
||||
$hash->{helper}{device}{inputapps}{ $devices->{appId} }
|
||||
)
|
||||
)
|
||||
@ -1011,11 +1003,11 @@ sub LGTV_WebOS_WriteReadings {
|
||||
}
|
||||
|
||||
elsif ( ref( $decode_json->{payload}{programList} ) eq "ARRAY"
|
||||
and scalar( @{ $decode_json->{payload}{programList} } ) > 0 )
|
||||
&& scalar( @{ $decode_json->{payload}{programList} } ) > 0 )
|
||||
{
|
||||
use Date::Parse;
|
||||
my $count = 0;
|
||||
foreach my $programList ( @{ $decode_json->{payload}{programList} } ) {
|
||||
for my $programList ( @{ $decode_json->{payload}{programList} } ) {
|
||||
|
||||
if (
|
||||
str2time(
|
||||
@ -1072,13 +1064,13 @@ sub LGTV_WebOS_WriteReadings {
|
||||
}
|
||||
|
||||
elsif (defined( $decode_json->{payload}{'mute'} )
|
||||
or defined( $decode_json->{payload}{'muted'} ) )
|
||||
|| defined( $decode_json->{payload}{'muted'} ) )
|
||||
{
|
||||
|
||||
if (
|
||||
defined( $decode_json->{payload}{'mute'} )
|
||||
and ( $decode_json->{payload}{'mute'} eq 'true'
|
||||
or $decode_json->{payload}{'mute'} == 1 )
|
||||
&& ( $decode_json->{payload}{'mute'} eq 'true'
|
||||
|| $decode_json->{payload}{'mute'} == 1 )
|
||||
)
|
||||
{
|
||||
|
||||
@ -1087,7 +1079,7 @@ sub LGTV_WebOS_WriteReadings {
|
||||
}
|
||||
elsif ( defined( $decode_json->{payload}{'mute'} ) ) {
|
||||
if ( $decode_json->{payload}{'mute'} eq 'false'
|
||||
or $decode_json->{payload}{'mute'} == 0 )
|
||||
|| $decode_json->{payload}{'mute'} == 0 )
|
||||
{
|
||||
|
||||
readingsBulkUpdateIfChanged( $hash, 'mute', 'off' );
|
||||
@ -1096,8 +1088,8 @@ sub LGTV_WebOS_WriteReadings {
|
||||
|
||||
if (
|
||||
defined( $decode_json->{payload}{'muted'} )
|
||||
and ( $decode_json->{payload}{'muted'} eq 'true'
|
||||
or $decode_json->{payload}{'muted'} == 1 )
|
||||
&& ( $decode_json->{payload}{'muted'} eq 'true'
|
||||
|| $decode_json->{payload}{'muted'} == 1 )
|
||||
)
|
||||
{
|
||||
|
||||
@ -1106,8 +1098,8 @@ sub LGTV_WebOS_WriteReadings {
|
||||
}
|
||||
elsif (
|
||||
defined( $decode_json->{payload}{'muted'} )
|
||||
and ( $decode_json->{payload}{'muted'} eq 'false'
|
||||
or $decode_json->{payload}{'muted'} == 0 )
|
||||
&& ( $decode_json->{payload}{'muted'} eq 'false'
|
||||
|| $decode_json->{payload}{'muted'} == 0 )
|
||||
)
|
||||
{
|
||||
|
||||
@ -1117,14 +1109,14 @@ sub LGTV_WebOS_WriteReadings {
|
||||
|
||||
elsif ( defined( $decode_json->{payload}{status3D}{status} ) ) {
|
||||
if ( $decode_json->{payload}{status3D}{status} eq 'false'
|
||||
or $decode_json->{payload}{status3D}{status} == 0 )
|
||||
|| $decode_json->{payload}{status3D}{status} == 0 )
|
||||
{
|
||||
|
||||
readingsBulkUpdateIfChanged( $hash, '3D', 'off' );
|
||||
|
||||
}
|
||||
elsif ($decode_json->{payload}{status3D}{status} eq 'true'
|
||||
or $decode_json->{payload}{status3D}{status} == 1 )
|
||||
|| $decode_json->{payload}{status3D}{status} == 1 )
|
||||
{
|
||||
|
||||
readingsBulkUpdateIfChanged( $hash, '3D', 'on' );
|
||||
@ -1139,14 +1131,14 @@ sub LGTV_WebOS_WriteReadings {
|
||||
if (
|
||||
(
|
||||
$decode_json->{payload}{appId} =~ /com.webos.app.externalinput/
|
||||
or $decode_json->{payload}{appId} =~ /com.webos.app.hdmi/
|
||||
|| $decode_json->{payload}{appId} =~ /com.webos.app.hdmi/
|
||||
)
|
||||
and defined(
|
||||
&& defined(
|
||||
$hash->{helper}{device}{inputapps}
|
||||
{ $decode_json->{payload}{appId} }
|
||||
)
|
||||
and
|
||||
$hash->{helper}{device}{inputapps}{ $decode_json->{payload}{appId} }
|
||||
&& $hash->{helper}{device}{inputapps}
|
||||
{ $decode_json->{payload}{appId} }
|
||||
)
|
||||
{
|
||||
|
||||
@ -1158,7 +1150,7 @@ sub LGTV_WebOS_WriteReadings {
|
||||
}
|
||||
elsif (
|
||||
defined( $openAppsPackageName{ $decode_json->{payload}{appId} } )
|
||||
and $openAppsPackageName{ $decode_json->{payload}{appId} } )
|
||||
&& $openAppsPackageName{ $decode_json->{payload}{appId} } )
|
||||
{
|
||||
|
||||
readingsBulkUpdateIfChanged( $hash, 'launchApp',
|
||||
@ -1171,7 +1163,7 @@ sub LGTV_WebOS_WriteReadings {
|
||||
if ( defined( $decode_json->{type} ) ) {
|
||||
|
||||
if ( $decode_json->{type} eq 'registered'
|
||||
and defined( $decode_json->{payload}{'client-key'} ) )
|
||||
&& defined( $decode_json->{payload}{'client-key'} ) )
|
||||
{
|
||||
|
||||
$hash->{helper}{device}{registered} = 1;
|
||||
@ -1180,11 +1172,11 @@ sub LGTV_WebOS_WriteReadings {
|
||||
elsif (
|
||||
(
|
||||
$decode_json->{type} eq 'response'
|
||||
and ( $decode_json->{payload}{returnValue} eq 'true'
|
||||
or $decode_json->{payload}{returnValue} == 1 )
|
||||
&& ( $decode_json->{payload}{returnValue} eq 'true'
|
||||
|| $decode_json->{payload}{returnValue} == 1 )
|
||||
)
|
||||
or ( $decode_json->{type} eq 'registered' )
|
||||
and defined( $decode_json->{payload}{'client-key'} )
|
||||
|| ( $decode_json->{type} eq 'registered' )
|
||||
&& defined( $decode_json->{payload}{'client-key'} )
|
||||
)
|
||||
{
|
||||
|
||||
@ -1201,7 +1193,7 @@ sub LGTV_WebOS_WriteReadings {
|
||||
if ( $decode_json->{error} ne '404 no such service or method' );
|
||||
|
||||
if ( $decode_json->{error} eq '401 insufficient permissions'
|
||||
or $decode_json->{error} eq
|
||||
|| $decode_json->{error} eq
|
||||
'401 insufficient permissions (not registered)' )
|
||||
{
|
||||
|
||||
@ -1257,7 +1249,6 @@ sub LGTV_WebOS_WriteReadings {
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_Pairing {
|
||||
|
||||
my $hash = shift;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
@ -1340,13 +1331,12 @@ sub LGTV_WebOS_Pairing {
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_CreateSendCommand {
|
||||
|
||||
my ( $hash, $uri, $payload, $type ) = @_;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my $err;
|
||||
|
||||
$type = 'request' if ( not defined($type) );
|
||||
$type = 'request' if ( !defined($type) );
|
||||
|
||||
my $command = {};
|
||||
$command->{'client-key'} = ReadingsVal( $name, 'lgKey', '' )
|
||||
@ -1368,11 +1358,9 @@ sub LGTV_WebOS_CreateSendCommand {
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_Hybi10Encode {
|
||||
|
||||
my ( $payload, $type, $masked ) = @_;
|
||||
|
||||
$type //= "text";
|
||||
$masked //= 1;
|
||||
my $payload = shift;
|
||||
my $type = shift // 'text';
|
||||
my $masked = shift // 1;
|
||||
|
||||
my @frameHead;
|
||||
my $frame = "";
|
||||
@ -1419,7 +1407,7 @@ sub LGTV_WebOS_Hybi10Encode {
|
||||
if ( $frameHead[2] > 127 ) {
|
||||
|
||||
#$this->close(1004);
|
||||
return undef;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1469,7 +1457,6 @@ sub LGTV_WebOS_Hybi10Encode {
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_GetAudioStatus {
|
||||
|
||||
my $hash = shift;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
@ -1482,7 +1469,6 @@ sub LGTV_WebOS_GetAudioStatus {
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_GetCurrentChannel {
|
||||
|
||||
my $hash = shift;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
@ -1496,7 +1482,6 @@ sub LGTV_WebOS_GetCurrentChannel {
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_GetForgroundAppInfo {
|
||||
|
||||
my $hash = shift;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
@ -1511,7 +1496,6 @@ sub LGTV_WebOS_GetForgroundAppInfo {
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_GetExternalInputList {
|
||||
|
||||
my $hash = shift;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
@ -1526,7 +1510,6 @@ sub LGTV_WebOS_GetExternalInputList {
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_Get3DStatus {
|
||||
|
||||
my $hash = shift;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
@ -1540,7 +1523,6 @@ sub LGTV_WebOS_Get3DStatus {
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_GetChannelProgramInfo {
|
||||
|
||||
my $hash = shift;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
@ -1557,8 +1539,8 @@ sub LGTV_WebOS_GetChannelProgramInfo {
|
||||
### my little Helper
|
||||
|
||||
sub LGTV_WebOS_ParseMsg {
|
||||
|
||||
my ( $hash, $buffer ) = @_;
|
||||
my $hash = shift;
|
||||
my $buffer = shift;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my $open = 0;
|
||||
@ -1567,7 +1549,7 @@ sub LGTV_WebOS_ParseMsg {
|
||||
my $tail = '';
|
||||
|
||||
if ($buffer) {
|
||||
foreach my $c ( split //, $buffer ) {
|
||||
for my $c ( split //, $buffer ) {
|
||||
if ( $open == $close && $open > 0 ) {
|
||||
$tail .= $c;
|
||||
Log3 $name, 5,
|
||||
@ -1609,11 +1591,10 @@ sub LGTV_WebOS_ParseMsg {
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_Header2Hash {
|
||||
|
||||
my $string = shift;
|
||||
my %hash = ();
|
||||
|
||||
foreach my $line ( split( "\r\n", $string ) ) {
|
||||
for my $line ( split( "\r\n", $string ) ) {
|
||||
my ( $key, $value ) = split( ": ", $line );
|
||||
next if ( !$value );
|
||||
|
||||
@ -1625,7 +1606,6 @@ sub LGTV_WebOS_Header2Hash {
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_FormartStartEndTime {
|
||||
|
||||
my $string = shift;
|
||||
|
||||
my @timeArray = split( ',', $string );
|
||||
@ -1636,7 +1616,6 @@ sub LGTV_WebOS_FormartStartEndTime {
|
||||
|
||||
############ Presence Erkennung Begin #################
|
||||
sub LGTV_WebOS_Presence {
|
||||
|
||||
my $hash = shift;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
@ -1649,7 +1628,6 @@ sub LGTV_WebOS_Presence {
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_PresenceRun {
|
||||
|
||||
my $string = shift;
|
||||
my ( $name, $host ) = split( "\\|", $string );
|
||||
|
||||
@ -1658,17 +1636,16 @@ sub LGTV_WebOS_PresenceRun {
|
||||
|
||||
$tmp = qx(ping -c 3 -w 2 $host 2>&1);
|
||||
|
||||
if ( defined($tmp) and $tmp ne "" ) {
|
||||
if ( defined($tmp) && $tmp ne "" ) {
|
||||
|
||||
chomp $tmp;
|
||||
Log3 $name, 5,
|
||||
"LGTV_WebOS ($name) - ping command returned with output:\n$tmp";
|
||||
$response = "$name|"
|
||||
. (
|
||||
(
|
||||
$tmp =~ /\d+ [Bb]ytes (from|von)/
|
||||
and not $tmp =~ /[Uu]nreachable/
|
||||
) ? "present" : "absent"
|
||||
( $tmp =~ /\d+ [Bb]ytes (from|von)/ && !$tmp =~ /[Uu]nreachable/ )
|
||||
? "present"
|
||||
: "absent"
|
||||
);
|
||||
|
||||
}
|
||||
@ -1679,12 +1656,12 @@ sub LGTV_WebOS_PresenceRun {
|
||||
|
||||
Log3 $name, 4,
|
||||
"Sub LGTV_WebOS_PresenceRun ($name) - Sub finish, Call LGTV_WebOS_PresenceDone";
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_PresenceDone {
|
||||
|
||||
my ($string) = @_;
|
||||
my $string = shift;
|
||||
|
||||
my ( $name, $response ) = split( "\\|", $string );
|
||||
my $hash = $defs{$name};
|
||||
@ -1706,8 +1683,7 @@ sub LGTV_WebOS_PresenceDone {
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_PresenceAborted {
|
||||
|
||||
my ($hash) = @_;
|
||||
my $hash = shift;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
delete( $hash->{helper}{RUNNING_PID} );
|
||||
@ -1721,12 +1697,13 @@ sub LGTV_WebOS_PresenceAborted {
|
||||
|
||||
sub LGTV_WebOS_SocketClosePresenceAbsent {
|
||||
|
||||
my ( $hash, $presence ) = @_;
|
||||
my $hash = shift;
|
||||
my $presence = shift;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
LGTV_WebOS_Close($hash)
|
||||
if ( $presence eq 'absent' and not IsDisabled($name) and $hash->{CD} )
|
||||
if ( $presence eq 'absent' && !IsDisabled($name) && $hash->{CD} )
|
||||
; # https://forum.fhem.de/index.php/topic,66671.msg694578.html#msg694578
|
||||
# Sobald pingPresence absent meldet und der Socket noch steht soll er geschlossen werden, da sonst FHEM nach 4-6 min für 10 min blockiert
|
||||
|
||||
@ -1734,7 +1711,6 @@ sub LGTV_WebOS_SocketClosePresenceAbsent {
|
||||
}
|
||||
|
||||
sub LGTV_WebOS_WakeUp_Udp {
|
||||
|
||||
my ( $hash, $mac_addr, $host, $port ) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
@ -1865,7 +1841,7 @@ sub LGTV_WebOS_WakeUp_Udp {
|
||||
Broadcast Address of the Network - wakeOnLanBroadcast <network>.255
|
||||
</ul>
|
||||
</ul>
|
||||
<ul>
|
||||
<ul>
|
||||
<ul>
|
||||
<li>wakeupCmd</li>
|
||||
Set a command to be executed when turning on an absent device. Can be an FHEM command or Perl command in {}.
|
||||
@ -1978,14 +1954,14 @@ sub LGTV_WebOS_WakeUp_Udp {
|
||||
</ul>
|
||||
</ul>
|
||||
</ul>
|
||||
<ul>
|
||||
<ul>
|
||||
<ul>
|
||||
<ul>
|
||||
<li>wakeupCmd</li>
|
||||
Befehl zum Einschalten des LG TV. Möglich ist ein FHEM Befehl oder Perl in {}.
|
||||
</ul>
|
||||
</ul>
|
||||
</ul>
|
||||
</ul>
|
||||
<p><br /><br /><strong>Generierte Readings/Events:</strong></p>
|
||||
<ul>
|
||||
<ul>
|
||||
@ -2032,7 +2008,7 @@ sub LGTV_WebOS_WakeUp_Udp {
|
||||
],
|
||||
"release_status": "stable",
|
||||
"license": "GPL_2",
|
||||
"version": "v3.3.0",
|
||||
"version": "v3.3.5",
|
||||
"author": [
|
||||
"Marko Oldenburg <fhemdevelopment@cooltux.net>"
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user