Enable strict typing for webhook (#107946)

This commit is contained in:
Marc Mueller 2024-01-13 20:08:26 +01:00 committed by GitHub
parent ca421d4f86
commit 9221f5da10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 5 deletions

View file

@ -439,6 +439,7 @@ homeassistant.components.waqi.*
homeassistant.components.water_heater.*
homeassistant.components.watttime.*
homeassistant.components.weather.*
homeassistant.components.webhook.*
homeassistant.components.webostv.*
homeassistant.components.websocket_api.*
homeassistant.components.wemo.*

View file

@ -174,7 +174,7 @@ async def async_handle_webhook(
)
try:
response = await webhook["handler"](hass, webhook_id, request)
response: Response | None = await webhook["handler"](hass, webhook_id, request)
if response is None:
response = Response(status=HTTPStatus.OK)
return response

View file

@ -3,8 +3,9 @@ from __future__ import annotations
from dataclasses import dataclass
import logging
from typing import Any
from aiohttp import hdrs
from aiohttp import hdrs, web
import voluptuous as vol
from homeassistant.const import CONF_PLATFORM, CONF_WEBHOOK_ID
@ -57,9 +58,11 @@ class TriggerInstance:
job: HassJob
async def _handle_webhook(hass, webhook_id, request):
async def _handle_webhook(
hass: HomeAssistant, webhook_id: str, request: web.Request
) -> None:
"""Handle incoming webhook."""
base_result = {"platform": "webhook", "webhook_id": webhook_id}
base_result: dict[str, Any] = {"platform": "webhook", "webhook_id": webhook_id}
if "json" in request.headers.get(hdrs.CONTENT_TYPE, ""):
base_result["json"] = await request.json()
@ -133,7 +136,7 @@ async def async_attach_trigger(
triggers[webhook_id].append(trigger_instance)
@callback
def unregister():
def unregister() -> None:
"""Unregister webhook."""
if issue_id:
async_delete_issue(hass, DOMAIN, issue_id)

View file

@ -4153,6 +4153,16 @@ disallow_untyped_defs = true
warn_return_any = true
warn_unreachable = true
[mypy-homeassistant.components.webhook.*]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
warn_return_any = true
warn_unreachable = true
[mypy-homeassistant.components.webostv.*]
check_untyped_defs = true
disallow_incomplete_defs = true