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
19 changed files with 4588 additions and 192 deletions

View File

@@ -1,7 +1,7 @@
"""Support for Homekit covers."""
from __future__ import annotations
from typing import Any
from typing import TYPE_CHECKING, Any
from aiohomekit.model.characteristics import CharacteristicsTypes
from aiohomekit.model.services import Service, ServicesTypes
@@ -28,6 +28,12 @@ from . import KNOWN_DEVICES
from .connection import HKDevice
from .entity import HomeKitEntity
if TYPE_CHECKING:
from functools import cached_property
else:
from homeassistant.backports.functools import cached_property
STATE_STOPPED = "stopped"
CURRENT_GARAGE_STATE_MAP = {
@@ -128,6 +134,12 @@ class HomeKitGarageDoorCover(HomeKitEntity, CoverEntity):
class HomeKitWindowCover(HomeKitEntity, CoverEntity):
"""Representation of a HomeKit Window or Window Covering."""
@callback
def _async_reconfigure(self) -> None:
"""Reconfigure entity."""
self._async_clear_property_cache(("supported_features",))
super()._async_reconfigure()
def get_characteristic_types(self) -> list[str]:
"""Define the homekit characteristics the entity cares about."""
return [
@@ -142,7 +154,7 @@ class HomeKitWindowCover(HomeKitEntity, CoverEntity):
CharacteristicsTypes.OBSTRUCTION_DETECTED,
]
@property
@cached_property
def supported_features(self) -> CoverEntityFeature:
"""Flag supported features."""
features = (