Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions homeassistant/components/sensor/yr.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@
})


@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 Yr.no sensor."""
elevation = config.get(CONF_ELEVATION, hass.config.elevation or 0)
forecast = config.get(CONF_FORECAST)
Expand All @@ -93,7 +92,7 @@ def async_setup_platform(hass, config, async_add_entities,

weather = YrData(hass, coordinates, forecast, dev)
async_track_utc_time_change(hass, weather.updating_devices, minute=31)
yield from weather.fetching_data()
await weather.fetching_data()


class YrSensor(Entity):
Expand Down Expand Up @@ -156,8 +155,7 @@ def __init__(self, hass, coordinates, forecast, devices):
self.data = {}
self.hass = hass

@asyncio.coroutine
def fetching_data(self, *_):
async def fetching_data(self, *_):
"""Get the latest data from yr.no."""
import xmltodict

Expand All @@ -169,12 +167,12 @@ def try_again(err: str):
try:
websession = async_get_clientsession(self.hass)
with async_timeout.timeout(10, loop=self.hass.loop):
resp = yield from websession.get(
resp = await websession.get(
self._url, params=self._urlparams)
if resp.status != 200:
try_again('{} returned {}'.format(resp.url, resp.status))
return
text = yield from resp.text()
text = await resp.text()

except (asyncio.TimeoutError, aiohttp.ClientError) as err:
try_again(err)
Expand All @@ -186,11 +184,10 @@ def try_again(err: str):
try_again(err)
return

yield from self.updating_devices()
await self.updating_devices()
async_call_later(self.hass, 60*60, self.fetching_data)

@asyncio.coroutine
def updating_devices(self, *_):
async def updating_devices(self, *_):
"""Find the current data from self.data."""
if not self.data:
return
Expand Down Expand Up @@ -256,4 +253,4 @@ def updating_devices(self, *_):
tasks.append(dev.async_update_ha_state())

if tasks:
yield from asyncio.wait(tasks, loop=self.hass.loop)
await asyncio.wait(tasks, loop=self.hass.loop)