Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions homeassistant/components/hassio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare Jul 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: Maybe we could make the Store class generic to be able to type the return value of Store.async_load and the input to Store.async_save, similar to how we can type the update coordinator.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a quick look - and that's going to be a big job!
See #74617


refresh_token = None
if "hassio_user" in data:
user = await hass.auth.async_get_user(data["hassio_user"])
Expand Down Expand Up @@ -710,6 +712,7 @@ async def async_handle_core_service(call: ServiceCall) -> None:
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
Expand Down Expand Up @@ -877,7 +880,7 @@ async def _async_update_data(self) -> dict[str, Any]:
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)
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/hassio/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def _check_access(self, request: web.Request):
"""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
):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/hassio/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
3 changes: 3 additions & 0 deletions homeassistant/components/hassio/ingress.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

import asyncio
from collections.abc import Iterable
from ipaddress import ip_address
import logging
import os
Expand Down Expand Up @@ -73,6 +74,7 @@ async def _handle_websocket(
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())
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/hassio/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions homeassistant/components/hassio/system_health.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Provide info to system health."""
from __future__ import annotations

import os

from homeassistant.components import system_health
Expand All @@ -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:
Expand All @@ -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:
Expand Down
9 changes: 5 additions & 4 deletions homeassistant/components/hassio/websocket_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Websocekt API handlers for the hassio integration."""
import logging
from numbers import Number
import re

import voluptuous as vol
Expand Down Expand Up @@ -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
):
Expand All @@ -74,13 +75,13 @@ def forward_messages(data):
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
):
Expand All @@ -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
):
Expand Down
21 changes: 0 additions & 21 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2662,27 +2662,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

Expand Down
7 changes: 0 additions & 7 deletions script/hassfest/mypy_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@
"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",
Expand Down