Enable strict typing for system_health (#107283)

This commit is contained in:
Marc Mueller 2024-01-08 10:40:49 +01:00 committed by GitHub
parent 82e0fc5f4e
commit b22cd2deaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 5 deletions

View File

@ -380,6 +380,7 @@ homeassistant.components.switchbee.*
homeassistant.components.switchbot_cloud.* homeassistant.components.switchbot_cloud.*
homeassistant.components.switcher_kis.* homeassistant.components.switcher_kis.*
homeassistant.components.synology_dsm.* homeassistant.components.synology_dsm.*
homeassistant.components.system_health.*
homeassistant.components.systemmonitor.* homeassistant.components.systemmonitor.*
homeassistant.components.tag.* homeassistant.components.tag.*
homeassistant.components.tailscale.* homeassistant.components.tailscale.*

View File

@ -6,7 +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 from typing import Any, Protocol
import aiohttp import aiohttp
import voluptuous as vol import voluptuous as vol
@ -30,13 +30,22 @@ INFO_CALLBACK_TIMEOUT = 5
CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN) CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN)
class SystemHealthProtocol(Protocol):
"""Define the format of system_health platforms."""
def async_register(
self, hass: HomeAssistant, register: SystemHealthRegistration
) -> None:
"""Register system health callbacks."""
@bind_hass @bind_hass
@callback @callback
def async_register_info( def async_register_info(
hass: HomeAssistant, hass: HomeAssistant,
domain: str, domain: str,
info_callback: Callable[[HomeAssistant], Awaitable[dict]], info_callback: Callable[[HomeAssistant], Awaitable[dict]],
): ) -> None:
"""Register an info callback. """Register an info callback.
Deprecated. Deprecated.
@ -61,7 +70,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
return True return True
async def _register_system_health_platform(hass, integration_domain, platform): async def _register_system_health_platform(
hass: HomeAssistant, integration_domain: str, platform: SystemHealthProtocol
) -> None:
"""Register a system health platform.""" """Register a system health platform."""
platform.async_register(hass, SystemHealthRegistration(hass, integration_domain)) platform.async_register(hass, SystemHealthRegistration(hass, integration_domain))
@ -89,7 +100,7 @@ async def get_integration_info(
@callback @callback
def _format_value(val): def _format_value(val: Any) -> Any:
"""Format a system health value.""" """Format a system health value."""
if isinstance(val, datetime): if isinstance(val, datetime):
return {"value": val.isoformat(), "type": "date"} return {"value": val.isoformat(), "type": "date"}
@ -207,7 +218,7 @@ class SystemHealthRegistration:
self, self,
info_callback: Callable[[HomeAssistant], Awaitable[dict]], info_callback: Callable[[HomeAssistant], Awaitable[dict]],
manage_url: str | None = None, manage_url: str | None = None,
): ) -> None:
"""Register an info callback.""" """Register an info callback."""
self.info_callback = info_callback self.info_callback = info_callback
self.manage_url = manage_url self.manage_url = manage_url

View File

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