Merge pull request 'dev' (#18) from dev into main

Reviewed-on: #18
This commit is contained in:
Marko Oldenburg 2024-10-12 07:10:41 +00:00
commit cfa3f8d7a6
3 changed files with 195 additions and 200 deletions

View File

@ -2,7 +2,7 @@
# #
# Developed with VSCodium and richterger perl plugin. # Developed with VSCodium and richterger perl plugin.
# #
# (c) 2017-2023 Copyright: Marko Oldenburg (fhemdevelopment at cooltux dot net) # (c) 2017-2025 Copyright: Marko Oldenburg (fhemdevelopment at cooltux dot net)
# All rights reserved # All rights reserved
# #
# Special thanks goes to comitters: # Special thanks goes to comitters:
@ -369,7 +369,7 @@ __END__
], ],
"release_status": "stable", "release_status": "stable",
"license": "GPL_2", "license": "GPL_2",
"version": "v3.6.9", "version": "v3.7.0",
"author": [ "author": [
"Marko Oldenburg <fhemdevelopment@cooltux.net>" "Marko Oldenburg <fhemdevelopment@cooltux.net>"
], ],

View File

@ -1,2 +1,2 @@
UPD 2023-11-15_19:19:41 19028 FHEM/82_LGTV_WebOS.pm UPD 2024-10-12_08:39:35 19028 FHEM/82_LGTV_WebOS.pm
UPD 2023-11-17_18:00:13 56133 lib/FHEM/Devices/LGTV/LGTVWebOS.pm UPD 2024-10-12_08:45:10 55683 lib/FHEM/Devices/LGTV/LGTVWebOS.pm

View File

