From bbecb98927c23059c015eda8e78eeefa952e7ef9 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 10 Apr 2024 11:44:25 -1000 Subject: [PATCH] Fix type on known_object_ids in _entity_id_available and async_generate_entity_id (#115378) --- homeassistant/helpers/entity_platform.py | 4 ++-- homeassistant/helpers/entity_registry.py | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/homeassistant/helpers/entity_platform.py b/homeassistant/helpers/entity_platform.py index 261512c14af..ec4eef1f6a7 100644 --- a/homeassistant/helpers/entity_platform.py +++ b/homeassistant/helpers/entity_platform.py @@ -801,7 +801,7 @@ class EntityPlatform: get_initial_options=entity.get_initial_entity_options, has_entity_name=entity.has_entity_name, hidden_by=hidden_by, - known_object_ids=self.entities.keys(), + known_object_ids=self.entities, original_device_class=entity.device_class, original_icon=entity.icon, original_name=entity_name, @@ -839,7 +839,7 @@ class EntityPlatform: if self.entity_namespace is not None: suggested_object_id = f"{self.entity_namespace} {suggested_object_id}" entity.entity_id = entity_registry.async_generate_entity_id( - self.domain, suggested_object_id, self.entities.keys() + self.domain, suggested_object_id, self.entities ) # Make sure it is valid in case an entity set the value themselves diff --git a/homeassistant/helpers/entity_registry.py b/homeassistant/helpers/entity_registry.py index d6e7395a2cb..3a26505c7da 100644 --- a/homeassistant/helpers/entity_registry.py +++ b/homeassistant/helpers/entity_registry.py @@ -10,7 +10,7 @@ timer. from __future__ import annotations -from collections.abc import Callable, Hashable, Iterable, KeysView, Mapping +from collections.abc import Callable, Container, Hashable, KeysView, Mapping from datetime import datetime, timedelta from enum import StrEnum from functools import cached_property @@ -714,7 +714,7 @@ class EntityRegistry(BaseRegistry): return list(self.entities.get_device_ids()) def _entity_id_available( - self, entity_id: str, known_object_ids: Iterable[str] | None + self, entity_id: str, known_object_ids: Container[str] | None ) -> bool: """Return True if the entity_id is available. @@ -740,7 +740,7 @@ class EntityRegistry(BaseRegistry): self, domain: str, suggested_object_id: str, - known_object_ids: Iterable[str] | None = None, + known_object_ids: Container[str] | None = None, ) -> str: """Generate an entity ID that does not conflict. @@ -753,7 +753,7 @@ class EntityRegistry(BaseRegistry): test_string = preferred_string[:MAX_LENGTH_STATE_ENTITY_ID] if known_object_ids is None: - known_object_ids = {} + known_object_ids = set() tries = 1 while not self._entity_id_available(test_string, known_object_ids): @@ -773,7 +773,7 @@ class EntityRegistry(BaseRegistry): unique_id: str, *, # To influence entity ID generation - known_object_ids: Iterable[str] | None = None, + known_object_ids: Container[str] | None = None, suggested_object_id: str | None = None, # To disable or hide an entity if it gets created disabled_by: RegistryEntryDisabler | None = None,