Async syntax 6, sensor (#17020)
This commit is contained in:
1 parent
121dba659c
commit
9e4c8f45d6
45 files changed
+195
-319
No files matched your search
@@ -7,7 +7,6 @@ https://home-assistant.io/components/sensor.startca/
|
||||
from datetime import timedelta
|
||||
from xml.parsers.expat import ExpatError
|
||||
import logging
|
||||
import asyncio
|
||||
import async_timeout
|
||||
|
||||
import voluptuous as vol
|
||||
@@ -57,16 +56,15 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
})
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, async_add_entities,
|
||||
discovery_info=None):
|
||||
async def async_setup_platform(hass, config, async_add_entities,
|
||||
discovery_info=None):
|
||||
"""Set up the sensor platform."""
|
||||
websession = async_get_clientsession(hass)
|
||||
apikey = config.get(CONF_API_KEY)
|
||||
bandwidthcap = config.get(CONF_TOTAL_BANDWIDTH)
|
||||
|
||||
ts_data = StartcaData(hass.loop, websession, apikey, bandwidthcap)
|
||||
ret = yield from ts_data.async_update()
|
||||
ret = await ts_data.async_update()
|
||||
if ret is False:
|
||||
_LOGGER.error("Invalid Start.ca API key: %s", apikey)
|
||||
return
|
||||
@@ -111,10 +109,9 @@ class StartcaSensor(Entity):
|
||||
"""Icon to use in the frontend, if any."""
|
||||
return self._icon
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_update(self):
|
||||
async def async_update(self):
|
||||
"""Get the latest data from Start.ca and update the state."""
|
||||
yield from self.startcadata.async_update()
|
||||
await self.startcadata.async_update()
|
||||
if self.type in self.startcadata.data:
|
||||
self._state = round(self.startcadata.data[self.type], 2)
|
||||
|
||||
|
||||
Reference in new issue
Block a user