@ -32,7 +32,8 @@ package FHEM::Devices::LGTV::LGTVWebOS;
use strict; use strict;
use warnings; use warnings;
use experimental qw /switch/;
# use experimental qw /switch/; deprecated
## try / catch ## try / catch
use Try::Tiny; use Try::Tiny;
@ -406,234 +407,230 @@ sub Set { ## no critic (Subroutine "Set" with high complexity score)
my $uri; my $uri;
my %payload; my %payload;
given ($cmd) { if ( $cmd eq 'connect' ) {
when ('connect') { return "usage: connect" if ( @args != 0 );
return "usage: connect" if ( @args != 0 );
Open($hash); Open($hash);
return;
}
elsif ( $cmd eq 'clearInputList' ) {
return "usage: clearInputList" if ( @args != 0 );
delete $hash->{helper}{device}{inputs};
delete $hash->{helper}{device}{inputapps};
return;
}
elsif ( $cmd eq 'pairing' ) {
return "usage: pairing" if ( @args != 0 );
Pairing($hash);
return;
}
elsif ( $cmd eq 'screenMsg' ) {
return "usage: screenMsg <message>" if ( @args < 1 );
my $msg = join( " ", @args );
$payload{ $lgCommands{$cmd}->[1] } = decode_utf8($msg);
$uri = $lgCommands{$cmd}->[0];
}
elsif ( $cmd eq 'off' ) {
return "usage: on/off" if ( @args != 0 );
$uri = $lgCommands{powerOff};
}
elsif ( $cmd eq 'on' ) {
if ( ::AttrVal( $name, 'wakeOnLanMAC', 'none' ) ne 'none' ) {
WakeUp_Udp(
$hash,
::AttrVal( $name, 'wakeOnLanMAC', 0 ),
::AttrVal( $name, 'wakeOnLanBroadcast', '255.255.255.255' )
);
return; return;
} }
when ('clearInputList') { elsif ( ::AttrVal( $name, 'wakeupCmd', 'none' ) ne 'none' ) {
return "usage: clearInputList" if ( @args != 0 ); my $wakeupCmd = ::AttrVal( $name, 'wakeupCmd', 'none' );
if ( $wakeupCmd =~ s/^[ \t]*\{|\}[ \t]*$//xg ) {
delete $hash->{helper}{device}{inputs}; ::Log3( $name, 4,
delete $hash->{helper}{device}{inputapps}; "LGTV_WebOS executing wake-up command (Perl): $wakeupCmd" );
eval { $wakeupCmd } or do {
return; ::Log3( $name, 2,
"LGTV_WebOS executing wake-up command (Perl): $wakeupCmd failed"
} );
when ('pairing') { return;
return "usage: pairing" if ( @args != 0 ); };
Pairing($hash);
return;
}
when ('screenMsg') {
return "usage: screenMsg <message>" if ( @args < 1 );
my $msg = join( " ", @args );
$payload{ $lgCommands{$cmd}->[1] } = decode_utf8($msg);
$uri = $lgCommands{$cmd}->[0];
}
when ('off') {
return "usage: on/off" if ( @args != 0 );
$uri = $lgCommands{powerOff};
}
when ('on') {
if ( ::AttrVal( $name, 'wakeOnLanMAC', 'none' ) ne 'none' ) {
WakeUp_Udp(
$hash,
::AttrVal( $name, 'wakeOnLanMAC', 0 ),
::AttrVal( $name, 'wakeOnLanBroadcast', '255.255.255.255' )
);
return; return;
} }
elsif ( ::AttrVal( $name, 'wakeupCmd', 'none' ) ne 'none' ) {
my $wakeupCmd = ::AttrVal( $name, 'wakeupCmd', 'none' );
if ( $wakeupCmd =~ s/^[ \t]*\{|\}[ \t]*$//xg ) {
::Log3( $name, 4,
"LGTV_WebOS executing wake-up command (Perl): $wakeupCmd"
);
eval { $wakeupCmd } or do {
::Log3( $name, 2,
"LGTV_WebOS executing wake-up command (Perl): $wakeupCmd failed"
);
return;
};
return;
}
else {
::Log3( $name, 4,
"LGTV_WebOS executing wake-up command (fhem): $wakeupCmd"
);
::fhem $wakeupCmd;
return;
}
}
else { else {
$uri = $lgCommands{powerOn}; ::Log3( $name, 4,
"LGTV_WebOS executing wake-up command (fhem): $wakeupCmd" );
::fhem $wakeupCmd;
return;
} }
} }
when ('3D') { else {
return "usage: 3D on/off" if ( @args != 1 ); $uri = $lgCommands{powerOn};
}
}
elsif ( $cmd eq '3D' ) {
return "usage: 3D on/off" if ( @args != 1 );
if ( $args[0] eq 'off' ) { if ( $args[0] eq 'off' ) {
$uri = $lgCommands{'3DOff'}; $uri = $lgCommands{'3DOff'};
} }
elsif ( $args[0] eq 'on' ) { elsif ( $args[0] eq 'on' ) {
$uri = $lgCommands{'3DOn'}; $uri = $lgCommands{'3DOn'};
} }
}
elsif ( $cmd eq 'mute' ) {
return "usage: mute" if ( @args != 1 );
if ( $args[0] eq 'off' ) {
$uri = $lgCommands{volumeDown}->[0];
} }
when ('mute') { elsif ( $args[0] eq 'on' ) {
return "usage: mute" if ( @args != 1 );
if ( $args[0] eq 'off' ) { $payload{ $lgCommands{$cmd}->[1] } = 'true';
$uri = $lgCommands{volumeDown}->[0];
}
elsif ( $args[0] eq 'on' ) {
$payload{ $lgCommands{$cmd}->[1] } = 'true';
$uri = $lgCommands{$cmd}->[0];
}
}
when ('volume') {
return "usage: volume" if ( @args != 1 );
$payload{ $lgCommands{$cmd}->[1] } = int( join( " ", @args ) );
$uri = $lgCommands{$cmd}->[0]; $uri = $lgCommands{$cmd}->[0];
} }
when ('launchApp') {
return "usage: launchApp" if ( @args != 1 );
$payload{ $lgCommands{$cmd}->[1] } = }
$openApps{ join( " ", @args ) }; elsif ( $cmd eq 'volume' ) {
$uri = $lgCommands{$cmd}->[0]; return "usage: volume" if ( @args != 1 );
} $payload{ $lgCommands{$cmd}->[1] } = int( join( " ", @args ) );
when ('input') { $uri = $lgCommands{$cmd}->[0];
return "usage: input" if ( @args != 1 );
my $inputLabel = join( " ", @args ); }
$payload{ $lgCommands{launchApp}->[1] } = elsif ( $cmd eq 'launchApp' ) {
$hash->{helper}{device}{inputs}{$inputLabel}; return "usage: launchApp" if ( @args != 1 );
$uri = $lgCommands{launchApp}->[0];
} $payload{ $lgCommands{$cmd}->[1] } =
when ('volumeUp') { $openApps{ join( " ", @args ) };
return "usage: volumeUp" if ( @args != 0 ); $uri = $lgCommands{$cmd}->[0];
$uri = $lgCommands{$cmd}->[0]; }
elsif ( $cmd eq 'input' ) {
return "usage: input" if ( @args != 1 );
} my $inputLabel = join( " ", @args );
when ('volumeDown') { $payload{ $lgCommands{launchApp}->[1] } =
return "usage: volumeDown" if ( @args != 0 ); $hash->{helper}{device}{inputs}{$inputLabel};
$uri = $lgCommands{launchApp}->[0];
$uri = $lgCommands{$cmd}->[0]; }
elsif ( $cmd eq 'volumeUp' ) {
return "usage: volumeUp" if ( @args != 0 );
} $uri = $lgCommands{$cmd}->[0];
when ('channelDown') {
return "usage: channelDown" if ( @args != 0 );
$uri = $lgCommands{$cmd}->[0]; }
elsif ( $cmd eq 'volumeDown' ) {
return "usage: volumeDown" if ( @args != 0 );
} $uri = $lgCommands{$cmd}->[0];
when ('channelUp') {
return "usage: channelUp" if ( @args != 0 );
$uri = $lgCommands{$cmd}->[0]; }
elsif ( $cmd eq 'channelDown' ) {
return "usage: channelDown" if ( @args != 0 );
} $uri = $lgCommands{$cmd}->[0];
when ('channel') {
return "usage: channel" if ( @args != 1 );
$payload{ $lgCommands{openChannel}->[1] } = join( " ", @args ); }
$uri = $lgCommands{openChannel}->[0]; elsif ( $cmd eq 'channelUp' ) {
return "usage: channelUp" if ( @args != 0 );
} $uri = $lgCommands{$cmd}->[0];
when ('getServiceList') {
return "usage: getServiceList" if ( @args != 0 );
$uri = $lgCommands{$cmd}->[0]; }
elsif ( $cmd eq 'channel' ) {
return "usage: channel" if ( @args != 1 );
} $payload{ $lgCommands{openChannel}->[1] } = join( " ", @args );
when ('getChannelList') { $uri = $lgCommands{openChannel}->[0];
return "usage: getChannelList" if ( @args != 0 );
$uri = $lgCommands{$cmd}->[0]; }
elsif ( $cmd eq 'getServiceList' ) {
return "usage: getServiceList" if ( @args != 0 );
} $uri = $lgCommands{$cmd}->[0];
when ('getAppList') {
return "usage: getAppList" if ( @args != 0 );
$uri = $lgCommands{$cmd}->[0]; }
elsif ( $cmd eq 'getChannelList' ) {
return "usage: getChannelList" if ( @args != 0 );
} $uri = $lgCommands{$cmd}->[0];
when ('getExternalInputList') {
return "usage: getExternalInputList" if ( @args != 0 );
$uri = $lgCommands{$cmd}->[0]; }
elsif ( $cmd eq 'getAppList' ) {
return "usage: getAppList" if ( @args != 0 );
} $uri = $lgCommands{$cmd}->[0];
when ('play') {
return "usage: play" if ( @args != 0 );
$uri = $lgCommands{$cmd}->[0]; }
elsif ( $cmd eq 'getExternalInputList' ) {
return "usage: getExternalInputList" if ( @args != 0 );
} $uri = $lgCommands{$cmd}->[0];
when ('stop') {
return "usage: stop" if ( @args != 0 );
$uri = $lgCommands{$cmd}->[0]; }
elsif ( $cmd eq 'play' ) {
return "usage: play" if ( @args != 0 );
} $uri = $lgCommands{$cmd}->[0];
when ('fastForward') {
return "usage: fastForward" if ( @args != 0 );
$uri = $lgCommands{$cmd}->[0]; }
elsif ( $cmd eq 'stop' ) {
return "usage: stop" if ( @args != 0 );
} $uri = $lgCommands{$cmd}->[0];
when ('rewind') {
return "usage: rewind" if ( @args != 0 );
$uri = $lgCommands{$cmd}->[0]; }
elsif ( $cmd eq 'fastForward' ) {
return "usage: fastForward" if ( @args != 0 );
} $uri = $lgCommands{$cmd}->[0];
when ('pause') {
return "usage: pause" if ( @args != 0 );
$uri = $lgCommands{$cmd}->[0]; }
elsif ( $cmd eq 'rewind' ) {
return "usage: rewind" if ( @args != 0 );
} $uri = $lgCommands{$cmd}->[0];
default {
my $list = ""; }
$list .= elsif ( $cmd eq 'pause' ) {
return "usage: pause" if ( @args != 0 );
$uri = $lgCommands{$cmd}->[0];
}
else {
my $list = "";
$list .=
'connect:noArg pairing:noArg screenMsg mute:on,off volume:slider,0,1,100 volumeUp:noArg volumeDown:noArg channelDown:noArg channelUp:noArg getServiceList:noArg on:noArg off:noArg'; 'connect:noArg pairing:noArg screenMsg mute:on,off volume:slider,0,1,100 volumeUp:noArg volumeDown:noArg channelDown:noArg channelUp:noArg getServiceList:noArg on:noArg off:noArg';
$list .= $list .=
' 3D:on,off stop:noArg play:noArg pause:noArg rewind:noArg fastForward:noArg clearInputList:noArg channel'; ' 3D:on,off stop:noArg play:noArg pause:noArg rewind:noArg fastForward:noArg clearInputList:noArg channel';
$list .= $list .=
## no critic (Expression form of map. See page 169 of PBP) ## no critic (Expression form of map. See page 169 of PBP)
' launchApp:' . join( ',', => map qq{$_} => keys %openApps ); ' launchApp:' . join( ',', => map qq{$_} => keys %openApps );
$list .= ' input:' . join( $list .= ' input:' . join(
',', ',',
## no critic (Expression form of map. See page 169 of PBP) ## no critic (Expression form of map. See page 169 of PBP)
=> map qq{$_} => keys %{ $hash->{helper}{device}{inputs} } => map qq{$_} => keys %{ $hash->{helper}{device}{inputs} }
) )
if ( exists( $hash->{helper}{device}{inputs} ) if ( exists( $hash->{helper}{device}{inputs} )
&& ref( $hash->{helper}{device}{inputs} ) eq "HASH" ); && ref( $hash->{helper}{device}{inputs} ) eq "HASH" );
return "Unknown argument $cmd, choose one of $list"; return "Unknown argument $cmd, choose one of $list";
}
} }
$hash->{helper}{device}{runsetcmd} = $hash->{helper}{device}{runsetcmd} + 1; $hash->{helper}{device}{runsetcmd} = $hash->{helper}{device}{runsetcmd} + 1;
@ -1499,27 +1496,25 @@ sub Hybi10Encode {
my $frame = ""; my $frame = "";
my $payloadLength = length($payload); my $payloadLength = length($payload);
given ($type) { if ( $type eq 'text' ) {
when ('text') {
# first byte indicates FIN, Text-Frame (10000001): # first byte indicates FIN, Text-Frame (10000001):
$frameHead[0] = 129; $frameHead[0] = 129;
} }
when ('close') { elsif ( $type eq 'close' ) {
# first byte indicates FIN, Close Frame(10001000): # first byte indicates FIN, Close Frame(10001000):
$frameHead[0] = 136; $frameHead[0] = 136;
} }
when ('ping') { elsif ( $type eq 'ping' ) {
# first byte indicates FIN, Ping frame (10001001): # first byte indicates FIN, Ping frame (10001001):
$frameHead[0] = 137; $frameHead[0] = 137;
} }
when ('pong') { elsif ( $type eq 'pong' ) {
# first byte indicates FIN, Pong frame (10001010): # first byte indicates FIN, Pong frame (10001010):
$frameHead[0] = 138; $frameHead[0] = 138;
}
} }
# set mask and payload length (using 1, 3 or 9 bytes) # set mask and payload length (using 1, 3 or 9 bytes)