Async syntax 3/8 (#17017)

* Async syntax 3, device_tracker & fan & hassio & image_processing & input

* Pylint fixes
This commit is contained in:
cdce8p authored and Paulus Schoutsen committed 2018-10-01 08:59:45 +02:00
1 parent 134eeecd65
commit b24f9f5dfa
23 files changed
+194 -286

No files matched your search

@@ -4,7 +4,6 @@ Component that will help set the Microsoft face detect processing.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/image_processing.microsoft_face_detect/
"""
import asyncio
import logging
import voluptuous as vol
@@ -45,9 +44,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
})
@asyncio.coroutine
def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
async def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
"""Set up the Microsoft Face detection platform."""
api = hass.data[DATA_MICROSOFT_FACE]
attributes = config[CONF_ATTRIBUTES]
@@ -88,15 +86,14 @@ class MicrosoftFaceDetectEntity(ImageProcessingFaceEntity):
"""Return the name of the entity."""
return self._name
@asyncio.coroutine
def async_process_image(self, image):
async def async_process_image(self, image):
"""Process image.
This method is a coroutine.
"""
face_data = None
try:
face_data = yield from self._api.call_api(
face_data = await self._api.call_api(
'post', 'detect', image, binary=True,
params={'returnFaceAttributes': ",".join(self._attributes)})
@@ -4,7 +4,6 @@ Component that will help set the Microsoft face for verify processing.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/image_processing.microsoft_face_identify/
"""
import asyncio
import logging
import voluptuous as vol
@@ -29,9 +28,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
})
@asyncio.coroutine
def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
async def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
"""Set up the Microsoft Face identify platform."""
api = hass.data[DATA_MICROSOFT_FACE]
face_group = config[CONF_GROUP]
@@ -80,22 +78,21 @@ class MicrosoftFaceIdentifyEntity(ImageProcessingFaceEntity):
"""Return the name of the entity."""
return self._name
@asyncio.coroutine
def async_process_image(self, image):
async def async_process_image(self, image):
"""Process image.
This method is a coroutine.
"""
detect = None
try:
face_data = yield from self._api.call_api(
face_data = await self._api.call_api(
'post', 'detect', image, binary=True)
if not face_data:
return
face_ids = [data['faceId'] for data in face_data]
detect = yield from self._api.call_api(
detect = await self._api.call_api(
'post', 'identify',
{'faceIds': face_ids, 'personGroupId': self._face_group})
@@ -48,9 +48,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
})
@asyncio.coroutine
def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
async def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
"""Set up the OpenALPR cloud API platform."""
confidence = config[CONF_CONFIDENCE]
params = {
@@ -101,8 +100,7 @@ class OpenAlprCloudEntity(ImageProcessingAlprEntity):
"""Return the name of the entity."""
return self._name
@asyncio.coroutine
def async_process_image(self, image):
async def async_process_image(self, image):
"""Process image.
This method is a coroutine.
@@ -116,11 +114,11 @@ class OpenAlprCloudEntity(ImageProcessingAlprEntity):
try:
with async_timeout.timeout(self.timeout, loop=self.hass.loop):
request = yield from websession.post(
request = await websession.post(
OPENALPR_API_URL, params=params, data=body
)
data = yield from request.json()
data = await request.json()
if request.status != 200:
_LOGGER.error("Error %d -> %s.",
@@ -55,9 +55,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
})
@asyncio.coroutine
def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
async def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
"""Set up the OpenALPR local platform."""
command = [config[CONF_ALPR_BIN], '-c', config[CONF_REGION], '-']
confidence = config[CONF_CONFIDENCE]
@@ -173,8 +172,7 @@ class OpenAlprLocalEntity(ImageProcessingAlprEntity):
"""Return the name of the entity."""
return self._name
@asyncio.coroutine
def async_process_image(self, image):
async def async_process_image(self, image):
"""Process image.
This method is a coroutine.
@@ -182,7 +180,7 @@ class OpenAlprLocalEntity(ImageProcessingAlprEntity):
result = {}
vehicles = 0
alpr = yield from asyncio.create_subprocess_exec(
alpr = await asyncio.create_subprocess_exec(
*self._cmd,
loop=self.hass.loop,
stdin=asyncio.subprocess.PIPE,
@@ -191,7 +189,7 @@ class OpenAlprLocalEntity(ImageProcessingAlprEntity):
)
# Send image
stdout, _ = yield from alpr.communicate(input=image)
stdout, _ = await alpr.communicate(input=image)
stdout = io.StringIO(str(stdout, 'utf-8'))
while True:
@@ -4,7 +4,6 @@ Local optical character recognition processing of seven segments displays.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/image_processing.seven_segments/
"""
import asyncio
import logging
import io
import os
@@ -44,9 +43,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
})
@asyncio.coroutine
def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
async def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
"""Set up the Seven segments OCR platform."""
entities = []
for camera in config[CONF_SOURCE]: