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]]
|
pollable_characteristics: list[tuple[int, int]]
|
||||||
watchable_characteristics: list[tuple[int, int]]
|
watchable_characteristics: list[tuple[int, int]]
|
||||||
all_characteristics: set[tuple[int, int]]
|
all_characteristics: set[tuple[int, int]]
|
||||||
|
all_iids: set[int]
|
||||||
accessory_info: Service
|
accessory_info: Service
|
||||||
|
|
||||||
def __init__(self, accessory: HKDevice, devinfo: ConfigType) -> None:
|
def __init__(self, accessory: HKDevice, devinfo: ConfigType) -> None:
|
||||||
|
@ -149,6 +150,7 @@ class HomeKitEntity(Entity):
|
||||||
self.pollable_characteristics = []
|
self.pollable_characteristics = []
|
||||||
self.watchable_characteristics = []
|
self.watchable_characteristics = []
|
||||||
self.all_characteristics = set()
|
self.all_characteristics = set()
|
||||||
|
self.all_iids = set()
|
||||||
|
|
||||||
char_types = self.get_characteristic_types()
|
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.pollable_characteristics)
|
||||||
self.all_characteristics.update(self.watchable_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:
|
def _setup_characteristic(self, char: Characteristic) -> None:
|
||||||
"""Configure an entity based on a HomeKit characteristics metadata."""
|
"""Configure an entity based on a HomeKit characteristics metadata."""
|
||||||
|
@ -219,11 +222,11 @@ class HomeKitEntity(Entity):
|
||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
"""Return True if entity is available."""
|
"""Return True if entity is available."""
|
||||||
return self._accessory.available and all(
|
all_iids = self.all_iids
|
||||||
c.available
|
for char in self.service.characteristics:
|
||||||
for c in self.service.characteristics
|
if char.iid in all_iids and not char.available:
|
||||||
if (self._aid, c.iid) in self.all_characteristics
|
return False
|
||||||
)
|
return self._accessory.available
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_info(self) -> DeviceInfo:
|
def device_info(self) -> DeviceInfo:
|
||||||
|
|
Loading…
Add table
Reference in a new issue