From e392f7f3bff668cc68d7c294ce99bbfcd1d82ee3 Mon Sep 17 00:00:00 2001 From: Mark Hilbush Date: Tue, 10 Jan 2023 09:02:40 -0500 Subject: [PATCH] Fix for NPE when playerState is null (#14191) Signed-off-by: Mark Hilbush --- .../internal/ChromecastStatusUpdater.java | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/ChromecastStatusUpdater.java b/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/ChromecastStatusUpdater.java index 53af64a9fef..7fccd1a4c51 100644 --- a/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/ChromecastStatusUpdater.java +++ b/bundles/org.openhab.binding.chromecast/src/main/java/org/openhab/binding/chromecast/internal/ChromecastStatusUpdater.java @@ -157,30 +157,32 @@ public class ChromecastStatusUpdater { return; } - switch (mediaStatus.playerState) { - case IDLE: - break; - case PAUSED: - callback.updateState(CHANNEL_CONTROL, PlayPauseType.PAUSE); - callback.updateState(CHANNEL_STOP, OnOffType.OFF); - break; - case BUFFERING: - case LOADING: - case PLAYING: - callback.updateState(CHANNEL_CONTROL, PlayPauseType.PLAY); - callback.updateState(CHANNEL_STOP, OnOffType.OFF); - break; - default: - logger.debug("Unknown media status: {}", mediaStatus.playerState); - break; + if (mediaStatus.playerState != null) { + switch (mediaStatus.playerState) { + case IDLE: + break; + case PAUSED: + callback.updateState(CHANNEL_CONTROL, PlayPauseType.PAUSE); + callback.updateState(CHANNEL_STOP, OnOffType.OFF); + break; + case BUFFERING: + case LOADING: + case PLAYING: + callback.updateState(CHANNEL_CONTROL, PlayPauseType.PLAY); + callback.updateState(CHANNEL_STOP, OnOffType.OFF); + break; + default: + logger.debug("Unknown media status: {}", mediaStatus.playerState); + break; + } } callback.updateState(CHANNEL_CURRENT_TIME, new QuantityType<>(mediaStatus.currentTime, Units.SECOND)); // If we're playing, paused or buffering but don't have any MEDIA information don't null everything out. Media media = mediaStatus.media; - if (media == null && (mediaStatus.playerState == PLAYING || mediaStatus.playerState == PAUSED - || mediaStatus.playerState == BUFFERING)) { + if (media == null && (mediaStatus.playerState == null || mediaStatus.playerState == PLAYING + || mediaStatus.playerState == PAUSED || mediaStatus.playerState == BUFFERING)) { return; }