core icon indicating copy to clipboard operation
core copied to clipboard

Add queue_to_iterable util function

Open synesthesiam opened this issue 1 year ago • 6 comments

Breaking change

Proposed change

Adds a new async utility function queue_to_iterable which transforms an async queue into an iterable stream with an optional timeout for each item.

To start, this will be used for Assist audio streams in several integrations.

Type of change

  • [ ] Dependency upgrade
  • [ ] Bugfix (non-breaking change which fixes an issue)
  • [ ] New integration (thank you!)
  • [x] 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

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

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:

synesthesiam avatar Aug 27 '24 16:08 synesthesiam

Not yet, I was told to split this into a separate PR first :smile:

But there are 3 places where it will be used in Assist satellite entities, replacing code like this: https://github.com/home-assistant/core/blob/55c42fde88c7a6989a8489b755375fef92360f35/homeassistant/components/esphome/voice_assistant.py#L114

synesthesiam avatar Aug 27 '24 17:08 synesthesiam

Test failure seems to be unrelated

synesthesiam avatar Aug 27 '24 18:08 synesthesiam

We normally don't add a util until there are at least two existing places that needs it. Until then we can just copy the suggested code here and use where needed. Then it's an easy replace later.

MartinHjelmare avatar Aug 28 '24 00:08 MartinHjelmare

We normally don't add a util until there are at least two existing places that needs it. Until then we can just copy the suggested code here and use where needed. Then it's an easy replace later.

Yeah, I agree with this. We would also wait to refactor to a util until the function is used in more than one place.

emontnemery avatar Aug 28 '24 06:08 emontnemery

As is written in the description:

To start, this will be used for Assist audio streams in several integrations.

It is going to be used by every integration that is going to implement Assist Satellite: wyoming, esphome and voip. Both voip and esphome platforms will use it and will be included in the assist satellite branch.

Joost asked Mike to extract it into a separate PR, so here it is. If that's not the suggest approach, that's fine too, and we can close this PR.

balloob avatar Aug 28 '24 16:08 balloob

Let's keep this PR in draft until there are two places that need it. We don't need to close it.

MartinHjelmare avatar Aug 28 '24 16:08 MartinHjelmare