Make Throttle async aware (#13027)

* Make Throttle async aware

* Lint
This commit is contained in:
Paulus Schoutsen committed 2018-03-09 19:42:35 -08:00
1 parent 8f807a3006
commit 6ffc53b290
11 files changed
+54 -48

No files matched your search

+3 -4
View File
@@ -140,21 +140,20 @@ class StartcaData(object):
"""
return float(value) * 10 ** -9
@asyncio.coroutine
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def async_update(self):
async def async_update(self):
"""Get the Start.ca bandwidth data from the web service."""
import xmltodict
_LOGGER.debug("Updating Start.ca usage data")
url = 'https://www.start.ca/support/usage/api?key=' + \
self.api_key
with async_timeout.timeout(REQUEST_TIMEOUT, loop=self.loop):
req = yield from self.websession.get(url)
req = await self.websession.get(url)
if req.status != 200:
_LOGGER.error("Request failed with status: %u", req.status)
return False
data = yield from req.text()
data = await req.text()
try:
xml_data = xmltodict.parse(data)
except ExpatError: