Async syntax 8/8 (#17022)

* Async syntax 8

* Pylint fixes
This commit is contained in:
cdce8p authored and Paulus Schoutsen committed 2018-10-01 08:52:42 +02:00
1 parent ea7b1e4573
commit 9aaf11de8c
54 files changed
+223 -382

No files matched your search

+15 -25
View File
@@ -4,7 +4,6 @@ Component that will help set the FFmpeg component.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/ffmpeg/
"""
import asyncio
import logging
import voluptuous as vol
@@ -76,8 +75,7 @@ def async_restart(hass, entity_id=None):
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_RESTART, data))
@asyncio.coroutine
def async_setup(hass, config):
async def async_setup(hass, config):
"""Set up the FFmpeg component."""
conf = config.get(DOMAIN, {})
@@ -88,8 +86,7 @@ def async_setup(hass, config):
)
# Register service
@asyncio.coroutine
def async_service_handle(service):
async def async_service_handle(service):
"""Handle service ffmpeg process."""
entity_ids = service.data.get(ATTR_ENTITY_ID)
@@ -131,8 +128,7 @@ class FFmpegManager:
"""Return ffmpeg binary from config."""
return self._bin
@asyncio.coroutine
def async_run_test(self, input_source):
async def async_run_test(self, input_source):
"""Run test on this input. TRUE is deactivate or run correct.
This method must be run in the event loop.
@@ -146,7 +142,7 @@ class FFmpegManager:
# run test
ffmpeg_test = Test(self.binary, loop=self.hass.loop)
success = yield from ffmpeg_test.run_test(input_source)
success = await ffmpeg_test.run_test(input_source)
if not success:
_LOGGER.error("FFmpeg '%s' test fails!", input_source)
self._cache[input_source] = False
@@ -163,8 +159,7 @@ class FFmpegBase(Entity):
self.ffmpeg = None
self.initial_state = initial_state
@asyncio.coroutine
def async_added_to_hass(self):
async def async_added_to_hass(self):
"""Register dispatcher & events.
This method is a coroutine.
@@ -189,40 +184,36 @@ class FFmpegBase(Entity):
"""Return True if entity has to be polled for state."""
return False
@asyncio.coroutine
def _async_start_ffmpeg(self, entity_ids):
async def _async_start_ffmpeg(self, entity_ids):
"""Start a FFmpeg process.
This method is a coroutine.
"""
raise NotImplementedError()
@asyncio.coroutine
def _async_stop_ffmpeg(self, entity_ids):
async def _async_stop_ffmpeg(self, entity_ids):
"""Stop a FFmpeg process.
This method is a coroutine.
"""
if entity_ids is None or self.entity_id in entity_ids:
yield from self.ffmpeg.close()
await self.ffmpeg.close()
@asyncio.coroutine
def _async_restart_ffmpeg(self, entity_ids):
async def _async_restart_ffmpeg(self, entity_ids):
"""Stop a FFmpeg process.
This method is a coroutine.
"""
if entity_ids is None or self.entity_id in entity_ids:
yield from self._async_stop_ffmpeg(None)
yield from self._async_start_ffmpeg(None)
await self._async_stop_ffmpeg(None)
await self._async_start_ffmpeg(None)
@callback
def _async_register_events(self):
"""Register a FFmpeg process/device."""
@asyncio.coroutine
def async_shutdown_handle(event):
async def async_shutdown_handle(event):
"""Stop FFmpeg process."""
yield from self._async_stop_ffmpeg(None)
await self._async_stop_ffmpeg(None)
self.hass.bus.async_listen_once(
EVENT_HOMEASSISTANT_STOP, async_shutdown_handle)
@@ -231,10 +222,9 @@ class FFmpegBase(Entity):
if not self.initial_state:
return
@asyncio.coroutine
def async_start_handle(event):
async def async_start_handle(event):
"""Start FFmpeg process."""
yield from self._async_start_ffmpeg(None)
await self._async_start_ffmpeg(None)
self.async_schedule_update_ha_state()
self.hass.bus.async_listen_once(