code: def _detect_devices(self) -> None:
          '''Detect whether devices connected.'''
          devices_num = len(self.devices_list)
          if devices_num == 0:
              raise DeviceConnectionException(
                  'No devices are connected. Please connect the device with USB or via WLAN and turn on the USB debugging option.')
          elif not self.device_sn and devices_num > 1:
              raise DeviceConnectionException(
                  f"Multiple devices detected: {' | '.join(self.devices_list)}, please specify device serial number or host.")
          else:
              self.device_sn = self.devices_list[0]
          if self.get_state() == 'offline':
              raise DeviceConnectionException(
                  'The device is offline. Please reconnect.'f _detect_devices(self) -> None:
          '''Detect whether devices connected.'''
          devices_num = len(self.devices_list)
          if devices_num == 0:
              raise DeviceConnectionException(
                  'No devices are connected. Please connect the device with USB or via WLAN and turn on the USB debugging option.')
          elif not self.device_sn and devices_num > 1:
              raise DeviceConnectionException(
                  f"Multiple devices detected: {' | '.join(self.devices_list)}, please specify device serial number or host.")
          else:
              self.device_sn = self.devices_list[0]
          if self.get_state() == 'offline':
              raise DeviceConnectionException(
                  'The device is offline. Please reconnect.')
docs: Detect whether devices connected.