Reduce task overhead in homekit_controller (#111670)

This commit is contained in:
J. Nick Koston 2024-02-27 14:49:29 -10:00 committed by GitHub
parent 147c261389
commit e62b709dea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -330,12 +330,19 @@ class HKDevice:
self.config_entry.async_on_unload(
async_track_time_interval(
self.hass,
self.async_request_update,
self._async_schedule_update,
self.pairing.poll_interval,
name=f"HomeKit Device {self.unique_id} availability check poll",
)
)
@callback
def _async_schedule_update(self, now: datetime) -> None:
"""Schedule an update."""
self.hass.async_create_task(
self._debounced_update.async_call(), eager_start=True
)
async def async_add_new_entities(self) -> None:
"""Add new entities to Home Assistant."""
await self.async_load_platforms()
@ -685,7 +692,9 @@ class HKDevice:
def process_config_changed(self, config_num: int) -> None:
"""Handle a config change notification from the pairing."""
self.hass.async_create_task(self.async_update_new_accessories_state())
self.hass.async_create_task(
self.async_update_new_accessories_state(), eager_start=True
)
async def async_update_new_accessories_state(self) -> None:
"""Process a change in the pairings accessories state."""