mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Update docstrings and comments (#7626)
This commit is contained in:
parent
d2ed3a131f
commit
f0b2a6d0e6
@ -1,17 +1,18 @@
|
|||||||
"""
|
"""
|
||||||
Component that will help set the OpenALPR cloud for ALPR processing.
|
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/
|
https://home-assistant.io/components/image_processing.openalpr_cloud/
|
||||||
"""
|
"""
|
||||||
import asyncio
|
import asyncio
|
||||||
from base64 import b64encode
|
|
||||||
import logging
|
import logging
|
||||||
|
from base64 import b64encode
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import async_timeout
|
import async_timeout
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.core import split_entity_id
|
from homeassistant.core import split_entity_id
|
||||||
from homeassistant.const import CONF_API_KEY
|
from homeassistant.const import CONF_API_KEY
|
||||||
from homeassistant.components.image_processing import (
|
from homeassistant.components.image_processing import (
|
||||||
@ -19,7 +20,6 @@ from homeassistant.components.image_processing import (
|
|||||||
from homeassistant.components.image_processing.openalpr_local import (
|
from homeassistant.components.image_processing.openalpr_local import (
|
||||||
ImageProcessingAlprEntity)
|
ImageProcessingAlprEntity)
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -44,8 +44,7 @@ CONF_REGION = 'region'
|
|||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Required(CONF_API_KEY): cv.string,
|
vol.Required(CONF_API_KEY): cv.string,
|
||||||
vol.Required(CONF_REGION):
|
vol.Required(CONF_REGION): vol.All(vol.Lower, vol.In(OPENALPR_REGIONS)),
|
||||||
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):
|
class OpenAlprCloudEntity(ImageProcessingAlprEntity):
|
||||||
"""OpenALPR cloud entity."""
|
"""Representation of an OpenALPR cloud entity."""
|
||||||
|
|
||||||
def __init__(self, camera_entity, params, confidence, name=None):
|
def __init__(self, camera_entity, params, confidence, name=None):
|
||||||
"""Initialize OpenALPR cloud API."""
|
"""Initialize OpenALPR cloud API."""
|
||||||
@ -129,7 +128,7 @@ class OpenAlprCloudEntity(ImageProcessingAlprEntity):
|
|||||||
_LOGGER.error("Timeout for OpenALPR API")
|
_LOGGER.error("Timeout for OpenALPR API")
|
||||||
return
|
return
|
||||||
|
|
||||||
# processing api data
|
# Processing API data
|
||||||
vehicles = 0
|
vehicles = 0
|
||||||
result = {}
|
result = {}
|
||||||
|
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
"""
|
"""
|
||||||
Component that will help set the OpenALPR local for ALPR processing.
|
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/
|
https://home-assistant.io/components/image_processing.openalpr_local/
|
||||||
"""
|
"""
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
|
||||||
import io
|
import io
|
||||||
|
import logging
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.core import split_entity_id, callback
|
from homeassistant.core import split_entity_id, callback
|
||||||
from homeassistant.const import STATE_UNKNOWN
|
from homeassistant.const import STATE_UNKNOWN
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
from homeassistant.components.image_processing import (
|
from homeassistant.components.image_processing import (
|
||||||
PLATFORM_SCHEMA, ImageProcessingEntity, CONF_CONFIDENCE, CONF_SOURCE,
|
PLATFORM_SCHEMA, ImageProcessingEntity, CONF_CONFIDENCE, CONF_SOURCE,
|
||||||
CONF_ENTITY_ID, CONF_NAME, ATTR_ENTITY_ID, ATTR_CONFIDENCE)
|
CONF_ENTITY_ID, CONF_NAME, ATTR_ENTITY_ID, ATTR_CONFIDENCE)
|
||||||
@ -45,15 +45,13 @@ OPENALPR_REGIONS = [
|
|||||||
'vn2'
|
'vn2'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
CONF_REGION = 'region'
|
|
||||||
CONF_ALPR_BIN = 'alp_bin'
|
CONF_ALPR_BIN = 'alp_bin'
|
||||||
|
CONF_REGION = 'region'
|
||||||
|
|
||||||
DEFAULT_BINARY = 'alpr'
|
DEFAULT_BINARY = 'alpr'
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Required(CONF_REGION):
|
vol.Required(CONF_REGION): vol.All(vol.Lower, vol.In(OPENALPR_REGIONS)),
|
||||||
vol.All(vol.Lower, vol.In(OPENALPR_REGIONS)),
|
|
||||||
vol.Optional(CONF_ALPR_BIN, default=DEFAULT_BINARY): cv.string,
|
vol.Optional(CONF_ALPR_BIN, default=DEFAULT_BINARY): cv.string,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -77,9 +75,9 @@ class ImageProcessingAlprEntity(ImageProcessingEntity):
|
|||||||
"""Base entity class for ALPR image processing."""
|
"""Base entity class for ALPR image processing."""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Initialize base alpr entity."""
|
"""Initialize base ALPR entity."""
|
||||||
self.plates = {} # last scan data
|
self.plates = {}
|
||||||
self.vehicles = 0 # vehicles count
|
self.vehicles = 0
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
@ -128,7 +126,7 @@ class ImageProcessingAlprEntity(ImageProcessingEntity):
|
|||||||
if confidence >= self.confidence}
|
if confidence >= self.confidence}
|
||||||
new_plates = set(plates) - set(self.plates)
|
new_plates = set(plates) - set(self.plates)
|
||||||
|
|
||||||
# send events
|
# Send events
|
||||||
for i_plate in new_plates:
|
for i_plate in new_plates:
|
||||||
self.hass.async_add_job(
|
self.hass.async_add_job(
|
||||||
self.hass.bus.async_fire, EVENT_FOUND_PLATE, {
|
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.plates = plates
|
||||||
self.vehicles = vehicles
|
self.vehicles = vehicles
|
||||||
|
|
||||||
@ -192,7 +190,7 @@ class OpenAlprLocalEntity(ImageProcessingAlprEntity):
|
|||||||
stderr=asyncio.subprocess.DEVNULL
|
stderr=asyncio.subprocess.DEVNULL
|
||||||
)
|
)
|
||||||
|
|
||||||
# send image
|
# Send image
|
||||||
stdout, _ = yield from alpr.communicate(input=image)
|
stdout, _ = yield from alpr.communicate(input=image)
|
||||||
stdout = io.StringIO(str(stdout, 'utf-8'))
|
stdout = io.StringIO(str(stdout, 'utf-8'))
|
||||||
|
|
||||||
@ -204,12 +202,12 @@ class OpenAlprLocalEntity(ImageProcessingAlprEntity):
|
|||||||
new_plates = RE_ALPR_PLATE.search(line)
|
new_plates = RE_ALPR_PLATE.search(line)
|
||||||
new_result = RE_ALPR_RESULT.search(line)
|
new_result = RE_ALPR_RESULT.search(line)
|
||||||
|
|
||||||
# found new vehicle
|
# Found new vehicle
|
||||||
if new_plates:
|
if new_plates:
|
||||||
vehicles += 1
|
vehicles += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# found plate result
|
# Found plate result
|
||||||
if new_result:
|
if new_result:
|
||||||
try:
|
try:
|
||||||
result.update(
|
result.update(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user