Wait for valid device before installing

Fix #586