Skip to content

Commit

Permalink
Merge pull request #13 from digitaldan/activity-id-fix
Browse files Browse the repository at this point in the history
Breaking change for using a string as the activity id
  • Loading branch information
digitaldan authored Apr 12, 2024
2 parents 72dabd3 + 6377a3d commit 1734402
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 41 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: Set up Maven Central Repository
uses: actions/setup-java@v2
with:
java-version: '11'
java-version: '17'
distribution: 'adopt'
server-id: ossrh
server-username: MAVEN_USERNAME
Expand All @@ -22,4 +22,4 @@ jobs:
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Logitech Harmony WebSocket Client

License EPL v2.0

[![TravisCI Build Status](https://travis-ci.org/digitaldan/harmony-client.svg?branch=master)](https://travis-ci.org/digitaldan/harmony-client)
# Running

`mvn clean compile assembly:single`
Expand Down
17 changes: 8 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
<groupId>com.github.digitaldan</groupId>
<artifactId>harmony-client</artifactId>
<packaging>jar</packaging>
<version>1.1.6</version>
<version>1.1.7</version>
<name>Harmony Client</name>
<description>Logitech Harmony WebSocket Client</description>
<url>https://github.com/digitaldan/harmony-client</url>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.release>17</maven.compiler.release>
</properties>
<licenses>
<license>
Expand Down Expand Up @@ -42,7 +41,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.0.1</version>
<version>3.2.3</version>
<configuration>
<!-- Prevent gpg from using pinentry programs -->
<gpgArguments>
Expand All @@ -63,7 +62,7 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.2</version>
<version>1.6.6</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
Expand All @@ -87,7 +86,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.0.1</version>
<version>3.2.3</version>
<configuration>
<!-- Prevent gpg from using pinentry programs -->
<gpgArguments>
Expand Down Expand Up @@ -124,7 +123,7 @@
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<version>4.2.0</version>
<version>7.0.0</version>
<executions>
<execution>
<goals>
Expand All @@ -135,7 +134,7 @@
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<version>3.3.0</version>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
Expand All @@ -158,7 +157,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<version>3.3.0</version>
<executions>
<execution>
<id>attach-sources</id>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/digitaldan/harmony/HarmonyClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public CompletableFuture<Activity> getCurrentActivity() {
final CompletableFuture<Activity> future = new CompletableFuture<Activity>();
if (this.currentActivity == null) {
sendMessage(new GetCurrentActivityMessage.GetCurrentActivityRequestMessage()).thenAccept(m -> {
int activityId = ((GetCurrentActivityMessage.GetCurrentActivityResponseMessage) m).getActivityId();
String activityId = ((GetCurrentActivityMessage.GetCurrentActivityResponseMessage) m).getActivityId();
this.currentActivity = this.cachedConfig.getActivityById(activityId);
future.complete(this.currentActivity);
});
Expand All @@ -223,10 +223,10 @@ public CompletableFuture<Activity> getCurrentActivity() {
* @return {@link CompletableFuture}
* @throws IllegalArgumentException if activity does not exist
*/
public CompletableFuture<?> startActivity(int activityId) throws IllegalArgumentException {
public CompletableFuture<?> startActivity(String activityId) throws IllegalArgumentException {
if (cachedConfig != null) {
if (cachedConfig.getActivityById(activityId) == null) {
throw new IllegalArgumentException(String.format("Unknown activity '%d'", activityId));
throw new IllegalArgumentException(String.format("Unknown activity '%s'", activityId));
}
return sendMessage(new StartActivityMessage.StartActivityRequestMessage(activityId,
System.currentTimeMillis() - connectedTime));
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/digitaldan/harmony/config/Activity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class Activity {
private String label;
private String suggestedDisplay;
private Integer id;
private String id;
private String activityTypeDisplayName;
private List<ControlGroup> controlGroup = new ArrayList<>();
private Integer activityOrder;
Expand Down Expand Up @@ -56,11 +56,11 @@ public void setSuggestedDisplay(String suggestedDisplay) {
this.suggestedDisplay = suggestedDisplay;
}

public Integer getId() {
public String getId() {
return id;
}

public void setId(Integer id) {
public void setId(String id) {
this.id = id;
}

Expand Down Expand Up @@ -130,6 +130,6 @@ public void setBaseImageUri(String baseImageUri) {

@Override
public String toString() {
return format("Activity[%d]:%s", getId(), getLabel());
return format("Activity[%s]:%s", getId(), getLabel());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public void setGlobal(Global global) {
this.global = global;
}

public Activity getActivityById(int result) {
public Activity getActivityById(String result) {
for (Activity activity : activities) {
if (activity.getId() == result) {
if (activity.getId().equals(result)) {
return activity;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public ActivityFinished getActivityFinished() {
}

public static class ActivityFinished {
Integer activityId;
String activityId;
Integer errorCode;
String errorString;

public ActivityFinished() {

}

public Integer getActivityId() {
public String getActivityId() {
return activityId;
}

Expand Down
10 changes: 2 additions & 8 deletions src/main/java/com/digitaldan/harmony/messages/DigestMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,8 @@ public class Digest {
private Integer configVersion;
private String accountId;

public Integer getActivityId() {
if (activityId != null) {
try {
return Integer.parseInt(activityId);
} catch (NumberFormatException ignored) {
}
}
return null;
public String getActivityId() {
return activityId;
}

public Status getActivityStatus() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@ public GetCurrentActivityResponseMessage(int code, String id, String msg) {
super(code, id, msg);
}

public int getActivityId() {
try {
return Integer.parseInt(currentActivityResult.result);
} catch (Exception e) {
return -1;
}
public String getActivityId() {
return currentActivityResult.result;
}

private class CurrentActivityResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public static class StartActivityRequestMessage extends RequestMessage {

HashMap<String, Object> params = new HashMap<>();

public StartActivityRequestMessage(int activityId, long timeStamp) {
public StartActivityRequestMessage(String activityId, long timeStamp) {
super(MIME_TYPE);
HashMap<String, Object> args = new HashMap<>();
args.put("rule", "start");
params.put("activityId", String.valueOf(activityId));
params.put("activityId", activityId);
params.put("timeStamp", timeStamp);
params.put("args", args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class StartActivityCommand extends ShellCommand {
@Override
public void execute(HarmonyClient harmonyClient) {
try {
harmonyClient.startActivity(Integer.parseInt(activity));
} catch (NumberFormatException e) {
harmonyClient.startActivity(activity);
} catch (IllegalArgumentException e) {
harmonyClient.startActivityByName(activity);
}
println("Activity %s started", activity);
Expand Down

0 comments on commit 1734402

Please sign in to comment.