Convert more files to async/await syntax (#14142)
* Move more files to async/await syntax * Attempt Work around pylint bug Using lazytox :P
This commit is contained in:
1 parent
a0b14c2913
commit
a4bf421044
27 files changed
+229
-327
No files matched your search
@@ -122,8 +122,7 @@ def async_finish(hass, entity_id):
|
||||
DOMAIN, SERVICE_FINISH, {ATTR_ENTITY_ID: entity_id}))
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup(hass, config):
|
||||
async def async_setup(hass, config):
|
||||
"""Set up a timer."""
|
||||
component = EntityComponent(_LOGGER, DOMAIN, hass)
|
||||
|
||||
@@ -142,8 +141,7 @@ def async_setup(hass, config):
|
||||
if not entities:
|
||||
return False
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_handler_service(service):
|
||||
async def async_handler_service(service):
|
||||
"""Handle a call to the timer services."""
|
||||
target_timers = component.async_extract_from_service(service)
|
||||
|
||||
@@ -162,7 +160,7 @@ def async_setup(hass, config):
|
||||
timer.async_start(service.data.get(ATTR_DURATION))
|
||||
)
|
||||
if tasks:
|
||||
yield from asyncio.wait(tasks, loop=hass.loop)
|
||||
await asyncio.wait(tasks, loop=hass.loop)
|
||||
|
||||
hass.services.async_register(
|
||||
DOMAIN, SERVICE_START, async_handler_service,
|
||||
@@ -177,7 +175,7 @@ def async_setup(hass, config):
|
||||
DOMAIN, SERVICE_FINISH, async_handler_service,
|
||||
schema=SERVICE_SCHEMA)
|
||||
|
||||
yield from component.async_add_entities(entities)
|
||||
await component.async_add_entities(entities)
|
||||
return True
|
||||
|
||||
|
||||
@@ -224,19 +222,17 @@ class Timer(Entity):
|
||||
ATTR_REMAINING: str(self._remaining)
|
||||
}
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_added_to_hass(self):
|
||||
async def async_added_to_hass(self):
|
||||
"""Call when entity is about to be added to Home Assistant."""
|
||||
# If not None, we got an initial value.
|
||||
if self._state is not None:
|
||||
return
|
||||
|
||||
restore_state = self._hass.helpers.restore_state
|
||||
state = yield from restore_state.async_get_last_state(self.entity_id)
|
||||
state = await restore_state.async_get_last_state(self.entity_id)
|
||||
self._state = state and state.state == state
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_start(self, duration):
|
||||
async def async_start(self, duration):
|
||||
"""Start a timer."""
|
||||
if self._listener:
|
||||
self._listener()
|
||||
@@ -260,10 +256,9 @@ class Timer(Entity):
|
||||
self._listener = async_track_point_in_utc_time(self._hass,
|
||||
self.async_finished,
|
||||
self._end)
|
||||
yield from self.async_update_ha_state()
|
||||
await self.async_update_ha_state()
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_pause(self):
|
||||
async def async_pause(self):
|
||||
"""Pause a timer."""
|
||||
if self._listener is None:
|
||||
return
|
||||
@@ -273,10 +268,9 @@ class Timer(Entity):
|
||||
self._remaining = self._end - dt_util.utcnow()
|
||||
self._state = STATUS_PAUSED
|
||||
self._end = None
|
||||
yield from self.async_update_ha_state()
|
||||
await self.async_update_ha_state()
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_cancel(self):
|
||||
async def async_cancel(self):
|
||||
"""Cancel a timer."""
|
||||
if self._listener:
|
||||
self._listener()
|
||||
@@ -286,10 +280,9 @@ class Timer(Entity):
|
||||
self._remaining = timedelta()
|
||||
self._hass.bus.async_fire(EVENT_TIMER_CANCELLED,
|
||||
{"entity_id": self.entity_id})
|
||||
yield from self.async_update_ha_state()
|
||||
await self.async_update_ha_state()
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_finish(self):
|
||||
async def async_finish(self):
|
||||
"""Reset and updates the states, fire finished event."""
|
||||
if self._state != STATUS_ACTIVE:
|
||||
return
|
||||
@@ -299,10 +292,9 @@ class Timer(Entity):
|
||||
self._remaining = timedelta()
|
||||
self._hass.bus.async_fire(EVENT_TIMER_FINISHED,
|
||||
{"entity_id": self.entity_id})
|
||||
yield from self.async_update_ha_state()
|
||||
await self.async_update_ha_state()
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_finished(self, time):
|
||||
async def async_finished(self, time):
|
||||
"""Reset and updates the states, fire finished event."""
|
||||
if self._state != STATUS_ACTIVE:
|
||||
return
|
||||
@@ -312,4 +304,4 @@ class Timer(Entity):
|
||||
self._remaining = timedelta()
|
||||
self._hass.bus.async_fire(EVENT_TIMER_FINISHED,
|
||||
{"entity_id": self.entity_id})
|
||||
yield from self.async_update_ha_state()
|
||||
await self.async_update_ha_state()
|
||||
Reference in new issue
Block a user