From f0b2a6d0e63e1a8810d4c85d495ecad590fc1ff4 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Wed, 17 May 2017 09:14:11 +0200 Subject: [PATCH] Update docstrings and comments (#7626) --- .../image_processing/openalpr_cloud.py | 13 ++++----- .../image_processing/openalpr_local.py | 28 +++++++++---------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/homeassistant/components/image_processing/openalpr_cloud.py b/homeassistant/components/image_processing/openalpr_cloud.py index 1143c1e04ae..2fdc3d72f2e 100644 --- a/homeassistant/components/image_processing/openalpr_cloud.py +++ b/homeassistant/components/image_processing/openalpr_cloud.py @@ -1,17 +1,18 @@ """ Component that will help set the OpenALPR cloud for ALPR processing. -For more details about this component, please refer to the documentation at +For more details about this platform, please refer to the documentation at https://home-assistant.io/components/image_processing.openalpr_cloud/ """ import asyncio -from base64 import b64encode import logging +from base64 import b64encode import aiohttp import async_timeout import voluptuous as vol +import homeassistant.helpers.config_validation as cv from homeassistant.core import split_entity_id from homeassistant.const import CONF_API_KEY from homeassistant.components.image_processing import ( @@ -19,7 +20,6 @@ from homeassistant.components.image_processing import ( from homeassistant.components.image_processing.openalpr_local import ( ImageProcessingAlprEntity) from homeassistant.helpers.aiohttp_client import async_get_clientsession -import homeassistant.helpers.config_validation as cv _LOGGER = logging.getLogger(__name__) @@ -44,8 +44,7 @@ CONF_REGION = 'region' PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_API_KEY): cv.string, - vol.Required(CONF_REGION): - vol.All(vol.Lower, vol.In(OPENALPR_REGIONS)), + vol.Required(CONF_REGION): vol.All(vol.Lower, vol.In(OPENALPR_REGIONS)), }) @@ -70,7 +69,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None): class OpenAlprCloudEntity(ImageProcessingAlprEntity): - """OpenALPR cloud entity.""" + """Representation of an OpenALPR cloud entity.""" def __init__(self, camera_entity, params, confidence, name=None): """Initialize OpenALPR cloud API.""" @@ -129,7 +128,7 @@ class OpenAlprCloudEntity(ImageProcessingAlprEntity): _LOGGER.error("Timeout for OpenALPR API") return - # processing api data + # Processing API data vehicles = 0 result = {} diff --git a/homeassistant/components/image_processing/openalpr_local.py b/homeassistant/components/image_processing/openalpr_local.py index 05ca2cffcd0..b0ef93611ea 100644 --- a/homeassistant/components/image_processing/openalpr_local.py +++ b/homeassistant/components/image_processing/openalpr_local.py @@ -1,19 +1,19 @@ """ Component that will help set the OpenALPR local for ALPR processing. -For more details about this component, please refer to the documentation at +For more details about this platform, please refer to the documentation at https://home-assistant.io/components/image_processing.openalpr_local/ """ import asyncio -import logging import io +import logging import re import voluptuous as vol +import homeassistant.helpers.config_validation as cv from homeassistant.core import split_entity_id, callback from homeassistant.const import STATE_UNKNOWN -import homeassistant.helpers.config_validation as cv from homeassistant.components.image_processing import ( PLATFORM_SCHEMA, ImageProcessingEntity, CONF_CONFIDENCE, CONF_SOURCE, CONF_ENTITY_ID, CONF_NAME, ATTR_ENTITY_ID, ATTR_CONFIDENCE) @@ -45,15 +45,13 @@ OPENALPR_REGIONS = [ 'vn2' ] - -CONF_REGION = 'region' CONF_ALPR_BIN = 'alp_bin' +CONF_REGION = 'region' DEFAULT_BINARY = 'alpr' PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ - vol.Required(CONF_REGION): - vol.All(vol.Lower, vol.In(OPENALPR_REGIONS)), + vol.Required(CONF_REGION): vol.All(vol.Lower, vol.In(OPENALPR_REGIONS)), vol.Optional(CONF_ALPR_BIN, default=DEFAULT_BINARY): cv.string, }) @@ -77,9 +75,9 @@ class ImageProcessingAlprEntity(ImageProcessingEntity): """Base entity class for ALPR image processing.""" def __init__(self): - """Initialize base alpr entity.""" - self.plates = {} # last scan data - self.vehicles = 0 # vehicles count + """Initialize base ALPR entity.""" + self.plates = {} + self.vehicles = 0 @property def state(self): @@ -128,7 +126,7 @@ class ImageProcessingAlprEntity(ImageProcessingEntity): if confidence >= self.confidence} new_plates = set(plates) - set(self.plates) - # send events + # Send events for i_plate in new_plates: self.hass.async_add_job( self.hass.bus.async_fire, EVENT_FOUND_PLATE, { @@ -138,7 +136,7 @@ class ImageProcessingAlprEntity(ImageProcessingEntity): } ) - # update entity store + # Update entity store self.plates = plates self.vehicles = vehicles @@ -192,7 +190,7 @@ class OpenAlprLocalEntity(ImageProcessingAlprEntity): stderr=asyncio.subprocess.DEVNULL ) - # send image + # Send image stdout, _ = yield from alpr.communicate(input=image) stdout = io.StringIO(str(stdout, 'utf-8')) @@ -204,12 +202,12 @@ class OpenAlprLocalEntity(ImageProcessingAlprEntity): new_plates = RE_ALPR_PLATE.search(line) new_result = RE_ALPR_RESULT.search(line) - # found new vehicle + # Found new vehicle if new_plates: vehicles += 1 continue - # found plate result + # Found plate result if new_result: try: result.update(