]> git.basschouten.com Git - openhab-addons.git/commitdiff
[digitalstrom] fixes StringIndexOutOfBoundsException (#9194)
authorGaétan Collaud <gaetancollaud@gmail.com>
Sat, 5 Dec 2020 00:06:59 +0000 (01:06 +0100)
committerGitHub <noreply@github.com>
Sat, 5 Dec 2020 00:06:59 +0000 (16:06 -0800)
* [digitalstrom] catch issues when adding devices

Signed-off-by: Gaétan Collaud <gaetancollaud@gmail.com>
* Update bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/DiscoveryServiceManager.java

Signed-off-by: Gaétan Collaud <gaetancollaud@gmail.com>
bundles/org.openhab.binding.digitalstrom/src/main/java/org/openhab/binding/digitalstrom/internal/discovery/DiscoveryServiceManager.java

index 7866ed6e8804f0a8c529546d5c7bc65e785044d3..187d71bac1ae78500ba5aa9a4c106fb28e893761 100644 (file)
@@ -40,6 +40,8 @@ import org.openhab.core.thing.ThingTypeUID;
 import org.openhab.core.thing.type.ThingType;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * The {@link DiscoveryServiceManager} manages the different scene and device discovery services and informs them about
@@ -51,6 +53,8 @@ import org.osgi.framework.ServiceRegistration;
 public class DiscoveryServiceManager
         implements SceneStatusListener, DeviceStatusListener, TemperatureControlStatusListener {
 
+    private final Logger logger = LoggerFactory.getLogger(DiscoveryServiceManager.class);
+
     private final Map<String, AbstractDiscoveryService> discoveryServices;
     private final Map<String, ServiceRegistration<?>> discoveryServiceRegs = new HashMap<>();
     private final String bridgeUID;
@@ -194,20 +198,25 @@ public class DiscoveryServiceManager
 
     @Override
     public void onDeviceAdded(GeneralDeviceInformation device) {
-        if (device instanceof Device) {
-            String id = ((Device) device).getHWinfo().substring(0, 2);
-            if (((Device) device).isSensorDevice()) {
-                id = ((Device) device).getHWinfo();
-            }
-            if (discoveryServices.get(id) != null) {
-                ((DeviceDiscoveryService) discoveryServices.get(id)).onDeviceAdded(device);
+        try {
+            if (device instanceof Device) {
+                String id = ((Device) device).getHWinfo().substring(0, 2);
+                if (((Device) device).isSensorDevice()) {
+                    id = ((Device) device).getHWinfo();
+                }
+                if (discoveryServices.get(id) != null) {
+                    ((DeviceDiscoveryService) discoveryServices.get(id)).onDeviceAdded(device);
+                }
             }
-        }
-        if (device instanceof Circuit) {
-            if (discoveryServices.get(DsDeviceThingTypeProvider.SupportedThingTypes.circuit.toString()) != null) {
-                ((DeviceDiscoveryService) discoveryServices
-                        .get(DsDeviceThingTypeProvider.SupportedThingTypes.circuit.toString())).onDeviceAdded(device);
+            if (device instanceof Circuit) {
+                if (discoveryServices.get(DsDeviceThingTypeProvider.SupportedThingTypes.circuit.toString()) != null) {
+                    ((DeviceDiscoveryService) discoveryServices
+                            .get(DsDeviceThingTypeProvider.SupportedThingTypes.circuit.toString()))
+                                    .onDeviceAdded(device);
+                }
             }
+        } catch (RuntimeException ex) {
+            logger.warn("Unable to add devices {}", device, ex);
         }
     }