Removes OpenALPR Local integration (#85544)
This commit is contained in:
parent
f7d69ee325
commit
566c0f63bd
27 changed files with 81 additions and 534 deletions
|
@ -10,25 +10,36 @@ import aiohttp
|
|||
import async_timeout
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.image_processing import CONF_CONFIDENCE, PLATFORM_SCHEMA
|
||||
from homeassistant.components.openalpr_local.image_processing import (
|
||||
ImageProcessingAlprEntity,
|
||||
from homeassistant.components.image_processing import (
|
||||
ATTR_CONFIDENCE,
|
||||
CONF_CONFIDENCE,
|
||||
PLATFORM_SCHEMA,
|
||||
ImageProcessingDeviceClass,
|
||||
ImageProcessingEntity,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
CONF_API_KEY,
|
||||
CONF_ENTITY_ID,
|
||||
CONF_NAME,
|
||||
CONF_REGION,
|
||||
CONF_SOURCE,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, split_entity_id
|
||||
from homeassistant.core import HomeAssistant, callback, split_entity_id
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.util.async_ import run_callback_threadsafe
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
ATTR_PLATE = "plate"
|
||||
ATTR_PLATES = "plates"
|
||||
ATTR_VEHICLES = "vehicles"
|
||||
|
||||
EVENT_FOUND_PLATE = "image_processing.found_plate"
|
||||
|
||||
OPENALPR_API_URL = "https://api.openalpr.com/v1/recognize"
|
||||
|
||||
OPENALPR_REGIONS = [
|
||||
|
@ -80,6 +91,72 @@ async def async_setup_platform(
|
|||
async_add_entities(entities)
|
||||
|
||||
|
||||
class ImageProcessingAlprEntity(ImageProcessingEntity):
|
||||
"""Base entity class for ALPR image processing."""
|
||||
|
||||
_attr_device_class = ImageProcessingDeviceClass.ALPR
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Initialize base ALPR entity."""
|
||||
self.plates: dict[str, float] = {}
|
||||
self.vehicles = 0
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the entity."""
|
||||
confidence = 0
|
||||
plate = None
|
||||
|
||||
# search high plate
|
||||
for i_pl, i_co in self.plates.items():
|
||||
if i_co > confidence:
|
||||
confidence = i_co
|
||||
plate = i_pl
|
||||
return plate
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self):
|
||||
"""Return device specific state attributes."""
|
||||
return {ATTR_PLATES: self.plates, ATTR_VEHICLES: self.vehicles}
|
||||
|
||||
def process_plates(self, plates: dict[str, float], vehicles: int) -> None:
|
||||
"""Send event with new plates and store data."""
|
||||
run_callback_threadsafe(
|
||||
self.hass.loop, self.async_process_plates, plates, vehicles
|
||||
).result()
|
||||
|
||||
@callback
|
||||
def async_process_plates(self, plates: dict[str, float], vehicles: int) -> None:
|
||||
"""Send event with new plates and store data.
|
||||
|
||||
Plates are a dict in follow format:
|
||||
{ '<plate>': confidence }
|
||||
This method must be run in the event loop.
|
||||
"""
|
||||
plates = {
|
||||
plate: confidence
|
||||
for plate, confidence in plates.items()
|
||||
if self.confidence is None or confidence >= self.confidence
|
||||
}
|
||||
new_plates = set(plates) - set(self.plates)
|
||||
|
||||
# Send events
|
||||
for i_plate in new_plates:
|
||||
self.hass.async_add_job(
|
||||
self.hass.bus.async_fire,
|
||||
EVENT_FOUND_PLATE,
|
||||
{
|
||||
ATTR_PLATE: i_plate,
|
||||
ATTR_ENTITY_ID: self.entity_id,
|
||||
ATTR_CONFIDENCE: plates.get(i_plate),
|
||||
},
|
||||
)
|
||||
|
||||
# Update entity store
|
||||
self.plates = plates
|
||||
self.vehicles = vehicles
|
||||
|
||||
|
||||
class OpenAlprCloudEntity(ImageProcessingAlprEntity):
|
||||
"""Representation of an OpenALPR cloud entity."""
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue