Remove hassio from mypy ignore list (#74603)

* Remove hassio from mypy ignore list

* Avoid if TYPE_CHECKING
This commit is contained in:
epenet 2022-07-07 15:14:36 +02:00 committed by GitHub
parent 996544da2d
commit 6540ba6239
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 20 additions and 36 deletions

View File

@ -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)

View File

@ -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
):

View File

@ -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():

View File

@ -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()

View File

@ -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:

View File

@ -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:

View File

@ -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
):

View File

@ -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

View File

@ -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",