Avoid tuple construction to check HKC available (#106902)
This commit is contained in:
parent
fde03d7888
commit
73b36086cf
1 changed files with 8 additions and 5 deletions
|
@ -27,6 +27,7 @@ class HomeKitEntity(Entity):
|
|||
pollable_characteristics: list[tuple[int, int]]
|
||||
watchable_characteristics: list[tuple[int, int]]
|
||||
all_characteristics: set[tuple[int, int]]
|
||||
all_iids: set[int]
|
||||
accessory_info: Service
|
||||
|
||||
def __init__(self, accessory: HKDevice, devinfo: ConfigType) -> None:
|
||||
|
@ -149,6 +150,7 @@ class HomeKitEntity(Entity):
|
|||
self.pollable_characteristics = []
|
||||
self.watchable_characteristics = []
|
||||
self.all_characteristics = set()
|
||||
self.all_iids = set()
|
||||
|
||||
char_types = self.get_characteristic_types()
|
||||
|
||||
|
@ -164,6 +166,7 @@ class HomeKitEntity(Entity):
|
|||
|
||||
self.all_characteristics.update(self.pollable_characteristics)
|
||||
self.all_characteristics.update(self.watchable_characteristics)
|
||||
self.all_iids = {iid for _, iid in self.all_characteristics}
|
||||
|
||||
def _setup_characteristic(self, char: Characteristic) -> None:
|
||||
"""Configure an entity based on a HomeKit characteristics metadata."""
|
||||
|
@ -219,11 +222,11 @@ class HomeKitEntity(Entity):
|
|||
@property
|
||||
def available(self) -> bool:
|
||||
"""Return True if entity is available."""
|
||||
return self._accessory.available and all(
|
||||
c.available
|
||||
for c in self.service.characteristics
|
||||
if (self._aid, c.iid) in self.all_characteristics
|
||||
)
|
||||
all_iids = self.all_iids
|
||||
for char in self.service.characteristics:
|
||||
if char.iid in all_iids and not char.available:
|
||||
return False
|
||||
return self._accessory.available
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
|
|
Loading…
Add table
Reference in a new issue