diff --git a/fhem/CHANGED b/fhem/CHANGED
index 2e621f189..38da16f3b 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 command "application" to start an application on TV
- feature: FHEMWEB: add structure to roomnames (Forum #63530)
- feature: 98_dewpoint: Generated readings are now subject to standard
processing.
diff --git a/fhem/FHEM/70_BRAVIA.pm b/fhem/FHEM/70_BRAVIA.pm
index ff0dbcf08..40599bfdc 100644
--- a/fhem/FHEM/70_BRAVIA.pm
+++ b/fhem/FHEM/70_BRAVIA.pm
@@ -135,6 +135,7 @@ sub BRAVIA_Set($@) {
my $channelId = ReadingsVal($name, "channelId", "");
my $channels = "";
my $inputs = "";
+ my $apps = "";
my $mutes = "toggle";
if ( ReadingsVal($name, "input", "") ne "-" ) {
@@ -190,6 +191,15 @@ sub BRAVIA_Set($@) {
$mutes .= ",on,off";
#$mutes .= ",off" if ( defined( $hash->{READINGS}{generation}{VAL} ) and $hash->{READINGS}{generation}{VAL} ne "1.0" );
+ # App handling
+ my @apps;
+ if ( defined( $hash->{helper}{device}{appPreset} )
+ && ref( $hash->{helper}{device}{appPreset} ) eq "HASH" ) {
+ @apps = keys %{ $hash->{helper}{device}{appPreset} };
+ }
+ @apps = sort(@apps);
+ $apps = join(",", @apps);
+
my $usage = "Unknown argument " . $a[1] . ", choose one of";
$usage .= " requestFormat:json,xml register";
$usage .= ":noArg"
@@ -198,6 +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 .= " text" if (ReadingsVal($name, "requestFormat", "") eq "json");
my $cmd = '';
@@ -477,6 +488,33 @@ sub BRAVIA_Set($@) {
}
}
+ # app
+ elsif ( $a[1] eq "app" ) {
+ 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] ) );
+
+ Log3 $name, 2, "BRAVIA set $name " . $a[1] . " " . $a[2];
+
+ # Resolve app uri
+ my $app_uri;
+ if ( defined( $hash->{helper}{device}{appPreset}{ $a[2] } ) ) {
+ $app_uri = $hash->{helper}{device}{appPreset}{ $a[2] }{uri};
+ } else {
+ return "Unknown app '" . $a[2] . "' on that device.";
+ }
+
+ if ( $presence eq "present" ) {
+ BRAVIA_SendCommand( $hash, "setActiveApp", $app_uri );
+ }
+ else {
+ return "Device needs to be reachable to start an app.";
+ }
+ }
+
# tvpause
elsif ( $a[1] eq "tvpause" ) {
Log3 $name, 2, "BRAVIA set $name " . $a[1];
@@ -788,6 +826,18 @@ sub BRAVIA_SendCommand($$;$$) {
} else {
$URL .= "/cersEx/api/" . $service;
}
+ } elsif ($service eq "getApplicationList") {
+ $URL .= $port->{SERVICE};
+ if ($requestFormat eq "json") {
+ $URL .= "/sony/appControl";
+ $data = "{\"id\":2,\"method\":\"getApplicationList\",\"version\":\"1.0\",\"params\":[]}";
+ }
+ } elsif ($service eq "setActiveApp") {
+ $URL .= $port->{SERVICE};
+ if ($requestFormat eq "json") {
+ $URL .= "/sony/appControl";
+ $data = "{\"id\":2,\"method\":\"setActiveApp\",\"version\":\"1.0\",\"params\":[{\"uri\":\"".$cmd."\"}]}";
+ }
} elsif ($service eq "text") {
$URL .= $port->{SERVICE};
if ($requestFormat eq "json") {
@@ -1376,6 +1426,13 @@ sub BRAVIA_ProcessCommandData ($$) {
&& ReadingsVal($name, "requestFormat", "") eq "json") {
BRAVIA_SendCommand( $hash, "getCurrentExternalInputsStatus" );
}
+
+ # load app list if just switched on
+ if ($newstate eq "on"
+ && (ReadingsVal($name, "state", "") ne "on" || !defined($hash->{helper}{device}{appPreset}))
+ && ReadingsVal($name, "requestFormat", "") eq "json") {
+ BRAVIA_SendCommand( $hash, "getApplicationList" );
+ }
}
# getScheduleList
@@ -1499,11 +1556,40 @@ sub BRAVIA_ProcessCommandData ($$) {
}
}
+ # getApplicationList
+ elsif ( $service eq "getApplicationList" ) {
+ my $channelIndex = 0;
+ if ( ref($return) eq "HASH" ) {
+ if (ref($return->{result}) eq "ARRAY") {
+ foreach ( @{ $return->{result} } ) {
+ foreach ( @{ $_ } ) {
+ my $appName;
+ my $appUri;
+ my $key;
+ foreach $key ( keys %{ $_ }) {
+ if ( $key eq "uri" ) {
+ $appUri = $_->{$key};
+ } elsif ( $key eq "title" ) {
+ $appName = BRAVIA_GetNormalizedName($_->{$key});
+ }
+ }
+ $hash->{helper}{device}{appPreset}{$appName}{uri} = $appUri;
+ }
+ }
+ }
+ }
+ }
+
# setPlayContent
elsif ( $service eq "setPlayContent" ) {
# nothing to do
}
+ # setActiveApp
+ elsif ( $service eq "setActiveApp" ) {
+ # nothing to do
+ }
+
# text
elsif ( $service eq "text" ) {
# nothing to do
@@ -1953,6 +2039,9 @@ sub BRAVIA_GetNormalizedName($) {
Options: