diff --git a/fhem/CHANGED b/fhem/CHANGED index 8e2c5052f..a4f2858f3 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - feature: 70_BRAVIA: new set command openUrl - bugfix: 59_Weather: fix change attribut model - bugfix: 98_livetracking: fixed initial Life360 data availability - feature: 73_PRESENCE: new set command active/inactive to temporarily diff --git a/fhem/FHEM/70_BRAVIA.pm b/fhem/FHEM/70_BRAVIA.pm index ddb7b8f2c..f111a613e 100644 --- a/fhem/FHEM/70_BRAVIA.pm +++ b/fhem/FHEM/70_BRAVIA.pm @@ -208,7 +208,7 @@ sub BRAVIA_Set($@) { $usage .= " mute:" . $mutes; $usage .= " input:" . $inputs if ( $inputs ne "" ); $usage .= " channel:$channels" if ( $channels ne "" ); - $usage .= " application:" . $apps if ( $apps ne "" ); + $usage .= " openUrl application:" . $apps if ( $apps ne "" ); $usage .= " text" if (ReadingsVal($name, "requestFormat", "") eq "json"); my $cmd = ''; @@ -440,10 +440,10 @@ sub BRAVIA_Set($@) { } } if ( $channelName =~ /^(\d)(\d?)(\d?)(\d?).*$/ ) { - BRAVIA_SendCommand( $hash, "ircc", $1, "blocking" ); - BRAVIA_SendCommand( $hash, "ircc", $2, "blocking" ) if (defined($2)); - BRAVIA_SendCommand( $hash, "ircc", $3, "blocking" ) if (defined($3)); - BRAVIA_SendCommand( $hash, "ircc", $4, "blocking" ) if (defined($4)); + BRAVIA_SendCommand( $hash, "ircc", $1, undef, "blocking" ); + BRAVIA_SendCommand( $hash, "ircc", $2, undef, "blocking" ) if (defined($2)); + BRAVIA_SendCommand( $hash, "ircc", $3, undef, "blocking" ) if (defined($3)); + BRAVIA_SendCommand( $hash, "ircc", $4, undef, "blocking" ) if (defined($4)); return; } return "Argument " . $channelName . " is not a valid channel name"; @@ -514,20 +514,58 @@ sub BRAVIA_Set($@) { return "No 2nd argument given" if ( !defined( $a[2] ) ); - shift(@a); shift(@a); - my $appStr = join("#", @a); - Log3 $name, 2, "BRAVIA set $name " . $a[1] . " " . $appStr; + shift(@a); shift(@a); + my $appStr; - # Resolve app uri + # Resolve app uri + data + my $app_name; my $app_uri; - if ( defined( $hash->{helper}{device}{appPreset}{ $appStr } ) ) { - $app_uri = $hash->{helper}{device}{appPreset}{ $appStr }{uri}; - } else { - return "Unknown app '" . $appStr . "' on that device."; - } + my $app_data; + while (@a) { + my $arg = shift(@a); + if (defined($appStr)) { + $appStr .= "#"; + $appStr .= $arg; + } else { + $appStr = $arg; + } + if ( defined( $hash->{helper}{device}{appPreset}{ $appStr } ) ) { + $app_name = $appStr; + $app_uri = $hash->{helper}{device}{appPreset}{ $appStr }{uri}; + $app_data = join(" ", @a); + } + } + + return "Unknown app '" . $appStr . "' on that device." unless defined($app_uri); if ( $presence eq "present" ) { - BRAVIA_SendCommand( $hash, "setActiveApp", $app_uri ); + Log3 $name, 2, "BRAVIA set $name " . $app_name . ($app_data ? " " . $app_data : ""); + BRAVIA_SendCommand( $hash, "setActiveApp", $app_uri, $app_data ); + } + else { + return "Device needs to be reachable to start an app."; + } + } + + # openUrl + elsif ( $a[1] eq "openUrl") { + if (defined($a[2]) && $presence eq "present" && $power ne "on" ) { + Log3 $name, 4, "BRAVIA $name: indirect switching request to ON"; + BRAVIA_Set( $hash, $name, "on" ); + } + + return "No 2nd argument given" if ( !defined( $a[2] ) ); + + if ( $presence eq "present" ) { + Log3 $name, 2, "BRAVIA set $name " . $a[1] . " " . $a[2]; + my $url = lc($a[2]); + if ($url !~ /^https?:\/\/.*/) { + $url = "http://$url"; + } + $url =~ s/([\x2F \x3A])/sprintf("%%%02X",ord($1))/eg; + $url = "localapp://webappruntime?url=$url"; + Log3 $name, 2, "BRAVIA set $name " . $a[1] . " " . $url; + BRAVIA_SendCommand( $hash, "setActiveApp", $url ); } else { return "Device needs to be reachable to start an app."; @@ -703,8 +741,8 @@ sub BRAVIA_Define($$) { ############################################################################################################ ################################### -sub BRAVIA_SendCommand($$;$$) { - my ( $hash, $service, $cmd, $type ) = @_; +sub BRAVIA_SendCommand($$;$$$) { + my ( $hash, $service, $cmd, $param, $type ) = @_; my $name = $hash->{NAME}; my $address = $hash->{helper}{ADDRESS}; my $port = $hash->{helper}{PORT}; @@ -861,7 +899,9 @@ sub BRAVIA_SendCommand($$;$$) { $URL .= $port->{SERVICE}; if ($requestFormat eq "json") { $URL .= "/sony/appControl"; - $data = "{\"id\":2,\"method\":\"setActiveApp\",\"version\":\"1.0\",\"params\":[{\"uri\":\"".$cmd."\"}]}"; + $data = "{\"id\":2,\"method\":\"setActiveApp\",\"version\":\"1.0\",\"params\":[{\"uri\":\"".$cmd."\""; + $data .= ",\"data\":\"".$param."\"" if (defined($param)); + $data .= "}]}"; } } elsif ($service eq "text") { $URL .= $port->{SERVICE}; @@ -2120,10 +2160,10 @@ sub BRAVIA_GetNormalizedName($) {