Skip to content

Added configurable volume step and fixed replaced volume commands#71

Merged
zehnm merged 17 commits into
unfoldedcircle:mainfrom
albaintor:volume_step
May 12, 2025
Merged

Added configurable volume step and fixed replaced volume commands#71
zehnm merged 17 commits into
unfoldedcircle:mainfrom
albaintor:volume_step

Conversation

@albaintor
Copy link
Copy Markdown
Contributor

@albaintor albaintor commented May 8, 2025

Hi Markus,

I just added a configurable volume step for Android TV, like in Denon or some other integrations.
I updated the config flow and the model

Also I have fixed 2 problems :

  • In the Chromecast PR I have replaced the volume up/down commands by the Chromecast volume control. But this replacement also applies when chromecast is disabled. I have added a condition to prevent this.
  • Also when you enable chromecast, you don't have access anymore to standard volume up/down functions and mute. So I have added 3 simple commands KEY_VOLUME_UP, KEY_VOLUME_DOWN, and KEY_VOLUME_MUTE for this

Thanks

@albaintor albaintor changed the title Added configurable volume step Added configurable volume step and fixed replaced volume commands May 10, 2025
Copy link
Copy Markdown
Contributor

@zehnm zehnm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Profile changes and volume commands are not required and need to be reverted. This was already implemented in the device profiles.
See:

  • Issue #72
  • profile features (present in all profiles), e.g.:
{
  "...": "",
  "features": [
    "...",
    "volume_up_down",
    "mute_toggle",
    "..." ]
}
  • MEDIA_PLAYER_COMMANDS in profiles.py
    media_player.Commands.VOLUME_UP.value: "VOLUME_UP",
    media_player.Commands.VOLUME_DOWN.value: "VOLUME_DOWN",
    media_player.Commands.MUTE_TOGGLE.value: "VOLUME_MUTE",
  • send_media_player_command method in AndroidTv passes through the Android TV keycodes

Using Google Cast for volume control needs to be an option since it doesn't always work.

@albaintor
Copy link
Copy Markdown
Contributor Author

albaintor commented May 12, 2025

Hi Markus,

1/ Volume commands were duplicated in profiles.py:192, which led to duplicate commands in the UI (volume up twice, ...)

                media_player.Features.VOLUME,
                media_player.Features.VOLUME_UP_DOWN,
                media_player.Features.MUTE_TOGGLE,

I just cleaned those 3 duplicate lines.

2/ To prevent volume commands to be replaced when chromecast is disabled, I just added this condition in driver.py:157

    if android_tv.device_config.use_chromecast:
        # If chromecast disabled, default mapping will be used
        if cmd_id == media_player.Commands.VOLUME_UP:
            return await android_tv.volume_up()
        if cmd_id == media_player.Commands.VOLUME_DOWN:
            return await android_tv.volume_down()
        if cmd_id == media_player.Commands.MUTE_TOGGLE:
            return await android_tv.volume_mute_toggle()
        if cmd_id == media_player.Commands.VOLUME:
            return await android_tv.volume_set(params.get("volume"))
        if cmd_id == media_player.Commands.SEEK:
            return await android_tv.media_seek(params.get("media_position", 0))

Maybe there is a cleaner way to handle 2 sets of volume commands :

  1. Volume up/down/mute from the buttons (androidtvremoveservice)
  2. Volume up/down/mute from Chromecast protocol : these commands let use a configurable volume step

But to keep using standard volume buttons while enabling chromecast, I added 3 simple commands in all profiles :

    "KEY_VOLUME_UP",
    "KEY_VOLUME_DOWN",
    "KEY_VOLUME_MUTE"
...

    "KEY_VOLUME_UP": {
      "keycode": "VOLUME_UP"
    },
    "KEY_VOLUME_DOWN": {
      "keycode": "VOLUME_DOWN"
    },
    "KEY_VOLUME_MUTE": {
      "keycode": "VOLUME_MUTE"
    }

So what you suggest (sorry I prefer to write everything to be sure to understand) :

  1. Remove the simple commands
  2. Add a checkbox in setup flow to use standard volume control or the one from chromecast
  3. Replace the test I put by the condition on the checkbox ?

@albaintor albaintor requested a review from zehnm May 12, 2025 14:06
@zehnm
Copy link
Copy Markdown
Contributor

zehnm commented May 12, 2025

So what you suggest (sorry I prefer to write everything to be sure to understand) :

  1. Remove the simple commands
  2. Add a checkbox in setup flow to use standard volume control or the one from chromecast

No problem:

  1. Correct. Completely revert all device profile files in config/profiles.
    VOLUME_UP, VOLUME_DOWN, MUTE_TOGGLE are automatically enabled with the volume_up_down and mute_toggle features defined in a profile.
    Note: "enabled" means the features are added to the media-player entity, which tells the UI that it can send the official media-player commands. There's no check in the driver if for example the VOLUME_UP command is "allowed", it just passes it on to androidtvremote2 (UC command mapping to Android TV keycode is in MEDIA_PLAYER_COMMANDS, called from AndroidTv.send_media_player_command -> Profile.command ).
  2. Configuration settings:
    Add these 2 volume settings below the "id": "chromecast" configuration. It doesn't matter that they are always shown, even if Chromecast is not enabled. Dependent settings are not supported, and creating an additional dynamic setup screen is overkill.
    • "Preview feature: Use Chromecast volume control (requires Chromecast)"
    • "Preview feature: Chromecast volume step in percent"
  1. Replace the test I put by the condition on the checkbox ?

What exactly do you mean? The if android_tv.device_config.use_chromecast: check in driver.py?

Feel free to only add your new volume step feature and I'll fix the rest.

@albaintor
Copy link
Copy Markdown
Contributor Author

albaintor commented May 12, 2025

  1. Replace the test I put by the condition on the checkbox ?

What exactly do you mean? The if android_tv.device_config.use_chromecast: check in driver.py?

This check is now replaced by a test condition on the new option use_chromecast_volume
This is necessary to trigger the chromecast volume commands instead of letting the standard mapping apply through

android_tv.send_media_player_command(cmd_id)

I have added a new option in the setup flow (for init/reconfigure) and mapped it in the driver to trigger chromecast volume commands when the option is enabled.

And I reverted changes on profile files

Copy link
Copy Markdown
Contributor

@zehnm zehnm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there!
After those changes it looks ready to merge.

Then I'll add the missing language texts and start cleaning up a few things, like de-duplicating the same setting options in the setup flow (as in the Denon AVR integration) and using better response codes in case of Chromecast failures.

Comment thread .idea/runConfigurations/check_black.xml
Comment thread src/driver.py Outdated
@albaintor albaintor requested a review from zehnm May 12, 2025 17:10
@albaintor
Copy link
Copy Markdown
Contributor Author

Done

Copy link
Copy Markdown
Contributor

@zehnm zehnm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.
Verified with Shield TV, hooked up to AVR with HDMI:

  • Normal volume control works again
  • Chromecast volume control also works
    It doesn't seem to make a difference if set to 5% or 10%. It either changes the volume by +/- 2.5 or 3. Likely one of the many Chromecast / HDMI CEC quirks...

Fixes #72

@zehnm zehnm merged commit 7f15814 into unfoldedcircle:main May 12, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants