Skip to content

Commit

Permalink
Add Onkyo to strict typing (home-assistant#124617)
Browse files Browse the repository at this point in the history
  • Loading branch information
arturpragacz authored Sep 4, 2024
1 parent 7266a16 commit bad305d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
1 change: 1 addition & 0 deletions .strict-typing
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ homeassistant.components.nut.*
homeassistant.components.onboarding.*
homeassistant.components.oncue.*
homeassistant.components.onewire.*
homeassistant.components.onkyo.*
homeassistant.components.open_meteo.*
homeassistant.components.openexchangerates.*
homeassistant.components.opensky.*
Expand Down
34 changes: 20 additions & 14 deletions homeassistant/components/onkyo/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import asyncio
import logging
from typing import Any
from typing import Any, Literal

import pyeiscp
import voluptuous as vol
Expand All @@ -23,7 +23,7 @@
CONF_NAME,
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.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
Expand Down Expand Up @@ -269,7 +269,7 @@ def async_onkyo_connect_callback(origin: str) -> None:
_LOGGER.debug("Manually creating receiver: %s (%s)", name, host)

@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."""
info = ReceiverInfo(conn.host, conn.port, conn.name, conn.identifier)
_LOGGER.debug("Receiver interviewed: %s (%s)", info.model_name, info.host)
Expand All @@ -285,7 +285,7 @@ async def async_onkyo_interview_callback(conn: pyeiscp.Connection):
_LOGGER.debug("Discovering receivers")

@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."""
info = ReceiverInfo(conn.host, conn.port, conn.name, conn.identifier)
_LOGGER.debug("Receiver discovered: %s (%s)", info.model_name, info.host)
Expand All @@ -298,7 +298,7 @@ async def async_onkyo_discovery_callback(conn: pyeiscp.Connection):
)

@callback
def close_receiver(_event):
def close_receiver(_event: Event) -> None:
for receiver in receivers.values():
receiver.conn.close()

Expand Down Expand Up @@ -495,19 +495,23 @@ def process_update(self, update: tuple[str, str, Any]) -> None:
self.async_write_ha_state()

@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,
# so we convert to a tuple, when it is a single value.
if not isinstance(source, tuple):
source = (source,)
if isinstance(source_raw, str | int):
source = (str(source_raw),)
else:
source = source_raw
for value in source:
if value in self._source_mapping:
self._attr_source = self._source_mapping[value]
break
self._attr_source = "_".join(source)
return
self._attr_source = "_".join(source)

@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,
# so only update the audio information, when it is not N/A.
if audio_information == "N/A":
Expand All @@ -523,7 +527,9 @@ def _parse_audio_information(self, audio_information):
}

@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,
# so only update the video information, when it is not N/A.
if video_information == "N/A":
Expand All @@ -538,11 +544,11 @@ def _parse_video_information(self, video_information):
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:

@callback
def _query_av_info():
def _query_av_info() -> None:
if self._supports_audio_info:
self._query_receiver("audio-information")
if self._supports_video_info:
Expand Down
10 changes: 10 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3166,6 +3166,16 @@ disallow_untyped_defs = true
warn_return_any = 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.*]
check_untyped_defs = true
disallow_incomplete_defs = true
Expand Down

0 comments on commit bad305d

Please sign in to comment.