Remove system_health from mypy ignore list (#74415)

This commit is contained in:
epenet 2022-07-04 16:46:59 +02:00 committed by GitHub
parent 18840c8af5
commit 035e96a79b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 15 deletions

View file

@ -6,6 +6,7 @@ from collections.abc import Awaitable, Callable
import dataclasses
from datetime import datetime
import logging
from typing import Any
import aiohttp
import async_timeout
@ -29,7 +30,7 @@ INFO_CALLBACK_TIMEOUT = 5
def async_register_info(
hass: HomeAssistant,
domain: str,
info_callback: Callable[[HomeAssistant], dict],
info_callback: Callable[[HomeAssistant], Awaitable[dict]],
):
"""Register an info callback.
@ -61,9 +62,10 @@ async def _register_system_health_platform(hass, integration_domain, platform):
async def get_integration_info(
hass: HomeAssistant, registration: SystemHealthRegistration
):
) -> dict[str, Any]:
"""Get integration system health."""
try:
assert registration.info_callback
async with async_timeout.timeout(INFO_CALLBACK_TIMEOUT):
data = await registration.info_callback(hass)
except asyncio.TimeoutError:
@ -72,7 +74,7 @@ async def get_integration_info(
_LOGGER.exception("Error fetching info")
data = {"error": {"type": "failed", "error": "unknown"}}
result = {"info": data}
result: dict[str, Any] = {"info": data}
if registration.manage_url:
result["manage_url"] = registration.manage_url
@ -88,15 +90,15 @@ def _format_value(val):
return val
@websocket_api.async_response
@websocket_api.websocket_command({vol.Required("type"): "system_health/info"})
@websocket_api.async_response
async def handle_info(
hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg: dict
):
hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg: dict[str, Any]
) -> None:
"""Handle an info request via a subscription."""
registrations: dict[str, SystemHealthRegistration] = hass.data[DOMAIN]
data = {}
pending_info = {}
pending_info: dict[tuple[str, str], asyncio.Task] = {}
for domain, domain_data in zip(
registrations,
@ -138,7 +140,10 @@ async def handle_info(
)
return
tasks = [asyncio.create_task(stop_event.wait()), *pending_info.values()]
tasks: set[asyncio.Task] = {
asyncio.create_task(stop_event.wait()),
*pending_info.values(),
}
pending_lookup = {val: key for key, val in pending_info.items()}
# One task is the stop_event.wait() and is always there
@ -160,8 +165,7 @@ async def handle_info(
"key": key,
}
if result.exception():
exception = result.exception()
if exception := result.exception():
_LOGGER.error(
"Error fetching system info for %s - %s",
domain,
@ -206,7 +210,7 @@ class SystemHealthRegistration:
async def async_check_can_reach_url(
hass: HomeAssistant, url: str, more_info: str | None = None
) -> str:
) -> str | dict[str, str]:
"""Test if the url can be reached."""
session = aiohttp_client.async_get_clientsession(hass)

View file

@ -2900,9 +2900,6 @@ ignore_errors = true
[mypy-homeassistant.components.sonos.statistics]
ignore_errors = true
[mypy-homeassistant.components.system_health]
ignore_errors = true
[mypy-homeassistant.components.telegram_bot.polling]
ignore_errors = true

View file

@ -112,7 +112,6 @@ IGNORED_MODULES: Final[list[str]] = [
"homeassistant.components.sonos.sensor",
"homeassistant.components.sonos.speaker",
"homeassistant.components.sonos.statistics",
"homeassistant.components.system_health",
"homeassistant.components.telegram_bot.polling",
"homeassistant.components.template.number",
"homeassistant.components.template.sensor",