]> nmode's Git Repositories - signal-cli/commitdiff
Add DeviceNotFound Error
authorAsamK <asamk@gmx.de>
Sat, 9 Oct 2021 15:04:01 +0000 (17:04 +0200)
committerAsamK <asamk@gmx.de>
Sat, 9 Oct 2021 15:04:17 +0000 (17:04 +0200)
src/main/java/org/asamk/Signal.java
src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java

index 2f81c196e714950dff561c48586c7e64578d925b..bf8265ffe933eed6083e9d569322d8b6d0c7f1c4 100644 (file)
@@ -326,6 +326,13 @@ public interface Signal extends DBusInterface {
             }
         }
 
+        class DeviceNotFound extends DBusExecutionException {
+
+            public DeviceNotFound(final String message) {
+                super(message);
+            }
+        }
+
         class GroupNotFound extends DBusExecutionException {
 
             public GroupNotFound(final String message) {
index d0e33a40e66ba2abc03d7ae61e5ae8883663ea72..ab19f0cec85116986de85e60184aeed8e8a5c290 100644 (file)
@@ -111,7 +111,11 @@ public class DbusSignalImpl implements Signal {
     @Override
     public DBusPath getDevice(long deviceId) {
         updateDevices();
-        return new DBusPath(getDeviceObjectPath(objectPath, deviceId));
+        final var deviceOptional = devices.stream().filter(g -> g.getId().equals(deviceId)).findFirst();
+        if (deviceOptional.isEmpty()) {
+            throw new Error.DeviceNotFound("Device not found");
+        }
+        return deviceOptional.get().getObjectPath();
     }
 
     @Override