diff --git a/homeassistant/components/demo/__init__.py b/homeassistant/components/demo/__init__.py index 45ce061fb1d..7ed989903e5 100644 --- a/homeassistant/components/demo/__init__.py +++ b/homeassistant/components/demo/__init__.py @@ -260,7 +260,7 @@ async def _insert_sum_statistics( start: datetime.datetime, end: datetime.datetime, max_diff: float, -): +) -> None: statistics: list[StatisticData] = [] now = start sum_ = 0.0 diff --git a/homeassistant/components/demo/image_processing.py b/homeassistant/components/demo/image_processing.py index 6ba498114a4..5d158db46ab 100644 --- a/homeassistant/components/demo/image_processing.py +++ b/homeassistant/components/demo/image_processing.py @@ -3,10 +3,7 @@ from __future__ import annotations from homeassistant.components.camera import Image from homeassistant.components.image_processing import ( - ATTR_AGE, - ATTR_CONFIDENCE, - ATTR_GENDER, - ATTR_NAME, + FaceInformation, ImageProcessingFaceEntity, ) from homeassistant.components.openalpr_local.image_processing import ( @@ -87,14 +84,14 @@ class DemoImageProcessingFace(ImageProcessingFaceEntity): def process_image(self, image: Image) -> None: """Process image.""" demo_data = [ - { - ATTR_CONFIDENCE: 98.34, - ATTR_NAME: "Hans", - ATTR_AGE: 16.0, - ATTR_GENDER: "male", - }, - {ATTR_NAME: "Helena", ATTR_AGE: 28.0, ATTR_GENDER: "female"}, - {ATTR_CONFIDENCE: 62.53, ATTR_NAME: "Luna"}, + FaceInformation( + confidence=98.34, + name="Hans", + age=16.0, + gender="male", + ), + FaceInformation(name="Helena", age=28.0, gender="female"), + FaceInformation(confidence=62.53, name="Luna"), ] self.process_faces(demo_data, 4) diff --git a/homeassistant/components/image_processing/__init__.py b/homeassistant/components/image_processing/__init__.py index 5c932826197..115d32c5d5b 100644 --- a/homeassistant/components/image_processing/__init__.py +++ b/homeassistant/components/image_processing/__init__.py @@ -2,7 +2,7 @@ import asyncio from datetime import timedelta import logging -from typing import final +from typing import Final, TypedDict, final import voluptuous as vol @@ -40,7 +40,7 @@ SERVICE_SCAN = "scan" EVENT_DETECT_FACE = "image_processing.detect_face" ATTR_AGE = "age" -ATTR_CONFIDENCE = "confidence" +ATTR_CONFIDENCE: Final = "confidence" ATTR_FACES = "faces" ATTR_GENDER = "gender" ATTR_GLASSES = "glasses" @@ -70,6 +70,18 @@ PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend( PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE.extend(PLATFORM_SCHEMA.schema) +class FaceInformation(TypedDict, total=False): + """Face information.""" + + confidence: float + name: str + age: float + gender: str + motion: str + glasses: str + entity_id: str + + async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the image processing.""" component = EntityComponent(_LOGGER, DOMAIN, hass, SCAN_INTERVAL) @@ -142,9 +154,9 @@ class ImageProcessingEntity(Entity): class ImageProcessingFaceEntity(ImageProcessingEntity): """Base entity class for face image processing.""" - def __init__(self): + def __init__(self) -> None: """Initialize base face identify/verify entity.""" - self.faces = [] + self.faces: list[FaceInformation] = [] self.total_faces = 0 @property @@ -182,14 +194,14 @@ class ImageProcessingFaceEntity(ImageProcessingEntity): """Return device specific state attributes.""" return {ATTR_FACES: self.faces, ATTR_TOTAL_FACES: self.total_faces} - def process_faces(self, faces, total): + def process_faces(self, faces: list[FaceInformation], total: int) -> None: """Send event with detected faces and store data.""" run_callback_threadsafe( self.hass.loop, self.async_process_faces, faces, total ).result() @callback - def async_process_faces(self, faces, total): + def async_process_faces(self, faces: list[FaceInformation], total: int) -> None: """Send event with detected faces and store data. known are a dict in follow format: diff --git a/homeassistant/components/mailbox/__init__.py b/homeassistant/components/mailbox/__init__.py index 89b646beee4..b6a727083c9 100644 --- a/homeassistant/components/mailbox/__init__.py +++ b/homeassistant/components/mailbox/__init__.py @@ -144,13 +144,13 @@ class MailboxEntity(Entity): class Mailbox: """Represent a mailbox device.""" - def __init__(self, hass, name): + def __init__(self, hass: HomeAssistant, name: str) -> None: """Initialize mailbox object.""" self.hass = hass self.name = name @callback - def async_update(self): + def async_update(self) -> None: """Send event notification of updated mailbox.""" self.hass.bus.async_fire(EVENT) diff --git a/homeassistant/components/openalpr_local/image_processing.py b/homeassistant/components/openalpr_local/image_processing.py index ef8c942189f..a2c0bc99287 100644 --- a/homeassistant/components/openalpr_local/image_processing.py +++ b/homeassistant/components/openalpr_local/image_processing.py @@ -102,9 +102,9 @@ async def async_setup_platform( class ImageProcessingAlprEntity(ImageProcessingEntity): """Base entity class for ALPR image processing.""" - def __init__(self): + def __init__(self) -> None: """Initialize base ALPR entity.""" - self.plates = {} + self.plates: dict[str, float] = {} self.vehicles = 0 @property @@ -130,18 +130,18 @@ class ImageProcessingAlprEntity(ImageProcessingEntity): """Return device specific state attributes.""" return {ATTR_PLATES: self.plates, ATTR_VEHICLES: self.vehicles} - def process_plates(self, plates, 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, vehicles): + 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 } + { '': confidence } This method must be run in the event loop. """