Skip to content

Conversation

epenet
Copy link
Contributor

@epenet epenet commented Apr 17, 2023

Proposed change

Allow config entries unload action to be coroutine

Linked to #91439 and #91456

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

  • 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 Black (black --fast 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.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@home-assistant home-assistant bot added cla-signed core new-feature small-pr PRs with less than 30 lines. labels Apr 17, 2023
@epenet epenet requested review from elupus and bdraco April 17, 2023 08:09
@epenet epenet marked this pull request as ready for review April 17, 2023 08:13
@epenet epenet requested a review from a team as a code owner April 17, 2023 08:13
@elupus
Copy link
Contributor

elupus commented Apr 17, 2023

I have missed this feature in unload. Making sure io bound things are fully closed down too make sense to me.

@elupus elupus added the second-opinion-wanted Add this label when a reviewer needs a second opinion from another member. label Apr 17, 2023
Copy link
Contributor

@elupus elupus left a comment

Choose a reason for hiding this comment

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

Would be good with second opinion on this. But im for it.

"""Process the on_unload callbacks and wait for pending tasks."""
if self._on_unload is not None:
while self._on_unload:
self._on_unload.pop()()
if job := self._on_unload.pop()():
self._tasks.add(hass.async_create_task(job))
Copy link
Member

Choose a reason for hiding this comment

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

This would pass a callback function to async_create_task ?

Copy link
Contributor Author

@epenet epenet Apr 17, 2023

Choose a reason for hiding this comment

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

No it shouldn't: see the double () in the pop.
Would that be clearer?

                callback = self._on_unload.pop()
                if job := callback():
                    self._tasks.add(hass.async_create_task(job))

Copy link
Member

Choose a reason for hiding this comment

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

Oh right.

@balloob balloob merged commit 3364f0f into home-assistant:dev Apr 17, 2023
@balloob balloob removed the second-opinion-wanted Add this label when a reviewer needs a second opinion from another member. label Apr 17, 2023
@epenet epenet deleted the config_entries_on_unload branch April 17, 2023 12:41
@epenet epenet mentioned this pull request Apr 17, 2023
20 tasks
@github-actions github-actions bot locked and limited conversation to collaborators Apr 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants