Add missing type hints to homekit_controller (#65368)
This commit is contained in:
parent
aef6f49eff
commit
9f5d77e0df
19 changed files with 389 additions and 312 deletions
|
@ -1,4 +1,6 @@
|
|||
"""Support for HomeKit Controller Televisions."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from aiohomekit.model.characteristics import (
|
||||
|
@ -7,7 +9,7 @@ from aiohomekit.model.characteristics import (
|
|||
RemoteKeyValues,
|
||||
TargetMediaStateValues,
|
||||
)
|
||||
from aiohomekit.model.services import ServicesTypes
|
||||
from aiohomekit.model.services import Service, ServicesTypes
|
||||
from aiohomekit.utils import clamp_enum_to_char
|
||||
|
||||
from homeassistant.components.media_player import (
|
||||
|
@ -53,7 +55,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.TELEVISION:
|
||||
return False
|
||||
info = {"aid": service.accessory.aid, "iid": service.iid}
|
||||
|
@ -68,7 +70,7 @@ class HomeKitTelevision(HomeKitEntity, MediaPlayerEntity):
|
|||
|
||||
_attr_device_class = MediaPlayerDeviceClass.TV
|
||||
|
||||
def get_characteristic_types(self):
|
||||
def get_characteristic_types(self) -> list[str]:
|
||||
"""Define the homekit characteristics the entity cares about."""
|
||||
return [
|
||||
CharacteristicsTypes.ACTIVE,
|
||||
|
@ -82,7 +84,7 @@ class HomeKitTelevision(HomeKitEntity, MediaPlayerEntity):
|
|||
]
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
def supported_features(self) -> int:
|
||||
"""Flag media player features that are supported."""
|
||||
features = 0
|
||||
|
||||
|
@ -108,10 +110,10 @@ class HomeKitTelevision(HomeKitEntity, MediaPlayerEntity):
|
|||
return features
|
||||
|
||||
@property
|
||||
def supported_media_states(self):
|
||||
def supported_media_states(self) -> set[TargetMediaStateValues]:
|
||||
"""Mediate state flags that are supported."""
|
||||
if not self.service.has(CharacteristicsTypes.TARGET_MEDIA_STATE):
|
||||
return frozenset()
|
||||
return set()
|
||||
|
||||
return clamp_enum_to_char(
|
||||
TargetMediaStateValues,
|
||||
|
@ -119,17 +121,17 @@ class HomeKitTelevision(HomeKitEntity, MediaPlayerEntity):
|
|||
)
|
||||
|
||||
@property
|
||||
def supported_remote_keys(self):
|
||||
def supported_remote_keys(self) -> set[str]:
|
||||
"""Remote key buttons that are supported."""
|
||||
if not self.service.has(CharacteristicsTypes.REMOTE_KEY):
|
||||
return frozenset()
|
||||
return set()
|
||||
|
||||
return clamp_enum_to_char(
|
||||
RemoteKeyValues, self.service[CharacteristicsTypes.REMOTE_KEY]
|
||||
)
|
||||
|
||||
@property
|
||||
def source_list(self):
|
||||
def source_list(self) -> list[str]:
|
||||
"""List of all input sources for this television."""
|
||||
sources = []
|
||||
|
||||
|
@ -147,7 +149,7 @@ class HomeKitTelevision(HomeKitEntity, MediaPlayerEntity):
|
|||
return sources
|
||||
|
||||
@property
|
||||
def source(self):
|
||||
def source(self) -> str | None:
|
||||
"""Name of the current input source."""
|
||||
active_identifier = self.service.value(CharacteristicsTypes.ACTIVE_IDENTIFIER)
|
||||
if not active_identifier:
|
||||
|
@ -165,7 +167,7 @@ class HomeKitTelevision(HomeKitEntity, MediaPlayerEntity):
|
|||
return char.value
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def state(self) -> str:
|
||||
"""State of the tv."""
|
||||
active = self.service.value(CharacteristicsTypes.ACTIVE)
|
||||
if not active:
|
||||
|
@ -177,7 +179,7 @@ class HomeKitTelevision(HomeKitEntity, MediaPlayerEntity):
|
|||
|
||||
return STATE_OK
|
||||
|
||||
async def async_media_play(self):
|
||||
async def async_media_play(self) -> None:
|
||||
"""Send play command."""
|
||||
if self.state == STATE_PLAYING:
|
||||
_LOGGER.debug("Cannot play while already playing")
|
||||
|
@ -192,7 +194,7 @@ class HomeKitTelevision(HomeKitEntity, MediaPlayerEntity):
|
|||
{CharacteristicsTypes.REMOTE_KEY: RemoteKeyValues.PLAY_PAUSE}
|
||||
)
|
||||
|
||||
async def async_media_pause(self):
|
||||
async def async_media_pause(self) -> None:
|
||||
"""Send pause command."""
|
||||
if self.state == STATE_PAUSED:
|
||||
_LOGGER.debug("Cannot pause while already paused")
|
||||
|
@ -207,7 +209,7 @@ class HomeKitTelevision(HomeKitEntity, MediaPlayerEntity):
|
|||
{CharacteristicsTypes.REMOTE_KEY: RemoteKeyValues.PLAY_PAUSE}
|
||||
)
|
||||
|
||||
async def async_media_stop(self):
|
||||
async def async_media_stop(self) -> None:
|
||||
"""Send stop command."""
|
||||
if self.state == STATE_IDLE:
|
||||
_LOGGER.debug("Cannot stop when already idle")
|
||||
|
@ -218,7 +220,7 @@ class HomeKitTelevision(HomeKitEntity, MediaPlayerEntity):
|
|||
{CharacteristicsTypes.TARGET_MEDIA_STATE: TargetMediaStateValues.STOP}
|
||||
)
|
||||
|
||||
async def async_select_source(self, source):
|
||||
async def async_select_source(self, source: str) -> None:
|
||||
"""Switch to a different media source."""
|
||||
this_accessory = self._accessory.entity_map.aid(self._aid)
|
||||
this_tv = this_accessory.services.iid(self._iid)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue