Skip to content

Commit

Permalink
Merge e609224 into c1998f3
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffLIrion committed Oct 20, 2023
2 parents c1998f3 + e609224 commit a805e68
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
15 changes: 10 additions & 5 deletions androidtv/basetv/basetv.py
Expand Up @@ -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
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion androidtv/basetv/basetv_async.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion androidtv/basetv/basetv_sync.py
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/test_basetv_sync.py
Expand Up @@ -35,7 +35,7 @@

DEVICE_PROPERTIES_OUTPUT2 = """Amazon
AFTT
5.1.1
"""

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a805e68

Please sign in to comment.