self.loop.create_task -> self.add_job (#6632)

* self.loop.create_task -> self.add_job

* Core to use create task
This commit is contained in:
Paulus Schoutsen 2017-03-15 22:58:54 -07:00 committed by Pascal Vizeli
parent 5b3dc7f2a5
commit e265401cd0
13 changed files with 16 additions and 15 deletions

View file

@ -113,7 +113,7 @@ def async_setup(hass, config):
if not alarm.should_poll: if not alarm.should_poll:
continue continue
update_coro = hass.loop.create_task( update_coro = hass.async_add_job(
alarm.async_update_ha_state(True)) alarm.async_update_ha_state(True))
if hasattr(alarm, 'async_update'): if hasattr(alarm, 'async_update'):
update_tasks.append(update_coro) update_tasks.append(update_coro)

View file

@ -224,7 +224,7 @@ def async_setup(hass, config):
if not climate.should_poll: if not climate.should_poll:
continue continue
update_coro = hass.loop.create_task( update_coro = hass.async_add_job(
climate.async_update_ha_state(True)) climate.async_update_ha_state(True))
if hasattr(climate, 'async_update'): if hasattr(climate, 'async_update'):
update_tasks.append(update_coro) update_tasks.append(update_coro)

View file

@ -166,7 +166,7 @@ def async_setup(hass, config):
if not cover.should_poll: if not cover.should_poll:
continue continue
update_coro = hass.loop.create_task( update_coro = hass.async_add_job(
cover.async_update_ha_state(True)) cover.async_update_ha_state(True))
if hasattr(cover, 'async_update'): if hasattr(cover, 'async_update'):
update_tasks.append(update_coro) update_tasks.append(update_coro)

View file

@ -218,7 +218,7 @@ def async_setup(hass, config: dict):
if not fan.should_poll: if not fan.should_poll:
continue continue
update_coro = hass.loop.create_task( update_coro = hass.async_add_job(
fan.async_update_ha_state(True)) fan.async_update_ha_state(True))
if hasattr(fan, 'async_update'): if hasattr(fan, 'async_update'):
update_tasks.append(update_coro) update_tasks.append(update_coro)

View file

@ -255,7 +255,7 @@ def async_setup(hass, config):
if not light.should_poll: if not light.should_poll:
continue continue
update_coro = hass.loop.create_task( update_coro = hass.async_add_job(
light.async_update_ha_state(True)) light.async_update_ha_state(True))
if hasattr(light, 'async_update'): if hasattr(light, 'async_update'):
update_tasks.append(update_coro) update_tasks.append(update_coro)

View file

@ -96,7 +96,7 @@ def async_setup(hass, config):
if not entity.should_poll: if not entity.should_poll:
continue continue
update_coro = hass.loop.create_task( update_coro = hass.async_add_job(
entity.async_update_ha_state(True)) entity.async_update_ha_state(True))
if hasattr(entity, 'async_update'): if hasattr(entity, 'async_update'):
update_tasks.append(update_coro) update_tasks.append(update_coro)

View file

@ -268,7 +268,7 @@ class KodiDevice(MediaPlayerDevice):
"Unable to connect to Kodi via websocket", exc_info=True) "Unable to connect to Kodi via websocket", exc_info=True)
# Websocket connection is not required. Just return. # Websocket connection is not required. Just return.
return return
self.hass.loop.create_task(self.async_ws_loop()) self.hass.async_add_job(self.async_ws_loop())
self._ws_connected = True self._ws_connected = True
@asyncio.coroutine @asyncio.coroutine
@ -297,7 +297,7 @@ class KodiDevice(MediaPlayerDevice):
return return
if self._enable_websocket and not self._ws_connected: if self._enable_websocket and not self._ws_connected:
self.hass.loop.create_task(self.async_ws_connect()) self.hass.async_add_job(self.async_ws_connect())
self._app_properties = \ self._app_properties = \
yield from self.server.Application.GetProperties( yield from self.server.Application.GetProperties(

View file

@ -112,7 +112,7 @@ def async_setup(hass, config):
if not remote.should_poll: if not remote.should_poll:
continue continue
update_coro = hass.loop.create_task( update_coro = hass.async_add_job(
remote.async_update_ha_state(True)) remote.async_update_ha_state(True))
if hasattr(remote, 'async_update'): if hasattr(remote, 'async_update'):
update_tasks.append(update_coro) update_tasks.append(update_coro)

View file

@ -358,7 +358,7 @@ class RflinkCommand(RflinkDevice):
self._protocol.send_command, self._device_id, cmd)) self._protocol.send_command, self._device_id, cmd))
if repetitions > 1: if repetitions > 1:
self._repetition_task = self.hass.loop.create_task( self._repetition_task = self.hass.async_add_job(
self._async_send_command(cmd, repetitions - 1)) self._async_send_command(cmd, repetitions - 1))

View file

@ -111,7 +111,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
# Make all device entities aware of new telegram # Make all device entities aware of new telegram
for device in devices: for device in devices:
device.telegram = telegram device.telegram = telegram
hass.async_add_job(device.async_update_ha_state) hass.async_add_job(device.async_update_ha_state())
# Creates a asyncio.Protocol factory for reading DSMR telegrams from serial # Creates a asyncio.Protocol factory for reading DSMR telegrams from serial
# and calls update_entities_telegram to update entities on arrival # and calls update_entities_telegram to update entities on arrival
@ -133,7 +133,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
def connect_and_reconnect(): def connect_and_reconnect():
"""Connect to DSMR and keep reconnecting until HA stops.""" """Connect to DSMR and keep reconnecting until HA stops."""
while hass.state != CoreState.stopping: while hass.state != CoreState.stopping:
# Start DSMR asycnio.Protocol reader # Start DSMR asyncio.Protocol reader
try: try:
transport, protocol = yield from hass.loop.create_task( transport, protocol = yield from hass.loop.create_task(
reader_factory()) reader_factory())
@ -161,6 +161,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
yield from asyncio.sleep(config[CONF_RECONNECT_INTERVAL], yield from asyncio.sleep(config[CONF_RECONNECT_INTERVAL],
loop=hass.loop) loop=hass.loop)
# Cannot be hass.async_add_job because job runs forever
hass.loop.create_task(connect_and_reconnect()) hass.loop.create_task(connect_and_reconnect())

View file

@ -112,7 +112,7 @@ def async_setup(hass, config):
if not switch.should_poll: if not switch.should_poll:
continue continue
update_coro = hass.loop.create_task( update_coro = hass.async_add_job(
switch.async_update_ha_state(True)) switch.async_update_ha_state(True))
if hasattr(switch, 'async_update'): if hasattr(switch, 'async_update'):
update_tasks.append(update_coro) update_tasks.append(update_coro)

View file

@ -141,7 +141,7 @@ class HomeAssistant(object):
def start(self) -> None: def start(self) -> None:
"""Start home assistant.""" """Start home assistant."""
# Register the async start # Register the async start
self.loop.create_task(self.async_start()) self.add_job(self.async_start())
# Run forever and catch keyboard interrupt # Run forever and catch keyboard interrupt
try: try:

View file

@ -419,7 +419,7 @@ class EntityPlatform(object):
update_coro = entity.async_update_ha_state(True) update_coro = entity.async_update_ha_state(True)
if hasattr(entity, 'async_update'): if hasattr(entity, 'async_update'):
tasks.append( tasks.append(
self.component.hass.loop.create_task(update_coro)) self.component.hass.async_add_job(update_coro))
else: else:
to_update.append(update_coro) to_update.append(update_coro)