core icon indicating copy to clipboard operation
core copied to clipboard

Fix playing TTS and local media source over DLNA

Open kepler opened this issue 11 months ago • 12 comments

Proposed change

This fixes https://github.com/home-assistant/core/issues/139580 (described below as well).

If I try TTS or playing a local media audio file on a DLNA compatible speaker, it doesn't work and shows an error in the log:

[homeassistant.components.dlna_dmr] Error during call async_play_media: UpnpActionResponseError('Error during async_call(), status: 500, upnp error: 716 (Resource not found)')

Right before the Resource not found error above, the HA logs show that there's a HEAD request coming in from the speaker and that fails with an HTTP 500 error. I also saw somewhere someone hinting that DLNA renderers might send a HEAD request before sending the GET one.

This PR adds support for HEAD requests for local_source media and TTS (also allowing signed requests for HEAD), which fixes this problem and likely related issues mentioned below.

Type of change

  • [ ] Dependency upgrade
  • [X] 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

There are several reports around the net about this or related DLNA problems, dating back to 2022:

Most replies to such issues end up pointing to configuring media_dirs (Setting up local media sources, Media Source), but nothing works, leading to complains about unclear documentation: https://github.com/home-assistant/home-assistant.io/issues/28940.

Also, the documentation says there might be hiccups with Samsung devices, but that might be exactly because of the missing support for HEAD requests:

Note that some devices, such as Samsung TVs, are rather picky about the source used to play from. The TTS action might not work in combination with these devices.

UPDATE 2025-03-01 ~~However, I haven't tried streaming videos yet. I'll check it later and submit a separate PR if necessary, and it seems to also be an issue like #67618.~~ Videos work with these changes and I also included a fix for local images.

Checklist

  • [x] The code change is tested and works locally.
  • [x] Local tests pass. Your PR cannot be merged unless tests pass
  • [x] There is no commented out code in this PR.
  • [x] I have followed the development checklist
  • [x] I have followed the perfect PR recommendations
  • [x] The code has been formatted using Ruff (ruff format homeassistant tests)
  • [x] 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:

kepler avatar Jan 06 '25 17:01 kepler

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

Learn more about our pull request process.

home-assistant[bot] avatar Jan 06 '25 17:01 home-assistant[bot]

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

Code owner commands

Code owners of tts 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 tts 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[bot] avatar Jan 06 '25 17:01 home-assistant[bot]

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

Code owner commands

Code owners of media_source 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 media_source 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[bot] avatar Jan 06 '25 17:01 home-assistant[bot]

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

Code owner commands

Code owners of http 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 http 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[bot] avatar Jan 06 '25 17:01 home-assistant[bot]

Just to confirm that this also fixes streaming video to my Samsung TV.

kepler avatar Jan 09 '25 08:01 kepler

Why is the merging blocked? I would be happy to see it in the next update. Thank you.

vitals5 avatar Feb 12 '25 15:02 vitals5

I actually don't know. Perhaps something in the CI didn't go well, but I can't see what I could do.

I'll create an issue and a new PR this weekend if nothing moves here (and close this one).

On Wed, Feb 12, 2025, 15:04 vitals5 @.***> wrote:

Why is the merging blocked? I would be happy to see it in the next update. Thank you.

— Reply to this email directly, view it on GitHub https://github.com/home-assistant/core/pull/134903#issuecomment-2653981202, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAASAHMVEX43LLBZKOJJBZT2PNPF5AVCNFSM6AAAAABUV76GOSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNJTHE4DCMRQGI . You are receiving this because you were mentioned.Message ID: @.***> [image: vitals5]vitals5 left a comment (home-assistant/core#134903) https://github.com/home-assistant/core/pull/134903#issuecomment-2653981202

Why is the merging blocked? I would be happy to see it in the next update. Thank you.

— Reply to this email directly, view it on GitHub https://github.com/home-assistant/core/pull/134903#issuecomment-2653981202, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAASAHMVEX43LLBZKOJJBZT2PNPF5AVCNFSM6AAAAABUV76GOSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNJTHE4DCMRQGI . You are receiving this because you were mentioned.Message ID: @.***>

kepler avatar Feb 13 '25 23:02 kepler

Hi, did you make a new issue? If so could you link it here for us that want to stay up to date?

valgeirhelgi avatar Feb 23 '25 16:02 valgeirhelgi

Thanks for doing this. This has been a issue with my home assistant.

TheManWhoLikesToCode avatar Feb 24 '25 23:02 TheManWhoLikesToCode

I've marked this PR a draft, as changes are requested that need to be processed. Please un-draft it once it is ready for review again by clicking the "Ready for review" button.

Thanks! 👍

../Frenck

Learn more about our pull request process.

frenck avatar Mar 02 '25 12:03 frenck

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes. Thank you for your contribution!

github-actions[bot] avatar May 01 '25 14:05 github-actions[bot]

Please guys keep this PR alive I've been waiting for this fix so badly ;)

StageS4 avatar May 01 '25 14:05 StageS4

Owner please consider finishing, I have 2x Samsung TVs that are affected

mr10points avatar Jun 04 '25 01:06 mr10points

Hi @chishm. Thank you for your review and apologies for the delay.

I addressed your comments and marked the PR as ready for review. Appreciate your look at it when possible.

kepler avatar Jun 09 '25 08:06 kepler