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