Nerwyn / android-tv-card

Universal Customizable TV Remote Card, with HA actions, super configurable touchpad, slider, haptics, and keyboard
Apache License 2.0
183 stars 9 forks source link

Problem with the implementation of the URL action compared with the implementation of HA's default cards #44

Closed adrienvsj closed 6 months ago

adrienvsj commented 6 months ago

Checklist:

Release with the issue: Start with 3.2.0 (introducing HA actions button)

Last working release (if known): No functional release

Browser and Operating System: HomeAssistant Companion iOS version : 2023.7 (2023.471) (latest version) HomeAssistant Core version : 2023.12.3 (latest version) android-tv-card version : 3.2.2 (latest version)

Description of problem: Since version 3.2.0 and the ability to use the HA actions button, I want to integrate a custom actions that opens an external application on my iPhone, which is the Apple TV remote control app. Code with the button card :

show_name: true
show_icon: true
type: button
tap_action:
  action: url
  url_path: tvremote://
entity: media_player.apple_tv
name: Open Apple TV remote

But using the same tap_action configuration in the android-tv-card does absolutely nothing. I get haptic feedback but nothing happens. I created another custom action that opens google.com and this one works but doesn't work exactly like HA's lovelace buton card. And I think that's where my problem comes from.

With a url_path on an HA button card, when clicked it opens the google.com in my default browser. Whereas the same configuration but in the android-tv-card navigates directly to google.com but within the HA companion iOS app webview. I think that the integration of button URL actions is not implemented exactly as it is on HA's default cards. Opening a url externally (towards the iOS browser) allows iOS to evaluate the nature of the link and, in the case of a URL scheme, open the targeted application.

Attached is a demo video : https://youtube.com/shorts/JTlR0I0GGIU?si=_Jy8qiT_2vzKZ2bs

Javascript errors shown in the web inspector (if applicable):

NA

Your Full Remote Config

type: custom:android-tv-card
remote_id: remote.television
slider_id: media_player.television
keyboard_id: media_player.television_adb
rows:
  - - back
    - home
    - source
    - apple_tv
    - google
    - power
  - - keyboard
    - ambilight
    - light_salon_film
    - light_salon_cocooning
  - touchpad
  - volume_buttons
  - - rewind
    - play
    - pause
    - fast_forward
custom_actions:
  google:
    icon: mdi:google
    tap_action:
      action: url
      url_path: https://www.google.com
  apple_tv:
    icon: mdi:apple
    tap_action:
      action: url
      url_path: tvremote://
  ambilight:
    icon: mdi:television-ambient-light
    tap_action:
      service: remote.send_command
      service_data:
        entity_id: remote.television
        command: AmbilightOnOff
  light_salon_film:
    icon: mdi:lightbulb-night
    tap_action:
      service: script.tv_salon_film
  light_salon_cocooning:
    icon: mdi:weather-night
    tap_action:
      service: script.tv_salon_cocooning
  power:
    icon: mdi:power
    tap_action:
      service: media_player.toggle
      service_data:
        entity_id: media_player.television
  back:
    icon: mdi:arrow-left
    tap_action:
      service: remote.send_command
      service_data:
        entity_id: remote.television
        command: Back
  info:
    icon: mdi:asterisk
    tap_action:
      service: remote.send_command
      service_data:
        entity_id: remote.television
        command: Info
  home:
    icon: mdi:home
    tap_action:
      service: remote.send_command
      service_data:
        entity_id: remote.television
        command: Home
  volume_up:
    icon: mdi:volume-plus
    tap_action:
      service: remote.send_command
      service_data:
        entity_id: remote.television
        command: VolumeUp
  volume_down:
    icon: mdi:volume-minus
    tap_action:
      service: remote.send_command
      service_data:
        entity_id: remote.television
        command: VolumeDown
  volume_mute:
    icon: mdi:volume-mute
    tap_action:
      service: remote.send_command
      service_data:
        entity_id: remote.television
        command: Mute
  up:
    icon: mdi:chevron-up
    tap_action:
      service: remote.send_command
      service_data:
        entity_id: remote.television
        command: CursorUp
  down:
    icon: mdi:chevron-down
    tap_action:
      service: remote.send_command
      service_data:
        entity_id: remote.television
        command: CursorDown
  left:
    icon: mdi:chevron-left
    tap_action:
      service: remote.send_command
      service_data:
        entity_id: remote.television
        command: CursorLeft
  right:
    icon: mdi:chevron-right
    tap_action:
      service: remote.send_command
      service_data:
        entity_id: remote.television
        command: CursorRight
  center:
    icon: mdi:circle
    tap_action:
      service: remote.send_command
      service_data:
        entity_id: remote.television
        command: Confirm
  rewind:
    icon: mdi:rewind
    tap_action:
      service: remote.send_command
      service_data:
        entity_id: remote.television
        command: Rewind
  fast_forward:
    icon: mdi:fast-forward
    tap_action:
      service: remote.send_command
      service_data:
        entity_id: remote.television
        command: FastForward
  play:
    icon: mdi:play
    tap_action:
      service: remote.send_command
      service_data:
        entity_id: remote.television
        command: Play
  pause:
    icon: mdi:pause
    tap_action:
      service: remote.send_command
      service_data:
        entity_id: remote.television
        command: Pause
  source:
    icon: mdi:import
    tap_action:
      service: remote.send_command
      service_data:
        entity_id: remote.television
        command: Source
  netflix:
    icon: mdi:netflix
    tap_action:
      service: media_player.select_source
      service_data:
        entity_id: media_player.television_adb
        source: com.netflix.ninja
  youtube:
    icon: mdi:youtube
    tap_action:
      service: media_player.select_source
      service_data:
        entity_id: media_player.television_adb
        source: com.teamsmart.videomanager.tv
  spotify:
    icon: mdi:spotify
    tap_action:
      service: media_player.select_source
      service_data:
        entity_id: media_player.television_adb
        source: com.spotify.tv.android
  plex:
    icon: mdi:plex
    tap_action:
      service: media_player.select_source
      service_data:
        entity_id: media_player.television_adb
        source: com.plexapp.android
  tv:
    icon: mdi:television-box
    tap_action:
      service: media_player.select_source
      service_data:
        entity_id: media_player.television_adb
        source: net.oqee.androidtv.store

Additional information:

Nerwyn commented 6 months ago

I finally found the Home Assistant frontend file that defines how actions are handled. Here is how URLs are handled. I'll try refactoring my code to more closely follow what's done here and then test that it all works.

Nerwyn commented 6 months ago

Should be fixed in v3.2.3. I tested it on an old iPhone and it opened the correct apps. I also added the assist and more-info commands using the information from the Home Assistant frontend repo.

adrienvsj commented 6 months ago

Work fine thank you for your work !