mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 18:28:14 +02:00
Add RSSI sensor to HomeKit Controller (#78906)
This commit is contained in:
@ -231,6 +231,9 @@ class HKDevice:
|
||||
self.async_update_available_state,
|
||||
timedelta(seconds=BLE_AVAILABILITY_CHECK_INTERVAL),
|
||||
)
|
||||
# BLE devices always get an RSSI sensor as well
|
||||
if "sensor" not in self.platforms:
|
||||
await self.async_load_platform("sensor")
|
||||
|
||||
async def async_add_new_entities(self) -> None:
|
||||
"""Add new entities to Home Assistant."""
|
||||
@ -455,7 +458,7 @@ class HKDevice:
|
||||
self.entities.append((accessory.aid, None, None))
|
||||
break
|
||||
|
||||
def add_char_factory(self, add_entities_cb) -> None:
|
||||
def add_char_factory(self, add_entities_cb: AddCharacteristicCb) -> None:
|
||||
"""Add a callback to run when discovering new entities for accessories."""
|
||||
self.char_factories.append(add_entities_cb)
|
||||
self._add_new_entities_for_char([add_entities_cb])
|
||||
@ -471,7 +474,7 @@ class HKDevice:
|
||||
self.entities.append((accessory.aid, service.iid, char.iid))
|
||||
break
|
||||
|
||||
def add_listener(self, add_entities_cb) -> None:
|
||||
def add_listener(self, add_entities_cb: AddServiceCb) -> None:
|
||||
"""Add a callback to run when discovering new entities for services."""
|
||||
self.listeners.append(add_entities_cb)
|
||||
self._add_new_entities([add_entities_cb])
|
||||
@ -513,22 +516,24 @@ class HKDevice:
|
||||
|
||||
async def async_load_platforms(self) -> None:
|
||||
"""Load any platforms needed by this HomeKit device."""
|
||||
tasks = []
|
||||
to_load: set[str] = set()
|
||||
for accessory in self.entity_map.accessories:
|
||||
for service in accessory.services:
|
||||
if service.type in HOMEKIT_ACCESSORY_DISPATCH:
|
||||
platform = HOMEKIT_ACCESSORY_DISPATCH[service.type]
|
||||
if platform not in self.platforms:
|
||||
tasks.append(self.async_load_platform(platform))
|
||||
to_load.add(platform)
|
||||
|
||||
for char in service.characteristics:
|
||||
if char.type in CHARACTERISTIC_PLATFORMS:
|
||||
platform = CHARACTERISTIC_PLATFORMS[char.type]
|
||||
if platform not in self.platforms:
|
||||
tasks.append(self.async_load_platform(platform))
|
||||
to_load.add(platform)
|
||||
|
||||
if tasks:
|
||||
await asyncio.gather(*tasks)
|
||||
if to_load:
|
||||
await asyncio.gather(
|
||||
*[self.async_load_platform(platform) for platform in to_load]
|
||||
)
|
||||
|
||||
@callback
|
||||
def async_update_available_state(self, *_: Any) -> None:
|
||||
|
Reference in New Issue
Block a user