Skip to content

Commit

Permalink
Improve generic event typing [recorder] (#114736)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p authored Apr 6, 2024
1 parent 2e3cb1a commit 8f425b9
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions homeassistant/components/recorder/entity_registry.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""Recorder entity registry helper."""

from collections.abc import Mapping
import logging
from typing import Any
from typing import TYPE_CHECKING

from homeassistant.core import Event, HomeAssistant, callback
from homeassistant.helpers import entity_registry as er
Expand All @@ -19,10 +18,14 @@ def async_setup(hass: HomeAssistant) -> None:
"""Set up the entity hooks."""

@callback
def _async_entity_id_changed(event: Event) -> None:
def _async_entity_id_changed(
event: Event[er.EventEntityRegistryUpdatedData],
) -> None:
instance = get_instance(hass)
old_entity_id: str = event.data["old_entity_id"]
new_entity_id: str = event.data["entity_id"]
if TYPE_CHECKING:
assert event.data["action"] == "update" and "old_entity_id" in event.data
old_entity_id = event.data["old_entity_id"]
new_entity_id = event.data["entity_id"]
instance.async_update_statistics_metadata(
old_entity_id, new_statistic_id=new_entity_id
)
Expand All @@ -31,7 +34,9 @@ def _async_entity_id_changed(event: Event) -> None:
)

@callback
def entity_registry_changed_filter(event_data: Mapping[str, Any]) -> bool:
def entity_registry_changed_filter(
event_data: er.EventEntityRegistryUpdatedData,
) -> bool:
"""Handle entity_id changed filter."""
return event_data["action"] == "update" and "old_entity_id" in event_data

Expand Down

0 comments on commit 8f425b9

Please sign in to comment.