def reset(cls, udid):
     """
     Reset the given CoreSimulator device.
     :param udid: The udid of the device.
     :type udid: str
     """
     SimulatedDevice.shutdown(udid)
     try:
         _log.debug('xcrun simctl erase %s', udid)
         subprocess.check_call(['xcrun', 'simctl', 'erase', udid])
     except subprocess.CalledProcessError:
         raise RuntimeError(
             '"xcrun simctl erase" failed: device state is {}'.format(
                 Simulator.device_state(udid)))
    def shutdown(cls, udid):
        """
        Shut down the given CoreSimulator device.
        :param udid: The udid of the device.
        :type udid: str
        """
        device_state = Simulator.device_state(udid)
        if device_state == Simulator.DeviceState.BOOTING or device_state == Simulator.DeviceState.BOOTED:
            _log.debug('xcrun simctl shutdown %s', udid)
            # Don't throw on error. Device shutdown seems to be racy with Simulator app killing.
            subprocess.call(['xcrun', 'simctl', 'shutdown', udid])

        Simulator.wait_until_device_is_in_state(udid,
                                                Simulator.DeviceState.SHUTDOWN)
 def state(self):
     """
     :returns: The current state of the device.
     :rtype: Simulator.DeviceState
     """
     return Simulator.device_state(self.udid)