diff --git a/androidtv/basetv/basetv.py b/androidtv/basetv/basetv.py index 8174d8e..c4c86fb 100644 --- a/androidtv/basetv/basetv.py +++ b/androidtv/basetv/basetv.py @@ -242,9 +242,14 @@ def _cmd_hdmi_input(self): return constants.CMD_HDMI_INPUT - def _cmd_volume_set(self): + def _cmd_volume_set(self, new_volume): """Get the command used to set volume for this device. + Parameters + ---------- + new_volume : int + The new volume level + Returns ------- str @@ -253,17 +258,17 @@ def _cmd_volume_set(self): """ # Is this an Android 11 device? if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "11": - return constants.CMD_VOLUME_SET_COMMAND11 + return constants.CMD_VOLUME_SET_COMMAND11.format(new_volume) # Is this an Android 12 device? if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "12": - return constants.CMD_VOLUME_SET_COMMAND11 + return constants.CMD_VOLUME_SET_COMMAND11.format(new_volume) # Is this an Android 13 device? if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "13": - return constants.CMD_VOLUME_SET_COMMAND11 + return constants.CMD_VOLUME_SET_COMMAND11.format(new_volume) - return constants.CMD_VOLUME_SET_COMMAND + return constants.CMD_VOLUME_SET_COMMAND.format(new_volume) def _cmd_launch_app(self, app): """Get the command to launch the specified app for this device. diff --git a/androidtv/basetv/basetv_async.py b/androidtv/basetv/basetv_async.py index b733fd8..13cc8d5 100644 --- a/androidtv/basetv/basetv_async.py +++ b/androidtv/basetv/basetv_async.py @@ -830,7 +830,7 @@ async def set_volume_level(self, volume_level): new_volume = int(min(max(round(self.max_volume * volume_level), 0.0), self.max_volume)) - await self._adb.shell(self._cmd_volume_set().format(new_volume)) + await self._adb.shell(self._cmd_volume_set(new_volume)) # return the new volume level return new_volume / self.max_volume diff --git a/androidtv/basetv/basetv_sync.py b/androidtv/basetv/basetv_sync.py index dfb230d..8d4480a 100644 --- a/androidtv/basetv/basetv_sync.py +++ b/androidtv/basetv/basetv_sync.py @@ -830,7 +830,7 @@ def set_volume_level(self, volume_level): new_volume = int(min(max(round(self.max_volume * volume_level), 0.0), self.max_volume)) - self._adb.shell("media volume --show --stream 3 --set {}".format(new_volume)) + self._adb.shell(self._cmd_volume_set(new_volume)) # return the new volume level return new_volume / self.max_volume diff --git a/tests/test_basetv_sync.py b/tests/test_basetv_sync.py index 073d676..dbb909a 100644 --- a/tests/test_basetv_sync.py +++ b/tests/test_basetv_sync.py @@ -35,7 +35,7 @@ DEVICE_PROPERTIES_OUTPUT2 = """Amazon AFTT - + 5.1.1 """ @@ -627,7 +627,7 @@ def test_get_device_properties(self): # _cmd_audio_state self.assertEqual(self.btv._cmd_audio_state(), constants.CMD_AUDIO_STATE11) # _cmd_volume_set - self.assertEqual(self.btv._cmd_volume_set(), constants.CMD_VOLUME_SET_COMMAND11) + self.assertEqual(self.btv._cmd_volume_set(5), constants.CMD_VOLUME_SET_COMMAND11.format(5)) # _cmd_current_app self.assertEqual(self.btv._cmd_current_app(), constants.CMD_CURRENT_APP11) # _cmd_current_app_media_session_state @@ -660,7 +660,7 @@ def test_get_device_properties(self): # _cmd_audio_state self.assertEqual(self.btv._cmd_audio_state(), constants.CMD_AUDIO_STATE11) # _cmd_volume_set - self.assertEqual(self.btv._cmd_volume_set(), constants.CMD_VOLUME_SET_COMMAND11) + self.assertEqual(self.btv._cmd_volume_set(5), constants.CMD_VOLUME_SET_COMMAND11.format(5)) # _cmd_current_app self.assertEqual(self.btv._cmd_current_app(), constants.CMD_CURRENT_APP12) # _cmd_current_app_media_session_state @@ -693,7 +693,7 @@ def test_get_device_properties(self): # _cmd_audio_state self.assertEqual(self.btv._cmd_audio_state(), constants.CMD_AUDIO_STATE11) # _cmd_volume_set - self.assertEqual(self.btv._cmd_volume_set(), constants.CMD_VOLUME_SET_COMMAND11) + self.assertEqual(self.btv._cmd_volume_set(5), constants.CMD_VOLUME_SET_COMMAND11.format(5)) # _cmd_current_app self.assertEqual(self.btv._cmd_current_app(), constants.CMD_CURRENT_APP13) # _cmd_current_app_media_session_state