diff --git a/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/ChromecastCommander.java b/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/ChromecastCommander.java index a3d5206079721..6497261098fc7 100644 --- a/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/ChromecastCommander.java +++ b/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/ChromecastCommander.java @@ -128,7 +128,18 @@ public void handleRefresh() { 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 void closeApp(@Nullable String appId) { 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()); } }