diff --git a/homeassistant/components/cloud/http_api.py b/homeassistant/components/cloud/http_api.py index 6086cef703a..8e5c214b388 100644 --- a/homeassistant/components/cloud/http_api.py +++ b/homeassistant/components/cloud/http_api.py @@ -419,6 +419,7 @@ async def websocket_hook_delete(hass, connection, msg): async def _account_data(hass: HomeAssistant, cloud: Cloud): """Generate the auth data JSON response.""" + assert hass.config.api if not cloud.is_logged_in: return { "logged_in": False, diff --git a/homeassistant/components/webhook/__init__.py b/homeassistant/components/webhook/__init__.py index fb9927f1b37..449de006bf9 100644 --- a/homeassistant/components/webhook/__init__.py +++ b/homeassistant/components/webhook/__init__.py @@ -6,7 +6,9 @@ from http import HTTPStatus from ipaddress import ip_address import logging import secrets +from typing import TYPE_CHECKING, Any +from aiohttp import StreamReader from aiohttp.web import Request, Response import voluptuous as vol @@ -17,7 +19,7 @@ from homeassistant.helpers.network import get_url from homeassistant.helpers.typing import ConfigType from homeassistant.loader import bind_hass from homeassistant.util import network -from homeassistant.util.aiohttp import MockRequest, serialize_response +from homeassistant.util.aiohttp import MockRequest, MockStreamReader, serialize_response _LOGGER = logging.getLogger(__name__) @@ -83,17 +85,20 @@ def async_generate_path(webhook_id: str) -> str: @bind_hass async def async_handle_webhook( - hass: HomeAssistant, webhook_id: str, request: Request + hass: HomeAssistant, webhook_id: str, request: Request | MockRequest ) -> Response: """Handle a webhook.""" - handlers = hass.data.setdefault(DOMAIN, {}) + handlers: dict[str, dict[str, Any]] = hass.data.setdefault(DOMAIN, {}) # Always respond successfully to not give away if a hook exists or not. if (webhook := handlers.get(webhook_id)) is None: + content_stream: StreamReader | MockStreamReader if isinstance(request, MockRequest): received_from = request.mock_source + content_stream = request.content else: received_from = request.remote + content_stream = request.content _LOGGER.info( "Received message for unregistered webhook %s from %s", @@ -102,13 +107,16 @@ async def async_handle_webhook( ) # Look at content to provide some context for received webhook # Limit to 64 chars to avoid flooding the log - content = await request.content.read(64) + content = await content_stream.read(64) _LOGGER.debug("%s", content) return Response(status=HTTPStatus.OK) if webhook["local_only"]: + if TYPE_CHECKING: + assert isinstance(request, Request) + assert request.remote is not None try: - remote = ip_address(request.remote) # type: ignore[arg-type] + remote = ip_address(request.remote) except ValueError: _LOGGER.debug("Unable to parse remote ip %s", request.remote) return Response(status=HTTPStatus.OK) diff --git a/mypy.ini b/mypy.ini index ab83c443d5a..5a3cbd7a05f 100644 --- a/mypy.ini +++ b/mypy.ini @@ -2656,12 +2656,6 @@ no_implicit_optional = false warn_return_any = false warn_unreachable = false -[mypy-homeassistant.components.cloud.client] -ignore_errors = true - -[mypy-homeassistant.components.cloud.http_api] -ignore_errors = true - [mypy-homeassistant.components.sonos] ignore_errors = true diff --git a/script/hassfest/mypy_config.py b/script/hassfest/mypy_config.py index 2e3e80ebc50..4bf8cfd68cf 100644 --- a/script/hassfest/mypy_config.py +++ b/script/hassfest/mypy_config.py @@ -16,8 +16,6 @@ from .model import Config, Integration # remove your component from this list to enable type checks. # Do your best to not add anything new here. IGNORED_MODULES: Final[list[str]] = [ - "homeassistant.components.cloud.client", - "homeassistant.components.cloud.http_api", "homeassistant.components.sonos", "homeassistant.components.sonos.alarms", "homeassistant.components.sonos.binary_sensor",