1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Async syntax 5, light & lock & remote & scene & telegram & helpers (#17019)

This commit is contained in:
cdce8p
2018-10-01 08:56:50 +02:00
committed by Paulus Schoutsen
parent 9e4c8f45d6
commit 3b5e5cbcd6
28 changed files with 112 additions and 195 deletions

View File

@@ -1,5 +1,4 @@
"""An abstract class for entities."""
import asyncio
from datetime import timedelta
import logging
import functools as ft
@@ -202,8 +201,7 @@ class Entity:
self._context = context
self._context_set = dt_util.utcnow()
@asyncio.coroutine
def async_update_ha_state(self, force_refresh=False):
async def async_update_ha_state(self, force_refresh=False):
"""Update Home Assistant with current state of entity.
If force_refresh == True will update entity before setting state.
@@ -220,7 +218,7 @@ class Entity:
# update entity data
if force_refresh:
try:
yield from self.async_device_update()
await self.async_device_update()
except Exception: # pylint: disable=broad-except
_LOGGER.exception("Update for %s fails", self.entity_id)
return
@@ -323,8 +321,7 @@ class Entity:
"""Schedule an update ha state change task."""
self.hass.async_add_job(self.async_update_ha_state(force_refresh))
@asyncio.coroutine
def async_device_update(self, warning=True):
async def async_device_update(self, warning=True):
"""Process 'update' or 'async_update' from entity.
This method is a coroutine.
@@ -335,7 +332,7 @@ class Entity:
# Process update sequential
if self.parallel_updates:
yield from self.parallel_updates.acquire()
await self.parallel_updates.acquire()
if warning:
update_warn = self.hass.loop.call_later(
@@ -347,9 +344,9 @@ class Entity:
try:
# pylint: disable=no-member
if hasattr(self, 'async_update'):
yield from self.async_update()
await self.async_update()
elif hasattr(self, 'update'):
yield from self.hass.async_add_job(self.update)
await self.hass.async_add_job(self.update)
finally:
self._update_staged = False
if warning: