From 035e96a79b29e49537a685eaa811eb49de8da513 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 4 Jul 2022 16:46:59 +0200 Subject: [PATCH] Remove system_health from mypy ignore list (#74415) --- .../components/system_health/__init__.py | 26 +++++++++++-------- mypy.ini | 3 --- script/hassfest/mypy_config.py | 1 - 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/homeassistant/components/system_health/__init__.py b/homeassistant/components/system_health/__init__.py index be7232245e1..4821537fc8b 100644 --- a/homeassistant/components/system_health/__init__.py +++ b/homeassistant/components/system_health/__init__.py @@ -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) diff --git a/mypy.ini b/mypy.ini index fb67983a31c..cab794e7bfe 100644 --- a/mypy.ini +++ b/mypy.ini @@ -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 diff --git a/script/hassfest/mypy_config.py b/script/hassfest/mypy_config.py index bbb628a76bb..94bb2682f3e 100644 --- a/script/hassfest/mypy_config.py +++ b/script/hassfest/mypy_config.py @@ -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",