diff --git a/homeassistant/components/hassio/__init__.py b/homeassistant/components/hassio/__init__.py index cd3c704d4c9..5b5cc48eed8 100644 --- a/homeassistant/components/hassio/__init__.py +++ b/homeassistant/components/hassio/__init__.py @@ -504,7 +504,7 @@ def is_hassio(hass: HomeAssistant) -> bool: @callback -def get_supervisor_ip() -> str: +def get_supervisor_ip() -> str | None: """Return the supervisor ip address.""" if "SUPERVISOR" not in os.environ: return None @@ -537,6 +537,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa: if (data := await store.async_load()) is None: data = {} + assert isinstance(data, dict) + refresh_token = None if "hassio_user" in data: user = await hass.auth.async_get_user(data["hassio_user"]) @@ -710,6 +712,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa: async_setup_discovery_view(hass, hassio) # Init auth Hass.io feature + assert user is not None async_setup_auth_view(hass, user) # Init ingress Hass.io feature @@ -877,7 +880,7 @@ class HassioDataUpdateCoordinator(DataUpdateCoordinator): except HassioAPIError as err: raise UpdateFailed(f"Error on Supervisor API: {err}") from err - new_data = {} + new_data: dict[str, Any] = {} supervisor_info = get_supervisor_info(self.hass) addons_info = get_addons_info(self.hass) addons_stats = get_addons_stats(self.hass) diff --git a/homeassistant/components/hassio/auth.py b/homeassistant/components/hassio/auth.py index f52a8ef0617..37687ee70df 100644 --- a/homeassistant/components/hassio/auth.py +++ b/homeassistant/components/hassio/auth.py @@ -43,6 +43,7 @@ class HassIOBaseAuth(HomeAssistantView): """Check if this call is from Supervisor.""" # Check caller IP hassio_ip = os.environ["SUPERVISOR"].split(":")[0] + assert request.transport if ip_address(request.transport.get_extra_info("peername")[0]) != ip_address( hassio_ip ): diff --git a/homeassistant/components/hassio/binary_sensor.py b/homeassistant/components/hassio/binary_sensor.py index c2bcd5eaf68..85cb402b0ca 100644 --- a/homeassistant/components/hassio/binary_sensor.py +++ b/homeassistant/components/hassio/binary_sensor.py @@ -59,7 +59,7 @@ async def async_setup_entry( """Binary sensor set up for Hass.io config entry.""" coordinator = hass.data[ADDONS_COORDINATOR] - entities = [] + entities: list[HassioAddonBinarySensor | HassioOSBinarySensor] = [] for entity_description in ADDON_ENTITY_DESCRIPTIONS: for addon in coordinator.data[DATA_KEY_ADDONS].values(): diff --git a/homeassistant/components/hassio/ingress.py b/homeassistant/components/hassio/ingress.py index 6caa97b788f..8aacbac99f6 100644 --- a/homeassistant/components/hassio/ingress.py +++ b/homeassistant/components/hassio/ingress.py @@ -2,6 +2,7 @@ from __future__ import annotations import asyncio +from collections.abc import Iterable from ipaddress import ip_address import logging import os @@ -73,6 +74,7 @@ class HassIOIngress(HomeAssistantView): self, request: web.Request, token: str, path: str ) -> web.WebSocketResponse: """Ingress route for websocket.""" + req_protocols: Iterable[str] if hdrs.SEC_WEBSOCKET_PROTOCOL in request.headers: req_protocols = [ str(proto.strip()) @@ -190,6 +192,7 @@ def _init_header(request: web.Request, token: str) -> CIMultiDict | dict[str, st # Set X-Forwarded-For forward_for = request.headers.get(hdrs.X_FORWARDED_FOR) + assert request.transport if (peername := request.transport.get_extra_info("peername")) is None: _LOGGER.error("Can't set forward_for header, missing peername") raise HTTPBadRequest() diff --git a/homeassistant/components/hassio/sensor.py b/homeassistant/components/hassio/sensor.py index 42be1ff4b0a..55fcb0bcd28 100644 --- a/homeassistant/components/hassio/sensor.py +++ b/homeassistant/components/hassio/sensor.py @@ -65,7 +65,7 @@ async def async_setup_entry( """Sensor set up for Hass.io config entry.""" coordinator = hass.data[ADDONS_COORDINATOR] - entities = [] + entities: list[HassioOSSensor | HassioAddonSensor] = [] for addon in coordinator.data[DATA_KEY_ADDONS].values(): for entity_description in ADDON_ENTITY_DESCRIPTIONS: diff --git a/homeassistant/components/hassio/system_health.py b/homeassistant/components/hassio/system_health.py index b1fc208de80..d8d29f44d68 100644 --- a/homeassistant/components/hassio/system_health.py +++ b/homeassistant/components/hassio/system_health.py @@ -1,4 +1,6 @@ """Provide info to system health.""" +from __future__ import annotations + import os from homeassistant.components import system_health @@ -24,6 +26,7 @@ async def system_health_info(hass: HomeAssistant): host_info = get_host_info(hass) supervisor_info = get_supervisor_info(hass) + healthy: bool | dict[str, str] if supervisor_info.get("healthy"): healthy = True else: @@ -32,6 +35,7 @@ async def system_health_info(hass: HomeAssistant): "error": "Unhealthy", } + supported: bool | dict[str, str] if supervisor_info.get("supported"): supported = True else: diff --git a/homeassistant/components/hassio/websocket_api.py b/homeassistant/components/hassio/websocket_api.py index 7eb037d8432..b25d9fda7a0 100644 --- a/homeassistant/components/hassio/websocket_api.py +++ b/homeassistant/components/hassio/websocket_api.py @@ -1,5 +1,6 @@ """Websocekt API handlers for the hassio integration.""" import logging +from numbers import Number import re import voluptuous as vol @@ -56,8 +57,8 @@ def async_load_websocket_api(hass: HomeAssistant): @websocket_api.require_admin -@websocket_api.async_response @websocket_api.websocket_command({vol.Required(WS_TYPE): WS_TYPE_SUBSCRIBE}) +@websocket_api.async_response async def websocket_subscribe( hass: HomeAssistant, connection: ActiveConnection, msg: dict ): @@ -74,13 +75,13 @@ async def websocket_subscribe( connection.send_message(websocket_api.result_message(msg[WS_ID])) -@websocket_api.async_response @websocket_api.websocket_command( { vol.Required(WS_TYPE): WS_TYPE_EVENT, vol.Required(ATTR_DATA): SCHEMA_WEBSOCKET_EVENT, } ) +@websocket_api.async_response async def websocket_supervisor_event( hass: HomeAssistant, connection: ActiveConnection, msg: dict ): @@ -89,16 +90,16 @@ async def websocket_supervisor_event( connection.send_result(msg[WS_ID]) -@websocket_api.async_response @websocket_api.websocket_command( { vol.Required(WS_TYPE): WS_TYPE_API, vol.Required(ATTR_ENDPOINT): cv.string, vol.Required(ATTR_METHOD): cv.string, vol.Optional(ATTR_DATA): dict, - vol.Optional(ATTR_TIMEOUT): vol.Any(cv.Number, None), + vol.Optional(ATTR_TIMEOUT): vol.Any(Number, None), } ) +@websocket_api.async_response async def websocket_supervisor_api( hass: HomeAssistant, connection: ActiveConnection, msg: dict ): diff --git a/mypy.ini b/mypy.ini index c4a135322fe..fc99119cda3 100644 --- a/mypy.ini +++ b/mypy.ini @@ -2653,27 +2653,6 @@ ignore_errors = true [mypy-homeassistant.components.evohome.water_heater] ignore_errors = true -[mypy-homeassistant.components.hassio] -ignore_errors = true - -[mypy-homeassistant.components.hassio.auth] -ignore_errors = true - -[mypy-homeassistant.components.hassio.binary_sensor] -ignore_errors = true - -[mypy-homeassistant.components.hassio.ingress] -ignore_errors = true - -[mypy-homeassistant.components.hassio.sensor] -ignore_errors = true - -[mypy-homeassistant.components.hassio.system_health] -ignore_errors = true - -[mypy-homeassistant.components.hassio.websocket_api] -ignore_errors = true - [mypy-homeassistant.components.icloud] ignore_errors = true diff --git a/script/hassfest/mypy_config.py b/script/hassfest/mypy_config.py index e7c5e0ed129..7f1faf00bb6 100644 --- a/script/hassfest/mypy_config.py +++ b/script/hassfest/mypy_config.py @@ -26,13 +26,6 @@ IGNORED_MODULES: Final[list[str]] = [ "homeassistant.components.evohome", "homeassistant.components.evohome.climate", "homeassistant.components.evohome.water_heater", - "homeassistant.components.hassio", - "homeassistant.components.hassio.auth", - "homeassistant.components.hassio.binary_sensor", - "homeassistant.components.hassio.ingress", - "homeassistant.components.hassio.sensor", - "homeassistant.components.hassio.system_health", - "homeassistant.components.hassio.websocket_api", "homeassistant.components.icloud", "homeassistant.components.icloud.account", "homeassistant.components.icloud.device_tracker",