Cache homekit_controller supported features (#106702)

This commit is contained in:
J. Nick Koston 2024-01-04 10:31:09 -10:00 committed by GitHub
parent f2514c0bde
commit bc26377c16
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 4588 additions and 192 deletions

View file

@ -1,6 +1,7 @@
"""Homekit Controller entities."""
from __future__ import annotations
import contextlib
from typing import Any
from aiohomekit.model.characteristics import (
@ -74,6 +75,16 @@ class HomeKitEntity(Entity):
if not self._async_remove_entity_if_accessory_or_service_disappeared():
self._async_reconfigure()
@callback
def _async_clear_property_cache(self, properties: tuple[str, ...]) -> None:
"""Clear the cache of properties."""
for prop in properties:
# suppress is slower than try-except-pass, but
# we do not expect to have many properties to clear
# or this to be called often.
with contextlib.suppress(AttributeError):
delattr(self, prop)
@callback
def _async_reconfigure(self) -> None:
"""Reconfigure the entity."""