Remove system_health from mypy ignore list (#74415)
This commit is contained in:
parent
18840c8af5
commit
035e96a79b
3 changed files with 15 additions and 15 deletions
|
@ -6,6 +6,7 @@ from collections.abc import Awaitable, Callable
|
||||||
import dataclasses
|
import dataclasses
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import async_timeout
|
import async_timeout
|
||||||
|
@ -29,7 +30,7 @@ INFO_CALLBACK_TIMEOUT = 5
|
||||||
def async_register_info(
|
def async_register_info(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
domain: str,
|
domain: str,
|
||||||
info_callback: Callable[[HomeAssistant], dict],
|
info_callback: Callable[[HomeAssistant], Awaitable[dict]],
|
||||||
):
|
):
|
||||||
"""Register an info callback.
|
"""Register an info callback.
|
||||||
|
|
||||||
|
@ -61,9 +62,10 @@ async def _register_system_health_platform(hass, integration_domain, platform):
|
||||||
|
|
||||||
async def get_integration_info(
|
async def get_integration_info(
|
||||||
hass: HomeAssistant, registration: SystemHealthRegistration
|
hass: HomeAssistant, registration: SystemHealthRegistration
|
||||||
):
|
) -> dict[str, Any]:
|
||||||
"""Get integration system health."""
|
"""Get integration system health."""
|
||||||
try:
|
try:
|
||||||
|
assert registration.info_callback
|
||||||
async with async_timeout.timeout(INFO_CALLBACK_TIMEOUT):
|
async with async_timeout.timeout(INFO_CALLBACK_TIMEOUT):
|
||||||
data = await registration.info_callback(hass)
|
data = await registration.info_callback(hass)
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
|
@ -72,7 +74,7 @@ async def get_integration_info(
|
||||||
_LOGGER.exception("Error fetching info")
|
_LOGGER.exception("Error fetching info")
|
||||||
data = {"error": {"type": "failed", "error": "unknown"}}
|
data = {"error": {"type": "failed", "error": "unknown"}}
|
||||||
|
|
||||||
result = {"info": data}
|
result: dict[str, Any] = {"info": data}
|
||||||
|
|
||||||
if registration.manage_url:
|
if registration.manage_url:
|
||||||
result["manage_url"] = registration.manage_url
|
result["manage_url"] = registration.manage_url
|
||||||
|
@ -88,15 +90,15 @@ def _format_value(val):
|
||||||
return val
|
return val
|
||||||
|
|
||||||
|
|
||||||
@websocket_api.async_response
|
|
||||||
@websocket_api.websocket_command({vol.Required("type"): "system_health/info"})
|
@websocket_api.websocket_command({vol.Required("type"): "system_health/info"})
|
||||||
|
@websocket_api.async_response
|
||||||
async def handle_info(
|
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."""
|
"""Handle an info request via a subscription."""
|
||||||
registrations: dict[str, SystemHealthRegistration] = hass.data[DOMAIN]
|
registrations: dict[str, SystemHealthRegistration] = hass.data[DOMAIN]
|
||||||
data = {}
|
data = {}
|
||||||
pending_info = {}
|
pending_info: dict[tuple[str, str], asyncio.Task] = {}
|
||||||
|
|
||||||
for domain, domain_data in zip(
|
for domain, domain_data in zip(
|
||||||
registrations,
|
registrations,
|
||||||
|
@ -138,7 +140,10 @@ async def handle_info(
|
||||||
)
|
)
|
||||||
return
|
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()}
|
pending_lookup = {val: key for key, val in pending_info.items()}
|
||||||
|
|
||||||
# One task is the stop_event.wait() and is always there
|
# One task is the stop_event.wait() and is always there
|
||||||
|
@ -160,8 +165,7 @@ async def handle_info(
|
||||||
"key": key,
|
"key": key,
|
||||||
}
|
}
|
||||||
|
|
||||||
if result.exception():
|
if exception := result.exception():
|
||||||
exception = result.exception()
|
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"Error fetching system info for %s - %s",
|
"Error fetching system info for %s - %s",
|
||||||
domain,
|
domain,
|
||||||
|
@ -206,7 +210,7 @@ class SystemHealthRegistration:
|
||||||
|
|
||||||
async def async_check_can_reach_url(
|
async def async_check_can_reach_url(
|
||||||
hass: HomeAssistant, url: str, more_info: str | None = None
|
hass: HomeAssistant, url: str, more_info: str | None = None
|
||||||
) -> str:
|
) -> str | dict[str, str]:
|
||||||
"""Test if the url can be reached."""
|
"""Test if the url can be reached."""
|
||||||
session = aiohttp_client.async_get_clientsession(hass)
|
session = aiohttp_client.async_get_clientsession(hass)
|
||||||
|
|
||||||
|
|
3
mypy.ini
3
mypy.ini
|
@ -2900,9 +2900,6 @@ ignore_errors = true
|
||||||
[mypy-homeassistant.components.sonos.statistics]
|
[mypy-homeassistant.components.sonos.statistics]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
[mypy-homeassistant.components.system_health]
|
|
||||||
ignore_errors = true
|
|
||||||
|
|
||||||
[mypy-homeassistant.components.telegram_bot.polling]
|
[mypy-homeassistant.components.telegram_bot.polling]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,6 @@ IGNORED_MODULES: Final[list[str]] = [
|
||||||
"homeassistant.components.sonos.sensor",
|
"homeassistant.components.sonos.sensor",
|
||||||
"homeassistant.components.sonos.speaker",
|
"homeassistant.components.sonos.speaker",
|
||||||
"homeassistant.components.sonos.statistics",
|
"homeassistant.components.sonos.statistics",
|
||||||
"homeassistant.components.system_health",
|
|
||||||
"homeassistant.components.telegram_bot.polling",
|
"homeassistant.components.telegram_bot.polling",
|
||||||
"homeassistant.components.template.number",
|
"homeassistant.components.template.number",
|
||||||
"homeassistant.components.template.sensor",
|
"homeassistant.components.template.sensor",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue