Improve homekit_controller typing (#107381)

This commit is contained in:
Marc Mueller 2024-01-06 22:02:30 +01:00 committed by GitHub
parent 427f7a7866
commit 4ea8c174f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 9 deletions

View File

@ -641,7 +641,9 @@ class HKDevice:
await self.async_add_new_entities() await self.async_add_new_entities()
@callback @callback
def async_entity_key_removed(self, entity_key: tuple[int, int | None, int | None]): def async_entity_key_removed(
self, entity_key: tuple[int, int | None, int | None]
) -> None:
"""Handle an entity being removed. """Handle an entity being removed.
Releases the entity from self.entities so it can be added again. Releases the entity from self.entities so it can be added again.
@ -666,7 +668,7 @@ class HKDevice:
self.char_factories.append(add_entities_cb) self.char_factories.append(add_entities_cb)
self._add_new_entities_for_char([add_entities_cb]) self._add_new_entities_for_char([add_entities_cb])
def _add_new_entities_for_char(self, handlers) -> None: def _add_new_entities_for_char(self, handlers: list[AddCharacteristicCb]) -> None:
for accessory in self.entity_map.accessories: for accessory in self.entity_map.accessories:
for service in accessory.services: for service in accessory.services:
for char in service.characteristics: for char in service.characteristics:
@ -768,7 +770,7 @@ class HKDevice:
"""Request an debounced update from the accessory.""" """Request an debounced update from the accessory."""
await self._debounced_update.async_call() await self._debounced_update.async_call()
async def async_update(self, now=None): async def async_update(self, now: datetime | None = None) -> None:
"""Poll state of all entities attached to this bridge/accessory.""" """Poll state of all entities attached to this bridge/accessory."""
if not self.pollable_characteristics: if not self.pollable_characteristics:
self.async_update_available_state() self.async_update_available_state()

View File

@ -115,7 +115,7 @@ class TriggerSource:
trigger_callbacks.append(event_handler) trigger_callbacks.append(event_handler)
def async_remove_handler(): def async_remove_handler() -> None:
trigger_callbacks.remove(event_handler) trigger_callbacks.remove(event_handler)
return async_remove_handler return async_remove_handler
@ -215,7 +215,7 @@ async def async_setup_triggers_for_entry(
conn: HKDevice = hass.data[KNOWN_DEVICES][hkid] conn: HKDevice = hass.data[KNOWN_DEVICES][hkid]
@callback @callback
def async_add_characteristic(service: Service): def async_add_characteristic(service: Service) -> bool:
aid = service.accessory.aid aid = service.accessory.aid
service_type = service.type service_type = service.type
@ -257,7 +257,9 @@ def async_get_or_create_trigger_source(
return source return source
def async_fire_triggers(conn: HKDevice, events: dict[tuple[int, int], dict[str, Any]]): def async_fire_triggers(
conn: HKDevice, events: dict[tuple[int, int], dict[str, Any]]
) -> None:
"""Process events generated by a HomeKit accessory into automation triggers.""" """Process events generated by a HomeKit accessory into automation triggers."""
trigger_sources: dict[str, TriggerSource] = conn.hass.data.get(TRIGGERS, {}) trigger_sources: dict[str, TriggerSource] = conn.hass.data.get(TRIGGERS, {})
if not trigger_sources: if not trigger_sources:

View File

@ -109,7 +109,7 @@ class HomeKitEntity(Entity):
self._accessory.async_entity_key_removed(self._entity_key) self._accessory.async_entity_key_removed(self._entity_key)
@callback @callback
def _async_unsubscribe_chars(self): def _async_unsubscribe_chars(self) -> None:
"""Handle unsubscribing from characteristics.""" """Handle unsubscribing from characteristics."""
if self._char_subscription: if self._char_subscription:
self._char_subscription() self._char_subscription()
@ -118,7 +118,7 @@ class HomeKitEntity(Entity):
self._accessory.remove_watchable_characteristics(self.watchable_characteristics) self._accessory.remove_watchable_characteristics(self.watchable_characteristics)
@callback @callback
def _async_subscribe_chars(self): def _async_subscribe_chars(self) -> None:
"""Handle registering characteristics to watch and subscribe.""" """Handle registering characteristics to watch and subscribe."""
self._accessory.add_pollable_characteristics(self.pollable_characteristics) self._accessory.add_pollable_characteristics(self.pollable_characteristics)
self._accessory.add_watchable_characteristics(self.watchable_characteristics) self._accessory.add_watchable_characteristics(self.watchable_characteristics)

View File

@ -72,7 +72,7 @@ class HomeKitEventEntity(BaseCharacteristicEntity, EventEntity):
) )
@callback @callback
def _handle_event(self): def _handle_event(self) -> None:
if self._char.value is None: if self._char.value is None:
# For IP backed devices the characteristic is marked as # For IP backed devices the characteristic is marked as
# pollable, but always returns None when polled # pollable, but always returns None when polled