Async cleanup part 3 (#4302)

This commit is contained in:
Pascal Vizeli 2016-11-08 07:31:40 +01:00 committed by Paulus Schoutsen
parent 231ef40f53
commit 2e0c185740
10 changed files with 14 additions and 15 deletions

View file

@ -35,7 +35,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
"""Setup a FFmpeg Camera.""" """Setup a FFmpeg Camera."""
if not async_run_test(hass, config.get(CONF_INPUT)): if not async_run_test(hass, config.get(CONF_INPUT)):
return return
hass.loop.create_task(async_add_devices([FFmpegCamera(hass, config)])) yield from async_add_devices([FFmpegCamera(hass, config)])
class FFmpegCamera(Camera): class FFmpegCamera(Camera):
@ -85,7 +85,7 @@ class FFmpegCamera(Camera):
break break
response.write(data) response.write(data)
finally: finally:
self.hass.loop.create_task(stream.close()) self.hass.async_add_job(stream.close())
yield from response.write_eof() yield from response.write_eof()
@property @property

View file

@ -43,7 +43,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
# pylint: disable=unused-argument # pylint: disable=unused-argument
def async_setup_platform(hass, config, async_add_devices, discovery_info=None): def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
"""Setup a generic IP Camera.""" """Setup a generic IP Camera."""
hass.loop.create_task(async_add_devices([GenericCamera(hass, config)])) yield from async_add_devices([GenericCamera(hass, config)])
class GenericCamera(Camera): class GenericCamera(Camera):

View file

@ -43,7 +43,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
# pylint: disable=unused-argument # pylint: disable=unused-argument
def async_setup_platform(hass, config, async_add_devices, discovery_info=None): def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
"""Setup a MJPEG IP Camera.""" """Setup a MJPEG IP Camera."""
hass.loop.create_task(async_add_devices([MjpegCamera(hass, config)])) yield from async_add_devices([MjpegCamera(hass, config)])
def extract_image_from_mjpeg(stream): def extract_image_from_mjpeg(stream):
@ -122,7 +122,7 @@ class MjpegCamera(Camera):
break break
response.write(data) response.write(data)
finally: finally:
self.hass.loop.create_task(stream.release()) self.hass.async_add_job(stream.release())
yield from response.write_eof() yield from response.write_eof()
@property @property

View file

@ -147,7 +147,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
devices.append(device) devices.append(device)
yield from asyncio.wait(tasks, loop=hass.loop) yield from asyncio.wait(tasks, loop=hass.loop)
hass.loop.create_task(async_add_devices(devices)) yield from async_add_devices(devices)
@asyncio.coroutine @asyncio.coroutine
@ -280,7 +280,7 @@ class SynologyCamera(Camera):
break break
response.write(data) response.write(data)
finally: finally:
self.hass.loop.create_task(stream.release()) self.hass.async_add_job(stream.release())
yield from response.write_eof() yield from response.write_eof()
@property @property

View file

@ -47,7 +47,7 @@ class LiteJetLight(Light):
def _on_load_changed(self): def _on_load_changed(self):
"""Called on a LiteJet thread when a load's state changes.""" """Called on a LiteJet thread when a load's state changes."""
_LOGGER.debug("Updating due to notification for %s", self._name) _LOGGER.debug("Updating due to notification for %s", self._name)
self._hass.loop.create_task(self.async_update_ha_state(True)) self._hass.async_add_job(self.async_update_ha_state(True))
@property @property
def name(self): def name(self):

View file

@ -55,8 +55,7 @@ def async_create(hass, message, title=None, notification_id=None):
] if value is not None ] if value is not None
} }
hass.loop.create_task( hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_CREATE, data))
hass.services.async_call(DOMAIN, SERVICE_CREATE, data))
@asyncio.coroutine @asyncio.coroutine

View file

@ -146,4 +146,4 @@ class TorqueSensor(Entity):
def async_on_update(self, value): def async_on_update(self, value):
"""Receive an update.""" """Receive an update."""
self._state = value self._state = value
self.hass.loop.create_task(self.async_update_ha_state()) self.hass.async_add_job(self.async_update_ha_state())

View file

@ -154,7 +154,7 @@ class YrData(object):
try_again('{} returned {}'.format(self._url, resp.status)) try_again('{} returned {}'.format(self._url, resp.status))
return return
text = yield from resp.text() text = yield from resp.text()
self.hass.loop.create_task(resp.release()) self.hass.async_add_job(resp.release())
except asyncio.TimeoutError as err: except asyncio.TimeoutError as err:
try_again(err) try_again(err)
return return

View file

@ -47,12 +47,12 @@ class LiteJetSwitch(SwitchDevice):
def _on_switch_pressed(self): def _on_switch_pressed(self):
_LOGGER.debug("Updating pressed for %s", self._name) _LOGGER.debug("Updating pressed for %s", self._name)
self._state = True self._state = True
self._hass.loop.create_task(self.async_update_ha_state()) self._hass.async_add_job(self.async_update_ha_state())
def _on_switch_released(self): def _on_switch_released(self):
_LOGGER.debug("Updating released for %s", self._name) _LOGGER.debug("Updating released for %s", self._name)
self._state = False self._state = False
self._hass.loop.create_task(self.async_update_ha_state()) self._hass.async_add_job(self.async_update_ha_state())
@property @property
def name(self): def name(self):

View file

@ -119,7 +119,7 @@ class NetioApiView(HomeAssistantView):
ndev.start_dates = start_dates ndev.start_dates = start_dates
for dev in DEVICES[host].entities: for dev in DEVICES[host].entities:
self.hass.loop.create_task(dev.async_update_ha_state()) self.hass.async_add_job(dev.async_update_ha_state())
return self.json(True) return self.json(True)