From c7ce929aa257dd989e6a7f22e6af7d119f837b1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20L=27hopital?= Date: Sat, 4 Nov 2023 10:28:46 +0100 Subject: [PATCH] [Freeboxos] npe when updating inactive Player (#15813) * Correcting npe * Added status update --------- Signed-off-by: clinique --- .../internal/api/rest/PlayerManager.java | 29 ++++++++++---- .../internal/handler/ActivePlayerHandler.java | 39 ++++++++++++------- 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/PlayerManager.java b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/PlayerManager.java index 0326c1e0f..31256516c 100644 --- a/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/PlayerManager.java +++ b/bundles/org.openhab.binding.freeboxos/src/main/java/org/openhab/binding/freeboxos/internal/api/rest/PlayerManager.java @@ -197,21 +197,30 @@ public class PlayerManager extends ListableRest subPaths = new HashMap<>(); + private final Map subPaths = new HashMap<>(); public PlayerManager(FreeboxOsSession session) throws FreeboxException { super(session, LoginManager.Permission.PLAYER, PlayerResponse.class, session.getUriBuilder().path(THING_PLAYER)); + } + + private @Nullable String getSubPath(int id) throws FreeboxException { + String subPath = subPaths.get(id); + if (subPath != null) { + return subPath; + } getDevices().stream().filter(Player::apiAvailable).forEach(player -> { String baseUrl = player.baseUrl(); if (baseUrl != null) { subPaths.put(player.id, baseUrl); } }); + return subPaths.get(id); } - public Status getPlayerStatus(int id) throws FreeboxException { - return getSingle(StatusResponse.class, subPaths.get(id), STATUS_PATH); + public @Nullable Status getPlayerStatus(int id) throws FreeboxException { + String subPath = getSubPath(id); + return subPath != null ? getSingle(StatusResponse.class, subPath, STATUS_PATH) : null; } // The player API does not allow to directly request a given player like others api parts @@ -220,8 +229,9 @@ public class PlayerManager extends ListableRest player.id == id).findFirst().orElse(null); } - public Configuration getConfig(int id) throws FreeboxException { - return getSingle(ConfigurationResponse.class, subPaths.get(id), SYSTEM_PATH); + public @Nullable Configuration getConfig(int id) throws FreeboxException { + String subPath = getSubPath(id); + return subPath != null ? getSingle(ConfigurationResponse.class, subPath, SYSTEM_PATH) : null; } public void sendKey(String ip, String code, String key, boolean longPress, int count) { @@ -240,7 +250,12 @@ public class PlayerManager extends ListableRest { try { - getManager(PlayerManager.class).reboot(getClientId()); + if (!getManager(PlayerManager.class).reboot(getClientId())) { + logger.warn("Unable to reboot the player - probably not reachable"); + } } catch (FreeboxException e) { logger.warn("Error rebooting: {}", e.getMessage()); }