Skip to content
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

Define sync hass.create_task function #50788

Merged
merged 3 commits into from
May 17, 2021
Merged

Conversation

KapJI
Copy link
Member

@KapJI KapJI commented May 17, 2021

Proposed change

For async_add_job which expects Callable there's a sync counterpart: add_job. But there's no sync counterpart for async_create_task which expects Coroutine, although it's needed sometimes.

Right now add_job is used for that but this bypasses type safety. Here is how it's being used:

def add_job(self, target: Callable[..., Any], *args: Any) -> None:

...

 self.loop.call_soon_threadsafe(self.async_add_job, target, *args)

...

def async_add_job(
        self, target: Callable[..., Any], *args: Any
    ) -> asyncio.Future | None:

...

  if asyncio.iscoroutine(target):
      return self.async_create_task(cast(Coroutine, target))

Define create_task function which streamlines this and enables type safety.

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)
  • 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
  • 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.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@bdraco
Copy link
Member

bdraco commented May 17, 2021

This is refactored quite a bit in #50784

Would you please remove the zeroconf changes. I'll make the switch in 50784

@KapJI
Copy link
Member Author

KapJI commented May 17, 2021

Sure, it was just a nice little demo 🙂

@bdraco
Copy link
Member

bdraco commented May 17, 2021

We should probably have coverage for the new function

@bdraco
Copy link
Member

bdraco commented May 17, 2021

Assuming the CI is happy, I'll rebase #50784 and adjust it after this merges

@KapJI
Copy link
Member Author

KapJI commented May 17, 2021

@raman325 tests/components/vizio/test_init.py::test_coordinator_update_failure[pyloop] is flaky and that's pretty annoying. Can you please fix that test?

Example: https://github.com/home-assistant/core/runs/2594855564

@bdraco
Copy link
Member

bdraco commented May 17, 2021

raman325 tests/components/vizio/test_init.py::test_coordinator_update_failure[pyloop] is flaky and that's pretty annoying. Can you please fix that test?

Example: #50788 (checks)

Please open an issue to track this.

@KapJI
Copy link
Member Author

KapJI commented May 17, 2021

Done :)

@bdraco bdraco merged commit 5ad71b5 into home-assistant:dev May 17, 2021
@KapJI KapJI deleted the create-task branch May 17, 2021 20:01
@KapJI KapJI restored the create-task branch May 17, 2021 21:53
@KapJI KapJI deleted the create-task branch May 17, 2021 21:53
@KapJI KapJI restored the create-task branch May 17, 2021 21:53
@github-actions github-actions bot locked and limited conversation to collaborators May 18, 2021
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