mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 10:47:10 +00:00
Update image_processing async (#15082)
* scan() -> async_job * added async_scan
This commit is contained in:
parent
2145ac5e46
commit
f3588a8782
@ -69,27 +69,32 @@ SERVICE_SCAN_SCHEMA = vol.Schema({
|
|||||||
|
|
||||||
@bind_hass
|
@bind_hass
|
||||||
def scan(hass, entity_id=None):
|
def scan(hass, entity_id=None):
|
||||||
"""Force process an image."""
|
"""Force process of all cameras or given entity."""
|
||||||
|
hass.add_job(async_scan, hass, entity_id)
|
||||||
|
|
||||||
|
|
||||||
|
@callback
|
||||||
|
@bind_hass
|
||||||
|
def async_scan(hass, entity_id=None):
|
||||||
|
"""Force process of all cameras or given entity."""
|
||||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
||||||
hass.services.call(DOMAIN, SERVICE_SCAN, data)
|
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_SCAN, data))
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def async_setup(hass, config):
|
||||||
def async_setup(hass, config):
|
|
||||||
"""Set up the image processing."""
|
"""Set up the image processing."""
|
||||||
component = EntityComponent(_LOGGER, DOMAIN, hass, SCAN_INTERVAL)
|
component = EntityComponent(_LOGGER, DOMAIN, hass, SCAN_INTERVAL)
|
||||||
|
|
||||||
yield from component.async_setup(config)
|
await component.async_setup(config)
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def async_scan_service(service):
|
||||||
def async_scan_service(service):
|
|
||||||
"""Service handler for scan."""
|
"""Service handler for scan."""
|
||||||
image_entities = component.async_extract_from_service(service)
|
image_entities = component.async_extract_from_service(service)
|
||||||
|
|
||||||
update_task = [entity.async_update_ha_state(True) for
|
update_task = [entity.async_update_ha_state(True) for
|
||||||
entity in image_entities]
|
entity in image_entities]
|
||||||
if update_task:
|
if update_task:
|
||||||
yield from asyncio.wait(update_task, loop=hass.loop)
|
await asyncio.wait(update_task, loop=hass.loop)
|
||||||
|
|
||||||
hass.services.async_register(
|
hass.services.async_register(
|
||||||
DOMAIN, SERVICE_SCAN, async_scan_service,
|
DOMAIN, SERVICE_SCAN, async_scan_service,
|
||||||
@ -124,8 +129,7 @@ class ImageProcessingEntity(Entity):
|
|||||||
"""
|
"""
|
||||||
return self.hass.async_add_job(self.process_image, image)
|
return self.hass.async_add_job(self.process_image, image)
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def async_update(self):
|
||||||
def async_update(self):
|
|
||||||
"""Update image and process it.
|
"""Update image and process it.
|
||||||
|
|
||||||
This method is a coroutine.
|
This method is a coroutine.
|
||||||
@ -134,7 +138,7 @@ class ImageProcessingEntity(Entity):
|
|||||||
image = None
|
image = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
image = yield from camera.async_get_image(
|
image = await camera.async_get_image(
|
||||||
self.camera_entity, timeout=self.timeout)
|
self.camera_entity, timeout=self.timeout)
|
||||||
|
|
||||||
except HomeAssistantError as err:
|
except HomeAssistantError as err:
|
||||||
@ -142,7 +146,7 @@ class ImageProcessingEntity(Entity):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# process image data
|
# process image data
|
||||||
yield from self.async_process_image(image.content)
|
await self.async_process_image(image.content)
|
||||||
|
|
||||||
|
|
||||||
class ImageProcessingFaceEntity(ImageProcessingEntity):
|
class ImageProcessingFaceEntity(ImageProcessingEntity):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user