Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d.adb_device.battery() 出错 #1030

Open
hick opened this issue Aug 25, 2024 · 2 comments
Open

d.adb_device.battery() 出错 #1030

hick opened this issue Aug 25, 2024 · 2 comments
Labels

Comments

@hick
Copy link

hick commented Aug 25, 2024

  • 手机型号 d.device_info 输出(序列化改了)

{'serial': 'xxx', 'sdk': 25, 'brand': 'SMARTISAN', 'model': 'OD103', 'arch': 'arm64-v8a', 'version': None}

  • uiautomator2的版本号(pip show uiautomator2)
Name: uiautomator2
Version: 3.2.2
Summary: uiautomator for android device
Home-page: https://github.com/openatx/uiautomator2
Author: codeskyblue
Author-email: [email protected]
License: MIT
Location: d:\program\python38win10\lib\site-packages
Requires: requests, retry, lxml, Pillow, adbutils
Required-by:
  • 相关日志(Python控制台错误信息, adb logcat完整信息, atxagent.log日志)

Traceback (most recent call last):
  File "uiautomator2-.py", line 100, in <module>
    main()
  File "uiautomator2-.py", line 27, in main
    hig.Log(d.adb_device.battery())
  File "D:\Program\Python38win10\lib\site-packages\adbutils\shell.py", line 522, in battery
    key, val = line.strip().split(':', 1)
ValueError: not enough values to unpack (expected 2, got 1)

  • 最好能附上可能复现问题的代码。
    d = u2.connect('192.168.31.173:5555') 
    hig.Log(d.device_info)
    hig.Log(d.adb_device.battery())

@codeskyblue
Copy link
Member

提供一下输出 adb shell dumpsys battery

@happyman
Copy link

我是自己寫一個,需要請自取

def dumpbattery():
    battery=dict()
    r = d.shell("dumpsys battery").output.strip().splitlines()
    for lines in r:
        if lines.find(": ") > 0:
            key, val = lines.split(": ")
            if val.lower() in [ "true" ]:
                val = True
            elif val.lower() in [ "false" ]:
                val = False
            elif val.isdigit():
                val = int(val)
            battery[key.replace(" ","").lower()]=val
    return battery

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants