change code to PBP style

This commit is contained in:
Marko Oldenburg 2022-01-04 22:01:26 +01:00
parent 79774e3352
commit ecd35d4526

View File

@ -410,46 +410,46 @@ sub LGTV_WebOS_Set {
my $uri; my $uri;
my %payload; my %payload;
if ( $cmd eq 'connect' ) { given ($cmd) {
return "usage: connect" if ( @args != 0 ); when ('connect') {
return "usage: connect" if ( @args != 0 );
LGTV_WebOS_Open($hash); LGTV_WebOS_Open($hash);
return; return;
} }
elsif ( $cmd eq 'clearInputList' ) { when ('clearInputList') {
return "usage: clearInputList" if ( @args != 0 ); return "usage: clearInputList" if ( @args != 0 );
delete $hash->{helper}{device}{inputs}; delete $hash->{helper}{device}{inputs};
delete $hash->{helper}{device}{inputapps}; delete $hash->{helper}{device}{inputapps};
return; return;
} }
elsif ( $cmd eq 'pairing' ) { when ('pairing') {
return "usage: pairing" if ( @args != 0 ); return "usage: pairing" if ( @args != 0 );
LGTV_WebOS_Pairing($hash); LGTV_WebOS_Pairing($hash);
return; return;
} }
elsif ( $cmd eq 'screenMsg' ) { when ('screenMsg') {
return "usage: screenMsg <message>" if ( @args < 1 ); return "usage: screenMsg <message>" if ( @args < 1 );
my $msg = join( " ", @args ); my $msg = join( " ", @args );
$payload{ $lgCommands{$cmd}->[1] } = decode_utf8($msg); $payload{ $lgCommands{$cmd}->[1] } = decode_utf8($msg);
$uri = $lgCommands{$cmd}->[0]; $uri = $lgCommands{$cmd}->[0];
} }
elsif ( $cmd eq 'on' || $cmd eq 'off' ) { when ('off') {
return "usage: on/off" if ( @args != 0 ); return "usage: on/off" if ( @args != 0 );
if ( $cmd eq 'off' ) {
$uri = $lgCommands{powerOff}; $uri = $lgCommands{powerOff};
} }
elsif ( $cmd eq 'on' ) { when ('on') {
if ( AttrVal( $name, 'wakeOnLanMAC', 'none' ) ne 'none' ) { if ( AttrVal( $name, 'wakeOnLanMAC', 'none' ) ne 'none' ) {
LGTV_WebOS_WakeUp_Udp( LGTV_WebOS_WakeUp_Udp(
$hash, $hash,
@ -481,156 +481,157 @@ sub LGTV_WebOS_Set {
$uri = $lgCommands{powerOn}; $uri = $lgCommands{powerOn};
} }
} }
when ('3D') {
return "usage: 3D on/off" if ( @args != 1 );
} if ( $args[0] eq 'off' ) {
elsif ( $cmd eq '3D' ) { $uri = $lgCommands{'3DOff'};
return "usage: 3D on/off" if ( @args != 1 ); }
elsif ( $args[0] eq 'on' ) {
if ( $args[0] eq 'off' ) { $uri = $lgCommands{'3DOn'};
$uri = $lgCommands{'3DOff'}; }
}
elsif ( $args[0] eq 'on' ) {
$uri = $lgCommands{'3DOn'};
}
}
elsif ( $cmd eq 'mute' ) {
return "usage: mute" if ( @args != 1 );
if ( $args[0] eq 'off' ) {
$uri = $lgCommands{volumeDown}->[0];
} }
elsif ( $args[0] eq 'on' ) { when ('mute') {
return "usage: mute" if ( @args != 1 );
$payload{ $lgCommands{$cmd}->[1] } = 'true'; if ( $args[0] eq 'off' ) {
$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] } =
elsif ( $cmd eq 'volume' ) { $openApps{ join( " ", @args ) };
return "usage: volume" if ( @args != 1 ); $uri = $lgCommands{$cmd}->[0];
$payload{ $lgCommands{$cmd}->[1] } = int( join( " ", @args ) ); }
$uri = $lgCommands{$cmd}->[0]; when ('input') {
return "usage: input" if ( @args != 1 );
} my $inputLabel = join( " ", @args );
elsif ( $cmd eq 'launchApp' ) { $payload{ $lgCommands{launchApp}->[1] } =
return "usage: launchApp" if ( @args != 1 ); $hash->{helper}{device}{inputs}{$inputLabel};
$uri = $lgCommands{launchApp}->[0];
$payload{ $lgCommands{$cmd}->[1] } = $openApps{ join( " ", @args ) }; }
$uri = $lgCommands{$cmd}->[0]; when ('volumeUp') {
return "usage: volumeUp" if ( @args != 0 );
} $uri = $lgCommands{$cmd}->[0];
elsif ( $cmd eq 'input' ) {
return "usage: input" if ( @args != 1 );
my $inputLabel = join( " ", @args ); }
$payload{ $lgCommands{launchApp}->[1] } = when ('volumeDown') {
$hash->{helper}{device}{inputs}{$inputLabel}; return "usage: volumeDown" if ( @args != 0 );
$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 );
elsif ( $cmd eq 'channelUp' ) { $uri = $lgCommands{openChannel}->[0];
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 ); }
$uri = $lgCommands{openChannel}->[0]; when ('getChannelList') {
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 = "";
elsif ( $cmd eq 'pause' ) { $list .=
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 .= ' launchApp:' . join( ',', => map qq{$_} => keys %openApps ); $list .=
$list .= ' input:' ' launchApp:' . join( ',', => map qq{$_} => keys %openApps );
. join( ',', $list .= ' input:'
=> map qq{$_} => keys %{ $hash->{helper}{device}{inputs} } ) . join( ',',
if ( defined( $hash->{helper}{device}{inputs} ) => map qq{$_} => keys %{ $hash->{helper}{device}{inputs} } )
&& ref( $hash->{helper}{device}{inputs} ) eq "HASH" ); if ( defined( $hash->{helper}{device}{inputs} )
&& 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;
@ -2022,7 +2023,7 @@ sub LGTV_WebOS_WakeUp_Udp {
], ],
"release_status": "stable", "release_status": "stable",
"license": "GPL_2", "license": "GPL_2",
"version": "v3.3.5", "version": "v3.4.0",
"author": [ "author": [
"Marko Oldenburg <fhemdevelopment@cooltux.net>" "Marko Oldenburg <fhemdevelopment@cooltux.net>"
], ],