config_device.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. from enum import Enum
  5. from pydantic import BaseModel, ValidationError, validator, Field
  6. from module.logger import logger
  7. class PackageName(str, Enum):
  8. AUTO = 'auto'
  9. NETEASE_ONMYOJI = 'com.netease.onmyoji.wyzymnqsd_cps' # 网易自家的阴阳师
  10. class ScreenshotMethod(str, Enum):
  11. ADB = 'adb'
  12. ADB_NC = 'adb_nc'
  13. UIAUTOMATOR2 = 'uiautomator2'
  14. DROIDCAST = 'droidcast'
  15. DROIDCAST_RAW = 'droidcast_raw'
  16. SCRCPY = 'scrcpy'
  17. WINDOW_BACKGROUND = 'window_background'
  18. class ControlMethod(str, Enum):
  19. ADB = 'adb'
  20. UIAUTOMATOR2 = 'uiautomator2'
  21. MINITOUCH = 'minitouch'
  22. WINDOW_MESSAGE = 'window_message'
  23. class Device(BaseModel):
  24. serial: str = Field(default="127.0.0.1:7555",
  25. description='Common emulator Serial can be queried in the list belowUse "auto" to auto-detect emulators, but if multiple emulators are running or use emulators that do not support auto-detect, "auto" cannot be used and serial must be filled in manually')
  26. handle: str = Field(default='auto',
  27. description='you can use auto or your emulator title')
  28. package_name: PackageName = Field(default=PackageName.AUTO,
  29. description='package name')
  30. screenshot_method: ScreenshotMethod = Field(default=ScreenshotMethod.WINDOW_BACKGROUND,
  31. description='only support window')
  32. control_method: ControlMethod = Field(default=ControlMethod.WINDOW_MESSAGE,
  33. description='only support window')
  34. adb_restart: bool = Field(default=False,
  35. description='')
  36. if __name__ == '__main__':
  37. d = Device()
  38. print(d.json())
  39. print(d.schema_json())
  40. try:
  41. d.control_method = 'adb'
  42. except ValidationError as e:
  43. print(e)