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

Make Throttle async aware #13027

Merged
merged 2 commits into from Mar 10, 2018
Merged

Make Throttle async aware #13027

merged 2 commits into from Mar 10, 2018

Conversation

balloob
Copy link
Member

@balloob balloob commented Mar 9, 2018

Description:

Throttle was not async aware. With coroutines these errors got swallowed but with async/await they surfaced, which is good as now we have been able to squash a bunch of bugs.

Found all instances where we combined an @async.coroutine with a @Throttle. I've converted them all to async/await and also fixed the Throttle decorator.

Found all instances with:

git grep -A3 -B3 Throttle | grep coroutine

Related issue (if applicable): fixes #13012

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

@balloob balloob requested a review from a team as a code owner March 9, 2018 23:35
"""Get the latest data from luftdaten.info and update the state."""
try:
yield from self.luftdaten.async_update()
except TypeError:
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed this type error because that would happen if Throttle was returning None

@balloob balloob added this to the 0.65.1 milestone Mar 9, 2018
@balloob balloob merged commit 36361d6 into dev Mar 10, 2018
@balloob balloob deleted the throttle-async branch March 10, 2018 03:38
balloob added a commit that referenced this pull request Mar 10, 2018
* Make Throttle async aware

* Lint
@balloob balloob mentioned this pull request Mar 10, 2018
@DavidFW1960
Copy link

DavidFW1960 commented Mar 10, 2018

Heres the sabnzdb log (I'm home now and I can paste it - not on iPad now)

Sat Mar 10 2018 14:27:14 GMT+1100 (Local Daylight Time)

Error while setting up platform sabnzbd
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 82, in async_setup
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result
    raise self._exception
  File "/usr/lib/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/sensor/sabnzbd.py", line 153, in async_setup_platform
    if not (yield from async_check_sabnzbd(SabnzbdApi, base_url, api_key)):
  File "/usr/lib/python3.6/site-packages/homeassistant/components/sensor/sabnzbd.py", line 62, in async_check_sabnzbd
    yield from sab_api.check_available()
  File "/usr/lib/python3.6/site-packages/pysabnzbd/__init__.py", line 43, in check_available
    with aiohttp.ClientSession() as session:
  File "/usr/lib/python3.6/site-packages/aiohttp/client.py", line 742, in __enter__
    raise TypeError("Use async with instead")
TypeError: Use async with instead

@balloob
Copy link
Member Author

balloob commented Mar 10, 2018

sabnzdb has been fixed in #13042

@thomasvt1
Copy link

thomasvt1 commented Mar 11, 2018

I think the Tado component suffers from the same issue (Also like #13012)

2018-03-11 00:56:28 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/device_tracker/__init__.py", line 738, in async_device_tracker_scan
    found_devices = yield from scanner.async_scan_devices()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/device_tracker/tado.py", line 81, in async_scan_devices
    yield from info
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/device_tracker/tado.py", line 121, in _update_info
    tado_json = yield from response.json()
TypeError: cannot 'yield from' a coroutine object in a non-coroutine generator

@balloob
Copy link
Member Author

balloob commented Mar 11, 2018

@thomasvt1 thanks for the report, opened #13078 with a fix

@home-assistant home-assistant locked and limited conversation to collaborators Jul 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wunderground not working since 0.65
4 participants