From 95f709e62555e677eef8d0d6d083b5143c14a6b4 Mon Sep 17 00:00:00 2001 From: Dan Cunningham Date: Fri, 12 Apr 2024 13:35:12 -0600 Subject: [PATCH] [harmonyhub] Updates harmony library, uses strings for ids (#16646) See #6732 Signed-off-by: Dan Cunningham Signed-off-by: Ciprian Pascu --- .../org.openhab.binding.harmonyhub/pom.xml | 2 +- .../internal/handler/HarmonyHubHandler.java | 31 +++++++------------ 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/bundles/org.openhab.binding.harmonyhub/pom.xml b/bundles/org.openhab.binding.harmonyhub/pom.xml index e5394ba4297..1149e8bf867 100644 --- a/bundles/org.openhab.binding.harmonyhub/pom.xml +++ b/bundles/org.openhab.binding.harmonyhub/pom.xml @@ -22,7 +22,7 @@ com.github.digitaldan harmony-client - 1.1.6 + 1.1.7 compile diff --git a/bundles/org.openhab.binding.harmonyhub/src/main/java/org/openhab/binding/harmonyhub/internal/handler/HarmonyHubHandler.java b/bundles/org.openhab.binding.harmonyhub/src/main/java/org/openhab/binding/harmonyhub/internal/handler/HarmonyHubHandler.java index 150cf83de2f..06b7a18d16c 100644 --- a/bundles/org.openhab.binding.harmonyhub/src/main/java/org/openhab/binding/harmonyhub/internal/handler/HarmonyHubHandler.java +++ b/bundles/org.openhab.binding.harmonyhub/src/main/java/org/openhab/binding/harmonyhub/internal/handler/HarmonyHubHandler.java @@ -32,7 +32,6 @@ import org.eclipse.jetty.client.HttpClient; import org.openhab.binding.harmonyhub.internal.HarmonyHubDynamicTypeProvider; import org.openhab.binding.harmonyhub.internal.config.HarmonyHubConfig; import org.openhab.core.config.core.Configuration; -import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.NextPreviousType; import org.openhab.core.library.types.PlayPauseType; import org.openhab.core.library.types.RewindFastforwardType; @@ -126,26 +125,20 @@ public class HarmonyHubHandler extends BaseBridgeHandler implements HarmonyClien switch (channel.getUID().getId()) { case CHANNEL_CURRENT_ACTIVITY: - if (command instanceof DecimalType decimalCommand) { + try { try { - client.startActivity(decimalCommand.intValue()); - } catch (Exception e) { - logger.warn("Could not start activity", e); - } - } else { - try { - try { - int actId = Integer.parseInt(command.toString()); - client.startActivity(actId); - } catch (NumberFormatException ignored) { - client.startActivityByName(command.toString()); - } - } catch (IllegalArgumentException e) { - logger.warn("Activity '{}' is not known by the hub, ignoring it.", command); - } catch (Exception e) { - logger.warn("Could not start activity", e); + // try starting by ID + client.startActivity(command.toString()); + } catch (IllegalArgumentException ignored) { + // if that fails, try starting by name + client.startActivityByName(command.toString()); } + } catch (IllegalArgumentException e) { + logger.warn("Activity '{}' is not known by the hub, ignoring it.", command); + } catch (Exception e) { + logger.warn("Could not start activity", e); } + break; case CHANNEL_BUTTON_PRESS: client.pressButtonCurrentActivity(command.toString()); @@ -358,7 +351,7 @@ public class HarmonyHubHandler extends BaseBridgeHandler implements HarmonyClien // trigger of power-off activity (with ID=-1) getConfigFuture().thenAccept(config -> { if (config != null) { - Activity powerOff = config.getActivityById(-1); + Activity powerOff = config.getActivityById("-1"); if (powerOff != null) { triggerChannel(CHANNEL_ACTIVITY_STARTING_TRIGGER, getEventName(powerOff)); }