diff --git a/homeassistant/components/logbook/helpers.py b/homeassistant/components/logbook/helpers.py index 0ac4efd60260..a8a07b26b6fe 100644 --- a/homeassistant/components/logbook/helpers.py +++ b/homeassistant/components/logbook/helpers.py @@ -2,7 +2,7 @@ from __future__ import annotations -from collections.abc import Callable, Mapping +from collections.abc import Callable, Collection, Mapping from typing import Any from homeassistant.components.sensor import ATTR_STATE_CLASS, NON_NUMERIC_DEVICE_CLASSES @@ -75,12 +75,12 @@ def _async_config_entries_for_ids( def async_determine_event_types( hass: HomeAssistant, entity_ids: list[str] | None, device_ids: list[str] | None -) -> tuple[EventType[Any] | str, ...]: +) -> set[EventType[Any] | str]: """Reduce the event types based on the entity ids and device ids.""" logbook_config: LogbookConfig = hass.data[DOMAIN] external_events = logbook_config.external_events if not entity_ids and not device_ids: - return (*BUILT_IN_EVENTS, *external_events) + return {*BUILT_IN_EVENTS, *external_events} interested_domains: set[str] = set() for entry_id in _async_config_entries_for_ids(hass, entity_ids, device_ids): @@ -93,16 +93,16 @@ def async_determine_event_types( # to add them since we have historically included # them when matching only on entities # - intrested_event_types: set[EventType[Any] | str] = { + interested_event_types: set[EventType[Any] | str] = { external_event for external_event, domain_call in external_events.items() if domain_call[0] in interested_domains } | AUTOMATION_EVENTS if entity_ids: # We also allow entity_ids to be recorded via manual logbook entries. - intrested_event_types.add(EVENT_LOGBOOK_ENTRY) + interested_event_types.add(EVENT_LOGBOOK_ENTRY) - return tuple(intrested_event_types) + return interested_event_types @callback @@ -187,7 +187,7 @@ def async_subscribe_events( hass: HomeAssistant, subscriptions: list[CALLBACK_TYPE], target: Callable[[Event[Any]], None], - event_types: tuple[EventType[Any] | str, ...], + event_types: Collection[EventType[Any] | str], entities_filter: Callable[[str], bool] | None, entity_ids: list[str] | None, device_ids: list[str] | None, diff --git a/homeassistant/components/logbook/processor.py b/homeassistant/components/logbook/processor.py index 7128d45e61c6..366127342f95 100644 --- a/homeassistant/components/logbook/processor.py +++ b/homeassistant/components/logbook/processor.py @@ -2,7 +2,7 @@ from __future__ import annotations -from collections.abc import Callable, Generator, Sequence +from collections.abc import Callable, Collection, Generator, Sequence from dataclasses import dataclass, field from datetime import datetime as dt import logging @@ -126,7 +126,7 @@ class EventProcessor: def __init__( self, hass: HomeAssistant, - event_types: tuple[EventType[Any] | str, ...], + event_types: Collection[EventType[Any] | str], entity_ids: list[str] | None = None, device_ids: list[str] | None = None, context_id: str | None = None, diff --git a/homeassistant/components/logbook/websocket_api.py b/homeassistant/components/logbook/websocket_api.py index e0d8989e633e..2d5119c7ae61 100644 --- a/homeassistant/components/logbook/websocket_api.py +++ b/homeassistant/components/logbook/websocket_api.py @@ -20,7 +20,6 @@ from homeassistant.helpers.event import async_track_point_in_utc_time from homeassistant.helpers.json import json_bytes from homeassistant.util import dt as dt_util from homeassistant.util.async_ import create_eager_task -from homeassistant.util.event_type import EventType from .const import DOMAIN from .helpers import ( @@ -366,16 +365,11 @@ async def ws_event_stream( # cache parent user_ids as they fire. Historical queries don't — the # context_only join fetches them by context_id regardless of type. # Unfiltered streams already include it via BUILT_IN_EVENTS. - live_event_types: tuple[EventType[Any] | str, ...] = ( - event_types - if EVENT_CALL_SERVICE in event_types - else (*event_types, EVENT_CALL_SERVICE) - ) async_subscribe_events( hass, subscriptions, _queue_or_cancel, - live_event_types, + {*event_types, EVENT_CALL_SERVICE}, entities_filter, entity_ids, device_ids,