Simplify ESPHome entity removal process (#111076)
This commit is contained in:
parent
bccd9bd21f
commit
fb7da1ba83
2 changed files with 4 additions and 34 deletions
|
@ -123,9 +123,6 @@ class RuntimeEntryData:
|
|||
entity_info_callbacks: dict[
|
||||
type[EntityInfo], list[Callable[[list[EntityInfo]], None]]
|
||||
] = field(default_factory=dict)
|
||||
entity_info_key_remove_callbacks: dict[
|
||||
tuple[type[EntityInfo], int], list[Callable[[], Coroutine[Any, Any, None]]]
|
||||
] = field(default_factory=dict)
|
||||
entity_info_key_updated_callbacks: dict[
|
||||
tuple[type[EntityInfo], int], list[Callable[[EntityInfo], None]]
|
||||
] = field(default_factory=dict)
|
||||
|
@ -177,18 +174,6 @@ class RuntimeEntryData:
|
|||
"""Unsubscribe to when static info is registered."""
|
||||
callbacks.remove(callback_)
|
||||
|
||||
@callback
|
||||
def async_register_key_static_info_remove_callback(
|
||||
self,
|
||||
static_info: EntityInfo,
|
||||
callback_: Callable[[], Coroutine[Any, Any, None]],
|
||||
) -> CALLBACK_TYPE:
|
||||
"""Register to receive callbacks when static info is removed for a specific key."""
|
||||
callback_key = (type(static_info), static_info.key)
|
||||
callbacks = self.entity_info_key_remove_callbacks.setdefault(callback_key, [])
|
||||
callbacks.append(callback_)
|
||||
return partial(self._async_unsubscribe_static_key_remove, callbacks, callback_)
|
||||
|
||||
@callback
|
||||
def _async_unsubscribe_static_key_remove(
|
||||
self,
|
||||
|
@ -243,7 +228,8 @@ class RuntimeEntryData:
|
|||
"""Unsubscribe to assist pipeline updates."""
|
||||
self.assist_pipeline_update_callbacks.remove(update_callback)
|
||||
|
||||
async def async_remove_entities(
|
||||
@callback
|
||||
def async_remove_entities(
|
||||
self, hass: HomeAssistant, static_infos: Iterable[EntityInfo], mac: str
|
||||
) -> None:
|
||||
"""Schedule the removal of an entity."""
|
||||
|
@ -255,14 +241,6 @@ class RuntimeEntryData:
|
|||
):
|
||||
ent_reg.async_remove(entry)
|
||||
|
||||
callbacks: list[Coroutine[Any, Any, None]] = []
|
||||
for static_info in static_infos:
|
||||
callback_key = (type(static_info), static_info.key)
|
||||
if key_callbacks := self.entity_info_key_remove_callbacks.get(callback_key):
|
||||
callbacks.extend([callback_() for callback_ in key_callbacks])
|
||||
if callbacks:
|
||||
await asyncio.gather(*callbacks)
|
||||
|
||||
@callback
|
||||
def async_update_entity_infos(self, static_infos: Iterable[EntityInfo]) -> None:
|
||||
"""Call static info updated callbacks."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue