]> git.basschouten.com Git - openhab-addons.git/commitdiff
[chromecast] Fix STOP command
authorlsiepel <leosiepel@gmail.com>
Tue, 1 Aug 2023 19:22:37 +0000 (21:22 +0200)
committerGitHub <noreply@github.com>
Tue, 1 Aug 2023 19:22:37 +0000 (21:22 +0200)
Fixes #14516

Signed-off-by: lsiepel <leosiepel@gmail.com>
bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/ChromecastCommander.java

index a3d5206079721145cec5373c7e3b63bd9fed8e41..6497261098fc7ba29e95d23ec534a7264ef09120 100644 (file)
@@ -128,7 +128,18 @@ public class ChromecastCommander {
 
     public void handleCloseApp(final Command command) {
         if (command == OnOffType.ON) {
-            closeApp(MEDIA_PLAYER);
+            Application app;
+            try {
+                app = chromeCast.getRunningApp();
+            } catch (final IOException e) {
+                logger.info("{} command failed: {}", command, e.getMessage());
+                statusUpdater.updateStatus(ThingStatus.OFFLINE, COMMUNICATION_ERROR, e.getMessage());
+                return;
+            }
+
+            if (app != null) {
+                closeApp(app.id);
+            }
         }
     }
 
@@ -250,13 +261,13 @@ public class ChromecastCommander {
         try {
             if (chromeCast.isAppRunning(appId)) {
                 Application app = chromeCast.getRunningApp();
-                if (app.id.equals(appId) && app.sessionId.equals(statusUpdater.getAppSessionId())) {
+                if (app.id.equals(appId)) {
                     chromeCast.stopApp();
                     logger.debug("Application closed: {}", appId);
                 }
             }
         } catch (final IOException e) {
-            logger.debug("Failed stopping media player app: {} with message: {}", appId, e.getMessage());
+            logger.debug("Failed stopping app: {} with message: {}", appId, e.getMessage());
         }
     }