Add image_processing device_class StrEnum (#79124)
This commit is contained in:
parent
4460953ff4
commit
50e732d00f
3 changed files with 23 additions and 20 deletions
|
@ -8,6 +8,7 @@ from typing import Any, Final, TypedDict, final
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
from homeassistant.backports.enum import StrEnum
|
||||||
from homeassistant.components.camera import Image
|
from homeassistant.components.camera import Image
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ENTITY_ID,
|
ATTR_ENTITY_ID,
|
||||||
|
@ -30,11 +31,19 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
DOMAIN = "image_processing"
|
DOMAIN = "image_processing"
|
||||||
SCAN_INTERVAL = timedelta(seconds=10)
|
SCAN_INTERVAL = timedelta(seconds=10)
|
||||||
|
|
||||||
DEVICE_CLASSES = [
|
|
||||||
"alpr", # Automatic license plate recognition
|
class ImageProcessingDeviceClass(StrEnum):
|
||||||
"face", # Face
|
"""Device class for image processing entities."""
|
||||||
"ocr", # OCR
|
|
||||||
]
|
# Automatic license plate recognition
|
||||||
|
ALPR = "alpr"
|
||||||
|
|
||||||
|
# Face
|
||||||
|
FACE = "face"
|
||||||
|
|
||||||
|
# OCR
|
||||||
|
OCR = "ocr"
|
||||||
|
|
||||||
|
|
||||||
SERVICE_SCAN = "scan"
|
SERVICE_SCAN = "scan"
|
||||||
|
|
||||||
|
@ -113,6 +122,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
class ImageProcessingEntity(Entity):
|
class ImageProcessingEntity(Entity):
|
||||||
"""Base entity class for image processing."""
|
"""Base entity class for image processing."""
|
||||||
|
|
||||||
|
_attr_device_class: ImageProcessingDeviceClass | str | None
|
||||||
timeout = DEFAULT_TIMEOUT
|
timeout = DEFAULT_TIMEOUT
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -156,6 +166,8 @@ class ImageProcessingEntity(Entity):
|
||||||
class ImageProcessingFaceEntity(ImageProcessingEntity):
|
class ImageProcessingFaceEntity(ImageProcessingEntity):
|
||||||
"""Base entity class for face image processing."""
|
"""Base entity class for face image processing."""
|
||||||
|
|
||||||
|
_attr_device_class = ImageProcessingDeviceClass.FACE
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
"""Initialize base face identify/verify entity."""
|
"""Initialize base face identify/verify entity."""
|
||||||
self.faces: list[FaceInformation] = []
|
self.faces: list[FaceInformation] = []
|
||||||
|
@ -185,11 +197,6 @@ class ImageProcessingFaceEntity(ImageProcessingEntity):
|
||||||
|
|
||||||
return state
|
return state
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self) -> str:
|
|
||||||
"""Return the class of this device, from component DEVICE_CLASSES."""
|
|
||||||
return "face"
|
|
||||||
|
|
||||||
@final
|
@final
|
||||||
@property
|
@property
|
||||||
def state_attributes(self) -> dict[str, Any]:
|
def state_attributes(self) -> dict[str, Any]:
|
||||||
|
|
|
@ -12,6 +12,7 @@ from homeassistant.components.image_processing import (
|
||||||
ATTR_CONFIDENCE,
|
ATTR_CONFIDENCE,
|
||||||
CONF_CONFIDENCE,
|
CONF_CONFIDENCE,
|
||||||
PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA,
|
||||||
|
ImageProcessingDeviceClass,
|
||||||
ImageProcessingEntity,
|
ImageProcessingEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
|
@ -102,6 +103,8 @@ async def async_setup_platform(
|
||||||
class ImageProcessingAlprEntity(ImageProcessingEntity):
|
class ImageProcessingAlprEntity(ImageProcessingEntity):
|
||||||
"""Base entity class for ALPR image processing."""
|
"""Base entity class for ALPR image processing."""
|
||||||
|
|
||||||
|
_attr_device_class = ImageProcessingDeviceClass.ALPR
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
"""Initialize base ALPR entity."""
|
"""Initialize base ALPR entity."""
|
||||||
self.plates: dict[str, float] = {}
|
self.plates: dict[str, float] = {}
|
||||||
|
@ -120,11 +123,6 @@ class ImageProcessingAlprEntity(ImageProcessingEntity):
|
||||||
plate = i_pl
|
plate = i_pl
|
||||||
return plate
|
return plate
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self):
|
|
||||||
"""Return the class of this device, from component DEVICE_CLASSES."""
|
|
||||||
return "alpr"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self):
|
||||||
"""Return device specific state attributes."""
|
"""Return device specific state attributes."""
|
||||||
|
|
|
@ -11,6 +11,7 @@ import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.image_processing import (
|
from homeassistant.components.image_processing import (
|
||||||
PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA,
|
||||||
|
ImageProcessingDeviceClass,
|
||||||
ImageProcessingEntity,
|
ImageProcessingEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.const import CONF_ENTITY_ID, CONF_NAME, CONF_SOURCE
|
from homeassistant.const import CONF_ENTITY_ID, CONF_NAME, CONF_SOURCE
|
||||||
|
@ -69,6 +70,8 @@ async def async_setup_platform(
|
||||||
class ImageProcessingSsocr(ImageProcessingEntity):
|
class ImageProcessingSsocr(ImageProcessingEntity):
|
||||||
"""Representation of the seven segments OCR image processing entity."""
|
"""Representation of the seven segments OCR image processing entity."""
|
||||||
|
|
||||||
|
_attr_device_class = ImageProcessingDeviceClass.OCR
|
||||||
|
|
||||||
def __init__(self, hass, camera_entity, config, name):
|
def __init__(self, hass, camera_entity, config, name):
|
||||||
"""Initialize seven segments processing."""
|
"""Initialize seven segments processing."""
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
|
@ -105,11 +108,6 @@ class ImageProcessingSsocr(ImageProcessingEntity):
|
||||||
)
|
)
|
||||||
self._command.append(self.filepath)
|
self._command.append(self.filepath)
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self):
|
|
||||||
"""Return the class of this device, from component DEVICE_CLASSES."""
|
|
||||||
return "ocr"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def camera_entity(self):
|
def camera_entity(self):
|
||||||
"""Return camera entity id from process pictures."""
|
"""Return camera entity id from process pictures."""
|
||||||
|
|
Loading…
Add table
Reference in a new issue