I just tried calling addChildDevice()
with a driver specified that I knew wouldn't work, and I got:
com.hubitat.app.exception.UnknownDeviceTypeException: Device type 'TestName' in namespace 'TestNamespace' not found
So, a catch (com.hubitat.app.exception.UnknownDeviceTypeException ex) ...
or similar should do the trick. But there are a few other things that could go wrong when creating a device, so you may want to also still catch a general Exception
, and note that the addChildDevice()
method should return the device that was created (technically a DeviceWrapper
), so if that is null
, something went wrong. If you only do this at the point when you actually create devices, I don't see any problems, but I'm not sure it satisfies the "check before you actually try" criterion that some are wishing for above.