mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Enable strict typing in HomeKit (#101968)
This commit is contained in:
parent
0e499e07d2
commit
5ed8de8348
@ -157,15 +157,7 @@ homeassistant.components.homeassistant_green.*
|
||||
homeassistant.components.homeassistant_hardware.*
|
||||
homeassistant.components.homeassistant_sky_connect.*
|
||||
homeassistant.components.homeassistant_yellow.*
|
||||
homeassistant.components.homekit
|
||||
homeassistant.components.homekit.accessories
|
||||
homeassistant.components.homekit.aidmanager
|
||||
homeassistant.components.homekit.config_flow
|
||||
homeassistant.components.homekit.diagnostics
|
||||
homeassistant.components.homekit.logbook
|
||||
homeassistant.components.homekit.type_locks
|
||||
homeassistant.components.homekit.type_triggers
|
||||
homeassistant.components.homekit.util
|
||||
homeassistant.components.homekit.*
|
||||
homeassistant.components.homekit_controller
|
||||
homeassistant.components.homekit_controller.alarm_control_panel
|
||||
homeassistant.components.homekit_controller.button
|
||||
|
@ -139,7 +139,7 @@ CONFIG_DEFAULTS = {
|
||||
|
||||
|
||||
@TYPES.register("Camera")
|
||||
class Camera(HomeAccessory, PyhapCamera):
|
||||
class Camera(HomeAccessory, PyhapCamera): # type: ignore[misc]
|
||||
"""Generate a Camera accessory."""
|
||||
|
||||
def __init__(
|
||||
@ -337,7 +337,8 @@ class Camera(HomeAccessory, PyhapCamera):
|
||||
|
||||
async def _async_get_stream_source(self) -> str | None:
|
||||
"""Find the camera stream source url."""
|
||||
if stream_source := self.config.get(CONF_STREAM_SOURCE):
|
||||
stream_source: str | None = self.config.get(CONF_STREAM_SOURCE)
|
||||
if stream_source:
|
||||
return stream_source
|
||||
try:
|
||||
stream_source = await camera.async_get_stream_source(
|
||||
@ -419,7 +420,7 @@ class Camera(HomeAccessory, PyhapCamera):
|
||||
|
||||
stderr_reader = await stream.get_reader(source=FFMPEG_STDERR)
|
||||
|
||||
async def watch_session(_):
|
||||
async def watch_session(_: Any) -> None:
|
||||
await self._async_ffmpeg_watch(session_info["id"])
|
||||
|
||||
session_info[FFMPEG_LOGGER] = asyncio.create_task(
|
||||
|
@ -104,6 +104,7 @@ class GarageDoorOpener(HomeAccessory):
|
||||
"""Initialize a GarageDoorOpener accessory object."""
|
||||
super().__init__(*args, category=CATEGORY_GARAGE_DOOR_OPENER)
|
||||
state = self.hass.states.get(self.entity_id)
|
||||
assert state
|
||||
|
||||
serv_garage_door = self.add_preload_service(SERV_GARAGE_DOOR_OPENER)
|
||||
self.char_current_state = serv_garage_door.configure_char(
|
||||
@ -124,7 +125,7 @@ class GarageDoorOpener(HomeAccessory):
|
||||
|
||||
self.async_update_state(state)
|
||||
|
||||
async def run(self):
|
||||
async def run(self) -> None:
|
||||
"""Handle accessory driver started event.
|
||||
|
||||
Run inside the Home Assistant event loop.
|
||||
@ -165,7 +166,7 @@ class GarageDoorOpener(HomeAccessory):
|
||||
detected,
|
||||
)
|
||||
|
||||
def set_state(self, value):
|
||||
def set_state(self, value: int) -> None:
|
||||
"""Change garage state if call came from HomeKit."""
|
||||
_LOGGER.debug("%s: Set state to %d", self.entity_id, value)
|
||||
|
||||
@ -180,7 +181,7 @@ class GarageDoorOpener(HomeAccessory):
|
||||
self.async_call_service(DOMAIN, SERVICE_CLOSE_COVER, params)
|
||||
|
||||
@callback
|
||||
def async_update_state(self, new_state):
|
||||
def async_update_state(self, new_state: State) -> None:
|
||||
"""Update cover state after state changed."""
|
||||
hass_state = new_state.state
|
||||
target_door_state = DOOR_TARGET_HASS_TO_HK.get(hass_state)
|
||||
@ -235,7 +236,7 @@ class OpeningDeviceBase(HomeAccessory):
|
||||
CHAR_CURRENT_TILT_ANGLE, value=0
|
||||
)
|
||||
|
||||
def set_stop(self, value):
|
||||
def set_stop(self, value: int) -> None:
|
||||
"""Stop the cover motion from HomeKit."""
|
||||
if value != 1:
|
||||
return
|
||||
@ -243,7 +244,7 @@ class OpeningDeviceBase(HomeAccessory):
|
||||
DOMAIN, SERVICE_STOP_COVER, {ATTR_ENTITY_ID: self.entity_id}
|
||||
)
|
||||
|
||||
def set_tilt(self, value):
|
||||
def set_tilt(self, value: float) -> None:
|
||||
"""Set tilt to value if call came from HomeKit."""
|
||||
_LOGGER.info("%s: Set tilt to %d", self.entity_id, value)
|
||||
|
||||
@ -256,7 +257,7 @@ class OpeningDeviceBase(HomeAccessory):
|
||||
self.async_call_service(DOMAIN, SERVICE_SET_COVER_TILT_POSITION, params, value)
|
||||
|
||||
@callback
|
||||
def async_update_state(self, new_state):
|
||||
def async_update_state(self, new_state: State) -> None:
|
||||
"""Update cover position and tilt after state changed."""
|
||||
# update tilt
|
||||
if not self._supports_tilt:
|
||||
|
@ -165,19 +165,19 @@ class RemoteInputSelectAccessory(HomeAccessory, ABC):
|
||||
return list(self._get_mapped_sources(state))
|
||||
|
||||
@abstractmethod
|
||||
def set_on_off(self, value):
|
||||
def set_on_off(self, value: bool) -> None:
|
||||
"""Move switch state to value if call came from HomeKit."""
|
||||
|
||||
@abstractmethod
|
||||
def set_input_source(self, value):
|
||||
def set_input_source(self, value: int) -> None:
|
||||
"""Send input set value if call came from HomeKit."""
|
||||
|
||||
@abstractmethod
|
||||
def set_remote_key(self, value):
|
||||
def set_remote_key(self, value: int) -> None:
|
||||
"""Send remote key value if call came from HomeKit."""
|
||||
|
||||
@callback
|
||||
def _async_update_input_state(self, hk_state, new_state):
|
||||
def _async_update_input_state(self, hk_state: int, new_state: State) -> None:
|
||||
"""Update input state after state changed."""
|
||||
# Set active input
|
||||
if not self.support_select_source or not self.sources:
|
||||
|
82
mypy.ini
82
mypy.ini
@ -1331,87 +1331,7 @@ disallow_untyped_defs = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.homekit]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
disallow_subclassing_any = true
|
||||
disallow_untyped_calls = true
|
||||
disallow_untyped_decorators = true
|
||||
disallow_untyped_defs = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.homekit.accessories]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
disallow_subclassing_any = true
|
||||
disallow_untyped_calls = true
|
||||
disallow_untyped_decorators = true
|
||||
disallow_untyped_defs = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.homekit.aidmanager]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
disallow_subclassing_any = true
|
||||
disallow_untyped_calls = true
|
||||
disallow_untyped_decorators = true
|
||||
disallow_untyped_defs = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.homekit.config_flow]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
disallow_subclassing_any = true
|
||||
disallow_untyped_calls = true
|
||||
disallow_untyped_decorators = true
|
||||
disallow_untyped_defs = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.homekit.diagnostics]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
disallow_subclassing_any = true
|
||||
disallow_untyped_calls = true
|
||||
disallow_untyped_decorators = true
|
||||
disallow_untyped_defs = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.homekit.logbook]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
disallow_subclassing_any = true
|
||||
disallow_untyped_calls = true
|
||||
disallow_untyped_decorators = true
|
||||
disallow_untyped_defs = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.homekit.type_locks]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
disallow_subclassing_any = true
|
||||
disallow_untyped_calls = true
|
||||
disallow_untyped_decorators = true
|
||||
disallow_untyped_defs = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.homekit.type_triggers]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
disallow_subclassing_any = true
|
||||
disallow_untyped_calls = true
|
||||
disallow_untyped_decorators = true
|
||||
disallow_untyped_defs = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.homekit.util]
|
||||
[mypy-homeassistant.components.homekit.*]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
disallow_subclassing_any = true
|
||||
|
Loading…
x
Reference in New Issue
Block a user