Skip to content

Commit

Permalink
[harmonyhub] Updates harmony library, uses strings for ids (#16646)
Browse files Browse the repository at this point in the history
See #6732

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
  • Loading branch information
digitaldan authored Apr 12, 2024
1 parent 995ea2d commit 0fca945
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
2 changes: 1 addition & 1 deletion bundles/org.openhab.binding.harmonyhub/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<dependency>
<groupId>com.github.digitaldan</groupId>
<artifactId>harmony-client</artifactId>
<version>1.1.6</version>
<version>1.1.7</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
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;
Expand Down Expand Up @@ -126,26 +125,20 @@ public void handleCommand(ChannelUID channelUID, Command command) {

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());
Expand Down Expand Up @@ -358,7 +351,7 @@ private void updateActivityStatus(@Nullable Activity activity, @Nullable Status
// 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));
}
Expand Down

0 comments on commit 0fca945

Please sign in to comment.