Async syntax 6, sensor (#17020)

This commit is contained in:
cdce8p authored and Paulus Schoutsen committed 2018-10-01 08:55:43 +02:00
1 parent 121dba659c
commit 9e4c8f45d6
45 files changed
+195 -319

No files matched your search

+7 -10
View File
@@ -63,9 +63,8 @@ PLATFORM_SCHEMA = vol.All(PLATFORM_SCHEMA.extend({
}, extra=vol.PREVENT_EXTRA), _check_sensor_schema)
@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 SMA WebConnect sensor."""
import pysma
@@ -107,10 +106,9 @@ def async_setup_platform(hass, config, async_add_entities,
sma = pysma.SMA(session, url, config[CONF_PASSWORD], group=grp)
# Ensure we logout on shutdown
@asyncio.coroutine
def async_close_session(event):
async def async_close_session(event):
"""Close the session."""
yield from sma.close_session()
await sma.close_session()
hass.bus.async_listen(EVENT_HOMEASSISTANT_STOP, async_close_session)
@@ -120,15 +118,14 @@ def async_setup_platform(hass, config, async_add_entities,
backoff = 0
@asyncio.coroutine
def async_sma(event):
async def async_sma(event):
"""Update all the SMA sensors."""
nonlocal backoff
if backoff > 1:
backoff -= 1
return
values = yield from sma.read(keys_to_query)
values = await sma.read(keys_to_query)
if values is None:
backoff = 3
return
@@ -142,7 +139,7 @@ def async_setup_platform(hass, config, async_add_entities,
if task:
tasks.append(task)
if tasks:
yield from asyncio.wait(tasks, loop=hass.loop)
await asyncio.wait(tasks, loop=hass.loop)
interval = config.get(CONF_SCAN_INTERVAL) or timedelta(seconds=5)
async_track_time_interval(hass, async_sma, interval)