Add Onkyo to strict typing (#124617)

This commit is contained in:
Artur Pragacz 2024-09-04 19:11:34 +02:00 committed by GitHub
parent 7266a16295
commit bad305dcbf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 14 deletions

View File

@ -341,6 +341,7 @@ homeassistant.components.nut.*
homeassistant.components.onboarding.* homeassistant.components.onboarding.*
homeassistant.components.oncue.* homeassistant.components.oncue.*
homeassistant.components.onewire.* homeassistant.components.onewire.*
homeassistant.components.onkyo.*
homeassistant.components.open_meteo.* homeassistant.components.open_meteo.*
homeassistant.components.openexchangerates.* homeassistant.components.openexchangerates.*
homeassistant.components.opensky.* homeassistant.components.opensky.*

View File

@ -4,7 +4,7 @@ from __future__ import annotations
import asyncio import asyncio
import logging import logging
from typing import Any from typing import Any, Literal
import pyeiscp import pyeiscp
import voluptuous as vol import voluptuous as vol
@ -23,7 +23,7 @@ from homeassistant.const import (
CONF_NAME, CONF_NAME,
EVENT_HOMEASSISTANT_STOP, EVENT_HOMEASSISTANT_STOP,
) )
from homeassistant.core import HomeAssistant, ServiceCall, callback from homeassistant.core import Event, HomeAssistant, ServiceCall, callback
from homeassistant.helpers import config_validation as cv from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
@ -269,7 +269,7 @@ async def async_setup_platform(
_LOGGER.debug("Manually creating receiver: %s (%s)", name, host) _LOGGER.debug("Manually creating receiver: %s (%s)", name, host)
@callback @callback
async def async_onkyo_interview_callback(conn: pyeiscp.Connection): async def async_onkyo_interview_callback(conn: pyeiscp.Connection) -> None:
"""Receiver interviewed, connection not yet active.""" """Receiver interviewed, connection not yet active."""
info = ReceiverInfo(conn.host, conn.port, conn.name, conn.identifier) info = ReceiverInfo(conn.host, conn.port, conn.name, conn.identifier)
_LOGGER.debug("Receiver interviewed: %s (%s)", info.model_name, info.host) _LOGGER.debug("Receiver interviewed: %s (%s)", info.model_name, info.host)
@ -285,7 +285,7 @@ async def async_setup_platform(
_LOGGER.debug("Discovering receivers") _LOGGER.debug("Discovering receivers")
@callback @callback
async def async_onkyo_discovery_callback(conn: pyeiscp.Connection): async def async_onkyo_discovery_callback(conn: pyeiscp.Connection) -> None:
"""Receiver discovered, connection not yet active.""" """Receiver discovered, connection not yet active."""
info = ReceiverInfo(conn.host, conn.port, conn.name, conn.identifier) info = ReceiverInfo(conn.host, conn.port, conn.name, conn.identifier)
_LOGGER.debug("Receiver discovered: %s (%s)", info.model_name, info.host) _LOGGER.debug("Receiver discovered: %s (%s)", info.model_name, info.host)
@ -298,7 +298,7 @@ async def async_setup_platform(
) )
@callback @callback
def close_receiver(_event): def close_receiver(_event: Event) -> None:
for receiver in receivers.values(): for receiver in receivers.values():
receiver.conn.close() receiver.conn.close()
@ -495,19 +495,23 @@ class OnkyoMediaPlayer(MediaPlayerEntity):
self.async_write_ha_state() self.async_write_ha_state()
@callback @callback
def _parse_source(self, source): def _parse_source(self, source_raw: str | int | tuple[str]) -> None:
# source is either a tuple of values or a single value, # source is either a tuple of values or a single value,
# so we convert to a tuple, when it is a single value. # so we convert to a tuple, when it is a single value.
if not isinstance(source, tuple): if isinstance(source_raw, str | int):
source = (source,) source = (str(source_raw),)
else:
source = source_raw
for value in source: for value in source:
if value in self._source_mapping: if value in self._source_mapping:
self._attr_source = self._source_mapping[value] self._attr_source = self._source_mapping[value]
break return
self._attr_source = "_".join(source) self._attr_source = "_".join(source)
@callback @callback
def _parse_audio_information(self, audio_information): def _parse_audio_information(
self, audio_information: tuple[str] | Literal["N/A"]
) -> None:
# If audio information is not available, N/A is returned, # If audio information is not available, N/A is returned,
# so only update the audio information, when it is not N/A. # so only update the audio information, when it is not N/A.
if audio_information == "N/A": if audio_information == "N/A":
@ -523,7 +527,9 @@ class OnkyoMediaPlayer(MediaPlayerEntity):
} }
@callback @callback
def _parse_video_information(self, video_information): def _parse_video_information(
self, video_information: tuple[str] | Literal["N/A"]
) -> None:
# If video information is not available, N/A is returned, # If video information is not available, N/A is returned,
# so only update the video information, when it is not N/A. # so only update the video information, when it is not N/A.
if video_information == "N/A": if video_information == "N/A":
@ -538,11 +544,11 @@ class OnkyoMediaPlayer(MediaPlayerEntity):
if len(value) > 0 if len(value) > 0
} }
def _query_av_info_delayed(self): def _query_av_info_delayed(self) -> None:
if self._zone == "main" and not self._query_timer: if self._zone == "main" and not self._query_timer:
@callback @callback
def _query_av_info(): def _query_av_info() -> None:
if self._supports_audio_info: if self._supports_audio_info:
self._query_receiver("audio-information") self._query_receiver("audio-information")
if self._supports_video_info: if self._supports_video_info:

View File

@ -3166,6 +3166,16 @@ disallow_untyped_defs = true
warn_return_any = true warn_return_any = true
warn_unreachable = true warn_unreachable = true
[mypy-homeassistant.components.onkyo.*]
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.open_meteo.*] [mypy-homeassistant.components.open_meteo.*]
check_untyped_defs = true check_untyped_defs = true
disallow_incomplete_defs = true disallow_incomplete_defs = true