From 7c03a729bcd90f59a57fc8fa6fe1e246ef175f65 Mon Sep 17 00:00:00 2001 From: Xiaojun Date: Mon, 15 Apr 2024 09:16:03 +0800 Subject: [PATCH] feat(shell): Add times for volume_up and volume_down --- adbutils/shell.py | 24 +++++++++++++++++++----- test_real_device/test_device.py | 4 ++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/adbutils/shell.py b/adbutils/shell.py index 9ded7f6..0807d63 100644 --- a/adbutils/shell.py +++ b/adbutils/shell.py @@ -6,7 +6,7 @@ import abc -import datetime +import time, datetime import json import re from typing import List, Optional, Union @@ -46,11 +46,25 @@ def keyevent(self, key_code: Union[int, str]): """adb shell input keyevent KEY_CODE""" self.shell(["input", "keyevent", str(key_code)]) - def volume_up(self): - self.shell("input keyevent VOLUME_UP") + def volume_up(self, times: int = 1): + """ + Increase the volume by times step + :param times: times to increase volumeļ¼Œdefault is 1(Wake up volume bar). + :return: + """ + for i in range(times): + self.shell("input keyevent VOLUME_UP") + time.sleep(0.5) - def volume_down(self): - self.shell("input keyevent VOLUME_DOWN") + def volume_down(self, times: int = 1): + """ + Decrease the volume by times step + :param times: times to decrease volumeļ¼Œdefault is 1(Wake up volume bar). + :return: + """ + for i in range(times): + self.shell("input keyevent VOLUME_DOWN") + time.sleep(0.5) def volume_mute(self): self.shell("input keyevent VOLUME_MUTE") diff --git a/test_real_device/test_device.py b/test_real_device/test_device.py index de2ad0a..1a1d058 100644 --- a/test_real_device/test_device.py +++ b/test_real_device/test_device.py @@ -61,8 +61,8 @@ def test_get_xxx(device: AdbDevice): def test_keyevent(device: AdbDevice): # make sure no error raised device.keyevent(4) - device.volume_up() - device.volume_down() + device.volume_up(2) + device.volume_down(3) device.volume_mute()