From 1c55ba0cb2d6f20835e97d5b634486ed570e332e Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sun, 18 Feb 2024 13:21:55 +0100 Subject: [PATCH] Use covariant for fire event data type (#110843) --- homeassistant/components/image_processing/__init__.py | 2 +- homeassistant/components/logbook/helpers.py | 4 ++-- homeassistant/components/logbook/models.py | 4 ++-- homeassistant/components/zha/logbook.py | 2 +- homeassistant/core.py | 6 +++--- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/image_processing/__init__.py b/homeassistant/components/image_processing/__init__.py index bb356c09367..178d40d1139 100644 --- a/homeassistant/components/image_processing/__init__.py +++ b/homeassistant/components/image_processing/__init__.py @@ -262,7 +262,7 @@ class ImageProcessingFaceEntity(ImageProcessingEntity): continue face.update({ATTR_ENTITY_ID: self.entity_id}) - self.hass.bus.async_fire(EVENT_DETECT_FACE, face) # type: ignore[arg-type] + self.hass.bus.async_fire(EVENT_DETECT_FACE, face) # Update entity store self.faces = faces diff --git a/homeassistant/components/logbook/helpers.py b/homeassistant/components/logbook/helpers.py index 839a742224f..b7293087e7e 100644 --- a/homeassistant/components/logbook/helpers.py +++ b/homeassistant/components/logbook/helpers.py @@ -1,7 +1,7 @@ """Event parser and human readable log generator.""" from __future__ import annotations -from collections.abc import Callable +from collections.abc import Callable, Mapping from typing import Any from homeassistant.components.sensor import ATTR_STATE_CLASS @@ -96,7 +96,7 @@ def async_determine_event_types( @callback -def extract_attr(source: dict[str, Any], attr: str) -> list[str]: +def extract_attr(source: Mapping[str, Any], attr: str) -> list[str]: """Extract an attribute as a list or string.""" if (value := source.get(attr)) is None: return [] diff --git a/homeassistant/components/logbook/models.py b/homeassistant/components/logbook/models.py index 84ae84a3b70..22420f243c6 100644 --- a/homeassistant/components/logbook/models.py +++ b/homeassistant/components/logbook/models.py @@ -1,7 +1,7 @@ """Event parser and human readable log generator.""" from __future__ import annotations -from collections.abc import Callable +from collections.abc import Callable, Mapping from dataclasses import dataclass from typing import TYPE_CHECKING, Any, cast @@ -103,7 +103,7 @@ class LazyEventPartialState: class EventAsRow: """Convert an event to a row.""" - data: dict[str, Any] + data: Mapping[str, Any] context: Context context_id_bin: bytes time_fired_ts: float diff --git a/homeassistant/components/zha/logbook.py b/homeassistant/components/zha/logbook.py index a82b1f87103..ce9c1f1227b 100644 --- a/homeassistant/components/zha/logbook.py +++ b/homeassistant/components/zha/logbook.py @@ -30,7 +30,7 @@ def async_describe_events( device: dr.DeviceEntry | None = None device_name: str = "Unknown device" zha_device: ZHADevice | None = None - event_data: dict = event.data + event_data = event.data event_type: str | None = None event_subtype: str | None = None diff --git a/homeassistant/core.py b/homeassistant/core.py index 6e8d45bd0bd..c49777a67fb 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -1067,7 +1067,7 @@ class Event: def __init__( self, event_type: str, - data: dict[str, Any] | None = None, + data: Mapping[str, Any] | None = None, origin: EventOrigin = EventOrigin.local, time_fired: datetime.datetime | None = None, context: Context | None = None, @@ -1204,7 +1204,7 @@ class EventBus: def fire( self, event_type: str, - event_data: dict[str, Any] | None = None, + event_data: Mapping[str, Any] | None = None, origin: EventOrigin = EventOrigin.local, context: Context | None = None, ) -> None: @@ -1217,7 +1217,7 @@ class EventBus: def async_fire( self, event_type: str, - event_data: dict[str, Any] | None = None, + event_data: Mapping[str, Any] | None = None, origin: EventOrigin = EventOrigin.local, context: Context | None = None, time_fired: datetime.datetime | None = None,