Add missing type hints to homekit_controller (#65368)

This commit is contained in:
Jc2k 2022-02-01 19:30:37 +00:00 committed by GitHub
parent aef6f49eff
commit 9f5d77e0df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 389 additions and 312 deletions

View file

@ -1,6 +1,10 @@
"""Support for HomeKit Controller locks."""
from __future__ import annotations
from typing import Any
from aiohomekit.model.characteristics import CharacteristicsTypes
from aiohomekit.model.services import ServicesTypes
from aiohomekit.model.services import Service, ServicesTypes
from homeassistant.components.lock import STATE_JAMMED, LockEntity
from homeassistant.config_entries import ConfigEntry
@ -37,7 +41,7 @@ async def async_setup_entry(
conn = hass.data[KNOWN_DEVICES][hkid]
@callback
def async_add_service(service):
def async_add_service(service: Service) -> bool:
if service.type != ServicesTypes.LOCK_MECHANISM:
return False
info = {"aid": service.accessory.aid, "iid": service.iid}
@ -50,7 +54,7 @@ async def async_setup_entry(
class HomeKitLock(HomeKitEntity, LockEntity):
"""Representation of a HomeKit Controller Lock."""
def get_characteristic_types(self):
def get_characteristic_types(self) -> list[str]:
"""Define the homekit characteristics the entity cares about."""
return [
CharacteristicsTypes.LOCK_MECHANISM_CURRENT_STATE,
@ -59,7 +63,7 @@ class HomeKitLock(HomeKitEntity, LockEntity):
]
@property
def is_locked(self):
def is_locked(self) -> bool | None:
"""Return true if device is locked."""
value = self.service.value(CharacteristicsTypes.LOCK_MECHANISM_CURRENT_STATE)
if CURRENT_STATE_MAP[value] == STATE_UNKNOWN:
@ -67,7 +71,7 @@ class HomeKitLock(HomeKitEntity, LockEntity):
return CURRENT_STATE_MAP[value] == STATE_LOCKED
@property
def is_locking(self):
def is_locking(self) -> bool:
"""Return true if device is locking."""
current_value = self.service.value(
CharacteristicsTypes.LOCK_MECHANISM_CURRENT_STATE
@ -81,7 +85,7 @@ class HomeKitLock(HomeKitEntity, LockEntity):
)
@property
def is_unlocking(self):
def is_unlocking(self) -> bool:
"""Return true if device is unlocking."""
current_value = self.service.value(
CharacteristicsTypes.LOCK_MECHANISM_CURRENT_STATE
@ -95,27 +99,27 @@ class HomeKitLock(HomeKitEntity, LockEntity):
)
@property
def is_jammed(self):
def is_jammed(self) -> bool:
"""Return true if device is jammed."""
value = self.service.value(CharacteristicsTypes.LOCK_MECHANISM_CURRENT_STATE)
return CURRENT_STATE_MAP[value] == STATE_JAMMED
async def async_lock(self, **kwargs):
async def async_lock(self, **kwargs: Any) -> None:
"""Lock the device."""
await self._set_lock_state(STATE_LOCKED)
async def async_unlock(self, **kwargs):
async def async_unlock(self, **kwargs: Any) -> None:
"""Unlock the device."""
await self._set_lock_state(STATE_UNLOCKED)
async def _set_lock_state(self, state):
async def _set_lock_state(self, state: str) -> None:
"""Send state command."""
await self.async_put_characteristics(
{CharacteristicsTypes.LOCK_MECHANISM_TARGET_STATE: TARGET_STATE_MAP[state]}
)
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the optional state attributes."""
attributes = {}