Skip to content

Add androidtv_remote.send_text action #139033

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

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from

Conversation

tronikos
Copy link
Member

@tronikos tronikos commented Feb 22, 2025

Breaking change

Proposed change

Add androidtv_remote.send_text action for sending text to an Android TV device.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link

Hey there @Drafteed, mind taking a look at this pull request as it has been labeled with an integration (androidtv_remote) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of androidtv_remote can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign androidtv_remote Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@home-assistant
Copy link

Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration (default_config) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of default_config can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign default_config Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@tronikos tronikos changed the title Add androidtv_remote.send_text service Add androidtv_remote.send_text action Feb 23, 2025
Comment on lines 47 to 52
platform = entity_platform.async_get_current_platform()
platform.async_register_entity_service(
SERVICE_SEND_TEXT,
{vol.Required(ATTR_TEXT): cv.string},
"send_text",
)
Copy link
Member

Choose a reason for hiding this comment

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

I am wondering if this service isn't better suited for just a normal integration service, rather than an entity service. Since in that case you would pick either the config entry or the device, WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it would be more confusing to users since they won't know they can either specify config entry or entity without looking at the documentation and they will end up specifying both. The code will also be more complicated to handle the different selections. Searching for ConfigEntrySelector I only found 12 usages. None of them seem to support config entry or entity/device as target. Anyway it seems we could do what you suggested at any time in the future without being a breaking change so I'd rather stick to the simpler approach for now.

Copy link
Member

Choose a reason for hiding this comment

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

I dont mean to pick both, i just mean to pick a device, rather than an entity. Changing this will be a breaking change as users have to change their automations

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe instead of an action, it would be worth considering introducing a text entity that could also display the current entered text on TV, like the official app does.

Copy link
Member Author

Choose a reason for hiding this comment

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

@joostlek I guess I misunderstood what you are proposing. I personally don't like using a config entry or device in my automations since they are IDs that can change if you remove and re-add the device. I always like using entity IDs. What would the benefit be of your proposal?

@Drafteed the library doesn't support yet getting the current entered text. Somebody needs to reverse engineer that and implement it. I don't have such plans

Copy link

Choose a reason for hiding this comment

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

That sounds good to me, although input text and Lit_ are features of the underlying libraries used rather than Home Assistant design decisions. Mimicking that in the Android TV Remote component wouldn't be a bad idea.

You could also consider using the non-target device field, which seems to be used for IR remotes but not for media platform integrations that use the remote.send_command service.

action: remote.send_command
data:
  command: "{{ text }}"
  device: keyboard
target:
  entity_id: remote.living_room_tv

As someone who hasn't done much work on Home Assistant core, what is the difference between a service that runs on the integration vs entity vs config entry vs device? Is it the target? Service name? I've seen integration/entity/device/config entry service thrown around in this comment thread but don't fully understand the differences between them.

Copy link
Member Author

Choose a reason for hiding this comment

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

I switched to an integration service in this PR. So this now has to be called as:

action: androidtv_remote.send_text
data:
  config_entry_id: 0adab1e29ef310f1d2a97849c911dddd
  text: hi

As an alternative I have #142438. With that you'll call it with:

action: remote.send_command
data:
  device: keyboard
  command: hi
target:
  entity_id: remote.living_room_tv

I prefer the second option.

Copy link

Choose a reason for hiding this comment

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

I also STRONGLY prefer the second option. I can't even think of any services that act on config entry IDs like the first one does. Definitely nothing related to Android TV or any other media platform.

Copy link
Member Author

Choose a reason for hiding this comment

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

There are a few services that act on config entries but all the ones I'm aware of are for integrations that either don't have entities or the services aren't meant to be acted on their entities.

@joostlek you said:

Entity actions should only be used in specific cases where it fits the integration architecture, mostly because they are hard to validate when the device is offline, which leaves a subpar user experience

I think using the existing remote.send_command and device: keyboard better fits the remote platform. As I said earlier you will use this either from a custom card (such as Nerwyn's card) or from an automation that opens an app, sends buttons to navigate to search, sends back to close the keyboard (if your device pops it up), sends text as keyboard input, sends enter, sends buttons to navigate to the results. All these actions are performed on the remote entity and not the media player entity.

Also, as you can see in #142438 we do know when the device is offline as it returns ConnectionClosed.

Copy link
Member Author

Choose a reason for hiding this comment

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

FYI, all the 4 options implemented (at the latest or a previous commit) in the 2 PRs are in https://gist.github.com/tronikos/e5ea2c95c0300cfa1aeb2d4f5c9a2e90

I'd prefer 1 since it makes automations much easier but I'd be fine with either 2 or 3. I really don't want the 4, the one with the unreadable config_entry_id.

@home-assistant home-assistant bot marked this pull request as draft February 23, 2025 13:19
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@tronikos tronikos mentioned this pull request Feb 23, 2025
19 tasks
@tronikos tronikos marked this pull request as ready for review February 23, 2025 22:43
@home-assistant home-assistant bot requested a review from joostlek February 23, 2025 22:43
@tronikos tronikos marked this pull request as ready for review April 8, 2025 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants