Remove cloud from mypy ignore list (#74449)
This commit is contained in:
parent
3e98ac180c
commit
911402e747
4 changed files with 14 additions and 13 deletions
|
@ -419,6 +419,7 @@ async def websocket_hook_delete(hass, connection, msg):
|
||||||
async def _account_data(hass: HomeAssistant, cloud: Cloud):
|
async def _account_data(hass: HomeAssistant, cloud: Cloud):
|
||||||
"""Generate the auth data JSON response."""
|
"""Generate the auth data JSON response."""
|
||||||
|
|
||||||
|
assert hass.config.api
|
||||||
if not cloud.is_logged_in:
|
if not cloud.is_logged_in:
|
||||||
return {
|
return {
|
||||||
"logged_in": False,
|
"logged_in": False,
|
||||||
|
|
|
@ -6,7 +6,9 @@ from http import HTTPStatus
|
||||||
from ipaddress import ip_address
|
from ipaddress import ip_address
|
||||||
import logging
|
import logging
|
||||||
import secrets
|
import secrets
|
||||||
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
|
from aiohttp import StreamReader
|
||||||
from aiohttp.web import Request, Response
|
from aiohttp.web import Request, Response
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
@ -17,7 +19,7 @@ from homeassistant.helpers.network import get_url
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.loader import bind_hass
|
from homeassistant.loader import bind_hass
|
||||||
from homeassistant.util import network
|
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__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -83,17 +85,20 @@ def async_generate_path(webhook_id: str) -> str:
|
||||||
|
|
||||||
@bind_hass
|
@bind_hass
|
||||||
async def async_handle_webhook(
|
async def async_handle_webhook(
|
||||||
hass: HomeAssistant, webhook_id: str, request: Request
|
hass: HomeAssistant, webhook_id: str, request: Request | MockRequest
|
||||||
) -> Response:
|
) -> Response:
|
||||||
"""Handle a webhook."""
|
"""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.
|
# Always respond successfully to not give away if a hook exists or not.
|
||||||
if (webhook := handlers.get(webhook_id)) is None:
|
if (webhook := handlers.get(webhook_id)) is None:
|
||||||
|
content_stream: StreamReader | MockStreamReader
|
||||||
if isinstance(request, MockRequest):
|
if isinstance(request, MockRequest):
|
||||||
received_from = request.mock_source
|
received_from = request.mock_source
|
||||||
|
content_stream = request.content
|
||||||
else:
|
else:
|
||||||
received_from = request.remote
|
received_from = request.remote
|
||||||
|
content_stream = request.content
|
||||||
|
|
||||||
_LOGGER.info(
|
_LOGGER.info(
|
||||||
"Received message for unregistered webhook %s from %s",
|
"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
|
# Look at content to provide some context for received webhook
|
||||||
# Limit to 64 chars to avoid flooding the log
|
# 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)
|
_LOGGER.debug("%s", content)
|
||||||
return Response(status=HTTPStatus.OK)
|
return Response(status=HTTPStatus.OK)
|
||||||
|
|
||||||
if webhook["local_only"]:
|
if webhook["local_only"]:
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
assert isinstance(request, Request)
|
||||||
|
assert request.remote is not None
|
||||||
try:
|
try:
|
||||||
remote = ip_address(request.remote) # type: ignore[arg-type]
|
remote = ip_address(request.remote)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
_LOGGER.debug("Unable to parse remote ip %s", request.remote)
|
_LOGGER.debug("Unable to parse remote ip %s", request.remote)
|
||||||
return Response(status=HTTPStatus.OK)
|
return Response(status=HTTPStatus.OK)
|
||||||
|
|
6
mypy.ini
6
mypy.ini
|
@ -2656,12 +2656,6 @@ no_implicit_optional = false
|
||||||
warn_return_any = false
|
warn_return_any = false
|
||||||
warn_unreachable = 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]
|
[mypy-homeassistant.components.sonos]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,6 @@ from .model import Config, Integration
|
||||||
# remove your component from this list to enable type checks.
|
# remove your component from this list to enable type checks.
|
||||||
# Do your best to not add anything new here.
|
# Do your best to not add anything new here.
|
||||||
IGNORED_MODULES: Final[list[str]] = [
|
IGNORED_MODULES: Final[list[str]] = [
|
||||||
"homeassistant.components.cloud.client",
|
|
||||||
"homeassistant.components.cloud.http_api",
|
|
||||||
"homeassistant.components.sonos",
|
"homeassistant.components.sonos",
|
||||||
"homeassistant.components.sonos.alarms",
|
"homeassistant.components.sonos.alarms",
|
||||||
"homeassistant.components.sonos.binary_sensor",
|
"homeassistant.components.sonos.binary_sensor",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue